From 4fe4061a0f70c1f9d9286165b6b9f3d206a9fcdc Mon Sep 17 00:00:00 2001 From: eternnoir Date: Thu, 14 Apr 2016 15:17:53 +0800 Subject: [PATCH] All Updating messages methods done. --- telebot/__init__.py | 10 ++++++++++ telebot/apihelper.py | 28 ++++++++++++++++++++++++++++ tests/test_telebot.py | 12 ++++++++++++ 3 files changed, 50 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index f75004e..d54c55c 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -466,6 +466,16 @@ class TeleBot: apihelper.edit_message_text(self.token, text, chat_id, message_id, inline_message_id, parse_mode, disable_web_page_preview, reply_markup)) + def edit_message_replay_markup(self, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): + return types.Message.de_json( + apihelper.edit_message_replay_markup(self.token, chat_id, message_id, inline_message_id, reply_markup) + ) + + def edit_message_caption(self, caption, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): + return types.Message.de_json( + apihelper.edit_message_caption(self.token, caption, chat_id, message_id, inline_message_id, reply_markup) + ) + def reply_to(self, message, text, **kwargs): """ Convenience function for `send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)` diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 36d97e7..f37362f 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -332,6 +332,34 @@ def edit_message_text(token, text, chat_id=None, message_id=None, inline_message return _make_request(token, method_url, params=payload) +def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): + method_url = r'editMessageCaption' + payload = {'caption': caption} + 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 reply_markup: + payload['reply_markup'] = _convert_markup(reply_markup) + return _make_request(token, method_url, params=payload) + + +def edit_message_replay_markup(token, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): + method_url = r'editMessageReplyMarkup' + payload = {} + 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 reply_markup: + payload['reply_markup'] = _convert_markup(reply_markup) + return _make_request(token, method_url, params=payload) + + # InlineQuery def answer_callback_query(token, callback_query_id, text=None, show_alert=None): diff --git a/tests/test_telebot.py b/tests/test_telebot.py index 3c01125..d342bf9 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -331,6 +331,18 @@ class TestTeleBot: new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id) assert new_msg.text == 'Edit test' + def test_edit_markup(self): + text = 'CI Test Message' + tb = telebot.TeleBot(TOKEN) + markup = types.InlineKeyboardMarkup() + markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) + markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) + ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup) + markup.add(types.InlineKeyboardButton("Google2", url="http://www.google.com")) + markup.add(types.InlineKeyboardButton("Yahoo2", url="http://www.yahoo.com")) + new_msg = tb.edit_message_replay_markup(chat_id=CHAT_ID, message_id=ret_msg.message_id, reply_markup=markup) + assert new_msg.message_id + def create_text_message(self, text): params = {'text': text} chat = types.User(11, 'test')