簡體   English   中英

Telegraf框架。 如何使用telegram.forwardMessage();將消息轉發到給定的組,聊天或頻道?

[英]Telegraf framework. how to Forward message to a given group, chat or channel with telegram.forwardMessage();?

問題:我需要將來自aprox 400用戶的消息發送到電報機器人。 僵屍程序會偵聽消息中的特定標簽,並將消息路由到由僵屍程序所聽到的標簽定義的組通道或用戶。 當最終目的地回復時,漫游器需要知道將回復轉發到何處以實現雙向通信(一種方式是用戶通過群聊與整個部門進行通信,另一種方式是從僅向用戶答復的部門中進行通信)

因此,在這種背景下,我決定使用Telegraf Framework來構建機器人。 我是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

該文檔非常清楚,您可以查看官方電報文檔以了解更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM