yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.3k stars 1.5k forks source link

event new message #1009

Closed pedroota closed 1 year ago

pedroota commented 1 year ago

Hey, folks! I'm building a bot and I want to use it as a backup bot for my telegram channels. How it should work? Well, when a message be sent on one channel, the bot should automatically send in another given channel. How can I do it?

danielperez9430 commented 1 year ago

You have the update "channel_post". Use example:

bot.on('channel_post', (msg) => {
 console.log(msg)
})
pedroota commented 1 year ago

You have the update "channel_post". Use example:

bot.on('channel_post', (msg) => {
 console.log(msg)
})

Ok, but how can I take this messages from a given channel? For example, I can take one channel ID and for every new message, a sent this message in another channel. How can I specify the channel I want to take the "channel_post"?

danielperez9430 commented 1 year ago

That event captures all the events that are publications in a channels where you have the bot as an administrator. The event returns a message type object that includes the id of the channel where the publication is from, ....

Using that information at the end of the day is to put an if(msg.from.chat.id === XX...) because for example you use the method copyMessage.

If you use the piece of code that I passed before in the console you can see what the object you receive looks like