1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add editMessageText.

This commit is contained in:
eternnoir 2016-04-14 15:03:07 +08:00
parent 4dc7af71a0
commit 13327c371a
3 changed files with 33 additions and 1 deletions

View File

@ -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)`

View File

@ -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}

View File

@ -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')