2121"""This module contains an object that represents a Telegram Bot."""
2222
2323import functools
24+ import json
2425import logging
2526import warnings
2627from datetime import datetime
2728
29+ from future .utils import string_types
30+
2831from telegram import (User , Message , Update , Chat , ChatMember , UserProfilePhotos , File ,
2932 ReplyMarkup , TelegramObject , WebhookInfo , GameHighScore , StickerSet ,
3033 PhotoSize , Audio , Document , Sticker , Video , Voice , VideoNote , Location ,
@@ -335,7 +338,7 @@ def send_photo(self,
335338 disable_notification = False ,
336339 reply_to_message_id = None ,
337340 reply_markup = None ,
338- timeout = 20. ,
341+ timeout = 20 ,
339342 ** kwargs ):
340343 """Use this method to send photos.
341344
@@ -394,7 +397,7 @@ def send_audio(self,
394397 disable_notification = False ,
395398 reply_to_message_id = None ,
396399 reply_markup = None ,
397- timeout = 20. ,
400+ timeout = 20 ,
398401 ** kwargs ):
399402 """
400403 Use this method to send audio files, if you want Telegram clients to display them in the
@@ -465,7 +468,7 @@ def send_document(self,
465468 disable_notification = False ,
466469 reply_to_message_id = None ,
467470 reply_markup = None ,
468- timeout = 20. ,
471+ timeout = 20 ,
469472 ** kwargs ):
470473 """Use this method to send general files.
471474
@@ -576,7 +579,7 @@ def send_video(self,
576579 disable_notification = False ,
577580 reply_to_message_id = None ,
578581 reply_markup = None ,
579- timeout = 20. ,
582+ timeout = 20 ,
580583 width = None ,
581584 height = None ,
582585 ** kwargs ):
@@ -646,7 +649,7 @@ def send_voice(self,
646649 disable_notification = False ,
647650 reply_to_message_id = None ,
648651 reply_markup = None ,
649- timeout = 20. ,
652+ timeout = 20 ,
650653 ** kwargs ):
651654 """
652655 Use this method to send audio files, if you want Telegram clients to display the file
@@ -708,7 +711,7 @@ def send_video_note(self,
708711 disable_notification = False ,
709712 reply_to_message_id = None ,
710713 reply_markup = None ,
711- timeout = 20. ,
714+ timeout = 20 ,
712715 ** kwargs ):
713716 """Use this method to send video messages.
714717
@@ -757,6 +760,51 @@ def send_video_note(self,
757760
758761 return url , data
759762
763+ @log
764+ def send_media_group (self ,
765+ chat_id ,
766+ media ,
767+ disable_notification = None ,
768+ reply_to_message_id = None ,
769+ timeout = 20 ,
770+ ** kwargs ):
771+ """Use this method to send a group of photos or videos as an album.
772+
773+ Args:
774+ chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
775+ of the target channel (in the format @channelusername).
776+ media (List[:class:`telegram.InputMedia`]): An array describing photos and videos to be
777+ sent, must include 2–10 items.
778+ disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
779+ receive a notification with no sound.
780+ reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
781+ original message.
782+ timeout (:obj:`int` | :obj:`float`, optional): Send file timeout (default: 20 seconds).
783+ **kwargs (:obj:`dict`): Arbitrary keyword arguments.
784+
785+ Returns:
786+ List[:class:`telegram.Message`]: An array of the sent Messages.
787+
788+ Raises:
789+ :class:`telegram.TelegramError`
790+ """
791+ # TODO: Make InputMediaPhoto, InputMediaVideo and send_media_group work with new files
792+
793+ url = '{0}/sendMediaGroup' .format (self .base_url )
794+
795+ media = [med .to_dict () for med in media ]
796+
797+ data = {'chat_id' : chat_id , 'media' : media }
798+
799+ if reply_to_message_id :
800+ data ['reply_to_message_id' ] = reply_to_message_id
801+ if disable_notification :
802+ data ['disable_notification' ] = disable_notification
803+
804+ result = self ._request .post (url , data , timeout = timeout )
805+
806+ return [Message .de_json (res , self ) for res in result ]
807+
760808 @log
761809 @message
762810 def send_location (self ,
@@ -2153,6 +2201,7 @@ def send_invoice(self,
21532201 disable_notification = False ,
21542202 reply_to_message_id = None ,
21552203 reply_markup = None ,
2204+ provider_data = None ,
21562205 timeout = None ,
21572206 ** kwargs ):
21582207 """Use this method to send invoices.
@@ -2169,6 +2218,10 @@ def send_invoice(self,
21692218 currency (:obj:`str`): Three-letter ISO 4217 currency code.
21702219 prices (List[:class:`telegram.LabeledPrice`)]: Price breakdown, a list of components
21712220 (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
2221+ provider_data (:obj:`str` | :obj:`object`, optional): JSON-encoded data about the
2222+ invoice, which will be shared with the payment provider. A detailed description of
2223+ required fields should be provided by the payment provider. When an object is
2224+ passed, it will be encoded as JSON.
21722225 photo_url (:obj:`str`, optional): URL of the product photo for the invoice. Can be a
21732226 photo of the goods or a marketing image for a service. People like it better when
21742227 they see what they are paying for.
@@ -2216,7 +2269,11 @@ def send_invoice(self,
22162269 'currency' : currency ,
22172270 'prices' : [p .to_dict () for p in prices ]
22182271 }
2219-
2272+ if provider_data is not None :
2273+ if isinstance (provider_data , string_types ):
2274+ data ['provider_data' ] = provider_data
2275+ else :
2276+ data ['provider_data' ] = json .dumps (provider_data )
22202277 if photo_url is not None :
22212278 data ['photo_url' ] = photo_url
22222279 if photo_size is not None :
@@ -2965,6 +3022,7 @@ def __reduce__(self):
29653022 sendVideo = send_video
29663023 sendVoice = send_voice
29673024 sendVideoNote = send_video_note
3025+ sendMediaGroup = send_media_group
29683026 sendLocation = send_location
29693027 editMessageLiveLocation = edit_message_live_location
29703028 stopMessageLiveLocation = stop_message_live_location
0 commit comments