【问题标题】:How to properly implement the forwarding of a message from a bot to a telegram channel?如何正确实现将消息从机器人转发到电报频道?
【发布时间】:2021-10-23 15:48:41
【问题描述】:

我有一个错误。我不明白如何将消息从电报机器人转发到频道。我用telegraf.js 发送第一条消息后,想发送第二条,转发第一条。第一张照片是机器人中的答案。第二张照片是进入频道的。

我实现的代码本身:

bot.on('message', async (ctx) => {
  const getFilmId = await kinoInfo(ctx.message.text);
  const infoFilm = getFilmId.data.data;
  const id = infoFilm.filmId;

  const name = infoFilm.nameRu;

  ctx.reply(name, {
    reply_markup: {
      inline_keyboard: [
        [{ text: `Watch`, url: 'https://www.instagram.com/' }],
        [{ text: 'Telegram channel 1', callback_data: 'ONE' }],
      ],
    },
  });

  bot.on('callback_query', (ctx) => {
    const data = ctx.update.callback_query.data;
    if (data === 'ONE') {
      postToChannel(ctx);
    }
  });

  const postToChannel = (ctx) => {
    ctx.telegram.sendMessage('@fgdsfsdfsd', name, {
      parse_mode: 'html',
      reply_markup: {
        inline_keyboard: [[{ text: `Watch`, url: 'https://www.instagram.com/' }]],
      },
    });
  };
});

First photo

Second photo

【问题讨论】:

    标签: javascript node.js telegram-bot telegraf


    【解决方案1】:

    postToChannel 函数中使用ForwardMessage() 方法。并指定message_id 我有一个可行的解决方案。欢迎您!

    【讨论】: