8
n8n 中文网amn8n.com

多语言语音文本Telegram机器人(ElevenLabs TTS与LangChain代理)

高级

这是一个Support Chatbot, AI Chatbot领域的自动化工作流,包含 18 个节点。主要使用 If, Set, Switch, Telegram, Aggregate 等节点。 集成ElevenLabs语音合成与LangChain代理的多语言语音文本Telegram机器人

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "b01651a347630e90a4bc33ea9cf043eb9b1a7593a0e49cd5542c1c0d34c726d2",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "83497222-5524-4f63-9e45-b1bfe3397de1",
      "name": "Telegram 输入",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1680,
        -60
      ],
      "webhookId": "ec3858d1-90bb-47c3-9012-858bdf043eda",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "743ec068-df01-4bcb-89a4-499da2de1c58",
      "name": "添加 SessionId",
      "type": "n8n-nodes-base.set",
      "position": [
        -1500,
        -60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b5c25cd4-226b-4778-863f-79b13b4a5202",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $json.message.chat.id }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "9bbb8ed4-2458-4072-98bc-ccde13b80af0",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1320,
        -60
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "voice",
              "conditions": {
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a2869917-6c2d-4fe6-b3bb-68fb1f4447f8",
                    "operator": {
                      "type": "string",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text",
              "conditions": {
                "combinator": "and",
                "conditions": [
                  {
                    "id": "ba8aa838-8f6e-41dc-ab08-d44b444b3c5d",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2,
      "alwaysOutputData": false
    },
    {
      "id": "a5e0c4a8-041e-4252-8a77-7f090e565a5c",
      "name": "获取语音文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1120,
        -160
      ],
      "webhookId": "1c4105d0-21d7-4838-a3ff-3d8c5f53431a",
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file"
      },
      "typeVersion": 1.1
    },
    {
      "id": "3fe6c7c4-28ee-4bdb-9db6-67fd4b486b64",
      "name": "Transcribe ElevenLabs",
      "type": "@elevenlabs/n8n-nodes-elevenlabs.elevenLabs",
      "position": [
        -980,
        -160
      ],
      "parameters": {
        "resource": "speech",
        "operation": "speechToText",
        "requestOptions": {},
        "additionalOptions": {}
      },
      "typeVersion": 1
    },
    {
      "id": "c8520675-e456-4ac6-9959-81068c371bd4",
      "name": "编辑字段",
      "type": "n8n-nodes-base.set",
      "position": [
        -840,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "069636d6-2929-4044-8174-905689ef726d",
              "name": "message.text",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "id": "721a7962-d198-485f-8c9f-3e962d83db5f",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('Switch').item.json.sessionId }}"
            },
            {
              "id": "0f39588e-55eb-4bf3-9150-456c6597100c",
              "name": "voice",
              "type": "boolean",
              "value": true
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3eb68b11-1cca-4d03-ba1a-8f4e81199148",
      "name": "聚合",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -620,
        -60
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "5f477900-a311-4b6e-ba2c-7a5460937978",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -720,
        200
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash"
      },
      "typeVersion": 1
    },
    {
      "id": "4948f23a-ddde-4973-963c-cfe1aec5119a",
      "name": "Groq 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        -560,
        200
      ],
      "parameters": {
        "model": "deepseek-r1-distill-llama-70b",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "dddd3d08-b63c-4a64-9def-e694ca2efd47",
      "name": "语音助手",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -420,
        -60
      ],
      "parameters": {
        "text": "={{ $json.data[0].message.text }}",
        "options": {
          "systemMessage": "You are the woman **CoinMarketCap AI Data Analyst**, a powerful, multi-source crypto intelligence system that integrates three specialized agents..."
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "b459ce91-2261-4fc4-8cc0-8e39d2093512",
      "name": "如果是语音",
      "type": "n8n-nodes-base.if",
      "position": [
        -60,
        -60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "combinator": "and",
          "conditions": [
            {
              "id": "290be484-45fd-497f-917e-00df36476bf2",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Aggregate').item.json.data[0].voice }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "73d99c4c-c968-44ef-9196-94e5b372051c",
      "name": "ElevenLabs",
      "type": "@elevenlabs/n8n-nodes-elevenlabs.elevenLabs",
      "position": [
        160,
        -160
      ],
      "parameters": {
        "text": "={{ $('Voice Assistant').item.json.output }}",
        "voice": {
          "mode": "list",
          "value": "9BWtsMINqrJLrRacOk9x",
          "cachedResultName": "Aria"
        },
        "resource": "speech",
        "requestOptions": {},
        "additionalOptions": {
          "model": {
            "mode": "list",
            "value": "eleven_multilingual_v2"
          },
          "languageCode": "={{ $('Telegram Input').item.json.message.from.language_code }}",
          "outputFormat": "opus_48000_64"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4b661df9-08fc-498f-ae5f-945956120287",
      "name": "Telegram 发送消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        160,
        20
      ],
      "webhookId": "fe51631a-9bde-41e5-a12c-357f00377dd7",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Input').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b68da635-54b8-4c42-8c72-2b12cc805b12",
      "name": "Telegram 发送语音消息",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        380,
        -160
      ],
      "parameters": {
        "url": "https://api.telegram.org/bot{{$credentials.telegramToken}}/sendVoice",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $('Telegram Input').item.json.message.chat.id }}"
            },
            {
              "name": "voice",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "multipart/form-data"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "420ec75a-87e4-4d29-b4b7-81299cc42760",
      "name": "语音助手记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -420,
        200
      ],
      "parameters": {
        "sessionKey": "={{ $json.data[0].sessionId }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "73674764-4bfd-4fc1-91ad-42ad03aae79d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -440,
        -300
      ],
      "parameters": {
        "width": 300,
        "height": 180,
        "content": "**自动语言检测**:"
      },
      "typeVersion": 1
    },
    {
      "id": "6a439698-ca32-4188-a6ba-ac427cf995eb",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        120
      ],
      "parameters": {
        "width": 300,
        "height": 300,
        "content": "🎙️ 语音/文本路由逻辑"
      },
      "typeVersion": 1
    },
    {
      "id": "d12487ce-023d-468d-9204-ebf4d86df3d8",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -280,
        140
      ],
      "parameters": {
        "width": 380,
        "height": 440,
        "content": "## 🛠️ 自定义工具集成"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Get Voice File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If voice": {
      "main": [
        [
          {
            "node": "ElevenLabs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Voice Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ElevenLabs": {
      "main": [
        [
          {
            "node": "Telegram send voice message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Adds SessionId": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Voice File": {
      "main": [
        [
          {
            "node": "Transcribe ElevenLabs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        []
      ]
    },
    "Voice Assistant": {
      "main": [
        [
          {
            "node": "If voice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe ElevenLabs": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Voice Assistant Memory": {
      "ai_memory": [
        [
          {
            "node": "Voice Assistant",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Voice Assistant",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客服机器人, AI 聊天机器人

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流