Telegraf框架。如何使用telegram.forwardMessage();将消息转发到给定的组,聊天或频道?

时间:2019-09-06 15:46:12

标签: javascript telegram telegram-bot node-telegram-bot-api

问题:我需要将来自aprox 400用户的消息发送到电报机器人。僵尸程序会侦听消息中的特定标签,并将消息路由到由僵尸程序所听到的标签定义的组通道或用户。当最终目的地答复时,机器人需要知道将答复转发到何处以实现双向通信(一种方式是用户通过小组聊天传递给整个部门,另一种方式是从仅答复用户的部门发送给另一部门)

因此在这种背景下,我决定使用Telegraf Framework来构建机器人。我是JS和所有相关技术的新手,但这似乎是完成此任务的最佳选择。我正在尝试使用telegram.forwardMessage();方法,但我不确定如何填充该方法所需的参数。

telefgraf文档显示

telegram.forwardMessage(chatId, fromChatId, messageId, [extra]) => Promise

但找不到该方法的实际使用示例

const Telegraf = require('telegraf');   // Module to use Telegraf API.
const {Extra, Markup} = Telegraf;   // Extract Extra, Markups from Telegraf module.
const config = require('./config'); // Configuration file that holds telegraf_token API key.

const bot = new Telegraf(config.mon_telegraf_token) //this line extracts the variable where the api token is stored
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me message with the destination #TAG '))
bot.hears('hi', (ctx) => ctx.reply('Hey there')) //just playing around 
bot.hears('#RH', (ctx) => ctx.telegram.forwardMessage()) //aditionally need to reply to the user a confirmation that the message sent correctly and can't send a new message in 5 minutes

1 个答案:

答案 0 :(得分:0)

一个例子是

ctx.telegram.forwardMessage(whereToSendId, fromWhereToSendId, whatIdToSend).then(function(){
console.log("mesage forwaded")
});

在您的情况下,fromWhereToSendctx.message.chat.id,而whatIdToSendctx.message.message_id

文档非常清楚,您可以查看官方电报文档以了解更多信息