Telegram sendMessage ignores botId and sends message via the wrong bot

当你在 LobeChat 中配置了多个 Telegram bot provider(分属不同 agent),再通过消息工具调用 sendMessage 时,消息没有走你传入的 botId ,而是走了“最后保存的那个 Telegram bot”。这通常发生在消息工具运行时的凭据解析环节,优先排查凭据是

快速结论:当你在 LobeChat 中配置了多个 Telegram bot provider(分属不同 agent),再通过消息工具调用 sendMessage 时,消息没有走你传入的 botId,而是走了“最后保存的那个 Telegram bot”。这通常发生在消息工具运行时的凭据解析环节,优先排查凭据是否按 botId/applicationId 过滤。

适用环境:LobeChat 桌面端(Electron)、Windows、自托管 Docker 部署,版本 2.2.2。Issue 未提供 Python、CUDA、显卡或依赖版本信息。

最快修复方案:暂无确认的一步修复方案。该问题被判断为消息工具运行时的凭据解析逻辑缺陷,需要修改代码让凭据解析按传入的 botId/applicationId 过滤,而非仅按平台类型取第一个可用 provider。

注意事项:仅在配置了多个 Telegram bot provider 时才会暴露该问题;单一 Telegram bot 环境下通常不会触发。相关修复 PR #15268 只处理了 webhook 的 installation 解析,并未修复工具运行时里的 agent-bot 绑定,不要误以为合并后就已解决。

问题场景

用户在 LobeChat 中为不同 agent 配置了多个 Telegram bot provider,然后在某个 agent 中调用消息工具的 sendMessageplatform = telegrambotId = 3e4c6085-fdb7-4697-9ccd-332b16a37931channelId 为指定 Telegram 聊天 ID、content 为测试消息。工具返回成功,但实际上消息是通过“另一个 agent 下最后保存的 Telegram bot”发出的,而不是传入 botId 对应的 bot。

报错原文

Telegram sendMessage ignores botId and sends message via the wrong bot

Tool result says:
Message sent to telegram:<chat_id>

Actual behavior:
The message was sent through the last saved Telegram bot, which is configured under another agent, instead of the Telegram bot associated with the provided botId.

原因分析

根据 Issue 讨论,根因在于 sendMessage 被调用时的凭据解析逻辑:它按平台类型(”telegram”)查询 provider,并返回**最近更新的已启用 provider**,而没有按传入的 botId/applicationId 过滤。具体来说,findEnabledByPlatform() 查询按 updatedAt 降序返回第一个匹配项,忽略了当前指定的是哪个 agent 或哪个 botId,因此表现为“总是用最后保存的 bot”。

对比之下,Webhook 路由会通过 applicationId 正确匹配 bot,但消息工具执行路径没有应用相同的过滤。此外,PR #15268 中的多消息路由修复只解决了 webhook 的 installation 解析,并未处理工具运行时中的 agent-bot 绑定。

环境排查

  • 确认 LobeChat 版本(Issue 中为 2.2.2 桌面端 Electron)。
  • 确认是否配置了多个 Telegram bot provider,并分别绑定到不同 agent。
  • 确认调用时传入的 botId 与目标 agent 下 bot provider 的 applicationId/botId 是否一致。
  • 确认这些 bot provider 的启用状态与 updatedAt 顺序,判断是否与“被发错的那个 bot”一致。
  • Issue 未提供 Python、CUDA、PyTorch、显卡或依赖版本,无需据此排查。

解决步骤

  1. 先做最小复现:保留两个及以上 Telegram bot provider,分别在两个 agent 下,按 Issue 的调用方式传入明确的 botId,观察实际接收消息的 bot。
  2. 对照消息工具运行时中的凭据解析代码(src/server/services/toolExecution/serverRuntimes/message/index.ts 附近),确认 findEnabledByPlatform() 是否按 updatedAt 降序取首个 telegram provider,而没有使用传入的 botId/applicationId
  3. 可优先尝试:在凭据解析中加入按 botId/applicationId 过滤,使其与 webhook 路由(src/server/services/bot/BotMessageRouter.ts)的匹配逻辑保持一致。
  4. 修改后重启服务/桌面端,重新执行相同调用进行验证。

验证方法

在多个 agent 各自配置不同 Telegram bot 的前提下,向指定的 botId 调用 sendMessage,确认消息是由该 botId 对应的 bot 发出,而不是最后保存的那个 bot;同时确认其他 agent 的 bot 不再收到误发的消息。

参考来源

lobehub/lobe-chat #15511

相关代码与 PR:message runtime 凭据解析BotMessageRouterfindEnabledByPlatformPR #15268

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 25331

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注