From 4b9b77614fcc1ddaa750652abdec11969f25e3bd Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 4 Jan 2019 11:13:13 +0100 Subject: [PATCH] Support answering inline queries with empty text (#1053) --- telethon/tl/custom/inlinebuilder.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/telethon/tl/custom/inlinebuilder.py b/telethon/tl/custom/inlinebuilder.py index a03338bb..db0a06cb 100644 --- a/telethon/tl/custom/inlinebuilder.py +++ b/telethon/tl/custom/inlinebuilder.py @@ -125,8 +125,11 @@ class InlineBuilder: type='photo', photo=fh, send_message=await self._message( - text=text, parse_mode=parse_mode, link_preview=link_preview, - geo=geo, period=period, + text=text or '', + parse_mode=parse_mode, + link_preview=link_preview, + geo=geo, + period=period, contact=contact, game=game, buttons=buttons @@ -200,8 +203,14 @@ class InlineBuilder: type=type, document=fh, send_message=await self._message( - text=text, parse_mode=parse_mode, link_preview=link_preview, - geo=geo, period=period, + # Empty string for text if there's media but text is None. + # We may want to display a document but send text; however + # default to sending the media (without text, i.e. stickers). + text=text or '', + parse_mode=parse_mode, + link_preview=link_preview, + geo=geo, + period=period, contact=contact, game=game, buttons=buttons @@ -247,8 +256,9 @@ class InlineBuilder: text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None ): - args = (text, geo, contact, game) - if sum(1 for x in args if x) != 1: + # Empty strings are valid but false-y; if they're empty use dummy '\0' + args = ('\0' if text == '' else text, geo, contact, game) + if sum(1 for x in args if x is not None and x is not False) != 1: raise ValueError( 'Must set exactly one of text, geo, contact or game (set {})' .format(', '.join(x[0] for x in zip( @@ -256,7 +266,10 @@ class InlineBuilder: ) markup = self._client.build_reply_markup(buttons, inline_only=True) - if text: + if text is not None: + if not text: # Automatic media on empty string, like stickers + return types.InputBotInlineMessageMediaAuto('') + text, msg_entities = await self._client._parse_message_text( text, parse_mode )