Skip to content

Commit 27a79c4

Browse files
authored
Merge pull request eternnoir#254 from Kondra007/patch-2
Bot API November updates
2 parents f413ccf + c99bb16 commit 27a79c4

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎telebot/apihelper.py‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,28 +443,31 @@ def send_game(token, chat_id, game_short_name, disable_notification=None, reply_
443443

444444

445445
# https://core.telegram.org/bots/api#setgamescore
446-
def set_game_score(token, user_id, score, chat_id=None, message_id=None, inline_message_id=None, edit_message=None):
446+
def set_game_score(token, user_id, score, force=None, disable_edit_message=None, chat_id=None, message_id=None, inline_message_id=None):
447447
"""
448448
Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat.
449449
:param token: Bot's token (you don't need to fill this)
450450
:param user_id: User identifier
451-
:param score: New score, must be positive
451+
:param score: New score, must be non-negative
452+
:param force: (Optional) Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
453+
:param disable_edit_message: (Optional) Pass True, if the game message should not be automatically edited to include the current scoreboard
452454
:param chat_id: (Optional, required if inline_message_id is not specified) Unique identifier for the target chat (or username of the target channel in the format @channelusername)
453455
:param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message
454456
:param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message
455-
:param edit_message: (Optional) Pass True, if the game message should be automatically edited to include the current scoreboard
456457
:return:
457458
"""
458459
method_url = r'setGameScore'
459460
payload = {'user_id': user_id, 'score': score}
461+
if force:
462+
payload['force'] = force
460463
if chat_id:
461464
payload['chat_id'] = chat_id
462465
if message_id:
463466
payload['message_id'] = message_id
464467
if inline_message_id:
465468
payload['inline_message_id'] = inline_message_id
466-
if edit_message:
467-
payload['edit_message'] = edit_message
469+
if disable_edit_message:
470+
payload['disable_edit_message'] = disable_edit_message
468471
return _make_request(token, method_url, params=payload)
469472

470473

@@ -493,7 +496,20 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
493496

494497
# InlineQuery
495498

496-
def answer_callback_query(token, callback_query_id, text=None, show_alert=None, url=None):
499+
def answer_callback_query(token, callback_query_id, text=None, show_alert=None, url=None, cache_time=None):
500+
"""
501+
Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
502+
Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via BotFather and accept the terms. Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
503+
504+
:param token: Bot's token (you don't need to fill this)
505+
:param callback_query_id: Unique identifier for the query to be answered
506+
:param text: (Optional) Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
507+
:param show_alert: (Optional) If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
508+
:param url: (Optional) URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button.
509+
Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
510+
:param cache_time: (Optional) The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
511+
:return:
512+
"""
497513
method_url = 'answerCallbackQuery'
498514
payload = {'callback_query_id': callback_query_id}
499515
if text:
@@ -502,6 +518,8 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None,
502518
payload['show_alert'] = show_alert
503519
if url:
504520
payload['url'] = url
521+
if cache_time:
522+
payload['cache_time'] = cache_time
505523
return _make_request(token, method_url, params=payload, method='post')
506524

507525

‎telebot/types.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def de_json(cls, json_type):
103103
message = Message.de_json(obj['message'])
104104
if 'edited_message' in obj:
105105
edited_message = Message.de_json(obj['edited_message'])
106+
if 'channel_post' in obj:
107+
channel_post = Message.de_json(obj['channel_post'])
108+
if 'edited_channel_post' in obj:
109+
edited_channel_post = Message.de_json(obj['edited_channel_post'])
106110
if 'inline_query' in obj:
107111
inline_query = InlineQuery.de_json(obj['inline_query'])
108112
if 'chosen_inline_result' in obj:
@@ -213,8 +217,10 @@ def de_json(cls, json_string):
213217
opts['forward_from'] = User.de_json(obj['forward_from'])
214218
if 'forward_from_chat' in obj:
215219
opts['forward_from_chat'] = Chat.de_json(obj['forward_from_chat'])
220+
if 'forward_from_message_id' in obj:
221+
opts['forward_from_message_id'] = obj.get('forward_from_message_id')
216222
if 'forward_date' in obj:
217-
opts['forward_date'] = obj['forward_date']
223+
opts['forward_date'] = obj.get('forward_date')
218224
if 'reply_to_message' in obj:
219225
opts['reply_to_message'] = Message.de_json(obj['reply_to_message'])
220226
if 'edit_date' in obj:
@@ -572,12 +578,12 @@ def to_json(self):
572578
return json.dumps(json_dict)
573579

574580

575-
class ReplyKeyboardHide(JsonSerializable):
581+
class ReplyKeyboardRemove(JsonSerializable):
576582
def __init__(self, selective=None):
577583
self.selective = selective
578584

579585
def to_json(self):
580-
json_dict = {'hide_keyboard': True}
586+
json_dict = {'remove_keyboard': True}
581587
if self.selective:
582588
json_dict['selective'] = True
583589
return json.dumps(json_dict)

0 commit comments

Comments
 (0)