I'm using python-telegram-bot to build a bot that answers to inline queries. The query result is kind of complex to process. I'm using @run_async
.
As a user types an inline query, the client produces several queries, every one of them spawning a handler on my bot that takes time to process.
Of all of those queries, only the latest one is actually important. For example, if I query for "Beach Voley", the bot will receive successive queries for:
- Bea
- Beach
- Beach Vo
- Beach Voley
as I type, pause and continue typing.
Then, my bot lags processing the incomplete queries before processing the actually important one, and telegram gives me invalid id errors for the outdated ones, and timeout for the actually important query.
I would like to, upon receive a query, cancel any other inline queries being processed for that user with an older timestamp, killing their threads or something.
Telepot, another telegram bot library for python I used, had this included as a feature. From what I could understand of the source code, it keeps a running tasks queue internally.
How could I mimic this behavior in python-telegram-bot? Is this a feaure that I'm just not finding?