AutomationFlowsData & Sheets › Monitor Customer Risk and AI Feedback Using Postgresql, Gmail and Discord

Monitor Customer Risk and AI Feedback Using Postgresql, Gmail and Discord

ByAvkash Kakdiya @itechnotion on n8n.io

This workflow monitors customer health by combining payment behavior, complaint signals, and AI-driven feedback analysis. It runs on daily and weekly schedules to evaluate risk levels, escalate high-risk customers, and generate structured product insights. High-risk cases are…

Cron / scheduled trigger★★★★☆ complexity27 nodesGoogle SheetsHTTP RequestGmailPostgresDiscord
Data & Sheets Trigger: Cron / scheduled Nodes: 27 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #12254 — we link there as the canonical source.

This workflow follows the Discord → HTTP Request recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "jQW3R92K7qUOAajM",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Customer Health Monitoring & Product Feedback Intelligence",
  "tags": [],
  "nodes": [
    {
      "id": "49c8bb24-a4ee-45bb-be6a-066f45335fb9",
      "name": "Get row(s) in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        0,
        1536
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "your-google-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your-document-id-here",
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "Customer Risk & Escalation Logs"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "20a4d950-d390-4b42-8263-234d2b7d96a7",
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        656,
        1680
      ],
      "parameters": {
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ $json.requestBody }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "c399da16-08d8-4a4d-bff4-3ec025ddc857",
      "name": "Prompt For Model1",
      "type": "n8n-nodes-base.code",
      "position": [
        448,
        1680
      ],
      "parameters": {
        "jsCode": "const body = {\n  model: \"llama-3.3-70b-versatile\",\n  messages: [\n    {\n      role: \"system\",\n      content: \"You are a senior product analyst assisting product and leadership teams. You convert raw customer complaints into clear, actionable product feedback. Be professional, concise, and insight-focused. Do not sound like an AI.\"\n    },\n    {\n      role: \"user\",\n      content: `\nPRODUCT NAME: ${$input.item.json.product_name}\nCUSTOMER NAME: ${$input.item.json.customer_name}\nCOMPLAINT COUNT: ${$input.item.json.complaint_count}\nSOURCE: ${$input.item.json.source || \"support\"}\nRAW CUSTOMER COMPLAINTS:\n${$input.item.json.reason}\n\nTASK:\nAnalyze the above customer complaints and generate structured product feedback.\n\nOUTPUT REQUIREMENTS:\n- Identify overall sentiment (Positive / Neutral / Negative)\n- Identify main problem themes (Billing, Product Quality, Support, UX, Performance, Feature Request, Other)\n- Explain the root cause in simple business language\n- Provide 2\u20133 clear, actionable product improvement suggestions\n- Write in an executive-ready tone\n- Do NOT mention AI or the word \"complaint\"\n- Keep it concise and clear\n- Return only the final feedback text (no headings, no markdown)\n`\n    }\n  ],\n  temperature: 0.5,\n  max_tokens: 220\n};\n\n// IMPORTANT: Store original data in a separate field so HTTP Request doesn't overwrite it\nreturn {\n  json: {\n    requestBody: body,\n    // Preserve ALL original customer data here\n    originalCustomerData: {\n      row_number: $input.item.json.row_number,\n      customer_id: $input.item.json.customer_id,\n      customer_name: $input.item.json.customer_name,\n      email: $input.item.json.email,\n      product_name: $input.item.json.product_name,\n      payment_status: $input.item.json.payment_status,\n      complaint_count: $input.item.json.complaint_count,\n      risk_level: $input.item.json.risk_level,\n      reason: $input.item.json.reason,\n      action_required: $input.item.json.action_required,\n      notification_status: $input.item.json.notification_status,\n      logged_at: $input.item.json.logged_at\n    }\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "0e383847-6910-45d2-b423-c47ac2b99208",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        624,
        1376
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=<h2>\ud83d\udcca Weekly Customer Risk Summary</h2>\n\n<p>\nThis automated report summarizes customer risk levels based on\n<strong>payment status</strong> and <strong>support complaints</strong>.\nPlease review <strong>High-Risk customers immediately</strong>.\n</p>\n\n<hr/>\n\n<!-- HIGH / VERY HIGH RISK CUSTOMERS -->\n<h3 style=\"color:#d93025;\">\ud83d\udea8 High / Very High Risk Customers (Immediate Action Required)</h3>\n\n<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">\n  <tr style=\"background-color:#fce8e6;\">\n    <th>Customer</th>\n    <th>Email</th>\n    <th>Product</th>\n    <th>Payment</th>\n    <th>Complaints</th>\n    <th>Complaint Details</th>\n    <th>Risk Level</th>\n    <th>Action</th>\n    <th>Feedback</th>\n    <th>Created_at</th>\n  </tr>\n\n  {{ $items().filter(i => i.json.risk_level !== 'Low').map(i => `\n  <tr>\n    <td>${i.json.customer_name}</td>\n    <td>${i.json.email}</td>\n    <td>${i.json.product_name}</td>\n    <td><strong>${i.json.payment_status}</strong></td>\n    <td>${i.json.complaint_count}</td>\n    <td>${i.json.reason}</td>\n    <td><strong style=\"color:red;\">${i.json.risk_level}</strong></td>\n    <td>${i.json.action_required}</td>\n    <td>${i.json.ai_feedback}</td>\n    <td>${i.json.feedback_generated_at}</td>\n  </tr>\n  `).join('') }}\n</table>\n\n<br/>\n\n<!-- LOW RISK CUSTOMERS -->\n<h3 style=\"color:#188038;\">\u2705 Low Risk Customers (No Immediate Action Required)</h3>\n\n<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">\n  <tr style=\"background-color:#e6f4ea;\">\n    <th>Customer</th>\n    <th>Email</th>\n    <th>Product</th>\n    <th>Payment</th>\n    <th>Complaints</th>\n    <th>Complaint Details</th>\n    <th>Risk Level</th>\n    <th>Action</th>\n    <th>Feedback</th>\n    <th>Created_at</th>\n  </tr>\n\n  {{ $items().filter(i => i.json.risk_level === 'Low').map(i => `\n  <tr>\n    <td>${i.json.customer_name}</td>\n    <td>${i.json.email}</td>\n    <td>${i.json.product_name}</td>\n    <td>${i.json.payment_status}</td>\n    <td>${i.json.complaint_count}</td>\n    <td>${i.json.reason}</td>\n    <td>${i.json.risk_level}</td>\n    <td>${i.json.action_required}</td>\n    <td>${i.json.ai_feedback}</td>\n    <td>${i.json.feedback_generated_at}</td>\n  </tr>\n  `).join('') }}\n</table>\n\n<hr/>\n\n<p>\n<strong>Recommended Next Steps:</strong><br/>\n\u2022 Assign an owner to each high-risk customer<br/>\n\u2022 Follow up on failed payments immediately<br/>\n\u2022 Resolve complaints to prevent churn\n</p>\n\n<p style=\"font-size:12px;color:gray;\">\nThis email was generated automatically by the Customer Risk Monitoring Workflow.\n</p>\n",
        "options": {},
        "subject": "=\ud83e\udd16 AI Product Feedback Analysis \u2013 {{ new Date().toLocaleDateString() }}"
      },
      "typeVersion": 2.2
    },
    {
      "id": "65c11aa1-c95b-4633-be18-65e1cde88d5f",
      "name": "Loop Over Items1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        208,
        1536
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "28a05055-10a4-4731-93c3-0ab6c49b4319",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        432,
        1376
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "c11b9708-dca8-40bb-9191-51faaf5e2037",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "position": [
        1328,
        1680
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "937882db-fded-4585-8990-ee2a550de148",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        864,
        1680
      ],
      "parameters": {
        "jsCode": "// Get the AI response\nconst aiResponse = $input.item.json.choices[0].message.content;\n\n// Get the preserved original customer data\nconst originalData = $('Prompt For Model1').first().json.originalCustomerData\n\n// Merge everything together\nreturn {\n  json: {\n    // Spread all original customer data\n    ...originalData,\n    \n    // Add the AI-generated feedback\n    ai_feedback: aiResponse,\n    feedback_generated_at: new Date().toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "e25491e2-b55b-4944-824e-e6b533c837a2",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1120,
        1680
      ],
      "parameters": {
        "columns": {
          "value": {
            "email": "={{ $json.email }}",
            "reason": "={{ $json.reason }}",
            "risk_level": "={{ $json.risk_level }}",
            "ai_feedback": "={{ $json.ai_feedback }}",
            "customer_id": "={{ $json.customer_id }}",
            "product_name": "={{ $json.product_name }}",
            "customer_name": "={{ $json.customer_name }}",
            "payment_status": "={{ $json.payment_status }}",
            "action_required": "={{ $json.action_required }}",
            "complaint_count": "={{ $json.complaint_count }}",
            "feedback_generated_at": "={{ $json.feedback_generated_at }}"
          },
          "schema": [
            {
              "id": "customer_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "customer_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "customer_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "product_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "product_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "payment_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "payment_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "complaint_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "complaint_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "risk_level",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "risk_level",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action_required",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action_required",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ai_feedback",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ai_feedback",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "feedback_generated_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "feedback_generated_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "customer_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2092498842,
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "your-google-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your-document-id-here",
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "Customer Risk & Escalation Logs"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "8052fb12-4a9b-4c55-83eb-85ef176ed0d2",
      "name": "Weekly schedule1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -736,
        1360
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "67f0f63a-6fd0-4d73-ab64-7ed6e2969810",
      "name": "Edit Fields2",
      "type": "n8n-nodes-base.set",
      "position": [
        -544,
        1360
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ed58a143-9739-4318-9054-7d01660d1d9a",
              "name": "isWeekly",
              "type": "string",
              "value": "true"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d1216d5e-7211-4918-9d8d-3392ac9a22cd",
      "name": "Switch1",
      "type": "n8n-nodes-base.switch",
      "position": [
        -320,
        1216
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "efd47450-32ac-4b6e-aec6-a1e6792fe9dc",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.isDaily }}",
                    "rightValue": "true"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b7084bf7-3de2-497d-89de-3324529a5564",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.isWeekly }}",
                    "rightValue": "true"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "c8eb6f4d-18ba-4f03-b293-8fb3db8ed238",
      "name": "Edit Fields3",
      "type": "n8n-nodes-base.set",
      "position": [
        -560,
        1024
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0339f986-3f8f-4f3a-b828-6acd47499d35",
              "name": "isDaily",
              "type": "string",
              "value": "true"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ab395ee2-12ef-453d-b8f6-451716f2460e",
      "name": "Fetch Customer Risk Data",
      "type": "n8n-nodes-base.postgres",
      "position": [
        0,
        944
      ],
      "parameters": {
        "query": "SELECT\n  c.customer_id,\n  c.customer_name,\n  c.email,\n  p.product_name,\n  ph.status AS payment_status,\n\n  COUNT(cc.complaint_id) AS complaint_count,\n\n  STRING_AGG(cc.complaint, ' | ') AS complaints\nFROM customer c\nJOIN payment_history ph \n  ON c.customer_id = ph.customer_id\nJOIN products p \n  ON ph.product_id = p.product_id\nLEFT JOIN customer_complaint cc \n  ON c.customer_id = cc.customer_id\nGROUP BY\n  c.customer_id,\n  c.customer_name,\n  c.email,\n  p.product_name,\n  ph.status;\n",
        "options": {},
        "operation": "executeQuery"
      },
      "typeVersion": 2.6
    },
    {
      "id": "7f150f40-00fb-4fa6-a39d-ace9e1ffe2a6",
      "name": "Is High Risk Customer?",
      "type": "n8n-nodes-base.if",
      "position": [
        208,
        944
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "315c59b0-6a1a-45e9-be08-3ab88ea5a426",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.payment_status }}",
              "rightValue": "success"
            },
            {
              "id": "c9fe3a53-a259-4512-9f22-47e252538de1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.complaint_count }}",
              "rightValue": "1"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "cc8bcac8-ac7b-498e-af68-c8583fabdd88",
      "name": "Send a message4",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1024,
        848
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=<h2>\ud83d\udcca Daily Customer Risk Summary</h2>\n\n<p>\nThis automated report summarizes customer risk levels based on\n<strong>payment status</strong> and <strong>support complaints</strong>.\nPlease review <strong>High-Risk customers immediately</strong>.\n</p>\n\n<hr/>\n\n<!-- HIGH / VERY HIGH RISK CUSTOMERS -->\n<h3 style=\"color:#d93025;\">\ud83d\udea8 High / Very High Risk Customers (Immediate Action Required)</h3>\n\n<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">\n  <tr style=\"background-color:#fce8e6;\">\n    <th>Customer</th>\n    <th>Email</th>\n    <th>Product</th>\n    <th>Payment</th>\n    <th>Complaints</th>\n    <th>Complaint Details</th>\n    <th>Risk Level</th>\n    <th>Action</th>\n  </tr>\n\n  {{ $items().filter(i => i.json.risk_level !== 'Low').map(i => `\n  <tr>\n    <td>${i.json.customer_name}</td>\n    <td>${i.json.email}</td>\n    <td>${i.json.product_name}</td>\n    <td><strong>${i.json.payment_status}</strong></td>\n    <td>${i.json.complaint_count}</td>\n    <td>${i.json.reason}</td>\n    <td><strong style=\"color:red;\">${i.json.risk_level}</strong></td>\n    <td>${i.json.action_required}</td>\n  </tr>\n  `).join('') }}\n</table>\n\n<br/>\n\n<!-- LOW RISK CUSTOMERS -->\n<h3 style=\"color:#188038;\">\u2705 Low Risk Customers (No Immediate Action Required)</h3>\n\n<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">\n  <tr style=\"background-color:#e6f4ea;\">\n    <th>Customer</th>\n    <th>Email</th>\n    <th>Product</th>\n    <th>Payment</th>\n    <th>Complaints</th>\n    <th>Complaint Details</th>\n    <th>Risk Level</th>\n  </tr>\n\n  {{ $items().filter(i => i.json.risk_level === 'Low').map(i => `\n  <tr>\n    <td>${i.json.customer_name}</td>\n    <td>${i.json.email}</td>\n    <td>${i.json.product_name}</td>\n    <td>${i.json.payment_status}</td>\n    <td>${i.json.complaint_count}</td>\n    <td>${i.json.reason}</td>\n    <td>${i.json.risk_level}</td>\n  </tr>\n  `).join('') }}\n</table>\n\n<hr/>\n\n<p>\n<strong>Recommended Next Steps:</strong><br/>\n\u2022 Assign an owner to each high-risk customer<br/>\n\u2022 Follow up on failed payments immediately<br/>\n\u2022 Resolve complaints to prevent churn\n</p>\n\n<p style=\"font-size:12px;color:gray;\">\nThis email was generated automatically by the Customer Risk Monitoring Workflow.\n</p>\n",
        "options": {},
        "subject": "\ud83d\udea8 Daily Customer Risk Summary \u2013 Action Required"
      },
      "typeVersion": 2.2
    },
    {
      "id": "23c4158b-793e-49e9-8c9b-ad4d881e7cbc",
      "name": "Merge Risk Result",
      "type": "n8n-nodes-base.merge",
      "position": [
        768,
        944
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "45dc326e-9cf3-4b35-a3f0-819cafc5ec8c",
      "name": "Prepare Escalation Summary For Low Risk User",
      "type": "n8n-nodes-base.set",
      "position": [
        480,
        816
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5e581a7f-fcb7-4682-ae73-e1ffd7fab159",
              "name": "customer_id",
              "type": "number",
              "value": "={{ $json.customer_id }}"
            },
            {
              "id": "7f1c661b-71b7-43b4-8650-4d8f78dbde30",
              "name": "customer_name",
              "type": "string",
              "value": "={{ $json.customer_name }}"
            },
            {
              "id": "8ea0faff-abbf-42a6-abae-f3f48efacb6e",
              "name": "email",
              "type": "string",
              "value": "={{ $json.email }}"
            },
            {
              "id": "2c08bab5-b379-4164-93d1-c58b678f3ed6",
              "name": "product_name",
              "type": "string",
              "value": "={{ $json.product_name }}"
            },
            {
              "id": "a6f8c34c-355b-465e-ad2d-bf2033211807",
              "name": "payment_status",
              "type": "string",
              "value": "={{ $json.payment_status }}"
            },
            {
              "id": "e60b3bec-e22d-4062-82ed-67c88415640c",
              "name": "complaint_count",
              "type": "string",
              "value": "={{ $json.complaint_count }}"
            },
            {
              "id": "e57bb3fc-806d-4402-b7dd-c3d73326c6bd",
              "name": "risk_level",
              "type": "string",
              "value": "Low"
            },
            {
              "id": "5e5c20c3-b4f5-4689-a79a-70aa805975f3",
              "name": "reason",
              "type": "string",
              "value": "Payment is successfull and the compliants are low"
            },
            {
              "id": "c7cd524f-e689-4484-9aa2-cda64f49bbaf",
              "name": "action_required",
              "type": "string",
              "value": "No"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7cdc752d-eb50-4e7c-b500-f4544b63da29",
      "name": "Prepare Escalation Summary For High Risk User",
      "type": "n8n-nodes-base.set",
      "position": [
        480,
        1088
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5e581a7f-fcb7-4682-ae73-e1ffd7fab159",
              "name": "customer_id",
              "type": "number",
              "value": "={{ $json.customer_id }}"
            },
            {
              "id": "7f1c661b-71b7-43b4-8650-4d8f78dbde30",
              "name": "customer_name",
              "type": "string",
              "value": "={{ $json.customer_name }}"
            },
            {
              "id": "8ea0faff-abbf-42a6-abae-f3f48efacb6e",
              "name": "email",
              "type": "string",
              "value": "={{ $json.email }}"
            },
            {
              "id": "2c08bab5-b379-4164-93d1-c58b678f3ed6",
              "name": "product_name",
              "type": "string",
              "value": "={{ $json.product_name }}"
            },
            {
              "id": "a6f8c34c-355b-465e-ad2d-bf2033211807",
              "name": "payment_status",
              "type": "string",
              "value": "={{ $json.payment_status }}"
            },
            {
              "id": "e60b3bec-e22d-4062-82ed-67c88415640c",
              "name": "complaint_count",
              "type": "string",
              "value": "={{ $json.complaint_count }}"
            },
            {
              "id": "e57bb3fc-806d-4402-b7dd-c3d73326c6bd",
              "name": "risk_level",
              "type": "string",
              "value": "Very_High"
            },
            {
              "id": "5e5c20c3-b4f5-4689-a79a-70aa805975f3",
              "name": "reason",
              "type": "string",
              "value": "Payment failure or multiple complaints detected"
            },
            {
              "id": "c7cd524f-e689-4484-9aa2-cda64f49bbaf",
              "name": "action_required",
              "type": "string",
              "value": "Immediate follow-up needed"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "25b76243-1ac2-4a98-9499-74dba8e5af06",
      "name": "Code in JavaScript3",
      "type": "n8n-nodes-base.code",
      "position": [
        1312,
        928
      ],
      "parameters": {
        "jsCode": "// Get all items from the node BEFORE notification\nconst previousItems = $items('Merge Risk Result');\n\n// Add notification status to each item\nreturn previousItems.map(item => {\n  return {\n    json: {\n      ...item.json,\n      notification_status: 'sent',\n      logged_at: new Date().toISOString()\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "24ab89ed-374e-4c9b-8155-c651d89dfde1",
      "name": "Append or update row in sheet3",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1520,
        928
      ],
      "parameters": {
        "columns": {
          "value": {
            "email": "={{ $json.email }}",
            "reason": "={{ $json.reason }}",
            "logged_at": "={{ $json.logged_at }}",
            "risk_level": "={{ $json.risk_level }}",
            "customer_id": "={{ $json.customer_id }}",
            "product_name": "={{ $json.product_name }}",
            "customer_name": "={{ $json.customer_name }}",
            "payment_status": "={{ $json.payment_status }}",
            "action_required": "={{ $json.action_required }}",
            "complaint_count": "={{ $json.complaint_count }}",
            "notification_status": "={{ $json.notification_status }}"
          },
          "schema": [
            {
              "id": "customer_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "customer_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "customer_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "product_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "product_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "payment_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "payment_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "complaint_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "complaint_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "risk_level",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "risk_level",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action_required",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action_required",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notification_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "notification_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "logged_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "logged_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "customer_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "your-google-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your list value",
          "cachedResultUrl": "your-google-sheet-url",
          "cachedResultName": "your-google-sheet-name"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "71439232-d3d2-4692-96aa-4b6f9ba12ff9",
      "name": "Send a message5",
      "type": "n8n-nodes-base.discord",
      "position": [
        1040,
        1072
      ],
      "parameters": {
        "content": "=\ud83d\udea8 **Daily Customer Risk Report**\n\n\ud83d\udcc5 **Date:** {{ new Date().toLocaleDateString() }}\n\n---\n\n\ud83d\udd25 **High / Very High Risk Customers**\n(Immediate action required)\n\n{{ $items().filter(i => i.json.risk_level !== 'Low').length === 0\n  ? '\u2705 No high-risk customers detected today.'\n  : $items()\n      .filter(i => i.json.risk_level !== 'Low')\n      .map(i => `\n**Customer:** ${i.json.customer_name}\n**Email:** ${i.json.email}\n**Product:** ${i.json.product_name}\n**Payment Status:** ${i.json.payment_status}\n**Complaints:** ${i.json.complaint_count}\n**Risk Level:** \ud83d\udea8 ${i.json.risk_level}\n**Action:** ${i.json.action_required}\n----------------------------`)\n      .join('\\n')\n}}\n\n---\n\n\u2705 **Low Risk Customers**\n(No immediate action required)\n\n{{ $items().filter(i => i.json.risk_level === 'Low').length === 0\n  ? '\u26a0\ufe0f No low-risk customers found.'\n  : $items()\n      .filter(i => i.json.risk_level === 'Low')\n      .map(i => `\n\u2022 ${i.json.customer_name} \u2013 ${i.json.product_name} (\u2705 OK)\n`)\n      .join('\\n')\n}}\n\n\ud83d\udccc **Next Steps**\n\u2022 Assign owners to high-risk customers  \n\u2022 Resolve complaints quickly  \n\u2022 Follow up on failed payments  \n\n\ud83e\udd16 _Automated by Customer Risk Monitoring Workflow_\n",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 2
    },
    {
      "id": "528a94a8-4521-41dc-b47f-893ab8867d43",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        1280
      ],
      "parameters": {
        "color": 7,
        "width": 1728,
        "height": 640,
        "content": "## Step3: AI Feedback & Reporting\nGenerates product insights from customer issues.\nSends summaries and logs results for audits and analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "fa8e9436-7516-4579-a4cb-9b00c0f69c6d",
      "name": "Daily Risk Check Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -736,
        1024
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "94cccad1-44ed-4615-b32b-3f2a251cbfcf",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1456,
        832
      ],
      "parameters": {
        "color": 7,
        "width": 624,
        "height": 1008,
        "content": "## Customer Health Monitoring & Product Feedback Intelligence\n\n### How it works\nThis workflow monitors customer health by combining payment behavior and customer feedback with AI-driven product intelligence. It runs automatically on a daily and weekly schedule to detect churn risk, classify customers by risk level, and convert raw customer issues into clear, executive-ready product insights.\n\nCustomer, payment, product, and feedback data are fetched from the database and evaluated using predefined rules. Customers are classified into Low, High, or Very High risk categories based on payment failures and issue frequency. High-risk customers are escalated immediately, while low-risk customers are logged for visibility without noise.\n\nFor customers with recurring issues, the workflow sends feedback data to an AI model that analyzes sentiment, identifies key problem themes, explains root causes, and generates actionable product improvement recommendations. These insights are stored alongside customer records for tracking and analysis.\n\nDaily and weekly summaries are automatically sent to stakeholders via email and collaboration tools. All risk evaluations, feedback insights, and notification statuses are logged to Google Sheets, creating a reliable audit trail for leadership, support, and product teams.\n\n### Setup steps\n1. Configure daily and weekly Schedule Trigger nodes  \n2. Connect PostgreSQL to fetch customer, payment, and feedback data  \n3. Adjust risk rules in IF and Set nodes if needed  \n4. Add your AI API key to the HTTP Request node  \n5. Connect Gmail, Discord, and Google Sheets  \n6. Activate the workflow\n"
      },
      "typeVersion": 1
    },
    {
      "id": "592a6d55-7dcd-4435-9f49-147ea7c66020",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        832
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 1008,
        "content": "## Step 1: Triggers & Mode Selection\nRuns on daily and weekly schedules.\nDetermines whether the execution is a risk scan or a summary run."
      },
      "typeVersion": 1
    },
    {
      "id": "7f379dae-ba02-4b76-902c-f18b06dcc469",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        656
      ],
      "parameters": {
        "color": 7,
        "width": 1728,
        "height": 608,
        "content": "## Step2: Risk Evaluation & Escalation\nFetches customer and payment data.\nClassifies customers into low or high risk and prepares escalation records."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7d342fc6-b40e-4d49-8613-70b5a9e2f643",
  "connections": {
    "Wait1": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch1": {
      "main": [
        [
          {
            "node": "Fetch Customer Risk Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get row(s) in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "Switch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields3": {
      "main": [
        [
          {
            "node": "Switch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message4": {
      "main": [
        [
          {
            "node": "Code in JavaScript3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prompt For Model1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly schedule1": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Risk Result": {
      "main": [
        [
          {
            "node": "Send a message4",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a message5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prompt For Model1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript3": {
      "main": [
        [
          {
            "node": "Append or update row in sheet3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet1": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is High Risk Customer?": {
      "main": [
        [
          {
            "node": "Prepare Escalation Summary For Low Risk User",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Escalation Summary For High Risk User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Risk Check Trigger": {
      "main": [
        [
          {
            "node": "Edit Fields3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Customer Risk Data": {
      "main": [
        [
          {
            "node": "Is High Risk Customer?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Escalation Summary For Low Risk User": {
      "main": [
        [
          {
            "node": "Merge Risk Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Escalation Summary For High Risk User": {
      "main": [
        [
          {
            "node": "Merge Risk Result",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow monitors customer health by combining payment behavior, complaint signals, and AI-driven feedback analysis. It runs on daily and weekly schedules to evaluate risk levels, escalate high-risk customers, and generate structured product insights. High-risk cases are…

Source: https://n8n.io/workflows/12254/ — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Data & Sheets

Continuous monitoring: Real-time surveillance of supplier performance, financial health, and operational status Risk scoring: AI-powered assessment of supplier risks across multiple dimensions (financ

Postgres, HTTP Request, Gmail +1
Data & Sheets

Regulatory monitoring: Continuously tracks changes in laws, regulations, and compliance requirements across multiple jurisdictions Contract analysis: AI-powered review of existing contracts to identif

HTTP Request, Postgres, Gmail +1
Data & Sheets

This workflow is designed for Customer Success Managers, Growth Teams, and SaaS Business Owners who want to proactively reduce churn using AI. It automates the analysis of customer health and the deli

HTTP Request, Postgres, OpenAI +2
Data & Sheets

Code Postgres. Uses httpRequest, splitInBatches, postgres, hubspot. Scheduled trigger; 23 nodes.

HTTP Request, Postgres, HubSpot +1
Data & Sheets

This workflow automatically monitors and reports data quality for any SQL table using configurable checks and thresholds. It evaluates key metrics—including null values, duplicate records, row count a

Postgres, Google Sheets, Gmail