I'm currently using python-telegram-bot and basically what I want to achieve with it is to send telegram messages like this:
So the message consists of 2+ photos/videos with text message underneath.
What I've already tried:
sending message with send_message method, and including photo URLs, but it only shows 1 picture which is under the text
sending media group using send_media_group, but this method has no caption
parameter as send_photo.
Getting StartedOpen the telegram app and search for @BotFather. Click on the start button or send “/start”. Then send “/newbot” message to set up a name and a username. After setting name and username BotFather will give you an API token which is your bot token.
You should use sendMediaGroup, where you can specify media field with an array of photo / video objects but the trick is to set caption property only for the first element of an array. In this case telegram will show that caption below the media content.
How to Send a Direct Message on Telegram. 1 Launch Telegram. 2 Press “New message.”. 3 Select the recipient of the message. 4 Press the username of the person to open your chat with them. 5 Type in your message. 6 Hit the “Send” button, and you’re good to go.
Telegram Sender is a software for Windows PC to send bulk messages to Telegram group or channel members. With one click, you can send messages to all the Telegram users you have. You can add users manually or import them from a file. It helps you extract the user ID of all users from groups, whether you’re the admin or not.
You can search for Telegram groups of your interest, type a personalised message and send it to each member individually. With one tap, all Telegram group members receive your promotional message. You can also get the details of the users who received your message. 3. Python script to send bulk messages on Telegram
You should use sendMediaGroup, where you can specify media
field with an array of photo/video objects but the trick is to set caption
property only for the first element of an array. In this case telegram will show that caption below the media content.
If you'll specify captions for more than one element telegram will show them only when you click on photo preview for each photo separately.
send_media_group
works but the caption has to be added when creating the media_group
and to the first image only. Let's say we have three images img0.png
, img1.png
and img2.png
, we add them to the media_group
using InputMediaPhoto
with the parameter caption
equal to the text we want to send only for the first image, otherwise we set caption
equal to ''
.
import telegram
from telegram import InputMediaPhoto
TOKEN = '' # token to access the HTTP API of your bot created with @BotFather
CHANNEL_ID = '' # id of your channel, for example @durov
bot = telegram.Bot(token = TOKEN)
media_group = []
text = 'some caption for album'
for num in range(3):
media_group.append(InputMediaPhoto(open('img%d.png' % num, 'rb'),
caption = text if num == 0 else ''))
bot.send_media_group(chat_id = CHANNEL_ID, media = media_group)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With