Search code examples
pythontelegramtelepot

how to forward a message from the bot(not a person) to a chat


I want to forward the whole conversation of my bot and another person to myself

This is my code:

import telepot
bot = telepot.Bot('<Token>')
def handle(msg):
    my_id = 123456789    # this is my id for example
    chat_id = telepot.glance(msg)[2]
    bot_msg = bot.sendMessage(chat_id, 'this message is sent by bot')
    bot.forwardMessage(my_id, bot_msg['from']['id'], bot_msg['message_id']) # this line gets error

But when I try to forward messages from bot I get this error:

telepot.exception.TelegramError: ('Bad Request: message to forward not found', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: message to forward not found'})

Am I doing somthing wrong? or It's just restricted by telegram?


Solution

  • Second param to forward should be originating chat id, not user id. Try calling:

    bot.forwardMessage(my_id, bot_msg['chat']['id'], bot_msg['message_id'])