Implementing a timeout for FormActions?


I’m working on implementing a sort of “command-less chatbot” for Discord. This means that along with the general challenges of handling multiple users at once, I want to be able to handle abandoned conversations gracefully.

Suppose I have a user who starts up a FormAction but abandons the conversation midway. To prevent it from potentially interfering with other people’s experience (or even that user’s experience when they return) I would like to implement a timeout to my FormActions. (I specify FormActions because my Actions are all designed around being one-statement-one-response anyways.) How can I approach implementing this?

Hi @ActuallyAcey,

I am curious that you said you want to time out form Actions here. Because when you time out a form action its going to deactivate the bot form action right. In your Implementation you are creating bot answers multiple users at once from that I understand its going to be one chat bot.

Instead of Timing out the form action, why don’t you use the sender_id to get the conversations from the GET /conversations/(str: sender_id)/tracker

Time out the sender_id using http async. In that way you distinguished the user from others and does not affect the bot to its goal.

These are all my thoughts.! :slightly_smiling_face:

Hi Murali.

I know that I can use different Sender IDs to avoid confusing the bot between who’s sending the messages, and that’s what I intended as well. However, if user A abandons a conversation and comes back to it 4 hours later, I would like the bot to forget the previously abandoned conversation for A.

Hello @ActuallyAcey

Maybe you can implement some kind of timer on your Discord connector, every time the user chats with the bot the timer is reset. If the timer timeout, you send a “/restart” command to the bot: {“sender”: user_id, “text”: “/restart”} which will restart the whole conversation.

Although there can be a performance problem if you have a lot of users cause that means you’ll have to create and manage a lot of timers.

Hi @ActuallyAcey Do you have any solution for it?

I used a package named func-timeout and implemented it on the Discord server side of things. That being said, it should be fairly easy to implement it into the Action Server as well, like so:

class ActionDoSomething(Action):

# Make sure this method is called in a try-except block that catches FunctionTimedOut
    return []

def some_timed_method():
    # Do something here.