From f99b4874c8b3d6de7e39e81aac1f2b0f6b1e6819 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 4 Jan 2019 11:15:11 +0100 Subject: [PATCH] Support passing media objects to inline results (#1053) --- telethon/tl/custom/inlinebuilder.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telethon/tl/custom/inlinebuilder.py b/telethon/tl/custom/inlinebuilder.py index db0a06cb..05816f2c 100644 --- a/telethon/tl/custom/inlinebuilder.py +++ b/telethon/tl/custom/inlinebuilder.py @@ -113,7 +113,11 @@ class InlineBuilder: Same as ``file`` for `client.send_file `. """ - fh = await self._client.upload_file(file, use_cache=types.InputPhoto) + try: + fh = utils.get_input_photo(file) + except TypeError: + fh = await self._client.upload_file(file, use_cache=types.InputPhoto) + if not isinstance(fh, types.InputPhoto): r = await self._client(functions.messages.UploadMediaRequest( types.InputPeerSelf(), media=types.InputMediaUploadedPhoto(fh) @@ -177,8 +181,12 @@ class InlineBuilder: else: type = 'document' - use_cache = types.InputDocument if use_cache else None - fh = await self._client.upload_file(file, use_cache=use_cache) + try: + fh = utils.get_input_document(file) + except TypeError: + use_cache = types.InputDocument if use_cache else None + fh = await self._client.upload_file(file, use_cache=use_cache) + if not isinstance(fh, types.InputDocument): attributes, mime_type = utils.get_attributes( file,