2

The problem: I need to get messages from aprox 400 users to a telegram bot. the bot hears for specific tags in the message and routes the messages to a group channel or user defined by the tag that the bot hears. when the final destination replys the bot needs to know where to forward that reply to achieve 2 way communication (one way is user to a whole department in a groupchat and the other way if from the department who answers only to the user)

so with this background I decided to use Telegraf Framework to build the bot. i'm new to JS and all relative technologies but it seems to be the best choice for this task. I'm trying to use the telegram.forwardMessage(); method but I'm not sure exactly how to populate the arguments the method needs.

the telegraf documentation shows

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

but can't find any example of a practical use of the method

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

tdurnford
  • 3,632
  • 2
  • 6
  • 15
Kike_mskt
  • 45
  • 1
  • 6

1 Answers1

2

an example would be

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

in your case fromWhereToSend would be ctx.message.chat.id and the whatIdToSend would be ctx.message.message_id

The documentation is quite clear and you can check the official telegram documentation for more

painor
  • 1,119
  • 1
  • 8
  • 25
  • I'm new to this and english is not my native language. I'm not undertanding well the documentation. let me try this solution and thanks for your kind reply – Kike_mskt Sep 07 '19 at 17:37
  • ok I think i'm not understanding the concept of telegraf. if my bot receives a message. how can I access it? if I can acces that message I can poll every ID to reply forward etc etc. am I right? – Kike_mskt Sep 09 '19 at 15:06
  • the message object is `ctx.message` . bot.hears("whatever",(ctx)=>{ let mesage_id = ctx.message.message_id; let chat_id = ctx.message.chat.id; let sender_id = ctx.message.from.id; } – painor Sep 09 '19 at 15:31
  • that thing is what I wasn't understanding. thankyou now I can build my solution – Kike_mskt Sep 09 '19 at 15:58