{ "name": "Messenger bulk messages", "nodes": [ { "parameters": { "multipleMethods": true, "path": "c77a641c-03f0-4019-bbb4-65a3bede30c5", "responseMode": "responseNode", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ -608, -544 ], "id": "45f19b26-4c05-49b7-881b-0479f966714f", "name": "Webhook", "webhookId": "c77a641c-03f0-4019-bbb4-65a3bede30c5" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "abdb849a-8e8b-4472-834e-f54902ac3b97", "leftValue": "={{ $json.query['hub.mode'] }}", "rightValue": "subscribe", "operator": { "type": "string", "operation": "equals" } }, { "id": "b56f41c3-3617-4d59-babb-d7aebc2bfae4", "leftValue": "={{ $json.query['hub.verify_token'] }}", "rightValue": "mynewtoken", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ -320, -848 ], "id": "daa14d8c-9e35-4699-b2bf-d9a720aa6133", "name": "If" }, { "parameters": { "respondWith": "text", "responseBody": "={{ $json.query['hub.challenge'] }}", "options": {} }, "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.5, "position": [ -32, -848 ], "id": "bca14630-1022-46d6-9b1f-322b34f32fe5", "name": "Respond to Webhook" }, { "parameters": { "promptType": "define", "text": "={{ $json.body.entry[0].messaging[0].message }}", "options": { "systemMessage": "=You are a helpful Bot assistant.\n\n" } }, "type": "@n8n/n8n-nodes-langchain.agent", "typeVersion": 3.1, "position": [ -384, -656 ], "id": "68c83ab1-76a4-44ce-8362-cee23c5d9219", "name": "AI Agent" }, { "parameters": { "model": { "__rl": true, "mode": "list", "value": "gpt-4.1-mini" }, "builtInTools": {}, "options": {} }, "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "typeVersion": 1.3, "position": [ -384, -432 ], "id": "97fa9a5c-2c6b-42b3-b0e0-471d6212e655", "name": "OpenAI Chat Model", "credentials": { "openAiApi": { "id": "k9LlgnkWoOMbNkRw", "name": "OpenAi account 5" } } }, { "parameters": { "sessionIdType": "customKey", "sessionKey": "={{ $json.body.entry[0].messaging[0].sender }}" }, "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow", "typeVersion": 1.3, "position": [ -256, -432 ], "id": "0441b697-72b4-4839-a2c0-e6347eaaff39", "name": "Simple Memory" }, { "parameters": { "method": "POST", "url": "=https://graph.facebook.com/v24.0/{{ $('Webhook').item.json.body.entry[0].messaging[0].recipient.id }}/messages", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"recipient\": {\n \"id\": \"{{ $('Webhook').item.json.body.entry[0].messaging[0].sender.id }}\"\n },\n \"messaging_type\": \"RESPONSE\",\n \"message\": {\n \"text\": \"{{ $json.output }}\"\n }\n}\n", "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ -32, -544 ], "id": "3154dfdd-30e9-4ae9-ab1b-aea50a1693f2", "name": "HTTP Request", "credentials": { "httpHeaderAuth": { "id": "xBzDZHQnQKyjsDvL", "name": "Header Auth account" } } }, { "parameters": { "documentId": { "__rl": true, "value": "1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo", "mode": "list", "cachedResultName": "messenger PSIDs", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": "gid=0", "mode": "list", "cachedResultName": "Sheet1", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit#gid=0" }, "options": { "returnFirstMatch": true } }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ -432, 496 ], "id": "1c88aded-bc5d-426c-b88b-05b2e76c8a56", "name": "Get row(s) in sheet", "credentials": { "googleSheetsOAuth2Api": { "id": "T6R5MYFmKR8onpeW", "name": "Google Sheets account 3" } } }, { "parameters": { "jsCode": "const entries = $json.body.entry || [];\nlet results = [];\n\nfor (const entry of entries) {\n const messagingEvents = entry.messaging || [];\n for (const event of messagingEvents) {\n results.push({\n sender_id: event.sender?.id || null,\n recipient_id: event.recipient?.id || null,\n message_text: event.message?.text || null,\n timestamp: event.timestamp || Date.now()\n });\n }\n}\n\nreturn results.map(r => ({ json: r }));\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -320, -256 ], "id": "d345b0e9-9b7b-43de-9023-7a769d0acfbe", "name": "Extract FB PSIDs" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo", "mode": "list", "cachedResultName": "messenger PSIDs", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": "gid=0", "mode": "list", "cachedResultName": "Sheet1", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit#gid=0" }, "columns": { "mappingMode": "defineBelow", "value": { "recipient_id": "={{ $json.recipient_id }}", "sender_id": "={{ $json.sender_id }}" }, "matchingColumns": [], "schema": [ { "id": "sender_id", "displayName": "sender_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "recipient_id", "displayName": "recipient_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Status", "displayName": "Status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ -32, -256 ], "id": "680efacc-6c78-4f92-bfc1-e18e9e76c67c", "name": "Append row in sheet", "credentials": { "googleSheetsOAuth2Api": { "id": "T6R5MYFmKR8onpeW", "name": "Google Sheets account 3" } } }, { "parameters": { "method": "POST", "url": "=https://graph.facebook.com/v24.0/{{ $('Get row(s) in sheet').item.json.recipient_id }}/messages?access_token=EAAUxvtGtMcYBQLze3G5TRAJZCNSte3HfVGIdorJmy4TwWr0RVCNGJsoeDJNtPDRfoEGjYKr1MYGT9mt6ZCHMl7GZCNTPwFZBwbIEufVVt4j3OWNozshPHTqaihDbxZAMoFpGfuF09ocITjK5a1thtuO4h9yPZBUG2tF9QB7Ccd0tmxGCX8EQyHQ1nGZC04SCBH0fIgmBQZDZD", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"messaging_type\": \"MESSAGE_TAG\",\n \"tag\": \"CONFIRMED_EVENT_UPDATE\", \n \"recipient\": { \"id\": \"{{ $json.sender_id }}\" },\n \"message\": { \"text\": \" Découvrez notre collection de montres exceptionnelle ! Contactez-nous sur WhatsApp au : +212722010440\" }\n}", "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 464, 416 ], "id": "48094ee4-6f4e-4e70-8d39-5996eb6020b2", "name": "HTTP Request1", "alwaysOutputData": true, "credentials": { "httpHeaderAuth": { "id": "xBzDZHQnQKyjsDvL", "name": "Header Auth account" } }, "onError": "continueRegularOutput" }, { "parameters": {}, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 16, 496 ], "id": "99cdd159-2af9-4851-b924-0f5575c79f98", "name": "Wait", "webhookId": "2ffbc2bb-ff19-4161-bbc8-cdc5d4d71cd0" }, { "parameters": { "fieldToSplitOut": "sender_id", "options": {} }, "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [ -208, 496 ], "id": "ad456c76-902e-43a2-8289-1c45ee799771", "name": "Split Out" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo", "mode": "list", "cachedResultName": "messenger PSIDs", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": "gid=0", "mode": "list", "cachedResultName": "Sheet1", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1NGKAVaJIomjNHtQEeakRBfn8dC2Vqj4-CMoDs-y-CFo/edit#gid=0" }, "columns": { "mappingMode": "defineBelow", "value": { "sender_id": "={{ $('Wait').item.json.sender_id }}", "recipient_id": "={{ $('Get row(s) in sheet').item.json.recipient_id }}", "Status": "sent" }, "matchingColumns": [ "sender_id" ], "schema": [ { "id": "sender_id", "displayName": "sender_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "recipient_id", "displayName": "recipient_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "Status", "displayName": "Status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 688, 496 ], "id": "6d4c6a5c-32b0-42b0-ac2b-0b9b3b6f58e5", "name": "Update row in sheet", "credentials": { "googleSheetsOAuth2Api": { "id": "T6R5MYFmKR8onpeW", "name": "Google Sheets account 3" } } }, { "parameters": { "options": {} }, "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, "position": [ 240, 416 ], "id": "a1fd3291-6779-4f14-9bf6-fe8bd6c88474", "name": "Loop Over Items" }, { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -656, 496 ], "id": "63abc121-f1d7-4405-a78f-64e9b8caeb73", "name": "When clicking ‘Execute workflow’" }, { "parameters": { "content": "Messenger BULK Messages ", "height": 432, "width": 1728 }, "type": "n8n-nodes-base.stickyNote", "position": [ -800, 304 ], "typeVersion": 1, "id": "c663176c-a0d3-4ce6-a727-795ddd482059", "name": "Sticky Note" } ], "pinData": {}, "connections": { "Webhook": { "main": [ [ { "node": "If", "type": "main", "index": 0 } ], [ { "node": "AI Agent", "type": "main", "index": 0 }, { "node": "Extract FB PSIDs", "type": "main", "index": 0 } ] ] }, "If": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent", "type": "ai_languageModel", "index": 0 } ] ] }, "Simple Memory": { "ai_memory": [ [ { "node": "AI Agent", "type": "ai_memory", "index": 0 } ] ] }, "AI Agent": { "main": [ [ { "node": "HTTP Request", "type": "main", "index": 0 } ] ] }, "Get row(s) in sheet": { "main": [ [ { "node": "Split Out", "type": "main", "index": 0 } ] ] }, "Extract FB PSIDs": { "main": [ [ { "node": "Append row in sheet", "type": "main", "index": 0 } ] ] }, "Append row in sheet": { "main": [ [] ] }, "HTTP Request1": { "main": [ [ { "node": "Update row in sheet", "type": "main", "index": 0 } ] ] }, "Wait": { "main": [ [ { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "Split Out": { "main": [ [ { "node": "Wait", "type": "main", "index": 0 } ] ] }, "Loop Over Items": { "main": [ [], [ { "node": "HTTP Request1", "type": "main", "index": 0 } ] ] }, "Update row in sheet": { "main": [ [ { "node": "Wait", "type": "main", "index": 0 } ] ] }, "When clicking ‘Execute workflow’": { "main": [ [ { "node": "Get row(s) in sheet", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1", "availableInMCP": false }, "versionId": "ad89715b-8856-4241-a1a5-591b1f2df4c5", "meta": { "templateCredsSetupCompleted": true, "instanceId": "23830929e6c018b604abb710d12ca57ce411c63a552f9a21234ab1d153211b0b" }, "id": "1P9ujUwJy3oiELqB", "tags": [] }