【问题标题】:Telegram: Cannot send message/photo into a channel with Telegraf (NodeJs)Telegram:无法使用 Telegraf (NodeJs) 将消息/照片发送到频道
【发布时间】:2020-09-10 17:08:14
【问题描述】:

我会使用 telegraf 在电报频道上发送消息。我已邀请该机器人并让他成为管理员。

我已经用这段代码测试过:

bot.on('text', (ctx) => {
  // Explicit usage
  ctx.telegram.sendMessage(ctx.message.chat.id, `Hello ${ctx.state.role}`)

  // Using context shortcut
  // ctx.reply(`Hello ${ctx.state.role}`)
})
bot.launch();

但它只有在我私信时才会回复。 那么为什么它在频道上不起作用呢? 比我如何在没有命令的情况下在该频道中发送消息? (例如 with and 间隔?

我试试这个:

bot.use((ctx) => {
  console.log(ctx.message)
})

当我在私人聊天中(与他)使用机器人时,它会返回所有消息数据。在我收到未定义的频道上

【问题讨论】:

    标签: node.js telegram telegraf telegram-api


    【解决方案1】:

    在您的情况下,CTX 有当前聊天信息,如果您想向频道发送消息,请提供 Telegraf sendMessage 记录的正确 ID:

    telegram.sendMessage(process.env.TELEGRAM_CHANNEL, ctx.message.text);
    

    我正在为公共频道使用机器人,所以在我的情况下是:

    TELEGRAM_CHANNEL=@MY_PUBLIC_CHANNEL_NAME
    

    频道名称可在频道信息设置t.me/MY_PUBLIC_CHANNEL_NAME中找到

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 2019-04-27
      • 2018-11-12
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多