0

I'm making a Telegram bot that posts from Twitter. I have a problem if there are two or more images in the tweet, because my code uses bot.send_photo, which, as far as I understand, is designed to send only one, or the first image. As I read, to publish more than one image, you need to use bot.send_media_group, but the "telebot" library (pyTelegramBotAPI), I read in the documentation, doesn't provide "caption" and "parse_mode". That is, if there is text in the tweet, it will not be published. And in general, if I apply bot.send_media_group only one (first) image is published for some reason.

Here is a block of code:

    if 'media' in tweet.entities and tweet.entities['media']:
        
        image_url = tweet.entities['media'][0]['media_url_https']
        response = requests.get(image_url)
        image = response.content

        bot.send_photo(chat_id='@' + channel_name, photo=image, caption=message, parse_mode='HTML')
    else:
        bot.send_message(chat_id='@' + channel_name, text=message, parse_mode='HTML',
                         disable_web_page_preview=True)

Maybe I'm not right at all, and need to change everything. I would be grateful for help!

Here are the libraries I use in all of my code:

import tweepy
import telebot
import asyncio
from translate import Translator
from langdetect import detect
import requests

What I tried to do I described above

Nik
  • 7
  • 2

0 Answers0