From 13327c371a6d5f065e98a487e265b7e3bbc0b579 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Thu, 14 Apr 2016 15:03:07 +0800 Subject: [PATCH] Add editMessageText. --- telebot/__init__.py | 5 +++++ telebot/apihelper.py | 21 +++++++++++++++++++++ tests/test_telebot.py | 8 +++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 4487532..2ecbe71 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -460,6 +460,11 @@ class TeleBot: def answer_callback_query(self, callback_query_id, text=None, show_alert=None): return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert) + def edit_message_text(self, chat_id, text, message_id=None, inline_message_id=None, parse_mode=None, + disable_web_page_preview=None, reply_markup=None): + return types.Message.de_json(apihelper.edit_message_text(self.token, chat_id, text, message_id, inline_message_id, parse_mode, + disable_web_page_preview, 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 d087933..4337b92 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -311,6 +311,27 @@ def unban_chat_member(token, chat_id, user_id): return _make_request(token, method_url, params=payload, method='post') +# Updating messages + +def edit_message_text(token, chat_id, text, message_id=None, inline_message_id=None, parse_mode=None, + disable_web_page_preview=None, reply_markup=None): + method_url = r'editMessageText' + payload = {'chat_id': chat_id, 'text': text} + if message_id: + payload['message_id'] = message_id + if inline_message_id: + payload['inline_message_id'] = inline_message_id + if parse_mode: + payload['parse_mode'] = parse_mode + if disable_web_page_preview: + payload['disable_web_page_preview'] = disable_web_page_preview + 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): method_url = 'answerCallbackQuery' payload = {'callback_query_id': callback_query_id} diff --git a/tests/test_telebot.py b/tests/test_telebot.py index dc40993..9e70e84 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -315,7 +315,7 @@ class TestTeleBot: tb = telebot.TeleBot(TOKEN) lat = 26.3875591 lon = -161.2901042 - ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address",disable_notification=True) + ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True) assert ret_msg.venue.title == "Test Venue" def test_Chat(self): @@ -325,6 +325,12 @@ class TestTeleBot: assert me.id == msg.from_user.id assert msg.chat.id == int(CHAT_ID) + def test_edit_message_text(self): + tb = telebot.TeleBot(TOKEN) + msg = tb.send_message(CHAT_ID, 'Test') + new_msg = tb.edit_message_text(CHAT_ID, 'Edit test', message_id=msg.message_id) + assert new_msg.text == 'Edit test' + def create_text_message(self, text): params = {'text': text} chat = types.User(11, 'test')