From 9df1b89a86110980d9213e6031369e6c19c35b86 Mon Sep 17 00:00:00 2001 From: Carson True Date: Fri, 4 Sep 2020 07:51:55 -0400 Subject: [PATCH] Added send_media_group to "Working with Images" section --- Code-snippets.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Code-snippets.md b/Code-snippets.md index 5428731..fd47e62 100644 --- a/Code-snippets.md +++ b/Code-snippets.md @@ -23,6 +23,7 @@ It is also a follow-up to the page [Introduction to the API](https://github.com/ + [Post an audio from disk](#post-an-audio-from-disk) + [Post a file from disk](#post-a-file-from-disk) + [Post an image from memory](#post-an-image-from-memory) + + [Post a media group from a URL](#post-a-media-group-from-a-url) + [Get image with dimensions closest to a desired size](#get-image-with-dimensions-closest-to-a-desired-size) + [Download a file](#download-a-file) * [Keyboard Menus](#keyboard-menus) @@ -274,8 +275,26 @@ bot.send_animation(chat_id, animation, duration=None, width=None, height=None, t ``` See the [online documentation](https://python-telegram-bot.readthedocs.io/en/latest/telegram.bot.html#telegram.Bot.send_animation) +#### Post a media group from a URL +[ᵀᴱᴸᴱᴳᴿᴬᴹ](https://core.telegram.org/bots/api#sendmediagroup) +```python +from telegram import InputMediaPhoto +list_of_urls = [ + 'https://upload.wikimedia.org/wikipedia/commons/c/c7/Gigantic_galapagos_turtle_on_the_island_of_santa_cruz.JPG', + 'https://upload.wikimedia.org/wikipedia/commons/9/99/T.h._hermanni_con_speroni_5.JPG', + 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Sheldonbasking.JPG/1280px-Sheldonbasking.JPG' +] + +media_group = list() + +for number, url in enumerate(list_of_urls): + media_group.append(InputMediaPhoto(media=url), caption="Turtle" + number) + +bot.send_media_group(chat_id=chat_id, media=media_group) +``` +See the [online documentation](https://python-telegram-bot.readthedocs.io/en/latest/telegram.bot.html#telegram.Bot.send_media_group) #### Post an audio from disk [ᵀᴱᴸᴱᴳᴿᴬᴹ](https://core.telegram.org/bots/api#sendaudio)