From 58281f0a1000fe510d53ca541b4908754743e626 Mon Sep 17 00:00:00 2001 From: Alireza Date: Mon, 11 Jan 2021 02:50:17 +0330 Subject: [PATCH] Added copyMessage method --- telebot/__init__.py | 25 ++++++++++++++++++++++++- telebot/apihelper.py | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f166a27..91cd332 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -750,6 +750,24 @@ class TeleBot: return types.Message.de_json( apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification, timeout)) + def copy_message(self, chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, + reply_to_message_id=None, allow_sending_without_reply=None, reply_markup=None, + disable_notification=None, timeout=None): + # FIXME: rewrite the docstring + """ + Use this method to copy messages of any kind. + :param disable_notification: + :param chat_id: which chat to forward + :param from_chat_id: which chat message from + :param message_id: message id + :param timeout: + :return: API reply. + """ + return types.Message.de_json( + apihelper.copy_message(self.token, chat_id, from_chat_id, message_id, caption, parse_mode, caption_entities, + reply_to_message_id, allow_sending_without_reply, reply_markup, + disable_notification, timeout)) + def delete_message(self, chat_id, message_id, timeout=None): """ Use this method to delete message. Returns True on success. @@ -863,7 +881,7 @@ class TeleBot: """ parse_mode = self.parse_mode if (parse_mode is None) else parse_mode - return types.Message.de_json( + return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup, parse_mode, disable_notification, timeout, caption, thumb)) @@ -2267,6 +2285,11 @@ class AsyncTeleBot(TeleBot): def forward_message(self, *args, **kwargs): return TeleBot.forward_message(self, *args, **kwargs) + @util.async_dec() + def copy_message(self, *args, **kwargs): + return TeleBot.copy_message(self, *args, **kwargs) + + @util.async_dec() def delete_message(self, *args): return TeleBot.delete_message(self, *args) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 1cedbc8..9ba0a1a 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -326,6 +326,30 @@ def forward_message( return _make_request(token, method_url, params=payload) +def copy_message(token, chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, + reply_to_message_id=None, allow_sending_without_reply=None, reply_markup=None, + disable_notification=None, timeout=None): + method_url = r'copyMessage' + payload = {'chat_id': chat_id, 'from_chat_id': from_chat_id, 'message_id': message_id} + if caption is not None: + payload['caption'] = caption + if parse_mode is not None: + payload['parse_mode'] = parse_mode + if caption_entities is not None: + payload['caption_entities'] = caption_entities + if reply_to_message_id is not None: + payload['reply_to_message_id'] = reply_to_message_id + if reply_markup is not None: + payload['reply_markup'] = reply_markup + if allow_sending_without_reply is not None: + payload['allow_sending_without_reply'] = allow_sending_without_reply + if disable_notification is not None: + payload['disable_notification'] = disable_notification + if timeout: + payload['connect-timeout'] = timeout + return _make_request(token, method_url, params=payload) + + def send_dice( token, chat_id, emoji=None, disable_notification=None, reply_to_message_id=None,