diff --git a/telebot/__init__.py b/telebot/__init__.py index 37244b7..81912c7 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -594,6 +594,21 @@ class TeleBot: apihelper.send_video_note(self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup, disable_notification, timeout)) + def send_media_group(self, chat_id, media, disable_notification=None, reply_to_message_id=None): + """ + send a group of photos or videos as an album. On success, an array of the sent Messages is returned. + :param chat_id: + :param media: + :param disable_notification: + :param reply_to_message_id: + :return: + """ + result = apihelper.send_media_group(self.token, chat_id, media, disable_notification, reply_to_message_id) + ret = [] + for msg in result: + ret.append(types.Message.de_json(msg)) + return ret + def send_location(self, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None, disable_notification=None): """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 6d5a204..be19e7c 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -255,6 +255,18 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re return _make_request(token, method_url, params=payload, files=files, method='post') +def send_media_group(token, chat_id, media, disable_notification=None, reply_to_message_id=None): + method_url = r'sendMediaGroup' + media_json = _convert_list_json_serializable(media) + print(media_json) + payload = {'chat_id': chat_id, 'media': media_json} + if disable_notification: + payload['disable_notification'] = disable_notification + if reply_to_message_id: + payload['reply_to_message_id'] = reply_to_message_id + return _make_request(token, method_url, params=payload) + + def send_location(token, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None, disable_notification=None): method_url = r'sendLocation' diff --git a/telebot/types.py b/telebot/types.py index f060842..f14c9a1 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -1959,3 +1959,45 @@ class MaskPosition(JsonDeserializable, JsonSerializable): def to_dic(self): return {'point': self.point, 'x_shift': self.x_shift, 'y_shift': self.y_shift, 'scale': self.scale} + +# InputMedia + +class InputMediaPhoto(JsonSerializable): + def __init__(self, media, caption=None): + self.type = "photo" + self.media = media + self.caption = caption + + def to_json(self): + return json.dumps(self.to_dic()) + + def to_dic(self): + ret = {'type': self.type, 'media': self.media} + if self.caption: + ret['caption'] = self.caption + return ret + + +class InputMediaVideo(JsonSerializable): + def __init__(self, media, caption=None, width=None, height=None, duration=None): + self.type = "video" + self.media = media + self.caption = caption + self.width = width + self.height = height + self.duration = duration + + def to_json(self): + return json.dumps(self.to_dic()) + + def to_dic(self): + ret = {'type': self.type, 'media': self.media} + if self.caption: + ret['caption'] = self.caption + if self.width: + ret['width'] = self.width + if self.height: + ret['height'] = self.height + if self.duration: + ret['duration'] = self.duration + return ret