Search code examples
telegramtelegram-botpython-telegram-bot

How to get the message_id of a forwarded message in telegram


I want to get the original id of a message forwarded from a channel to my bot. I mean the ID of that message in that channel. I use the Python Telegram Bot library. This library had update.message.forward_from_message_id in versions before 21, but now I can't find an Alternative for it.


Solution

  • The Message object will have a forward_origin property if the message was forwarded to the bot and the sender information is visible.

    The forward_origin property will be of type MessageOrigin as per the documentation. Since, you've mentioned the message might be forwarded from the channel you'll receive a MessageOriginChannel object and hence you can get the message_id of the original message as follows: Message.forward_origin.message_id.

    Hope this helps.