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.
3
Answers
You should use sendMediaGroup, where you can specify
media
field with an array of photo/video objects but the trick is to setcaption
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 themedia_group
and to the first image only. Let’s say we have three imagesimg0.png
,img1.png
andimg2.png
, we add them to themedia_group
usingInputMediaPhoto
with the parametercaption
equal to the text we want to send only for the first image, otherwise we setcaption
equal to''
.Here is a vanilla Python implementation using
requests
: