I use telethon library.
I can show typing event one (for 5 seconds) but can’t continue doing it.
Because I am using OpenAI that is not super fast I need to show typing event for longer (I can do it with delays).
async with client.action(event.chat_id, 'typing'):
slow function here
How to do that?
Thank you.
2
Answers
Your "slow function" can be
asyncio.sleep
:…but the idea of having the context manager is for you to put your long-running operation inside:
which would be far more accurate than "a minute or two".
Make sure that
function_that_takes_long
does not block the thread, or theasyncio
event loop won’t be able to make any progress (and, by extension, Telethon won’t be able to keep sending the action notification).If your function is not really
async
, you should probably reach out forloop.run_in_executor
.To make typing status longer than 5 seconds, do something like this:
And execute it like this: