When using ConversationHandler with async handler callbacks and timeout, the timeout may trigger falsely. This is the case, when the callback returns CH.END, which currently the timeout callback doesn't know.
This can be solved by making CH._trigger_timeout check if the current conversations state as follows:
if isinstance(state, Promise):
if state.done and state.result() == CH.END:
return
This will still fail, if the promise is not yet done, when the timeout triggers but
- it's a best effort solution
- if a promise takes longer to run than the timeout is, then there are probably some other issues in the users code
Also when looking at the code I noticed that we don't handle nested conversations in CH._trigger_timeout, so that's a good opportunity to fix that …