{ "name": "Reply to WhatsApp keywords automatically", "nodes": [ { "parameters": { "session": "default", "events": [ "message" ] }, "name": "WhatsApp Trigger", "type": "n8n-nodes-whatsapp-retentionstack.whatsAppRetentionStackTrigger", "typeVersion": 1, "position": [ 0, 0 ], "webhookId": "whatsapp-keyword-reply" }, { "parameters": { "jsCode": "// Edit these. Only an exact keyword gets an answer, so two bots cannot keep replying to each other.\nconst replies = {\n hours: 'We are open Monday to Friday, 9am to 6pm.',\n help: 'Reply HOURS for opening times, or write your question and a person will answer.',\n};\nreturn $input.all().flatMap(({ json }) => {\n const message = json.payload || {};\n // Direct chats only: never our own messages, groups, channels or status updates.\n if (message.fromMe || !/@(c\\.us|s\\.whatsapp\\.net|lid)$/.test(message.from || '')) return [];\n const reply = replies[String(message.body || '').trim().toLowerCase()];\n return reply ? [{ json: { chatId: message.from, reply } }] : [];\n});" }, "name": "Match keyword", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 220, 0 ] }, { "parameters": { "resource": "message", "operation": "sendText", "session": "default", "chatId": "={{ $json.chatId }}", "text": "={{ $json.reply }}" }, "name": "Send reply", "type": "n8n-nodes-whatsapp-retentionstack.whatsAppRetentionStack", "typeVersion": 1, "position": [ 440, 0 ] }, { "parameters": { "content": "## Keyword auto-reply\nSomeone writes `hours` or `help` to your number and gets the matching answer. Everything else is left for you.\n\nPick your session token credential in both WhatsApp nodes, edit the replies, then publish the workflow.\n\nSubscribe to **message** only. Adding message.any would also deliver your own replies.", "height": 280, "width": 460 }, "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ 0, -320 ] } ], "connections": { "WhatsApp Trigger": { "main": [ [ { "node": "Match keyword", "type": "main", "index": 0 } ] ] }, "Match keyword": { "main": [ [ { "node": "Send reply", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" } }