Skip to content

Commit e1a3cca

Browse files
committed
Add sendMediaGroup method.
1 parent a43f037 commit e1a3cca

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎telebot/__init__.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,21 @@ def send_video_note(self, chat_id, data, duration=None, length=None, reply_to_me
594594
apihelper.send_video_note(self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
595595
disable_notification, timeout))
596596

597+
def send_media_group(self, chat_id, media, disable_notification=None, reply_to_message_id=None):
598+
"""
599+
send a group of photos or videos as an album. On success, an array of the sent Messages is returned.
600+
:param chat_id:
601+
:param media:
602+
:param disable_notification:
603+
:param reply_to_message_id:
604+
:return:
605+
"""
606+
result = apihelper.send_media_group(self.token, chat_id, media, disable_notification, reply_to_message_id)
607+
ret = []
608+
for msg in result:
609+
ret.append(types.Message.de_json(msg))
610+
return ret
611+
597612
def send_location(self, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
598613
disable_notification=None):
599614
"""

‎telebot/apihelper.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re
255255
return _make_request(token, method_url, params=payload, files=files, method='post')
256256

257257

258+
def send_media_group(token, chat_id, media, disable_notification=None, reply_to_message_id=None):
259+
method_url = r'sendMediaGroup'
260+
media_json = _convert_list_json_serializable(media)
261+
print(media_json)
262+
payload = {'chat_id': chat_id, 'media': media_json}
263+
if disable_notification:
264+
payload['disable_notification'] = disable_notification
265+
if reply_to_message_id:
266+
payload['reply_to_message_id'] = reply_to_message_id
267+
return _make_request(token, method_url, params=payload)
268+
269+
258270
def send_location(token, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
259271
disable_notification=None):
260272
method_url = r'sendLocation'

‎telebot/types.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,3 +1959,45 @@ def to_json(self):
19591959
def to_dic(self):
19601960
return {'point': self.point, 'x_shift': self.x_shift, 'y_shift': self.y_shift, 'scale': self.scale}
19611961

1962+
1963+
# InputMedia
1964+
1965+
class InputMediaPhoto(JsonSerializable):
1966+
def __init__(self, media, caption=None):
1967+
self.type = "photo"
1968+
self.media = media
1969+
self.caption = caption
1970+
1971+
def to_json(self):
1972+
return json.dumps(self.to_dic())
1973+
1974+
def to_dic(self):
1975+
ret = {'type': self.type, 'media': self.media}
1976+
if self.caption:
1977+
ret['caption'] = self.caption
1978+
return ret
1979+
1980+
1981+
class InputMediaVideo(JsonSerializable):
1982+
def __init__(self, media, caption=None, width=None, height=None, duration=None):
1983+
self.type = "video"
1984+
self.media = media
1985+
self.caption = caption
1986+
self.width = width
1987+
self.height = height
1988+
self.duration = duration
1989+
1990+
def to_json(self):
1991+
return json.dumps(self.to_dic())
1992+
1993+
def to_dic(self):
1994+
ret = {'type': self.type, 'media': self.media}
1995+
if self.caption:
1996+
ret['caption'] = self.caption
1997+
if self.width:
1998+
ret['width'] = self.width
1999+
if self.height:
2000+
ret['height'] = self.height
2001+
if self.duration:
2002+
ret['duration'] = self.duration
2003+
return ret

0 commit comments

Comments
 (0)