0
votes

I am trying to forward a message in telegram bot API in python . It shows "Bad Request: chat_id is empty" despite using same chat_id in sendMessage and works perfectly fine.

https://api.telegram.org/bot{BOT_TOKEN}/forwardMessage?chat_id={CHAT_ID}&from_chat_id={ID}&message_id={MID}

my problem is what is the message id and how can i find it? for example chat id is like this number 123456789.

what does message id look like ?

2

2 Answers

0
votes

You are a bot. So, people interact with you (directly or in a group). When a message is sent to your bot, you would receive a callback that includes the message details (including the chat_id, the sender chat id, the message id, and all other details). Something like this (see message->message_id and message->from_id):

{ 
   "update_id":1111,
   "message":{ 
      "message_id":111,
      "from":{ 
         "id":1111,
         "is_bot":false,
         "first_name":"...",
         "last_name":"...",
         "username":"...",
      },
      "chat":{ 
         "id":1111,
         "first_name":"...",
         "last_name":"...",
         "username":"...",
         "type":"private"
      },
      "date": 1111,
      "text":"...."
   }
}

So, you can store those details and use them to forward that message to another chat. In each chat (unique chat id), each message has a chat id (which is usually an incremental number) and by these two identifier, you can uniquely select which message from which chat should be forwarded.

0
votes

Depends on where you want to access a chat_id, you can use different ways. if you want to send a specific message to a user or bot that you don't know his chat_id, you can print a message from that user and access chat_id. Or simply forward a message from that user to @ShowChatIdBot and it returns you the related chat_id. In fact this bot extract data from your forwarded message and gives back chat_id in that message to you.