From 1691e84d0167eae901c7a9f954be48b0a77c39f0 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Wed, 16 Nov 2016 14:18:39 +0300 Subject: [PATCH 1/6] ReplyKeyboardHide -> ReplyKeyboardRemove Since Telegram changed object name in API docs: https://core.telegram.org/bots/api#replykeyboardremove --- telebot/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index f0c5953..9447064 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -572,7 +572,7 @@ class ForceReply(JsonSerializable): return json.dumps(json_dict) -class ReplyKeyboardHide(JsonSerializable): +class ReplyKeyboardRemove(JsonSerializable): def __init__(self, selective=None): self.selective = selective From 1c9a9b9622b164caeffe75e92cecffa01d4be106 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 21 Nov 2016 08:57:38 +0300 Subject: [PATCH 2/6] hide_keyboard -> remove_keyboard --- telebot/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 9447064..0434a33 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -577,7 +577,7 @@ class ReplyKeyboardRemove(JsonSerializable): self.selective = selective def to_json(self): - json_dict = {'hide_keyboard': True} + json_dict = {'remove_keyboard': True} if self.selective: json_dict['selective'] = True return json.dumps(json_dict) From b2cd3c9716a5395a0d753727465e65acf100c6b2 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 21 Nov 2016 09:06:36 +0300 Subject: [PATCH 3/6] Added channel_post and edited_channel_post to Update object --- telebot/types.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/telebot/types.py b/telebot/types.py index 0434a33..0ac978e 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -103,6 +103,10 @@ class Update(JsonDeserializable): message = Message.de_json(obj['message']) if 'edited_message' in obj: edited_message = Message.de_json(obj['edited_message']) + if 'channel_post' in obj: + channel_post = Message.de_json(obj['channel_post']) + if 'edited_channel_post' in obj: + edited_channel_post = Message.de_json(obj['edited_channel_post']) if 'inline_query' in obj: inline_query = InlineQuery.de_json(obj['inline_query']) if 'chosen_inline_result' in obj: From 8c8be81bb936ebbda4439cfb2b11593448468902 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 21 Nov 2016 09:10:51 +0300 Subject: [PATCH 4/6] Added optional forward_from_message_id And changed `forward_date` to optional (as it should be) --- telebot/types.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 0ac978e..7449ad2 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -217,8 +217,10 @@ class Message(JsonDeserializable): opts['forward_from'] = User.de_json(obj['forward_from']) if 'forward_from_chat' in obj: opts['forward_from_chat'] = Chat.de_json(obj['forward_from_chat']) + if 'forward_from_message_id' in obj: + opts['forward_from_message_id'] = obj.get('forward_from_message_id') if 'forward_date' in obj: - opts['forward_date'] = obj['forward_date'] + opts['forward_date'] = obj.get('forward_date') if 'reply_to_message' in obj: opts['reply_to_message'] = Message.de_json(obj['reply_to_message']) if 'edit_date' in obj: From 856af7259933f37a2bb703810a562d701325f6ff Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 21 Nov 2016 09:19:59 +0300 Subject: [PATCH 5/6] Added cache_time to answer_callback_query --- telebot/apihelper.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 489b02b..3306668 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -493,7 +493,20 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m # InlineQuery -def answer_callback_query(token, callback_query_id, text=None, show_alert=None, url=None): +def answer_callback_query(token, callback_query_id, text=None, show_alert=None, url=None, cache_time=None): + """ + 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. + 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. + + :param token: Bot's token (you don't need to fill this) + :param callback_query_id: Unique identifier for the query to be answered + :param text: (Optional) Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + :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. + :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. + Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter. + :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. + :return: + """ method_url = 'answerCallbackQuery' payload = {'callback_query_id': callback_query_id} if text: @@ -502,6 +515,8 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None, payload['show_alert'] = show_alert if url: payload['url'] = url + if cache_time: + payload['cache_time'] = cache_time return _make_request(token, method_url, params=payload, method='post') From c99bb166196d845ff1d67b1af0114eca4b236213 Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 21 Nov 2016 09:28:32 +0300 Subject: [PATCH 6/6] Updated set_game_score MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • New field `force` • Changed `edit_message` to `disable_edit_message` --- telebot/apihelper.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 3306668..c56b081 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -443,28 +443,31 @@ def send_game(token, chat_id, game_short_name, disable_notification=None, reply_ # https://core.telegram.org/bots/api#setgamescore -def set_game_score(token, user_id, score, chat_id=None, message_id=None, inline_message_id=None, edit_message=None): +def set_game_score(token, user_id, score, force=None, disable_edit_message=None, chat_id=None, message_id=None, inline_message_id=None): """ 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. :param token: Bot's token (you don't need to fill this) :param user_id: User identifier - :param score: New score, must be positive + :param score: New score, must be non-negative + :param force: (Optional) Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters + :param disable_edit_message: (Optional) Pass True, if the game message should not be automatically edited to include the current scoreboard :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) :param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message :param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message - :param edit_message: (Optional) Pass True, if the game message should be automatically edited to include the current scoreboard :return: """ method_url = r'setGameScore' payload = {'user_id': user_id, 'score': score} + if force: + payload['force'] = force if chat_id: payload['chat_id'] = chat_id if message_id: payload['message_id'] = message_id if inline_message_id: payload['inline_message_id'] = inline_message_id - if edit_message: - payload['edit_message'] = edit_message + if disable_edit_message: + payload['disable_edit_message'] = disable_edit_message return _make_request(token, method_url, params=payload)