whatsapp chatbot
Shared 8/5/2025
290 views
Visual Workflow
JSON Code
{
"id": "e6UoHBzaNXt9GTT0",
"meta": {
"instanceId": "e47d64555b1d2d790e503dd03eed2a46bc6f45fe0e9e7b451f71ccde8c29cc3e"
},
"name": "My workflow",
"tags": [],
"nodes": [
{
"id": "70f5d433-2d9a-4f84-ab81-505d1437845e",
"name": "WhatsApp Trigger",
"type": "n8n-nodes-base.whatsAppTrigger",
"position": [
-432,
592
],
"webhookId": "d3978cae-2aca-4553-8ac7-ab89068deabc",
"parameters": {
"options": {},
"updates": [
"messages"
]
},
"credentials": {
"whatsAppTriggerApi": {
"id": "NbTYEEdHfmaCXUWr",
"name": "WhatsApp OAuth account"
}
},
"typeVersion": 1
},
{
"id": "68816535-3ca5-407d-83c5-2432539a1cde",
"name": "Simple Memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
368,
800
],
"parameters": {
"sessionKey": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
"sessionIdType": "customKey",
"contextWindowLength": 20
},
"typeVersion": 1.3
},
{
"id": "ee022366-3450-4d90-99a9-2f1620c9477c",
"name": "Check Input Type",
"type": "n8n-nodes-base.switch",
"position": [
-224,
576
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Voice",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "b7b64446-f1ea-4622-990c-22f3999a8269",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.messages[0].audio }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "Image",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "202af928-a324-411a-bf15-68a349e7bf9e",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.messages[0].image }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "Text",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "08fd0c80-307e-4f45-b1de-35192ee4ec5e",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.messages[0].text.body }}",
"rightValue": ""
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "26c0eaa7-94a0-4222-811d-f4867edabbdd",
"name": "Get Image URL",
"type": "n8n-nodes-base.whatsApp",
"position": [
128,
352
],
"webhookId": "280bd5de-32d7-4d8f-93d2-e91e3b0bc161",
"parameters": {
"resource": "media",
"operation": "mediaUrlGet",
"mediaGetId": "={{ $('WhatsApp Trigger').item.json.messages[0].image.id }}"
},
"credentials": {
"whatsAppApi": {
"id": "du9FYCJf5favUKG3",
"name": "WhatsApp account"
}
},
"typeVersion": 1
},
{
"id": "90f9f54f-2782-48c2-952f-13d550346859",
"name": "Download Image",
"type": "n8n-nodes-base.httpRequest",
"position": [
288,
352
],
"parameters": {
"url": "={{ $json.url }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"typeVersion": 4.2
},
{
"id": "9eca2cb5-52e2-4202-b763-170af91e5147",
"name": "Analyze Image",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
448,
352
],
"parameters": {
"text": "=Describe the image in detail.",
"modelId": {
"__rl": true,
"mode": "list",
"value": "chatgpt-4o-latest",
"cachedResultName": "CHATGPT-4O-LATEST"
},
"options": {},
"resource": "image",
"inputType": "base64",
"operation": "analyze"
},
"typeVersion": 1.8
},
{
"id": "f2ee3d57-5627-43af-86a9-7f67c37dd934",
"name": "Image + Text Prompt",
"type": "n8n-nodes-base.set",
"position": [
608,
352
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "67552183-de2e-494a-878e-c2948e8cb6bb",
"name": "text",
"type": "string",
"value": "=# The user provided the following image and text.\n\n## IMAGE CONTENT:\n{{ $json.content }}\n\n## USER MESSAGE:\n{{ $('WhatsApp Trigger').item.json.messages[0].image.caption || \"Describe the image\" }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "d63fe474-53a8-4420-b675-078cdd78b2ce",
"name": "Text Only Prompt",
"type": "n8n-nodes-base.set",
"position": [
48,
624
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c05a7fbf-309a-407e-9fee-7e0b03f4a5c8",
"name": "text",
"type": "string",
"value": "={{ $('WhatsApp Trigger').item.json.messages[0].text.body }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "273a3227-1ecc-4503-ad5f-fefe03999903",
"name": "Get Audio URL",
"type": "n8n-nodes-base.whatsApp",
"position": [
128,
80
],
"webhookId": "87caa300-7204-47b5-959a-94f4a8fbf8cf",
"parameters": {
"resource": "media",
"operation": "mediaUrlGet",
"mediaGetId": "={{ $('WhatsApp Trigger').item.json.messages[0].audio.id }}"
},
"credentials": {
"whatsAppApi": {
"id": "du9FYCJf5favUKG3",
"name": "WhatsApp account"
}
},
"typeVersion": 1
},
{
"id": "60b075dc-b5fd-4369-8b66-d728042911b6",
"name": "Download Audio",
"type": "n8n-nodes-base.httpRequest",
"position": [
288,
80
],
"parameters": {
"url": "={{ $json.url }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"typeVersion": 4.2
},
{
"id": "f3f04be9-d5c7-45bd-ad16-87015ef3ee77",
"name": "Transcribe Audio",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
448,
80
],
"parameters": {
"options": {},
"resource": "audio",
"operation": "transcribe"
},
"typeVersion": 1.8
},
{
"id": "c3b32bff-c63b-4cde-8fdd-feeea6ebbce4",
"name": "Audio Prompt",
"type": "n8n-nodes-base.set",
"position": [
608,
80
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "219577d5-b028-48fc-90be-980f4171ab68",
"name": "text",
"type": "string",
"value": "={{ $json.text }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "3309a35e-de81-4ba4-ac2a-6a9da66dc49f",
"name": "If",
"type": "n8n-nodes-base.if",
"position": [
688,
624
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "b9d1d759-f585-4791-a743-b9d72951e77c",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $('WhatsApp Trigger').item.json.messages[0].audio }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "22bc84c4-23fe-4d8b-82bf-fa64b9c3b27d",
"name": "Generate Audio",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
944,
608
],
"parameters": {
"input": "={{ $('AI Agent').item.json.output }}",
"options": {},
"resource": "audio"
},
"typeVersion": 1.8
},
{
"id": "eae61adf-e1fe-4d16-9f64-e65da06034c8",
"name": "Respond with Audio",
"type": "n8n-nodes-base.whatsApp",
"position": [
1312,
608
],
"webhookId": "d18b2c98-84e4-43cf-a532-0c47d5161684",
"parameters": {
"mediaPath": "useMedian8n",
"operation": "send",
"messageType": "audio",
"phoneNumberId": "175940715605000",
"additionalFields": {},
"recipientPhoneNumber": "={{ $('Check Input Type').item.json.contacts[0].wa_id }}"
},
"typeVersion": 1
},
{
"id": "57423d6a-5c75-45de-9294-158b6f5b021e",
"name": "Respond with Text",
"type": "n8n-nodes-base.whatsApp",
"position": [
944,
800
],
"webhookId": "23834751-5066-48ba-8e19-549680df2b27",
"parameters": {
"textBody": "={{ $json.output }}",
"operation": "send",
"phoneNumberId": "175940715605000",
"additionalFields": {},
"recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
},
"typeVersion": 1
},
{
"id": "1b52dfed-6bc5-4156-bc2d-d54860c98faa",
"name": "Fix Mime Type",
"type": "n8n-nodes-base.code",
"position": [
1120,
608
],
"parameters": {
"jsCode": "// Loop over input items and change the MIME type of binary data\nfor (const item of $input.all()) {\n // Check if the item has binary data\n if (item.binary) {\n // Find the binary property name (assuming there's at least one)\n const binaryPropertyNames = Object.keys(item.binary);\n \n for (const propName of binaryPropertyNames) {\n // If the MIME type is 'audio/mp3', change it to 'audio/mpeg'\n if (item.binary[propName].mimeType === 'audio/mp3') {\n item.binary[propName].mimeType = 'audio/mpeg';\n }\n }\n }\n}\n\nreturn $input.all();"
},
"typeVersion": 2
},
{
"id": "cb139a46-6cda-487f-9ed4-eda071a51b34",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
0
],
"parameters": {
"width": 800,
"height": 240,
"content": "## Audio"
},
"typeVersion": 1
},
{
"id": "2f7c69da-aa27-4f49-bb66-39b94977c989",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
272
],
"parameters": {
"color": 4,
"width": 800,
"height": 280,
"content": "## Image & Text"
},
"typeVersion": 1
},
{
"id": "f27aadc4-2272-47c9-8133-8ed2d3ee222d",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-16,
1040
],
"parameters": {
"width": 820,
"height": 400,
"content": "## Tools"
},
"typeVersion": 1
},
{
"id": "f94b52fc-2d84-4c8b-8225-728f6f2bf552",
"name": "Web Search",
"type": "@n8n/n8n-nodes-langchain.toolSerpApi",
"position": [
32,
1152
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "b73f4b0b-9957-4b88-b594-38fcd7601207",
"name": "Calculator",
"type": "@n8n/n8n-nodes-langchain.toolCalculator",
"position": [
128,
1152
],
"parameters": {},
"typeVersion": 1
},
{
"id": "d0c25927-f419-4ef5-91b9-b06cc93aa5ee",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
240,
1280
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "lNctWWxGNRSipJLZ",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "31768cfe-ef8e-4dde-b178-6ec9108c1262",
"name": "Knowledge Base",
"type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
"position": [
224,
1152
],
"parameters": {
"mode": "retrieve-as-tool",
"options": {
"pineconeNamespace": "contacts"
},
"toolName": "contacts",
"pineconeIndex": {
"__rl": true,
"mode": "list",
"value": "n8n",
"cachedResultName": "n8n"
},
"toolDescription": "Returns contact information like email addresses."
},
"typeVersion": 1.1
},
{
"id": "43bb40a2-3b12-4fd3-b794-8b897e9eb9bf",
"name": "MCP Client",
"type": "@n8n/n8n-nodes-langchain.mcpClientTool",
"position": [
528,
1152
],
"parameters": {
"sseEndpoint": "https://n8n.leonvanzyl.com/mcp/mytools/sse"
},
"typeVersion": 1
},
{
"id": "0b9469c7-116b-4ca2-a157-b93a8243877a",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
192,
784
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "lNctWWxGNRSipJLZ",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "17fce357-521a-465f-a675-9b545ca34447",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
656,
1088
],
"parameters": {
"height": 300.48941882630095,
"content": "## Try me out\n1. In the OpenAI Assistant node, make sure your OpenAI credentials are set and choose an assistant to use (you'll need to create one if you don't have one already)\n2. Click the 'Chat' button below\n\n - In the first message, tell the AI what your name is\n - In a second message, ask the AI what your name is"
},
"typeVersion": 1
},
{
"id": "e3525ded-4b6c-4fb6-bd94-a3d9a6a612fe",
"name": "Calculator1",
"type": "@n8n/n8n-nodes-langchain.toolCalculator",
"position": [
400,
1920
],
"parameters": {},
"typeVersion": 1
},
{
"id": "57f20f68-085d-4140-9e63-048d18171fb3",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
16,
1840
],
"webhookId": "9eab0524-6cd7-4b81-8bd8-4d050a972a08",
"parameters": {
"public": true,
"options": {
"loadPreviousSession": "memory"
}
},
"typeVersion": 1.1
},
{
"id": "642139ed-5326-4d21-bc41-7ee96afc4e6d",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
224,
1600
],
"parameters": {
"color": 7,
"width": 398,
"height": 217,
"content": "Call the assistant, passing in the previous chat messages"
},
"typeVersion": 1
},
{
"id": "2e83b79f-e16b-46ed-b1c4-13d85d6ddd5a",
"name": "Simple Memory1",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
560,
1888
],
"parameters": {
"sessionKey": "={{ $('When chat message received').first().json.sessionId }}",
"sessionIdType": "customKey",
"contextWindowLength": 20
},
"typeVersion": 1.3
},
{
"id": "cbcf0bcb-0bf2-4a62-96b8-292c4d0551b2",
"name": "Message an assistant",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
288,
1680
],
"parameters": {
"text": "={{ $('When chat message received').item.json.chatInput }}",
"prompt": "define",
"options": {},
"resource": "assistant",
"assistantId": {
"__rl": true,
"mode": "list",
"value": "asst_octMBRtoHSjqBEE2fufsrMg0",
"cachedResultName": "dr.sounny's assistance"
}
},
"credentials": {
"openAiApi": {
"id": "lNctWWxGNRSipJLZ",
"name": "OpenAi account"
}
},
"typeVersion": 1.8
},
{
"id": "007ad4fb-861d-4f07-86d7-d27c9ec0f197",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
272,
624
],
"parameters": {
"text": "={{ $json.text }}",
"options": {
"systemMessage": "=You are a helpful assistant for Dr Sounny.\n\nYou are currently talking to {{ $('WhatsApp Trigger').item.json.contacts[0].profile.name }}\n\nThe current date and time is {{ $now.toString() }}"
},
"promptType": "define"
},
"typeVersion": 1.9
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "966a377d-23aa-4901-a44f-2da8b463b940",
"connections": {
"If": {
"main": [
[
{
"node": "Generate Audio",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond with Text",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[]
]
},
"Calculator": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"MCP Client": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Web Search": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Calculator1": {
"ai_tool": [
[
{
"node": "Message an assistant",
"type": "ai_tool",
"index": 0
}
]
]
},
"Audio Prompt": {
"main": [
[
{
"node": "Message an assistant",
"type": "main",
"index": 0
}
]
]
},
"Analyze Image": {
"main": [
[
{
"node": "Image + Text Prompt",
"type": "main",
"index": 0
}
]
]
},
"Fix Mime Type": {
"main": [
[
{
"node": "Respond with Audio",
"type": "main",
"index": 0
}
]
]
},
"Get Audio URL": {
"main": [
[
{
"node": "Download Audio",
"type": "main",
"index": 0
}
]
]
},
"Get Image URL": {
"main": [
[
{
"node": "Download Image",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Download Audio": {
"main": [
[
{
"node": "Transcribe Audio",
"type": "main",
"index": 0
}
]
]
},
"Download Image": {
"main": [
[
{
"node": "Analyze Image",
"type": "main",
"index": 0
}
]
]
},
"Generate Audio": {
"main": [
[
{
"node": "Fix Mime Type",
"type": "main",
"index": 0
}
]
]
},
"Knowledge Base": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Simple Memory1": {
"ai_memory": [
[
{
"node": "Message an assistant",
"type": "ai_memory",
"index": 0
},
{
"node": "When chat message received",
"type": "ai_memory",
"index": 0
}
]
]
},
"Check Input Type": {
"main": [
[
{
"node": "Get Audio URL",
"type": "main",
"index": 0
}
],
[
{
"node": "Get Image URL",
"type": "main",
"index": 0
}
],
[
{
"node": "Text Only Prompt",
"type": "main",
"index": 0
}
]
]
},
"Text Only Prompt": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Transcribe Audio": {
"main": [
[
{
"node": "Audio Prompt",
"type": "main",
"index": 0
}
]
]
},
"WhatsApp Trigger": {
"main": [
[
{
"node": "Check Input Type",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI": {
"ai_embedding": [
[
{
"node": "Knowledge Base",
"type": "ai_embedding",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Image + Text Prompt": {
"main": [
[
{
"node": "Message an assistant",
"type": "main",
"index": 0
}
]
]
},
"Message an assistant": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "Message an assistant",
"type": "main",
"index": 0
}
]
]
}
}
}