bot-myrtus / forward

Provides a message forwarding feature.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] 🐛 TG 无法发送至指定话题

Harry-zklcdc opened this issue · comments

版本信息

Koishi 4.16.8
@myrtus/koishi-plugin-forward 3.9.1

配置文件

image
image
image

日志文件

2024-02-14 16:56:49 [E] forward Error: Telegram API error 400. Bad Request: chat not found
    at _Internal.<computed> [as sendMessage] (koishi/node_modules/@satorijs/adapter-telegram/lib/index.js:88:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _TelegramMessageEncoder.flush (koishi/node_modules/@satorijs/adapter-telegram/lib/index.js:465:22)
    at async _TelegramMessageEncoder.send (koishi/node_modules/@satorijs/core/lib/index.cjs:571:5)
    at async _TelegramBot.sendMessage (koishi/node_modules/@satorijs/core/lib/index.cjs:336:22)
    at async Proxy.<anonymous> (koishi/node_modules/@myrtus/koishi-plugin-forward/lib/core.js:164:40)

猜测可能下面这行代码导致

const messageIds = await bot.sendMessage(target.channelId, payload, target.guildId)

Koishi 的 bot.sendMessage 方法不支持 guildId 了,文档:https://koishi.chat/zh-CN/api/resources/message.html#bot-getmessage

可能需要特殊判断,使用 telegram 适配器内部方法 internal.sendMessage() 代替

查看 tg 适配器源码,发现其读取的是 session 的guildId

https://github.com/satorijs/satori/blob/27822a0d4412a824ac46594fa2681a0e2d1109d5/adapters/telegram/src/message.ts#L38-L44

将报告代码修改为

const messageIds = await ctx.broadcast([target.platform+':'+target.channelId], payload)

即可正常工作

已发布 4.0.1,请在更新后重新填写频道 ID

依旧还是无法正常运行,能需要修改报告的那一行代码才可以运行

依旧还是无法正常运行,能需要修改报告的那一行代码才可以运行

截图配置

constants:
  TgFeed:
    type: full
    platform: telegram
    selfId: '67****'
    channelId: '5'
    name: TG Feed
  TgAsk:
    type: full
    platform: telegram
    selfId: '67****'
    channelId: '4'
    name: TG 求助提问
  TgChat:
    type: full
    platform: telegram
    selfId: '67****'
    channelId: '-10****'
    name: TG 闲聊灌水
  TgFeature:
    type: full
    platform: telegram
    selfId: '67****'
    channelId: '206'
    name: TG 功能需求
  QQFeed:
    type: full
    platform: qqguild
    selfId: '82****'
    channelId: '63****'
    name: QQ Feed
  QQAsk:
    type: full
    platform: qqguild
    selfId: '82****'
    channelId: '63****'
    name: QQ频道 求助提问
  QQChat:
    type: full
    platform: qqguild
    selfId: '82****'
    channelId: '63****'
    name: QQ频道 闲聊灌水
  QQFeature:
    type: full
    platform: qqguild
    selfId: '82****'
    channelId: '63****'
    name: QQ频道 功能需求
rules:
  - targets:
      - QQFeed
    source: TgFeed
  - targets:
      - TgFeed
    source: QQFeed
  - targets:
      - TgAsk
    source: QQAsk
  - targets:
      - QQAsk
    source: TgAsk
  - targets:
      - TgChat
    source: QQChat
  - targets:
      - QQChat
    source: TgChat
  - targets:
      - TgFeature
    source: QQFeature
  - targets:
      - QQFeature
    source: TgFeature

channelId 不对,请使用 inspect 插件获取

image

使用 ctx.broadcast 方法吧,bot.sendMessage 在 tg 适配器的实现中,并不是直接读取 guildId 的

参考: https://github.com/satorijs/satori/blob/27822a0d4412a824ac46594fa2681a0e2d1109d5/adapters/telegram/src/message.ts#L38-L44

image

使用 ctx.broadcast 方法吧,bot.sendMessage 在 tg 适配器的实现中,并不是直接读取 guildId 的

参考: https://github.com/satorijs/satori/blob/27822a0d4412a824ac46594fa2681a0e2d1109d5/adapters/telegram/src/message.ts#L38-L44

4.0.1 没有读取 guildId