diff --git a/davtelepot/bot.py b/davtelepot/bot.py index 0f0c9f4..b443370 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -643,10 +643,7 @@ class Bot(TelegramBot, ObjectWithDatabase): if type(reply) is str: reply = dict(text=reply) try: - if 'text' in reply: - return await self.send_message(update=update, **reply) - if 'photo' in reply: - return await self.send_photo(update=update, **reply) + return await self.reply(update=update, **reply) except Exception as e: logging.error( f"Failed to handle text message:\n{e}", @@ -901,6 +898,17 @@ class Bot(TelegramBot, ObjectWithDatabase): yield (prefix + text_chunk + suffix), is_last return + async def reply(self, update=None, *args, **kwargs): + """Reply to `update` with proper method according to `kwargs`.""" + method = None + if 'text' in kwargs: + method = self.send_message + elif 'photo' in kwargs: + method = self.send_photo + if method is not None: + return await method(update=update, *args, **kwargs) + raise Exception("Unsopported keyword arguments for `Bot().reply`.") + async def send_message(self, chat_id=None, text=None, parse_mode='HTML', disable_web_page_preview=None,