Search code examples
pythontelegramtelegram-botpython-telegram-bottelepot

Send a photo from php url in telegram bot


I'm trying to send a photo with a telegram bot through sendPhoto method (https://core.telegram.org/bots/api#sendphoto) with telepot api, but it only accepts image urls with .jpg, .jpeg .gif, .png, .tif or .bmp and the photo I want to use is displayed through a .php url. How can I manage to obtain a valid url? I could also upload it using multipart/form-data but it's not working.


Solution

  • Nevermind, I managed to do it saving the file and uploading it with

    urllib.request.urlretrieve("link.php", "./file.png")
    bot.sendPhoto(chat_id, photo=open('./file.png', 'rb'))