N
n8n Store
Workflow Market
whatsapp-bus-support

whatsapp-bus-support

by bayrak0 views

Description

Categories

🤖 AI & Machine Learning

Nodes Used

n8n-nodes-base.ifn8n-nodes-base.coden8n-nodes-base.coden8n-nodes-base.dateTimen8n-nodes-base.whatsAppn8n-nodes-base.whatsAppn8n-nodes-base.googleDocsn8n-nodes-base.aiTransformn8n-nodes-base.googleSheets@n8n/n8n-nodes-langchain.agent
PriceKostenlos
Views0
Last Updated11/28/2025
workflow.json
{
  "id": "eOnn0usOtRXAWFnA",
  "meta": {
    "instanceId": "9b335fa52c546d5c6158999e0c6e4bff2bbbb8a64c600fcbaf9588ca5c18ff7d",
    "templateCredsSetupCompleted": true
  },
  "name": "whatsapp-bus-support",
  "tags": [],
  "nodes": [
    {
      "id": "d0cdd573-db7f-4bad-957f-35414a3cb26f",
      "name": "cleanAnswer",
      "type": "n8n-nodes-base.code",
      "position": [
        -240,
        160
      ],
      "parameters": {
        "jsCode": "// cleanAnswer – run once per item\nlet txt = $('AI Agent').first().json.output || '';\n\n// 1. Remove bold / italic / strike markers\ntxt = txt.replace(/[*_~]+/g, '');\n\n// 2. Convert [Texto](https://url) → Texto https://url\ntxt = txt.replace(/\\[([^\\]]+)\\]\\((https?:\\/\\/[^\\s)]+)\\)/g, '$1 $2');\n\n// 3. Collapse 3+ blank lines\ntxt = txt.replace(/\\n{3,}/g, '\\n\\n').trim();\n\n// 4. Remove the unwanted source-reference preamble\ntxt = txt.replace(/^.*?based on the document you provided[,:]?\\s*/i, '');\n\nreturn [{ json: { answer: txt } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "71f15de1-8cdf-482b-b239-7594fa5a70ab",
      "name": "24-hour window check",
      "type": "n8n-nodes-base.code",
      "position": [
        -680,
        260
      ],
      "parameters": {
        "jsCode": "// within24h?  – run once per item\n// Meta (WhatsApp) timestamp arrives as seconds since epoch\nconst lastTs = Number($('when message received').first().json.messages[0].timestamp) * 1000;   // → ms\nconst withinWindow = Date.now() - lastTs < 24 * 60 * 60 * 1000;\n\nreturn [{ json: { withinWindow, answer: $json.answer, userId: $json.userId } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "82f43fa3-efa2-4c83-98fa-9e16e315f35f",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -460,
        260
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d33e218e-a49a-49ed-9c6b-55b9ea0b0dbb",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.withinWindow }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ade2b1ca-8fb0-4622-b156-07518a0c25c0",
      "name": "Send AI Agent's Answer",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -20,
        160
      ],
      "webhookId": "8da6eeda-31ec-448a-9d75-2d5dbc5f10f9",
      "parameters": {
        "textBody": "={{ $json.answer }}",
        "operation": "send",
        "phoneNumberId": "687083431157048",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('when message received').item.json.contacts[0].wa_id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "L6Ezo9L9L9iO6fnt",
          "name": "WhatsApp account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2e28f789-9e3c-4ceb-aac3-b4da028b3bec",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1460,
        480
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "yUhCnIuDvIzXVadJ",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2904f065-fc81-4d24-9ba5-490927c2e0b4",
      "name": "when message received",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -2140,
        260
      ],
      "webhookId": "6b645b70-61db-4d4d-af47-2f39295cf196",
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "o05Jk36W2gtL9pNU",
          "name": "WhatsApp OAuth account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2631cd36-f4b8-42f3-85ac-1aa044ae584e",
      "name": "Date & Time",
      "type": "n8n-nodes-base.dateTime",
      "position": [
        -1120,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "664c3660-7a71-41eb-a269-cf6eee3ed27c",
      "name": "company's knowledge",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        -1920,
        260
      ],
      "parameters": {
        "operation": "get",
        "documentURL": "=1dwioGWqvY3qTDzb8olUsc1EaJJkn7_ySeRC0AaE4NZQ"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "ymt0N6m9vFBPthUy",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "7a9bb146-c1d8-4ec4-96fd-a234f700c6eb",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -1340,
        480
      ],
      "parameters": {
        "sessionKey": "={{ $('when message received').item.json.contacts[0].wa_id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e3710403-d218-4861-9514-91c68d696986",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -900,
        260
      ],
      "parameters": {
        "columns": {
          "value": {
            "User": "={{ $('when message received').item.json.messages[0].from }}",
            "Message": "={{ $('when message received').item.json.messages[0].text.body }}",
            "Response": "={{ $('AI Agent').item.json.output }}",
            "Timestamp": "={{ $json.currentDate }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "User",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "User",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Response",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q-i3MNfTBLU8pf4Vhg1zR3PHWCiMDDc6buo35N708x8/edit#gid=0",
          "cachedResultName": "Sayfa1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Q-i3MNfTBLU8pf4Vhg1zR3PHWCiMDDc6buo35N708x8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q-i3MNfTBLU8pf4Vhg1zR3PHWCiMDDc6buo35N708x8/edit?usp=drivesdk",
          "cachedResultName": "history-whatsapp"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "0A2HzCF9xOmwKi6u",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "2466e7ce-b5ea-4598-a0d4-deee18cc1ff9",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "maxTries": 5,
      "position": [
        -1480,
        260
      ],
      "parameters": {
        "text": "={{ $json.finalPrompt }}\n",
        "options": {
          "systemMessage": "=Sen TechFlow Yazılım Şirketi için müşteri asistanısın. \nKuralların: \nİnsan gibi davranmanı istiyorum. \n\n\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "retryOnFail": false,
      "typeVersion": 1.7,
      "alwaysOutputData": true,
      "waitBetweenTries": null
    },
    {
      "id": "7d61f55c-fe0c-4197-8951-955fb9e12222",
      "name": "Prepare Prompt",
      "type": "n8n-nodes-base.aiTransform",
      "position": [
        -1700,
        260
      ],
      "parameters": {
        "jsCode": "const googleDocs = $input.all().map((item) => item.json);\nconst whatsappMessages = $(\"when message received\")\n  .all()\n  .map((item) => item.json);\n\nconst date = new Date();\nconst formattedDate = `${date.getMonth() + 1} ${date.getDate()}, ${date.getFullYear()}`;\n\nconst docText = googleDocs[0].content.split(\"\\n\").join(\" \");\n\nconst body = whatsappMessages[0].messages[0].text.body;\n\nconst finalPrompt = `Today's date is: ${formattedDate}\\n\\n${docText}\\n\\nUser's question:\\n${body}`;\n\nreturn { finalPrompt };\n",
        "instructions": "Write code to:\n• Get today’s date formatted “Month Day, Year”\n• Extract the Google Doc’s plain text by joining its body.content textRuns\n• Extract the WhatsApp message from messages[0].text.body\n• Build a field finalPrompt exactly as:\n\nvbnet\nCopy\nEdit\nToday's date is: [date]\n\n[doc text]\n\nUser's question:\n[body]\n• Return finalPrompt only.",
        "codeGeneratedForPrompt": "Write code to:\n• Get today’s date formatted “Month Day, Year”\n• Extract the Google Doc’s plain text by joining its body.content textRuns\n• Extract the WhatsApp message from messages[0].text.body\n• Build a field finalPrompt exactly as:\n\nvbnet\nCopy\nEdit\nToday's date is: [date]\n\n[doc text]\n\nUser's question:\n[body]\n• Return finalPrompt only."
      },
      "typeVersion": 1
    },
    {
      "id": "dc461011-4125-4d46-83d0-195105d4bcde",
      "name": "Send message",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -260,
        380
      ],
      "webhookId": "ac3e8306-8e32-4d7e-ba8a-46763999eb89",
      "parameters": {
        "textBody": "Mesajımızı 24 saat cevaplayamadığınız için süresi dolmuştur. Lütfen tekrar sohbet başlatın.",
        "operation": "send",
        "phoneNumberId": "687083431157048",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('when message received').item.json.contacts[0].wa_id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "L6Ezo9L9L9iO6fnt",
          "name": "WhatsApp account"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2928be66-1df6-4ba5-90b2-86ab8859bd70",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "cleanAnswer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Date & Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cleanAnswer": {
      "main": [
        [
          {
            "node": "Send AI Agent's Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Prompt": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "company's knowledge": {
      "main": [
        [
          {
            "node": "Prepare Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "24-hour window check": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "when message received": {
      "main": [
        [
          {
            "node": "company's knowledge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "24-hour window check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

相关工作流