has that knowledge, I'm trying to interact with a third-party bot, and when I'm clicking the bot MessageButtons using the usual mobile phone client i can observe the results very quickly, but when I'm using telethon to click them, there is a massive delay in the program. Most probably it is caused by the fact that the bot doesn't have answer_callback_query implemented in its code (yeah, lame, but unfortunately it's third party), and the telethon client is waiting for some ~20 seconds for a response, not getting any, and only then proceeding with the next one.
So the questions are:
1) is it possible to somehow override the telethon behaviour for request to make it more like telegram's official client that allows to click a lot of buttons without waiting for each request to resolve
or
2) is it somehow possible to modify the request to not receive bot answer at all, just to send the "clicking" part to telegram servers? I don't really need the answer and if I could just fire and forget only "the clicking" part it would be alright
or
3) is it at least possible to reduce somewhere the time gap for which the telethon is trying to get an answer? so say instead of 20 seconds it becomes like 2, click and forget
Unfortunately my knowledge of this lower-level implementations is poor, I've dug down to the click() implementation and i think this is the faulty place:
try:
return await self._client(req)
except BotResponseTimeoutError:
return None
unfortunately I then dug down to client._call and there I can't see where and how the BotResponseTimeoutError is raised or any parameters to influence it, I only see retry attempts number but not sure if it would change anything as it might be really 1 attempt but a long one
Thanks a lot for any input
Every call of client(req) has to return a result or raise rpc error to the context before the code proceeds in same context if you don't care about the return, you can fire and forget it as a task or cancel if it takes too long but you need the result, read about asyncio.wait_for() and set a timeout, average bot should take less than 2 seconds to deliver a response, you can also then expand on this and create a task for each button to click. abort the remaining when one returns or whatever you intend with asyncio.wait
> average bot should take less than 2 seconds to deliver a response that's exactly the problem, the bot that I have to use is third party, lame designed and don't have answer_callback_query implemented in the call handler, as such, telethon's waiting for like 20 seconds to throw a bot response error. I will try wait_for, I never heard about it. it can cancel the request resolving, right? that's what you mean?
Telethon is doing what it should. it's telegram kinda at fault for not timing out earlier, that's just intended. try: callback = await asyncio.wait_for(message.click(...), timeout=2) except asyncio.TimeoutError: callback = None you can abort the awaiting if your code must proceed like that
yeah, I'm not blaming telethon or anything, I'm just curious if anything can be modified a bit. after all, in the official telegram client i can click those buttons rapidly and it will work fine, so was just thinking if something is possible to do here. thanks a lot again, i will try as soon as I can , looks promising ;)
yes it is one attempt but a long one. telegram waits for the bot's answer before returning the result. if you want to fire-and-forget, use asyncio.create_task
Обсуждают сегодня