This workflow corresponds to n8n.io template #11920 — we link there as the canonical source.
This workflow follows the Agent → Datatable recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"nodes": [
{
"id": "8231a8c9-bc7f-45a4-afbe-0a64f8bc00a5",
"name": "Facebook Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
160,
2112
],
"parameters": {},
"typeVersion": 2.1
},
{
"id": "25331c8f-bf5f-4ece-8727-830d5297d0a2",
"name": "Set Context",
"type": "n8n-nodes-base.set",
"position": [
624,
2128
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "a379bafc-8aad-494e-8e7e-86cddde5cd5d",
"name": "Format for Facebook Output",
"type": "n8n-nodes-base.code",
"position": [
4000,
2512
],
"parameters": {},
"typeVersion": 2
},
{
"id": "2f9046ff-80f8-4f27-b4a4-3df90ff11a99",
"name": "Google Gemini Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
3536,
2752
],
"parameters": {},
"typeVersion": 1
},
{
"id": "9993ea41-4d0e-456c-93a7-cbd2fa9daaa3",
"name": "Get 15 newest rows",
"type": "n8n-nodes-base.code",
"position": [
3040,
2400
],
"parameters": {},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "3af0adfb-4a24-4cc3-90ac-5d90de35949a",
"name": "Delay Between Messages",
"type": "n8n-nodes-base.wait",
"notes": "Delay 100ms gi\u1eefa c\u00e1c tin nh\u1eafn \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1",
"position": [
4400,
2528
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "efc9e138-4776-4a8c-86ce-d6d5c36d2dc1",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"notes": "Loop tu\u1ea7n t\u1ef1 qua t\u1eebng tin nh\u1eafn",
"position": [
4192,
2512
],
"parameters": {},
"typeVersion": 3
},
{
"id": "2863c166-db11-46a0-9219-46f91924b029",
"name": "Comparison time",
"type": "n8n-nodes-base.set",
"position": [
1680,
2048
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "0b016590-727f-42dd-bf2a-8cd4584c9e9d",
"name": "Is still Pause?",
"type": "n8n-nodes-base.if",
"position": [
1936,
2048
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "7f998fe9-9b57-4555-be66-b9903413742c",
"name": "Merge History and Find Min_ID",
"type": "n8n-nodes-base.code",
"position": [
3232,
2400
],
"parameters": {},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "ed680ef1-f69e-4195-bc46-b60788eab997",
"name": "User is Reciepient",
"type": "n8n-nodes-base.set",
"position": [
1040,
1888
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "ae661c01-2023-4a87-9f94-3d25c0c90556",
"name": "User is Sender",
"type": "n8n-nodes-base.set",
"position": [
1024,
2144
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "bf100583-a714-471b-b7a9-33931085f3aa",
"name": "Insert to Paused List",
"type": "n8n-nodes-base.dataTable",
"position": [
1680,
1888
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "abb5fa73-63ee-46c0-95f6-11615b64bbe4",
"name": "Remove from Paused List",
"type": "n8n-nodes-base.dataTable",
"position": [
2208,
2048
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "ca7bbf15-08b8-4f31-ab40-fbabc31a6dbf",
"name": "Confirm Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
400,
2016
],
"parameters": {},
"typeVersion": 1.5
},
{
"id": "63f9b569-f368-4d2a-9866-53be6390f77e",
"name": "Is from page?",
"type": "n8n-nodes-base.if",
"position": [
816,
2128
],
"parameters": {},
"typeVersion": 2.3,
"alwaysOutputData": false
},
{
"id": "ff7f04c1-ce80-4b33-823f-788c7068cfe1",
"name": "Is from AI?",
"type": "n8n-nodes-base.if",
"position": [
1360,
1888
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "24bd07c6-d9f7-4411-baf0-eb2a481de405",
"name": "Insert human rep",
"type": "n8n-nodes-base.dataTable",
"position": [
1936,
1888
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "db3b33a9-cdf9-426e-953c-8c119bc17951",
"name": "Seen",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
2480,
2160
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "3a1ba4c3-82ac-4bdc-a4c3-129c376320d4",
"name": "Insert To Processed",
"type": "n8n-nodes-base.dataTable",
"position": [
2208,
1888
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "07c08ce9-4ddf-4750-a4e0-6bb4a8a6a3ed",
"name": "Insert To Unprocessed",
"type": "n8n-nodes-base.dataTable",
"position": [
2480,
2400
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "4e69c66f-3c88-4ed7-8b02-894462242371",
"name": "Get history message",
"type": "n8n-nodes-base.dataTable",
"position": [
2848,
2400
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "979dd07f-c2bc-4b8b-982d-f348a2178dcb",
"name": "Send Typing",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
3552,
2192
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "e8a1c2f1-fd27-444d-b5cc-6d4b26bfa6a8",
"name": "Process Merged Message",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
3552,
2512
],
"parameters": {},
"retryOnFail": true,
"typeVersion": 3.1,
"waitBetweenTries": 100
},
{
"id": "87c091c3-da21-4bd0-8c7a-402cc15ec7e9",
"name": "Send Text",
"type": "n8n-nodes-base.httpRequest",
"position": [
4608,
2528
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "ac1f7635-f1c0-4216-9ea2-04657d110289",
"name": "Update Page Rep",
"type": "n8n-nodes-base.dataTable",
"position": [
4464,
2256
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "be329203-b6d7-48be-8da9-121ec2d54018",
"name": "Update FALSE to TRUE",
"type": "n8n-nodes-base.dataTable",
"position": [
4304,
2256
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "6971f109-9243-460a-8509-34ca54c49c0d",
"name": "Clean History",
"type": "n8n-nodes-base.dataTable",
"position": [
4608,
2256
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "d9eeba67-b3ad-43ae-a6c8-1c6a64d501cf",
"name": "Is message",
"type": "n8n-nodes-base.if",
"position": [
400,
2144
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "c5920797-10a2-4f60-80b1-db0f74528cb1",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1184,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "18d8521d-0547-44ed-88c3-f2dfa3865be8",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
2400,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "c737f348-f1b5-456b-852a-2a6200ae910a",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
3392,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "1979f2a3-8a4b-49b8-b175-d049ab2aeafa",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
2320
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "a813d096-ea4e-44a7-8b0d-1542683da19b",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1184,
2320
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "649a920b-ceae-4a0a-b7ca-24c62393392e",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-544,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "1cbc90c5-cc4e-4996-b9e4-c2deb8049547",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "7f3dc277-5e63-441d-bb03-7a65c1c69854",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
3952,
1152
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "80bdcbe0-2a95-46df-b996-b57432bdadf7",
"name": "Check Paused List",
"type": "n8n-nodes-base.dataTable",
"position": [
1264,
2144
],
"parameters": {},
"executeOnce": false,
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "5ff3e545-1644-4588-9525-8aefc3c3ae9f",
"name": "In Paused List?",
"type": "n8n-nodes-base.if",
"position": [
1472,
2144
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "dc8c379f-bb27-459e-88e6-6f86de461799",
"name": "Get MaxID and Merged Mess",
"type": "n8n-nodes-base.code",
"position": [
2672,
2400
],
"parameters": {},
"typeVersion": 2
}
],
"connections": {
"Send Text": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Is message": {
"main": [
[
{
"node": "Set Context",
"type": "main",
"index": 0
}
]
]
},
"Is from AI?": {
"main": [
[],
[
{
"node": "Insert to Paused List",
"type": "main",
"index": 0
}
]
]
},
"Set Context": {
"main": [
[
{
"node": "Is from page?",
"type": "main",
"index": 0
}
]
]
},
"Is from page?": {
"main": [
[
{
"node": "User is Reciepient",
"type": "main",
"index": 0
}
],
[
{
"node": "User is Sender",
"type": "main",
"index": 0
}
]
]
},
"User is Sender": {
"main": [
[
{
"node": "Check Paused List",
"type": "main",
"index": 0
}
]
]
},
"Comparison time": {
"main": [
[
{
"node": "Is still Pause?",
"type": "main",
"index": 0
}
]
]
},
"In Paused List?": {
"main": [
[
{
"node": "Comparison time",
"type": "main",
"index": 0
}
],
[
{
"node": "Insert To Unprocessed",
"type": "main",
"index": 0
},
{
"node": "Seen",
"type": "main",
"index": 0
}
]
]
},
"Is still Pause?": {
"main": [
[
{
"node": "Insert To Processed",
"type": "main",
"index": 0
}
],
[
{
"node": "Remove from Paused List",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[
{
"node": "Update FALSE to TRUE",
"type": "main",
"index": 0
}
],
[
{
"node": "Delay Between Messages",
"type": "main",
"index": 0
}
]
]
},
"Update Page Rep": {
"main": [
[
{
"node": "Clean History",
"type": "main",
"index": 0
}
]
]
},
"Facebook Webhook": {
"main": [
[
{
"node": "Confirm Webhook",
"type": "main",
"index": 0
}
],
[
{
"node": "Confirm Webhook",
"type": "main",
"index": 0
},
{
"node": "Is message",
"type": "main",
"index": 0
}
]
]
},
"Check Paused List": {
"main": [
[
{
"node": "In Paused List?",
"type": "main",
"index": 0
}
]
]
},
"Get 15 newest rows": {
"main": [
[
{
"node": "Merge History and Find Min_ID",
"type": "main",
"index": 0
}
]
]
},
"User is Reciepient": {
"main": [
[
{
"node": "Is from AI?",
"type": "main",
"index": 0
}
]
]
},
"Get history message": {
"main": [
[
{
"node": "Get 15 newest rows",
"type": "main",
"index": 0
}
]
]
},
"Update FALSE to TRUE": {
"main": [
[
{
"node": "Update Page Rep",
"type": "main",
"index": 0
}
]
]
},
"Insert To Unprocessed": {
"main": [
[
{
"node": "Get MaxID and Merged Mess",
"type": "main",
"index": 0
}
]
]
},
"Insert to Paused List": {
"main": [
[
{
"node": "Insert human rep",
"type": "main",
"index": 0
}
]
]
},
"Delay Between Messages": {
"main": [
[
{
"node": "Send Text",
"type": "main",
"index": 0
}
]
]
},
"Process Merged Message": {
"main": [
[
{
"node": "Format for Facebook Output",
"type": "main",
"index": 0
}
]
]
},
"Remove from Paused List": {
"main": [
[
{
"node": "Insert To Unprocessed",
"type": "main",
"index": 0
},
{
"node": "Seen",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "Process Merged Message",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Get MaxID and Merged Mess": {
"main": [
[
{
"node": "Get history message",
"type": "main",
"index": 0
}
]
]
},
"Format for Facebook Output": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Merge History and Find Min_ID": {
"main": [
[
{
"node": "Send Typing",
"type": "main",
"index": 0
},
{
"node": "Process Merged Message",
"type": "main",
"index": 0
}
]
]
}
}
}
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
by Nguyen Thieu Toan (Jay Nguyen)
Source: https://n8n.io/workflows/11920/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Main-2.0. Uses agent, lmChatGoogleGemini, outputParserStructured, httpRequestTool. Webhook trigger; 37 nodes.
by Nguyen Thieu Toan (Jay Nguyen)
This workflow turns your Instagram Business or Creator account into an AI-powered customer support chatbot using Google Gemini and n8n Data Table for persistent conversation history. Every incoming Di
⏺ 🚀 How it works
CLINICAINTEGRAL_secretary. Uses postgres, mcpClientTool, googleDriveTool, toolWorkflow. Webhook trigger; 89 nodes.