This workflow corresponds to n8n.io template #9192 — 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 →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "7a2d3e40-921b-4f3e-b744-6de691988fb1",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "7b74805b-56d7-42dd-9f86-e00fac90f0cc",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1216,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "b3c91dc3-d19b-4f7d-9677-2f34a578590e",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
2208,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "ac913ab6-1fb1-4abf-bae0-9d7a7db5fbb3",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1072,
336
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "536f5f3e-6a86-46a8-a215-edb22a977173",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
336
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "452fdb7f-16d2-4a8a-be73-07764edff67a",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2240,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "ea973e23-685b-4a70-9176-5e0672655850",
"name": "Facebook Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
-1040,
64
],
"parameters": {},
"typeVersion": 2.1
},
{
"id": "1c260d50-1bf6-4a61-bc3f-1d0b98d83221",
"name": "Set Context",
"type": "n8n-nodes-base.set",
"position": [
-624,
160
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "de00ed02-4023-4a56-9dfe-f7d8300dcfd8",
"name": "Format for Facebook Output",
"type": "n8n-nodes-base.code",
"position": [
2304,
176
],
"parameters": {},
"typeVersion": 2
},
{
"id": "8f2d505a-a5ed-4aeb-9c70-f7b5d675b2e9",
"name": "Google Gemini Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
1824,
480
],
"parameters": {},
"typeVersion": 1
},
{
"id": "ff2edabd-80b5-44ac-b602-cff359a147f5",
"name": "Get 15 newest rows",
"type": "n8n-nodes-base.code",
"position": [
1472,
160
],
"parameters": {},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "57d2a6e8-a18a-47ae-9ae8-930a5d7ab972",
"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": [
2752,
192
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "17967446-b270-4576-b52d-5cd141c05933",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"notes": "Loop tu\u1ea7n t\u1ef1 qua t\u1eebng tin nh\u1eafn",
"position": [
2528,
176
],
"parameters": {},
"typeVersion": 3
},
{
"id": "1c7ec8ce-a21f-427f-8c9d-8fba1bf4345b",
"name": "Confirm Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
-848,
16
],
"parameters": {},
"typeVersion": 1.5
},
{
"id": "1228a3d3-5f0f-4934-b17a-f0151bdcd09e",
"name": "Is from page?",
"type": "n8n-nodes-base.if",
"position": [
-432,
160
],
"parameters": {},
"typeVersion": 2.3,
"alwaysOutputData": false
},
{
"id": "dee50a44-f9af-48e1-9113-0d678c732102",
"name": "Seen",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
80,
32
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "be60963c-2782-4c4e-8c89-9add21264a58",
"name": "Get history message",
"type": "n8n-nodes-base.dataTable",
"position": [
1264,
160
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "610a8af0-e903-4c87-bf47-1317cc578a02",
"name": "Send Typing",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
1968,
32
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "63ab2861-57c3-47c9-88ed-b92ddb9abd72",
"name": "Process Merged Message",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1920,
176
],
"parameters": {},
"retryOnFail": true,
"typeVersion": 3.1,
"waitBetweenTries": 100
},
{
"id": "f7b4b760-8d20-4200-9aa9-0bfd314c882d",
"name": "Send Text",
"type": "n8n-nodes-base.httpRequest",
"position": [
2976,
192
],
"parameters": {},
"typeVersion": 4.3
},
{
"id": "f6517b9e-09b1-4bab-b863-b013dc8ceb65",
"name": "Update Page Rep",
"type": "n8n-nodes-base.dataTable",
"position": [
2960,
48
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "fdf6a5bd-8435-4b57-bd3f-2d7c207c7d80",
"name": "Update FALSE to TRUE",
"type": "n8n-nodes-base.dataTable",
"position": [
2736,
48
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "6425fb79-e97b-4a8e-ba26-8136cacb0694",
"name": "Is message",
"type": "n8n-nodes-base.if",
"position": [
-848,
160
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "52c096bf-d57d-412e-81e5-78aeb028165d",
"name": "User is Sender",
"type": "n8n-nodes-base.set",
"position": [
-208,
160
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "9e91d080-9ab4-4c73-ac3c-8dc1b539c649",
"name": "Insert To Unprocessed",
"type": "n8n-nodes-base.dataTable",
"position": [
80,
160
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "929380ee-a254-4cd1-81b6-04a01070301c",
"name": "Wait",
"type": "n8n-nodes-base.wait",
"position": [
288,
160
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "916f920c-4bfd-4572-9bc5-92ecd28235ff",
"name": "Get unprocessed message",
"type": "n8n-nodes-base.dataTable",
"position": [
496,
160
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "9ad15b87-bd8b-41fc-9ae5-7d86b4288a19",
"name": "Get Max ID + Merged Mess",
"type": "n8n-nodes-base.code",
"position": [
720,
160
],
"parameters": {},
"typeVersion": 2
},
{
"id": "2093f057-77e7-4f45-93e1-d5907c6fb77a",
"name": "Is Max ID?",
"type": "n8n-nodes-base.if",
"position": [
912,
160
],
"parameters": {},
"typeVersion": 2.3
},
{
"id": "bdc76cde-b290-444d-a96e-75b6f0f54ff4",
"name": "Merge History and Find MinID",
"type": "n8n-nodes-base.code",
"position": [
1680,
160
],
"parameters": {},
"typeVersion": 2,
"alwaysOutputData": true
},
{
"id": "e6604ced-4443-4620-b089-2f8cc3d12524",
"name": "Clean History",
"type": "n8n-nodes-base.dataTable",
"position": [
3152,
48
],
"parameters": {},
"typeVersion": 1.1,
"alwaysOutputData": true
},
{
"id": "633ae695-402b-4ce5-b303-5e7403dc7ce4",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1072,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "956cc3e1-bdeb-4a60-a2fc-c869c0d25e06",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1520,
-768
],
"parameters": {
"content": ""
},
"typeVersion": 1
}
],
"connections": {
"Wait": {
"main": [
[
{
"node": "Get unprocessed message",
"type": "main",
"index": 0
}
]
]
},
"Send Text": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Is Max ID?": {
"main": [
[
{
"node": "Get history message",
"type": "main",
"index": 0
}
],
[]
]
},
"Is message": {
"main": [
[
{
"node": "Set Context",
"type": "main",
"index": 0
}
]
]
},
"Set Context": {
"main": [
[
{
"node": "Is from page?",
"type": "main",
"index": 0
}
]
]
},
"Is from page?": {
"main": [
[],
[
{
"node": "User is Sender",
"type": "main",
"index": 0
}
]
]
},
"User is Sender": {
"main": [
[
{
"node": "Seen",
"type": "main",
"index": 0
},
{
"node": "Insert To Unprocessed",
"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
}
]
]
},
"Get 15 newest rows": {
"main": [
[
{
"node": "Merge History and Find MinID",
"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": "Wait",
"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
}
]
]
},
"Get unprocessed message": {
"main": [
[
{
"node": "Get Max ID + Merged Mess",
"type": "main",
"index": 0
}
]
]
},
"Get Max ID + Merged Mess": {
"main": [
[
{
"node": "Is Max ID?",
"type": "main",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "Process Merged Message",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Format for Facebook Output": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Merge History and Find MinID": {
"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/9192/ — 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.
by Nguyen Thieu Toan (Jay Nguyen)
Main-2.0. Uses agent, lmChatGoogleGemini, outputParserStructured, httpRequestTool. Webhook trigger; 37 nodes.
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.