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