{
  "name": "Telegram AI bot-to-human handoff for sales calls",
  "nodes": [
    {
      "id": "5d6a5a45-8aa8-4c34-aa10-5dd85f05de9d",
      "name": "Human Handoff using Send and Wait",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1580,
        1040
      ]
    },
    {
      "id": "5d2f73ff-b233-4456-b34d-d5a5454dabda",
      "name": "Set Interaction to Bot",
      "type": "n8n-nodes-base.redis",
      "position": [
        1780,
        1040
      ]
    },
    {
      "id": "f799e213-f3ed-4479-aade-7a7c38eb5792",
      "name": "Set Interaction to Human",
      "type": "n8n-nodes-base.redis",
      "position": [
        1380,
        1040
      ]
    },
    {
      "id": "059c9b8c-ba50-4bdd-8969-6f5f35bba304",
      "name": "Get Interaction State",
      "type": "n8n-nodes-base.redis",
      "position": [
        -800,
        820
      ]
    },
    {
      "id": "8afd48ff-478d-4092-ac88-fb2e435ded00",
      "name": "Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -280,
        640
      ]
    },
    {
      "id": "19c5ef66-410d-47fd-9b2a-19776c53a681",
      "name": "Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        -160,
        640
      ]
    },
    {
      "id": "814e464d-a2e0-4ae1-83d1-df3732d3b430",
      "name": "Handoff Subworkflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        980,
        1040
      ]
    },
    {
      "id": "53c311ca-b7ad-4705-97c9-f6438a6c6b4e",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1000,
        820
      ]
    },
    {
      "id": "ea54c9f7-8ebc-4146-a4ec-6d05957f340d",
      "name": "Send Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1400,
        340
      ]
    },
    {
      "id": "7f895e2a-7aee-40be-a8b7-b2b0ff469b2d",
      "name": "Switch Interaction",
      "type": "n8n-nodes-base.switch",
      "position": [
        -620,
        820
      ]
    },
    {
      "id": "df203358-e6c7-4014-8e2b-ef934e331215",
      "name": "Information Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        440,
        460
      ]
    },
    {
      "id": "35bc11d2-6024-425b-ac67-a61ff26b9478",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        420,
        640
      ]
    },
    {
      "id": "20d71c5f-6e84-4b45-b324-0706ecd3a681",
      "name": "With Defaults",
      "type": "n8n-nodes-base.code",
      "position": [
        760,
        460
      ]
    },
    {
      "id": "76344f79-1afa-4fd9-9c01-ca3818f62f37",
      "name": "Has All Criteria?",
      "type": "n8n-nodes-base.if",
      "position": [
        920,
        460
      ]
    },
    {
      "id": "f76c1032-036b-46ad-91da-023d5af931fd",
      "name": "Onboarding Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -240,
        460
      ]
    },
    {
      "id": "0a5b19a5-9c19-436c-b1d3-23d962efd23e",
      "name": "Get Onboarding Chat History",
      "type": "n8n-nodes-base.redis",
      "position": [
        280,
        460
      ]
    },
    {
      "id": "4f247eb3-78f0-4ec1-8713-1373da07b5f3",
      "name": "After Sales Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        340,
        1000
      ]
    },
    {
      "id": "bce26253-f7da-49e8-952b-52e14eb4f9b5",
      "name": "Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        420,
        1180
      ]
    },
    {
      "id": "51c4549b-559c-400d-9951-dde0953ade4c",
      "name": "Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        300,
        1180
      ]
    },
    {
      "id": "63b8d9e8-7af2-4103-a365-ca5471bd7b36",
      "name": "Handoff Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        540,
        1180
      ]
    },
    {
      "id": "9a2b9077-0ead-4f2c-9e83-05ee341ff697",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1080,
        580
      ],
      "parameters": {
        "width": 660,
        "height": 460,
        "content": "## 1. Check Interaction State For Incoming Message\n[Learn more about the telegram trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.telegramtrigger/)\n\nThis is an example o"
      }
    },
    {
      "id": "ccca9a5c-595a-4c58-9316-933a8234ab91",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        260
      ],
      "parameters": {
        "width": 560,
        "height": 520,
        "content": "## 2. Onboarding Agent to Validate Customers\n[Read more about Agents](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent)\n\nThis agent unlike the common multi-t"
      }
    },
    {
      "id": "2d859430-1326-4cbc-a5cc-3af0d091e5c0",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        260
      ],
      "parameters": {
        "width": 880,
        "height": 520,
        "content": "## 3. Extract Customer Details from Conversation\n[Learn more about the Information Extractor](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.information-extracto"
      }
    },
    {
      "id": "754f0859-8af7-4a15-8e46-c9ad62b55bf3",
      "name": "Handoff Subworkflow1",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1220,
        340
      ]
    },
    {
      "id": "6f92128f-14dc-4b0a-b098-3d9535ac11e3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        140
      ],
      "parameters": {
        "width": 800,
        "height": 640,
        "content": "## 4. Human Handoff when Criteria Met\n[Learn more about subworkflows](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflow)\n\nHere, we initiate the hand-off which calls ou"
      }
    },
    {
      "id": "14500c4f-da43-460f-bf4d-80d0a2f4537b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        800
      ],
      "parameters": {
        "width": 520,
        "height": 440,
        "content": "## 5. Defer to Human\n\nWhen session state is \"human\", no further user messages can reach the agent. This is to ensure there isn't a parallel conversation happening which may confuse the human and agent"
      }
    },
    {
      "id": "4d74d479-8525-4b64-8291-e2b3058edeaa",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        800
      ],
      "parameters": {
        "width": 720,
        "height": 520,
        "content": "## 6. Interaction Switched Back to Bot\n[Read more about the Customer Workflow Tool](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow/)\n\nWhen the sessio"
      }
    },
    {
      "id": "a1c064d9-cc74-475d-b233-9deb4dfa81d7",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        820
      ],
      "parameters": {
        "width": 1580,
        "height": 560,
        "content": "## 7. Interaction Subworkflow\n[Learn more about n8n's human-in-the-loop feature](https://docs.n8n.io/advanced-ai/examples/human-fallback/)\n\nThe hand-off implementation here involves a \"human-in-the-lo"
      }
    },
    {
      "id": "33684768-2f21-4f30-9e56-934171b215fc",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -260
      ],
      "parameters": {
        "width": 440,
        "height": 1320,
        "content": "## Try it out\n### This n8n template demonstrates an approach to perform bot-to-human handoff using Human-in-the-loop functionality as a switch.\n\nIn this experiment, we play with the idea of states we "
      }
    },
    {
      "id": "187ca5ef-c804-4aca-8ad9-3c4b11676fbf",
      "name": "Send Response2",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2320,
        1040
      ]
    },
    {
      "id": "ab036106-84f2-4cf7-a5ad-7706a9e5ea0a",
      "name": "Memory2",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        1980,
        1200
      ]
    },
    {
      "id": "9d9d1aee-5632-499c-968d-63a555cc58d8",
      "name": "Update Agent Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        1980,
        1040
      ]
    },
    {
      "id": "8da2fefa-e51f-4258-8ded-e0f20db87641",
      "name": "Send Response3",
      "type": "n8n-nodes-base.telegram",
      "position": [
        680,
        1000
      ]
    },
    {
      "id": "f027afe0-0fd2-47a2-a0f8-f0d78f8fbc18",
      "name": "Get Canned Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -180,
        1000
      ]
    },
    {
      "id": "a1ada0c7-779e-44bc-bdbd-1d5285bedf3c",
      "name": "Notify user",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1180,
        1040
      ]
    },
    {
      "id": "31287a38-e7a7-4518-9f54-6e6c9b2486fe",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        1020
      ],
      "parameters": {
        "width": 220,
        "height": 320,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### Add Human Chat ID\nThis is needed to notify the human agent."
      }
    },
    {
      "id": "a58a82b9-2c37-4137-9b3e-17479c78a2d2",
      "name": "Memory3",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        1580,
        500
      ]
    },
    {
      "id": "4d3d5b46-6e82-4b97-9e5f-76f02ff79ce5",
      "name": "Update Agent Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        1580,
        340
      ]
    },
    {
      "id": "ced46068-440b-46b4-aa51-b5bb9d59a004",
      "name": "Continue Conversation",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1220,
        580
      ]
    }
  ],
  "connections": {
    "Model": {
      "ai_languageModel": [
        [
          {
            "node": "Onboarding Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Memory": {
      "ai_memory": [
        [
          {
            "node": "Onboarding Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Model1": {
      "ai_languageModel": [
        [
          {
            "node": "After Sales Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Memory1": {
      "ai_memory": [
        [
          {
            "node": "After Sales Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Memory2": {
      "ai_memory": [
        [
          {
            "node": "Update Agent Memory",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Memory3": {
      "ai_memory": [
        [
          {
            "node": "Update Agent Memory1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Notify user": {
      "main": [
        [
          {
            "node": "Set Interaction to Human",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Tool": {
      "ai_tool": [
        [
          {
            "node": "After Sales Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Send Response": {
      "main": [
        [
          {
            "node": "Update Agent Memory1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "With Defaults": {
      "main": [
        [
          {
            "node": "Has All Criteria?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Onboarding Agent": {
      "main": [
        [
          {
            "node": "Get Onboarding Chat History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Get Interaction State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "After Sales Agent": {
      "main": [
        [
          {
            "node": "Send Response3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has All Criteria?": {
      "main": [
        [
          {
            "node": "Handoff Subworkflow1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Continue Conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Switch Interaction": {
      "main": [
        [
          {
            "node": "Get Canned Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "After Sales Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Onboarding Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Subworkflow": {
      "main": [
        [
          {
            "node": "Notify user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Agent Memory": {
      "main": [
        [
          {
            "node": "Send Response2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handoff Subworkflow1": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Interaction State": {
      "main": [
        [
          {
            "node": "Switch Interaction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "With Defaults",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Interaction to Bot": {
      "main": [
        [
          {
            "node": "Update Agent Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Interaction to Human": {
      "main": [
        [
          {
            "node": "Human Handoff using Send and Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Onboarding Chat History": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human Handoff using Send and Wait": {
      "main": [
        [
          {
            "node": "Set Interaction to Bot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}