0

python's telepot library is no longer being maintained and updated in new telegram bot api update editMessageMedia was added

how to use it with http GET/POST request ? ( requests library or any other lib )

Khalil Abbas
  • 110
  • 2
  • 7

1 Answers1

1

You can invoke the endpoint by sending a request via requests like this but note that there are various maintained bot libraries out there you can utilize.

import requests
import json

BOT_TOKEN = ' ... '
CHAT_ID = ...
MESSAGE_ID = ...

files = {
    'media': open('./photo.jpg', 'rb'),
}

media = json.dumps({
    'type': 'photo',
    'media': 'attach://media'
})

message = f"https://api.telegram.org/bot{BOT_TOKEN}/editMessageMedia?chat_id={CHAT_ID}&message_id={MESSAGE_ID}&media={media}"

result = requests.post(message, files = files)

print(result.json())

set the values for CHAT_ID, MESSAGE_ID and BOT_TOKEN. Also, update './photo.jpg' with the path to the new file.

One last thing if the media you are trying to edit is not photo (audio and other files), update the line 'type' : 'photo' as well. (check out https://core.telegram.org/bots/api#inputmedia for details)

Tibebes. M
  • 6,940
  • 5
  • 15
  • 36