8
n8n 中文网amn8n.com

创建语音和文本Telegram助手(Lookio RAG和GPT-4.1)

高级

这是一个自动化工作流,包含 21 个节点。主要使用 If, Set, Switch, Telegram, HttpRequest 等节点。 使用Lookio RAG和GPT-4.1创建语音和文本Telegram助手

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "cad8de80-6b0b-430c-a3c0-8e6a6a25c393",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        240,
        544
      ],
      "webhookId": "c2c0c3f3-a4d1-4ccb-af97-7269b0debcc2",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "GQHcQvX9GizW5ai3",
          "name": "Duv Brain Telegram"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "3ccede32-2481-454e-9ccb-9e206b32d67f",
      "name": "我自己?",
      "type": "n8n-nodes-base.if",
      "position": [
        464,
        544
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fae16f10-e497-47ea-92ec-741f54cedd62",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message.from.username }}",
              "rightValue": "<Replace with your Telegram username>"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "87342e86-4f25-43ed-ae19-8a495b0888c3",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2256,
        560
      ],
      "parameters": {
        "text": "={{ $json.final_user_message }}",
        "options": {
          "systemMessage": "=You are a helpful assistant that answers the user based on a knowledge base.\n\nWhenever the user query requires specific knowledge (most queries except empty queries like \"hi\"), call the tool \"Query knowledge base\" with a question to have it output an answer based on the knowledge base.\n\nIf the output from the knowledge base tool indicates that the knowledge base doesn't contain enough insights to answer, communicate this to the user transparently.\n\nAnswer considring that this conversation happens on Telegram - adapt your style/format to that platform."
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "e17cfbab-3149-45b3-9903-6b5b8b264b8f",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        2272,
        816
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.from.username }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 7
      },
      "typeVersion": 1.3
    },
    {
      "id": "182a9d2e-8747-48bf-9c8b-ca606915ce7b",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        240
      ],
      "parameters": {
        "color": 2,
        "width": 873,
        "height": 325,
        "content": "# 处理音频"
      },
      "typeVersion": 1
    },
    {
      "id": "5ad3276d-f713-401f-8ee2-de72243eb426",
      "name": "获取音频文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        912,
        400
      ],
      "webhookId": "8f4d5e8a-20ed-41d9-980d-b246f016fb67",
      "parameters": {
        "fileId": "={{ $('Telegram Trigger').item.json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "GQHcQvX9GizW5ai3",
          "name": "Duv Brain Telegram"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4ac926fe-165b-4b11-ad8d-a5ebc040c4fc",
      "name": "消息路由器",
      "type": "n8n-nodes-base.switch",
      "position": [
        688,
        512
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b5d9f703-2a1b-4942-906c-7a7d1404a4d7",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $('Telegram Trigger').item.json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "342f0883-d959-44a2-b80d-379e39c76218",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "49027af2-e53b-4dfc-ac8e-b849cb6c9db6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2400,
        768
      ],
      "parameters": {
        "color": 6,
        "width": 336,
        "height": 400,
        "content": "## Lookio 工具"
      },
      "typeVersion": 1
    },
    {
      "id": "ce0b2d93-2276-47ca-857a-c83a72f0c3e1",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1904,
        768
      ],
      "parameters": {
        "color": 5,
        "width": 336,
        "height": 400,
        "content": "## AI 模型"
      },
      "typeVersion": 1
    },
    {
      "id": "f667095e-cf14-4784-9a55-a4261ae00f1a",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2192,
        320
      ],
      "parameters": {
        "color": 4,
        "width": 352,
        "height": 400,
        "content": "## 代理"
      },
      "typeVersion": 1
    },
    {
      "id": "615e79ce-d872-4b99-96a2-02c9436b63c2",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2032,
        832
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "dMiSy27YCK6c6rra",
          "name": "Duv's OpenAI"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a8da1688-7bfd-4c68-a1da-45523c8628a2",
      "name": "Telegram 回答",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2832,
        560
      ],
      "webhookId": "091fa9ae-790a-4f7e-86c2-b13c184951bc",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.from.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "GQHcQvX9GizW5ai3",
          "name": "Duv Brain Telegram"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1dbd7647-e5ac-449a-8e45-34126b4af8bf",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 265,
        "height": 277,
        "content": "### AI 转录"
      },
      "typeVersion": 1
    },
    {
      "id": "73f644d2-97f9-4718-b0e6-982a44129470",
      "name": "查询知识库",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        2544,
        832
      ],
      "parameters": {
        "url": "https://api.lookio.app/webhook/query",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `The query to the knowledge base, in the form of a question`, 'string') }}"
            },
            {
              "name": "assistant_id",
              "value": "<your-assistant-id>"
            },
            {
              "name": "query_mode",
              "value": "flash"
            }
          ]
        },
        "toolDescription": "Call this tool when the knowledge base is required to answer the user query.",
        "headerParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "<your-lookio-api-key>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "6d132f95-391c-4a97-a8fa-92663fa608f0",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        304
      ],
      "parameters": {
        "color": 3,
        "width": 265,
        "height": 405,
        "content": "### 将此机器人设为私有"
      },
      "typeVersion": 1
    },
    {
      "id": "d4f5488f-f234-4142-b561-4349550c57f5",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        592
      ],
      "parameters": {
        "color": 2,
        "width": 873,
        "height": 293,
        "content": "# 处理文本"
      },
      "typeVersion": 1
    },
    {
      "id": "dd9663af-3587-42c9-bdf0-a6c3cc2ba6d1",
      "name": "从音频准备消息",
      "type": "n8n-nodes-base.set",
      "position": [
        1584,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bffc2c1f-990e-4396-b59a-ab82b843e061",
              "name": "preset_user_message",
              "type": "string",
              "value": "={{ $json.choices[0].message.content }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c18dfaf8-6189-4d78-b0d1-47af2a6e17be",
      "name": "从文本准备消息",
      "type": "n8n-nodes-base.set",
      "position": [
        1168,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b37b48ba-8fef-4e6c-bbca-73e6c2e1e0a8",
              "name": "preset_user_message",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c348dadb-0377-4a6e-9e5e-2f8ec77bd411",
      "name": "整合用户消息",
      "type": "n8n-nodes-base.set",
      "position": [
        1872,
        560
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7db97ffc-b1eb-422e-8bb1-90eea55c7aa2",
              "name": "final_user_message",
              "type": "string",
              "value": "={{ $json.preset_user_message }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a881e44a-f8f4-456e-98e5-51850791967d",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -400
      ],
      "parameters": {
        "width": 880,
        "height": 544,
        "content": "# **带有 Lookio 和 GPT-4.1 的 RAG Telegram 机器人(文本 + 语音)**"
      },
      "typeVersion": 1
    },
    {
      "id": "eda43537-92a0-47f0-ba3f-377b3ba9f5a3",
      "name": "Mistral 转录",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1296,
        400
      ],
      "parameters": {
        "url": "https://api.mistral.ai/v1/audio/transcriptions",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "voxtral-mini-2507"
            },
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "nodeCredentialType": "mistralCloudApi"
      },
      "credentials": {
        "mistralCloudApi": {
          "id": "vakRnCmKyOQFpdEk",
          "name": "Mistral Cloud account"
        }
      },
      "typeVersion": 4.2
    }
  ],
  "connections": {
    "Myself?": {
      "main": [
        [
          {
            "node": "Message Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Telegram answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio File": {
      "main": [
        [
          {
            "node": "Mistral transcribe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Router": {
      "main": [
        [
          {
            "node": "Get Audio File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare message from text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Myself?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Mistral transcribe": {
      "main": [
        [
          {
            "node": "Prepare message from audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query knowledge base": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Consolidate user message": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare message from text": {
      "main": [
        [
          {
            "node": "Consolidate user message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare message from audio": {
      "main": [
        [
          {
            "node": "Consolidate user message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级

需要付费吗?

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

工作流信息
难度等级
高级
节点数量21
分类-
节点类型11
难度说明

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

作者
Guillaume Duvernay

Guillaume Duvernay

@duv

AI and automation expert

外部链接
在 n8n.io 查看

分享此工作流