Here is a vanilla Python implementation using requests
:
SEND_MEDIA_GROUP = f'https://api.telegram.org/bot{token}/sendMediaGroup'
def send_media_group(chat_id, images, caption=None, reply_to_message_id=None):
"""
Use this method to send an album of photos. On success, an array of Messages that were sent is returned.
:param chat_id: chat id
:param images: list of PIL images to send
:param caption: caption of image
:param reply_to_message_id: If the message is a reply, ID of the original message
:return: response with the sent message
"""
files = {}
media = []
for i, img in enumerate(images):
with BytesIO() as output:
img.save(output, format='PNG')
output.seek(0)
name = f'photo{i}'
files[name] = output.read()
# a list of InputMediaPhoto. attach refers to the name of the file in the files dict
media.append(dict(type='photo', media=f'attach://{name}'))
media[0]['caption'] = caption
return requests.post(SEND_MEDIA_GROUP, data={'chat_id': chat_id, 'media': json.dumps(media), 'reply_to_message_id': reply_to_message_id }, files=files)