8
n8n 中文网amn8n.com

Telegram AI 机器人转人工销售电话交接

高级

这是一个Sales, AI领域的自动化工作流,包含 39 个节点。主要使用 If, Code, Redis, Switch, Telegram 等节点,结合人工智能技术实现智能自动化。 Telegram AI 机器人转人工销售电话交接

前置要求
  • Redis 服务器连接信息
  • Telegram Bot Token
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "5d6a5a45-8aa8-4c34-aa10-5dd85f05de9d",
      "name": "使用发送并等待进行人工交接",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1580,
        1040
      ],
      "webhookId": "d2bbc82f-0509-470a-af4d-9d92cfed4d5f",
      "parameters": {
        "chatId": "=<human chat id>",
        "message": "=chatId: {{ $('Handoff Subworkflow').first().json.chatId }}\nsessionId: {{ $('Handoff Subworkflow').first().json.sessionId }}\nuser: {{ $('Handoff Subworkflow').first().json.username }} ({{ $('Handoff Subworkflow').item.json.userId }})\n\nSummary:\n{{ $('Handoff Subworkflow').item.json.summary }}\n\n---\nThis user has now been handed off to a human.\nClick the button to return user to bot.",
        "options": {},
        "operation": "sendAndWait",
        "responseType": "freeText"
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5d2f73ff-b233-4456-b34d-d5a5454dabda",
      "name": "将交互设置为机器人",
      "type": "n8n-nodes-base.redis",
      "position": [
        1780,
        1040
      ],
      "parameters": {
        "key": "=handoff_{{ $('Handoff Subworkflow').first().json.sessionId }}_state",
        "value": "bot",
        "keyType": "string",
        "operation": "set"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f799e213-f3ed-4479-aade-7a7c38eb5792",
      "name": "将交互设置为人工",
      "type": "n8n-nodes-base.redis",
      "position": [
        1380,
        1040
      ],
      "parameters": {
        "key": "=handoff_{{ $json.sessionId }}_state",
        "value": "=human",
        "keyType": "string",
        "operation": "set"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "059c9b8c-ba50-4bdd-8969-6f5f35bba304",
      "name": "获取交互状态",
      "type": "n8n-nodes-base.redis",
      "position": [
        -800,
        820
      ],
      "parameters": {
        "key": "=handoff_{{ $json.message.chat.id }}_state",
        "options": {},
        "operation": "get",
        "propertyName": "data"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8afd48ff-478d-4092-ac88-fb2e435ded00",
      "name": "模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -280,
        640
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "19c5ef66-410d-47fd-9b2a-19776c53a681",
      "name": "记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        -160,
        640
      ],
      "parameters": {
        "sessionKey": "=handoff_{{ $('Telegram Trigger').first().json.message.chat.id }}_chat",
        "sessionIdType": "customKey"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "814e464d-a2e0-4ae1-83d1-df3732d3b430",
      "name": "交接子工作流",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        980,
        1040
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "chatId"
            },
            {
              "name": "sessionId"
            },
            {
              "name": "userId"
            },
            {
              "name": "username"
            },
            {
              "name": "summary"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "53c311ca-b7ad-4705-97c9-f6438a6c6b4e",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1000,
        820
      ],
      "webhookId": "e905dd99-eefc-48ff-a62d-c7078e9bb216",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "ea54c9f7-8ebc-4146-a4ec-6d05957f340d",
      "name": "发送响应",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1400,
        340
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "=Thank you. I've now transferred you to a human agent who will reach out to you. Once complete, you can come back to this chat to finish the process.",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7f895e2a-7aee-40be-a8b7-b2b0ff469b2d",
      "name": "切换交互",
      "type": "n8n-nodes-base.switch",
      "position": [
        -620,
        820
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Human",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6bc61072-f7cf-4a6d-af81-36abede59d47",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data }}",
                    "rightValue": "human"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Bot",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6882db64-b522-4895-8949-d98d87b53b49",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data }}",
                    "rightValue": "bot"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Onboarding"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "df203358-e6c7-4014-8e2b-ef934e331215",
      "name": "信息提取器",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        440,
        460
      ],
      "parameters": {
        "text": "={{\n$json.data\n  .reverse()\n  .slice(0, 5)\n  .map(item => item.parseJson())\n  .map(item => `${item.type}: ${item.data.content}`)\n  .join('\\n')\n}}",
        "options": {
          "systemPromptTemplate": "Analyse the conversation history and extract the required customer details. If not found, leave blank."
        },
        "attributes": {
          "attributes": [
            {
              "name": "firstname",
              "required": true,
              "description": "first name of customer"
            },
            {
              "name": "lastname",
              "required": true,
              "description": "last name of customer"
            },
            {
              "name": "address_and_postcode",
              "required": true,
              "description": "address and postcode of customer"
            },
            {
              "name": "reason_for_call",
              "required": true,
              "description": "a summary of the reason for the call"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "35bc11d2-6024-425b-ac67-a61ff26b9478",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        420,
        640
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "20d71c5f-6e84-4b45-b324-0706ecd3a681",
      "name": "使用默认值",
      "type": "n8n-nodes-base.code",
      "position": [
        760,
        460
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return {\n  \"firstname\": \"\",\n  \"lastname\": \"\",\n  \"address_and_postcode\": \"\",\n  \"reason_for_call\": \"\",\n  ...$input.item.json.output,\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "76344f79-1afa-4fd9-9c01-ca3818f62f37",
      "name": "满足所有条件?",
      "type": "n8n-nodes-base.if",
      "position": [
        920,
        460
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "96d4a43f-aa0f-486a-b692-0105196d099a",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ Object.values($json).every(val => Boolean(val)) }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f76c1032-036b-46ad-91da-023d5af931fd",
      "name": "入职代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -240,
        460
      ],
      "parameters": {
        "text": "={{ $('Telegram Trigger').first().json.message.text }}",
        "options": {
          "systemMessage": "=You are a prescreen assistant whose task is to get the following details from a customer before handing them over to a human agent.\n* first name\n* last name\n* address and postcode\n* reason for calling - capture exact wording if possible.\n\nOnce all data is gathered, hand the user off to a human agent."
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "0a5b19a5-9c19-436c-b1d3-23d962efd23e",
      "name": "获取入职聊天历史",
      "type": "n8n-nodes-base.redis",
      "position": [
        280,
        460
      ],
      "parameters": {
        "key": "=handoff_{{ $('Telegram Trigger').first().json.message.chat.id }}_chat",
        "options": {},
        "operation": "get",
        "propertyName": "data"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4f247eb3-78f0-4ec1-8713-1373da07b5f3",
      "name": "售后代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        340,
        1000
      ],
      "parameters": {
        "text": "={{ $('Telegram Trigger').item.json.message.text }}",
        "options": {
          "systemMessage": "You are an aftersales agent helping the user answer questions about their recent purchase."
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "bce26253-f7da-49e8-952b-52e14eb4f9b5",
      "name": "记忆1",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        420,
        1180
      ],
      "parameters": {
        "sessionKey": "=handoff_{{ $('Telegram Trigger').first().json.message.chat.id }}_chat2",
        "sessionIdType": "customKey",
        "contextWindowLength": 30
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "51c4549b-559c-400d-9951-dde0953ade4c",
      "name": "模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        300,
        1180
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "63b8d9e8-7af2-4103-a365-ca5471bd7b36",
      "name": "交接工具",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        540,
        1180
      ],
      "parameters": {
        "name": "handoff_to_human",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "调用此工具以根据客户请求交接或转交给人工代理。确保首先获取交接原因的摘要。",
        "workflowInputs": {
          "value": {
            "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id.toString() }}",
            "userId": "={{ $('Telegram Trigger').first().json.message.from.id.toString() }}",
            "summary": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('summary', `Reason for human hand-off`, 'string') }}",
            "username": "={{ $('Telegram Trigger').first().json.message.from.username }}",
            "sessionId": "={{ $('Telegram Trigger').first().json.message.chat.id.toString() }}"
          },
          "schema": [
            {
              "id": "chatId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "chatId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sessionId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sessionId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "userId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "userId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "9a2b9077-0ead-4f2c-9e83-05ee341ff697",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1080,
        580
      ],
      "parameters": {
        "color": 7,
        "width": 660,
        "height": 460,
        "content": "## 1. 检查传入消息的交互状态"
      },
      "typeVersion": 1
    },
    {
      "id": "ccca9a5c-595a-4c58-9316-933a8234ab91",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        260
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 520,
        "content": "## 2. 入职代理验证客户"
      },
      "typeVersion": 1
    },
    {
      "id": "2d859430-1326-4cbc-a5cc-3af0d091e5c0",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        260
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 520,
        "content": "## 3. 从对话中提取客户详细信息"
      },
      "typeVersion": 1
    },
    {
      "id": "754f0859-8af7-4a15-8e46-c9ad62b55bf3",
      "name": "交接子工作流1",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1220,
        340
      ],
      "parameters": {
        "mode": "each",
        "options": {
          "waitForSubWorkflow": false
        },
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "workflowInputs": {
          "value": {
            "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id.toString() }}",
            "userId": "={{ $('Telegram Trigger').first().json.message.from.id.toString() }}",
            "summary": "=name: {{ $json.firstname }} {{ $json.lastname }}\naddress: {{ $json.address_and_postcode }}\nsummary: {{ $json.reason_for_call }}",
            "username": "={{ $('Telegram Trigger').first().json.message.from.username }}",
            "sessionId": "={{ $('Telegram Trigger').first().json.message.chat.id.toString() }}"
          },
          "schema": [
            {
              "id": "chatId",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "chatId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sessionId",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "sessionId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "userId",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "userId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6f92128f-14dc-4b0a-b098-3d9535ac11e3",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        140
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 640,
        "content": "## 4. 满足条件时进行人工交接"
      },
      "typeVersion": 1
    },
    {
      "id": "14500c4f-da43-460f-bf4d-80d0a2f4537b",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 440,
        "content": "## 5. 转交给人工"
      },
      "typeVersion": 1
    },
    {
      "id": "4d74d479-8525-4b64-8291-e2b3058edeaa",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        800
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 520,
        "content": "## 6. 交互切换回机器人"
      },
      "typeVersion": 1
    },
    {
      "id": "a1c064d9-cc74-475d-b233-9deb4dfa81d7",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        820
      ],
      "parameters": {
        "color": 7,
        "width": 1580,
        "height": 560,
        "content": "## 7. 交互子工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "33684768-2f21-4f30-9e56-934171b215fc",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -260
      ],
      "parameters": {
        "width": 440,
        "height": 1320,
        "content": "## 试用一下"
      },
      "typeVersion": 1
    },
    {
      "id": "187ca5ef-c804-4aca-8ad9-3c4b11676fbf",
      "name": "发送响应2",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2320,
        1040
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "=Hello again! I'm now ready to answer any remaining questions you may have.",
        "chatId": "={{ $('Handoff Subworkflow').first().json.chatId }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ab036106-84f2-4cf7-a5ad-7706a9e5ea0a",
      "name": "记忆2",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        1980,
        1200
      ],
      "parameters": {
        "sessionKey": "=handoff_{{ $('Handoff Subworkflow').first().json.chatId }}_chat2",
        "sessionIdType": "customKey",
        "contextWindowLength": 30
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1.5
    },
    {
      "id": "9d9d1aee-5632-499c-968d-63a555cc58d8",
      "name": "更新代理记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        1980,
        1040
      ],
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "ai",
              "message": "=Report from human agent says \"{{ $('Human Handoff using Send and Wait').first().json.data.text }}\"",
              "hideFromUI": true
            },
            {
              "type": "ai",
              "message": "Hello again! I'm now ready to answer any remaining questions you may have."
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8da2fefa-e51f-4258-8ded-e0f20db87641",
      "name": "发送响应3",
      "type": "n8n-nodes-base.telegram",
      "position": [
        680,
        1000
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f027afe0-0fd2-47a2-a0f8-f0d78f8fbc18",
      "name": "获取预设响应",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -180,
        1000
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "=This conversation has been handed-off to a human agent who will be in contact soon if not done so already. I cannot respond to your query until the human agent transfers you back to me.",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a1ada0c7-779e-44bc-bdbd-1d5285bedf3c",
      "name": "通知用户",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1180,
        1040
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "=You have now been transferred to a human. Unfortunately, I will not be able to respond until the human agent transfers you back to me.",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "31287a38-e7a7-4518-9f54-6e6c9b2486fe",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        1020
      ],
      "parameters": {
        "width": 220,
        "height": 320,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a58a82b9-2c37-4137-9b3e-17479c78a2d2",
      "name": "记忆3",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "position": [
        1580,
        500
      ],
      "parameters": {
        "sessionKey": "=handoff_{{ $('Telegram Trigger').first().json.message.chat.id }}_chat2",
        "sessionIdType": "customKey",
        "contextWindowLength": 30
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1.5
    },
    {
      "id": "4d3d5b46-6e82-4b97-9e5f-76f02ff79ce5",
      "name": "更新代理记忆1",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        1580,
        340
      ],
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "ai",
              "message": "=The person I'm speaking to has the following details:\nfirstname: {{ $('Handoff Subworkflow1').first().json.firstname }}\nlastname: {{ $('Handoff Subworkflow1').first().json.firstname }}\nreason for call: {{ $('Handoff Subworkflow1').first().json.reason_for_call }}",
              "hideFromUI": true
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "ced46068-440b-46b4-aa51-b5bb9d59a004",
      "name": "继续对话",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1220,
        580
      ],
      "webhookId": "55ecb0ba-72c8-4f16-a6c8-0c0bb8582554",
      "parameters": {
        "text": "={{ $('Onboarding Agent').first().json.output }}",
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "XVBXGXSsaCjU2DOS",
          "name": "jimleuk_handoff_bot"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "pinData": {},
  "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
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 销售, 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量39
分类2
节点类型15
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Jimleuk

Jimleuk

@jimleuk

Freelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at hello@jimle.uk LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk

外部链接
在 n8n.io 查看

分享此工作流