javascript - Telegram 框架。如何使用 telegram.forwardMessage(); 将消息转发到给定的群组、聊天或 channel ?

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

问题:我需要将大约 400 个用户的消息发送到 Telegram Bot 。机器人会监听消息中的特定标签,并将消息路由到由机器人监听的标签定义的组 channel 或用户。当最终目的地回复时,机器人需要知道将该回复转发到哪里,以实现两种方式的通信(一种方式是用户在群聊中发送给整个部门,另一种方式是来自只回复用户的部门)

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

telegraf 文档显示

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

最佳答案

一个例子是

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

在您的情况下,fromWhereToSend将为ctx.message.chat.idwhatIdToSend将为ctx.message.message_id

文档相当清晰,更多内容可以查看telegram官方文档

关于javascript - Telegram 框架。如何使用 telegram.forwardMessage(); 将消息转发到给定的群组、聊天或 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57825092/

相关文章:

javascript - 在 MxGraph 中单击获取顶点文本

javascript - 每次 iframe 使用 iframe 值重新加载时更新父值

javascript - 在nodejs模块中自执行函数被认为是一个好的实践吗?

c# - 如何从字节数组创建文件并将其发送到 TelegramBot

python - Telegram Bot API - 上传带有文件名的文档

c# - 使用 Telegram - API 接收照片

Javascript `this` - 包含对象的引用

c# - Sql 数据库中的字符串是问号 C#

java - 线程 "main"java.lang.NoClassDefFoundError : com/google/inject/Module 中出现异常

go - 如何使用 Telegram bot API 查找消息的文件唯一 ID?