1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add sendMediaGroup method.

This commit is contained in:
eternnoir 2017-11-29 13:45:25 +08:00
parent a43f037bc9
commit e1a3ccadb7
3 changed files with 69 additions and 0 deletions

View File

@ -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):
"""

View File

@ -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'

View File

@ -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