{
  "name": " Smart human takeover & auto pause AI-powered Facebook Messenger chatbot",
  "nodes": [
    {
      "id": "8231a8c9-bc7f-45a4-afbe-0a64f8bc00a5",
      "name": "Facebook Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        160,
        2112
      ]
    },
    {
      "id": "25331c8f-bf5f-4ece-8727-830d5297d0a2",
      "name": "Set Context",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        2128
      ]
    },
    {
      "id": "a379bafc-8aad-494e-8e7e-86cddde5cd5d",
      "name": "Format for Facebook Output",
      "type": "n8n-nodes-base.code",
      "position": [
        4000,
        2512
      ]
    },
    {
      "id": "2f9046ff-80f8-4f27-b4a4-3df90ff11a99",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        3536,
        2752
      ]
    },
    {
      "id": "9993ea41-4d0e-456c-93a7-cbd2fa9daaa3",
      "name": "Get 15 newest rows",
      "type": "n8n-nodes-base.code",
      "position": [
        3040,
        2400
      ]
    },
    {
      "id": "3af0adfb-4a24-4cc3-90ac-5d90de35949a",
      "name": "Delay Between Messages",
      "type": "n8n-nodes-base.wait",
      "position": [
        4400,
        2528
      ]
    },
    {
      "id": "efc9e138-4776-4a8c-86ce-d6d5c36d2dc1",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        4192,
        2512
      ]
    },
    {
      "id": "2863c166-db11-46a0-9219-46f91924b029",
      "name": "Comparison time",
      "type": "n8n-nodes-base.set",
      "position": [
        1680,
        2048
      ]
    },
    {
      "id": "0b016590-727f-42dd-bf2a-8cd4584c9e9d",
      "name": "Is still Pause?",
      "type": "n8n-nodes-base.if",
      "position": [
        1936,
        2048
      ]
    },
    {
      "id": "7f998fe9-9b57-4555-be66-b9903413742c",
      "name": "Merge History and Find Min_ID",
      "type": "n8n-nodes-base.code",
      "position": [
        3232,
        2400
      ]
    },
    {
      "id": "ed680ef1-f69e-4195-bc46-b60788eab997",
      "name": "User is Reciepient",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        1888
      ]
    },
    {
      "id": "ae661c01-2023-4a87-9f94-3d25c0c90556",
      "name": "User is Sender",
      "type": "n8n-nodes-base.set",
      "position": [
        1024,
        2144
      ]
    },
    {
      "id": "bf100583-a714-471b-b7a9-33931085f3aa",
      "name": "Insert to Paused List",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1680,
        1888
      ]
    },
    {
      "id": "abb5fa73-63ee-46c0-95f6-11615b64bbe4",
      "name": "Remove from Paused List",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        2208,
        2048
      ]
    },
    {
      "id": "ca7bbf15-08b8-4f31-ab40-fbabc31a6dbf",
      "name": "Confirm Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        400,
        2016
      ]
    },
    {
      "id": "63f9b569-f368-4d2a-9866-53be6390f77e",
      "name": "Is from page?",
      "type": "n8n-nodes-base.if",
      "position": [
        816,
        2128
      ]
    },
    {
      "id": "ff7f04c1-ce80-4b33-823f-788c7068cfe1",
      "name": "Is from AI?",
      "type": "n8n-nodes-base.if",
      "position": [
        1360,
        1888
      ]
    },
    {
      "id": "24bd07c6-d9f7-4411-baf0-eb2a481de405",
      "name": "Insert human rep",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1936,
        1888
      ]
    },
    {
      "id": "db3b33a9-cdf9-426e-953c-8c119bc17951",
      "name": "Seen",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2480,
        2160
      ]
    },
    {
      "id": "3a1ba4c3-82ac-4bdc-a4c3-129c376320d4",
      "name": "Insert To Processed",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        2208,
        1888
      ]
    },
    {
      "id": "07c08ce9-4ddf-4750-a4e0-6bb4a8a6a3ed",
      "name": "Insert To Unprocessed",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        2480,
        2400
      ]
    },
    {
      "id": "4e69c66f-3c88-4ed7-8b02-894462242371",
      "name": "Get history message",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        2848,
        2400
      ]
    },
    {
      "id": "979dd07f-c2bc-4b8b-982d-f348a2178dcb",
      "name": "Send Typing",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3552,
        2192
      ]
    },
    {
      "id": "e8a1c2f1-fd27-444d-b5cc-6d4b26bfa6a8",
      "name": "Process Merged Message",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3552,
        2512
      ]
    },
    {
      "id": "87c091c3-da21-4bd0-8c7a-402cc15ec7e9",
      "name": "Send Text",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4608,
        2528
      ]
    },
    {
      "id": "ac1f7635-f1c0-4216-9ea2-04657d110289",
      "name": "Update Page Rep",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        4464,
        2256
      ]
    },
    {
      "id": "be329203-b6d7-48be-8da9-121ec2d54018",
      "name": "Update FALSE to TRUE",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        4304,
        2256
      ]
    },
    {
      "id": "6971f109-9243-460a-8509-34ca54c49c0d",
      "name": "Clean History",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        4608,
        2256
      ]
    },
    {
      "id": "d9eeba67-b3ad-43ae-a6c8-1c6a64d501cf",
      "name": "Is message",
      "type": "n8n-nodes-base.if",
      "position": [
        400,
        2144
      ]
    },
    {
      "id": "c5920797-10a2-4f60-80b1-db0f74528cb1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "18d8521d-0547-44ed-88c3-f2dfa3865be8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2400,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "c737f348-f1b5-456b-852a-2a6200ae910a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3392,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "1979f2a3-8a4b-49b8-b175-d049ab2aeafa",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        2320
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "a813d096-ea4e-44a7-8b0d-1542683da19b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        2320
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "649a920b-ceae-4a0a-b7ca-24c62393392e",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "1cbc90c5-cc4e-4996-b9e4-c2deb8049547",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "7f3dc277-5e63-441d-bb03-7a65c1c69854",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3952,
        1152
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "80bdcbe0-2a95-46df-b996-b57432bdadf7",
      "name": "Check Paused List",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1264,
        2144
      ]
    },
    {
      "id": "5ff3e545-1644-4588-9525-8aefc3c3ae9f",
      "name": "In Paused List?",
      "type": "n8n-nodes-base.if",
      "position": [
        1472,
        2144
      ]
    },
    {
      "id": "dc8c379f-bb27-459e-88e6-6f86de461799",
      "name": "Get MaxID and Merged Mess",
      "type": "n8n-nodes-base.code",
      "position": [
        2672,
        2400
      ]
    }
  ],
  "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
          }
        ]
      ]
    }
  }
}