{"active":false,"connections":{"AI Agent":{"main":[[{"index":0,"node":"IF Handoff Needed","type":"main"}]]},"Format Handoff Summary":{"main":[[{"index":0,"node":"WhatsApp Agent Alert","type":"main"}]]},"IF Handoff Needed":{"main":[[{"index":0,"node":"Format Handoff Summary","type":"main"}],[{"index":0,"node":"Send Agent Reply","type":"main"}]]},"OpenAI Chat Model":{"ai_languageModel":[[{"index":0,"node":"AI Agent","type":"ai_languageModel"}]]},"WhatsApp Agent Alert":{"main":[[{"index":0,"node":"Slack Team Notify","type":"main"}]]},"WhatsApp Trigger":{"main":[[{"index":0,"node":"AI Agent","type":"main"}]]},"Window Buffer Memory":{"ai_memory":[[{"index":0,"node":"AI Agent","type":"ai_memory"}]]}},"meta":{"instanceId":"","templateCredsSetupCompleted":false},"name":"WhatsApp Business Support & Sales Chatbot","nodes":[{"credentials":{"whatsAppApi":{"id":"","name":"WhatsApp Business API"}},"id":"b2c3d4e5-1101-4a5b-8c9d-111111111111","name":"WhatsApp Trigger","parameters":{"options":{},"updates":["messages"]},"position":[240,300],"type":"n8n-nodes-base.whatsAppTrigger","typeVersion":1,"webhookId":"cortexflow-whatsapp-bot"},{"id":"b2c3d4e5-1102-4a5b-8c9d-222222222222","name":"AI Agent","parameters":{"options":{"systemMessage":"You are a friendly customer support and sales assistant for a small business, chatting over WhatsApp. Answer FAQs, help with orders, and qualify buyers (ask about budget, timeline, and needs). Keep replies short (under 80 words), warm, and conversational — plain text only, no markdown. IMPORTANT: if the customer asks to talk to a human, requests a pricing call, or sounds upset, end your reply with the exact token [HANDOFF] on its own line. The workflow routes flagged conversations to a human agent."},"promptType":"define","text":"={{ $json.entry[0].changes[0].value.messages[0].text.body }}"},"position":[480,300],"type":"@n8n/n8n-nodes-langchain.agent","typeVersion":2.2},{"credentials":{"openAiApi":{"id":"","name":"OpenAI API"}},"id":"b2c3d4e5-1103-4a5b-8c9d-333333333333","name":"OpenAI Chat Model","parameters":{"model":{"__rl":true,"cachedResultName":"gpt-4o-mini","mode":"list","value":"gpt-4o-mini"},"options":{}},"position":[480,500],"type":"@n8n/n8n-nodes-langchain.lmChatOpenAi","typeVersion":1.2},{"id":"b2c3d4e5-1104-4a5b-8c9d-444444444444","name":"Window Buffer Memory","parameters":{"contextWindowLength":10,"sessionIdType":"customKey","sessionKey":"={{ $json.entry[0].changes[0].value.messages[0].from }}"},"position":[700,500],"type":"@n8n/n8n-nodes-langchain.memoryBufferWindow","typeVersion":1.3},{"id":"b2c3d4e5-1105-4a5b-8c9d-555555555555","name":"IF Handoff Needed","parameters":{"conditions":{"combinator":"and","conditions":[{"id":"b2c3d4e5-11c1-4a5b-8c9d-121212121212","leftValue":"={{ $json.output }}","operator":{"name":"filter.operator.string.contains","operation":"contains","type":"string"},"rightValue":"[HANDOFF]"}],"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose"}},"looseTypeValidation":true,"options":{}},"position":[720,300],"type":"n8n-nodes-base.if","typeVersion":2.2},{"id":"b2c3d4e5-1106-4a5b-8c9d-666666666666","name":"Format Handoff Summary","parameters":{"assignments":{"assignments":[{"id":"b2c3d4e5-11a1-4a5b-8c9d-a1a1a1a1a1a1","name":"customer_phone","type":"string","value":"={{ $('WhatsApp Trigger').first().json.entry[0].changes[0].value.messages[0].from }}"},{"id":"b2c3d4e5-11a2-4a5b-8c9d-a2a2a2a2a2a2","name":"last_message","type":"string","value":"={{ $('WhatsApp Trigger').first().json.entry[0].changes[0].value.messages[0].text.body }}"},{"id":"b2c3d4e5-11a3-4a5b-8c9d-a3a3a3a3a3a3","name":"agent_summary","type":"string","value":"={{ $json.output }}"}]},"include":"none","options":{}},"position":[960,180],"type":"n8n-nodes-base.set","typeVersion":3.4},{"credentials":{"whatsAppApi":{"id":"","name":"WhatsApp Business API"}},"id":"b2c3d4e5-1107-4a5b-8c9d-777777777777","name":"WhatsApp Agent Alert","parameters":{"operation":"send","resource":"message","textBody":"=Handoff request from WhatsApp\nCustomer: {{ $json.customer_phone }}\nLast message: {{ $json.last_message }}\nAI summary: {{ $json.agent_summary }}\nPlease take over this conversation.","toPhoneNumber":"YOUR_AGENT_PHONE_NUMBER"},"position":[1200,180],"type":"n8n-nodes-base.whatsapp","typeVersion":1},{"credentials":{"slackOAuth2Api":{"id":"","name":"Slack API"}},"id":"b2c3d4e5-1108-4a5b-8c9d-888888888888","name":"Slack Team Notify","parameters":{"channelId":{"__rl":true,"mode":"name","value":"support-alerts"},"operation":"send","otherOptions":{},"resource":"message","select":"channel","text":"=Handoff request from WhatsApp\nCustomer: {{ $('Format Handoff Summary').first().json.customer_phone }}\nLast message: {{ $('Format Handoff Summary').first().json.last_message }}\nAI summary: {{ $('Format Handoff Summary').first().json.agent_summary }}"},"position":[1440,180],"type":"n8n-nodes-base.slack","typeVersion":2.2},{"credentials":{"whatsAppApi":{"id":"","name":"WhatsApp Business API"}},"id":"b2c3d4e5-1109-4a5b-8c9d-999999999999","name":"Send Agent Reply","parameters":{"operation":"send","resource":"message","textBody":"={{ $json.output }}","toPhoneNumber":"={{ $('WhatsApp Trigger').first().json.entry[0].changes[0].value.messages[0].from }}"},"position":[960,420],"type":"n8n-nodes-base.whatsapp","typeVersion":1},{"id":"b2c3d4e5-1110-4a5b-8c9d-000000000000","name":"Sticky Note","parameters":{"color":4,"content":"## WhatsApp Business Support & Sales Chatbot\n\n**Setup (10 min):**\n1. At developers.facebook.com create a Meta app (Business type), add the WhatsApp product, and copy your Phone Number ID + access token from WhatsApp -> API Setup.\n2. In n8n create a **WhatsApp API** credential with the token; select it in *WhatsApp Trigger* and both WhatsApp send nodes. Set your Phone Number ID (From) in the send nodes.\n3. Create an **OpenAI** credential; select it in *OpenAI Chat Model*.\n4. Create a **Slack** credential; select it in *Slack Team Notify* and set the channel name.\n5. In *WhatsApp Agent Alert* replace YOUR_AGENT_PHONE_NUMBER with your agent's number (country code, no +).\n6. Activate the workflow and message your business number.\n\n**How it works:** WhatsApp Trigger -> AI Agent (OpenAI + per-phone memory) -> IF Handoff Needed -> handoff path alerts your agent on WhatsApp + Slack; otherwise the AI reply goes straight back to the customer.\n\n**Notes:** Meta also sends delivery 'statuses' events — if you see empty runs, add an IF node after the trigger checking that a message exists. Message text and sender phone are read from entry[0].changes[0].value.messages[0]; adjust the expressions if your webhook shape differs. Replies inside the 24h customer-service window send as free text; business-initiated messages need an approved template.","height":420,"width":460},"position":[160,-80],"type":"n8n-nodes-base.stickyNote","typeVersion":1}],"pinData":{},"settings":{"executionOrder":"v1"},"tags":[{"name":"cortexflow-template"}],"versionId":"cortexflow-whatsapp-business-chatbot-v1"}