From f7cfb98b6089669647bd7fb2f24184942e73a64b Mon Sep 17 00:00:00 2001 From: Kylmakalle Date: Sun, 7 May 2017 17:37:03 +0300 Subject: [PATCH] Added option to delete messages. Added option to delete messages. Some bots do not support this method now, waiting for an official api release. --- telebot/__init__.py | 10 ++++++++++ telebot/apihelper.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index 3b70be9..9d201b8 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -33,6 +33,7 @@ class TeleBot: getMe sendMessage forwardMessage + deleteMessage sendPhoto sendAudio sendDocument @@ -408,6 +409,15 @@ class TeleBot: return types.Message.de_json( apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification)) + def delete_message(self, chat_id, message_id): + """ + Use this method to delete message. Returns True on success. + :param chat_id: in which chat to delete + :param message_id: which message to delete + :return: API reply. + """ + return types.Message.de_json(apihelper.delete_message(self.token, chat_id, message_id)) + def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None, disable_notification=None): """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 90a101a..c134cbc 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -446,6 +446,12 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa return _make_request(token, method_url, params=payload) +def delete_message(token, chat_id=None, message_id=None): + method_url = r'deleteMessage' + payload = {'chat_id': chat_id, 'message_id': message_id} + return _make_request(token, method_url, params=payload) + + # Game def send_game(token, chat_id, game_short_name, disable_notification=None, reply_to_message_id=None, reply_markup=None):