I used the code given here to receive new message from the user but it does not work when a new message arrives in the telegram channel.
@bot.on(events.NewMessage)
async def my_event_handler(event):
print(event.stringify())
Setting events.NewMessage(chat='chat')
or events.NewMessage(chat='channel')
didn’t work.
How can a telegram bot get new message event from a telegram channel ?
2
Answers
For a bot to receive all messages, you first need to configure it in @BotFather by disabling the bot privacy:
With that done, add the bot as admin to your broadcast channel (they can’t be normal members here). Your code should look like this:
If you want to handle messages from all broadcast channels your group is in, use a more advanced filter:
If you only want to get the message text instead of the entire json, you can try this