Skip to content

Commit 5f8d996

Browse files
committed
Bot API 3.4: new methods for live locations, new objects.
1 parent aaa968c commit 5f8d996

3 files changed

Lines changed: 98 additions & 7 deletions

File tree

‎telebot/__init__.py‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,32 @@ def get_chat_members_count(self, chat_id):
407407
result = apihelper.get_chat_members_count(self.token, chat_id)
408408
return result
409409

410+
def set_chat_sticker_set(self, chat_id, sticker_set_name):
411+
"""
412+
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
413+
in the chat for this to work and must have the appropriate admin rights.
414+
Use the field can_set_sticker_set optionally returned in getChat requests to check
415+
if the bot can use this method. Returns True on success.
416+
:param chat_id: Unique identifier for the target chat or username of the target supergroup
417+
(in the format @supergroupusername)
418+
:param sticker_set_name: Name of the sticker set to be set as the group sticker set
419+
:return:
420+
"""
421+
result = apihelper.set_chat_sticker_set(self.token, chat_id, sticker_set_name)
422+
return result
423+
424+
def delete_chat_sticker_set(self, chat_id):
425+
"""
426+
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat
427+
for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set
428+
optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
429+
:param chat_id: Unique identifier for the target chat or username of the target supergroup
430+
(in the format @supergroupusername)
431+
:return:
432+
"""
433+
result = apihelper.delete_chat_sticker_set(self.token, chat_id)
434+
return result
435+
410436
def get_chat_member(self, chat_id, user_id):
411437
"""
412438
Use this method to get information about a member of a chat. Returns a ChatMember object on success.
@@ -568,19 +594,20 @@ def send_video_note(self, chat_id, data, duration=None, length=None, reply_to_me
568594
apihelper.send_video_note(self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
569595
disable_notification, timeout))
570596

571-
def send_location(self, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None,
597+
def send_location(self, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
572598
disable_notification=None):
573599
"""
574600
Use this method to send point on the map.
575601
:param chat_id:
576602
:param latitude:
577603
:param longitude:
604+
:param live_period
578605
:param reply_to_message_id:
579606
:param reply_markup:
580607
:return: API reply.
581608
"""
582609
return types.Message.de_json(
583-
apihelper.send_location(self.token, chat_id, latitude, longitude, reply_to_message_id, reply_markup,
610+
apihelper.send_location(self.token, chat_id, latitude, longitude, live_period, reply_to_message_id, reply_markup,
584611
disable_notification))
585612

586613
def send_venue(self, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None,
@@ -1245,6 +1272,14 @@ def get_chat_administrators(self, *args):
12451272
def get_chat_members_count(self, *args):
12461273
return TeleBot.get_chat_members_count(self, *args)
12471274

1275+
@util.async()
1276+
def set_chat_sticker_set(self, *args):
1277+
return TeleBot.set_chat_sticker_set(self, *args)
1278+
1279+
@util.async()
1280+
def delete_chat_sticker_set(self, *args):
1281+
return TeleBot.delete_chat_sticker_set(self, *args)
1282+
12481283
@util.async()
12491284
def get_chat_member(self, *args):
12501285
return TeleBot.get_chat_member(self, *args)

‎telebot/apihelper.py‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ def get_chat_members_count(token, chat_id):
209209
return _make_request(token, method_url, params=payload)
210210

211211

212+
def set_chat_sticker_set(token, chat_id, sticker_set_name):
213+
method_url = r'setChatStickerSet'
214+
payload = {'chat_id': chat_id, 'sticker_set_name': sticker_set_name}
215+
return _make_request(token, method_url, params=payload)
216+
217+
218+
def delete_chat_sticker_set(token, chat_id):
219+
method_url = r'deleteChatStickerSet'
220+
payload = {'chat_id': chat_id}
221+
return _make_request(token, method_url, params=payload)
222+
223+
212224
def get_chat_member(token, chat_id, user_id):
213225
method_url = r'getChatMember'
214226
payload = {'chat_id': chat_id, 'user_id': user_id}
@@ -243,10 +255,12 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re
243255
return _make_request(token, method_url, params=payload, files=files, method='post')
244256

245257

246-
def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None,
258+
def send_location(token, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
247259
disable_notification=None):
248260
method_url = r'sendLocation'
249261
payload = {'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude}
262+
if live_period:
263+
payload['live_perion'] = live_period
250264
if reply_to_message_id:
251265
payload['reply_to_message_id'] = reply_to_message_id
252266
if reply_markup:
@@ -256,6 +270,36 @@ def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None,
256270
return _make_request(token, method_url, params=payload)
257271

258272

273+
def edit_message_live_location(token, latitude, longitude, chat_id=None, message_id=None,
274+
inline_message_id=None, reply_markup=None):
275+
method_url = r'editMessageLiveLocation'
276+
payload = {'latitude': latitude, 'longitude': longitude}
277+
if chat_id:
278+
payload['chat_id'] = chat_id
279+
if message_id:
280+
payload['message_id'] = message_id
281+
if inline_message_id:
282+
payload['inline_message_id'] = inline_message_id
283+
if reply_markup:
284+
payload['reply_markup'] = _convert_markup(reply_markup)
285+
return _make_request(token, method_url, params=payload)
286+
287+
288+
def stop_message_live_location(token, chat_id=None, message_id=None,
289+
inline_message_id=None, reply_markup=None):
290+
method_url = r'stopMessageLiveLocation'
291+
payload = {}
292+
if chat_id:
293+
payload['chat_id'] = chat_id
294+
if message_id:
295+
payload['message_id'] = message_id
296+
if inline_message_id:
297+
payload['inline_message_id'] = inline_message_id
298+
if reply_markup:
299+
payload['reply_markup'] = _convert_markup(reply_markup)
300+
return _make_request(token, method_url, params=payload)
301+
302+
259303
def send_venue(token, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None,
260304
reply_to_message_id=None, reply_markup=None):
261305
method_url = r'sendVenue'

‎telebot/types.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,14 @@ def de_json(cls, json_string):
225225
pinned_message = None
226226
if 'pinned_message' in obj:
227227
pinned_message = Message.de_json(obj['pinned_message'])
228+
sticker_set_name = obj.get('sticker_set_name')
229+
can_set_sticker_set = obj.get('can_set_sticker_set')
228230
return cls(id, type, title, username, first_name, last_name, all_members_are_administrators,
229-
photo, description, invite_link, pinned_message)
231+
photo, description, invite_link, pinned_message, sticker_set_name, can_set_sticker_set)
230232

231233
def __init__(self, id, type, title=None, username=None, first_name=None, last_name=None,
232234
all_members_are_administrators=None, photo=None, description=None, invite_link=None,
233-
pinned_message=None):
235+
pinned_message=None, sticker_set_name=None, can_set_sticker_set=None):
234236
self.type = type
235237
self.last_name = last_name
236238
self.first_name = first_name
@@ -242,6 +244,8 @@ def __init__(self, id, type, title=None, username=None, first_name=None, last_na
242244
self.description = description
243245
self.invite_link = invite_link
244246
self.pinned_message = pinned_message
247+
self.sticker_set_name = sticker_set_name
248+
self.can_set_sticker_set = can_set_sticker_set
245249

246250

247251
class Message(JsonDeserializable):
@@ -277,6 +281,8 @@ def de_json(cls, json_string):
277281
content_type = 'text'
278282
if 'entities' in obj:
279283
opts['entities'] = Message.parse_entities(obj['entities'])
284+
if 'caption_entities' in obj:
285+
opts['caption_entities'] = Message.parse_entities(obj['caption_entities'])
280286
if 'audio' in obj:
281287
opts['audio'] = Audio.de_json(obj['audio'])
282288
content_type = 'audio'
@@ -984,12 +990,15 @@ def to_dic(self):
984990

985991

986992
class InputLocationMessageContent(Dictionaryable):
987-
def __init__(self, latitude, longitude):
993+
def __init__(self, latitude, longitude, live_period=None):
988994
self.latitude = latitude
989995
self.longitude = longitude
996+
self.live_period = live_period
990997

991998
def to_dic(self):
992999
json_dic = {'latitude': self.latitude, 'longitude': self.longitude}
1000+
if self.live_period:
1001+
json_dic['live_period'] = self.live_period
9931002
return json_dic
9941003

9951004

@@ -1386,13 +1395,14 @@ def to_json(self):
13861395

13871396

13881397
class InlineQueryResultLocation(JsonSerializable):
1389-
def __init__(self, id, title, latitude, longitude, reply_markup=None,
1398+
def __init__(self, id, title, latitude, longitude, live_period=None, reply_markup=None,
13901399
input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None):
13911400
self.type = 'location'
13921401
self.id = id
13931402
self.title = title
13941403
self.latitude = latitude
13951404
self.longitude = longitude
1405+
self.live_period = live_period
13961406
self.reply_markup = reply_markup
13971407
self.input_message_content = input_message_content
13981408
self.thumb_url = thumb_url
@@ -1402,6 +1412,8 @@ def __init__(self, id, title, latitude, longitude, reply_markup=None,
14021412
def to_json(self):
14031413
json_dict = {'type': self.type, 'id': self.id, 'latitude': self.latitude, 'longitude': self.longitude,
14041414
'title': self.title}
1415+
if self.live_period:
1416+
json_dict['live_period'] = self.live_period
14051417
if self.thumb_url:
14061418
json_dict['thumb_url'] = self.thumb_url
14071419
if self.thumb_width:

0 commit comments

Comments
 (0)