skip to Main Content

I have been using PyTelegramAPI for some time and I am looking to send text with an attachment below, which would be a .png Image.

I can’t find a particular link in the docs to help me do this.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I didn't look far enough....

    .send_photo() method has a caption kwarg in...


  2. Try this, note that the path structure will depend on your operating system as well as where the file is actually located:

    def telegram_bot_sendphoto(bot_message, image_path):
    
        bot_token = TELEGRAM_BOT_TOKEN #make sure to switch these out 
        bot_chat_id = TELEGRAM_CHANNEL
        bot = telebot.TeleBot(bot_token, parse_mode=None)
        # photo = open('/images/sample.jpg', 'rb') #2 possible ways of writing the file path
        # photo = "https://example.com/image.pnh"
        photo = open(image_path, 'rb') #open the photo for reading
        status = bot.send_photo(bot_chat_id, photo, bot_message, timeout=100) #now send the photo with a message and a timeout (how long to wait before giving up if the send fails)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search