From 0eb18f2f5a38e4a2717a6c0d6968f0ba04b96b72 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 2 Mar 2022 13:13:43 +0100 Subject: [PATCH] Raise TimeoutError from inline_query instead --- telethon/_client/bots.py | 20 ++++++++++++-------- telethon/_client/telegramclient.py | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/telethon/_client/bots.py b/telethon/_client/bots.py index e1e5fe5f..b2b8c1c8 100644 --- a/telethon/_client/bots.py +++ b/telethon/_client/bots.py @@ -1,8 +1,9 @@ import typing +import asyncio from ..types import _custom from .._misc import hints -from .. import _tl +from .. import errors, _tl if typing.TYPE_CHECKING: from .telegramclient import TelegramClient @@ -22,12 +23,15 @@ async def inline_query( else: peer = _tl.InputPeerEmpty() - result = await self(_tl.fn.messages.GetInlineBotResults( - bot=bot, - peer=peer, - query=query, - offset=offset or '', - geo_point=geo_point - )) + try: + result = await self(_tl.fn.messages.GetInlineBotResults( + bot=bot, + peer=peer, + query=query, + offset=offset or '', + geo_point=geo_point + )) + except errors.BotResponseTimeoutError: + raise asyncio.TimeoutError from None return _custom.InlineResults(self, result, entity=peer if dialog else None) diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index 3c242647..3d32dd3b 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -733,6 +733,10 @@ class TelegramClient: The geo point location information to send to the bot for localised results. Available under some bots. + Raises + If the bot does not respond to the inline query in time, + `asyncio.TimeoutError` is raised. The timeout is decided by Telegram. + Returns A list of `_custom.InlineResult `.