Resetting a session (slots, active forms etc) if last user event is older than N seconds


I have a somewhat complicated Bot (Multiple actions, quite a few intents, forms etc). To enhance the user experience we decided to have a logical session timeout where the last time user interacted with the bot is older than N seconds, we want to reset the session. i.e. clear all slots, deactivate active forms etc. What is the best way to do this?

One simple way of doing it is for all actions to insert a snippet like this: But seems like there should be a better way of doing this in a more centralized and less repetitive manner. Any advice from anyone?

            # we are taking 1-last because last event is the user utterance that lead to this action.
            last_event_time =[-2].get('timestamp')
            logger.error("unable to obtain last event time. Defaulting to -1 which will trigger a restart")
            last_event_time = -1
        current_ts =
        time_since_last_event = current_ts - last_event_time # this is in seconds"current ts ={current_ts}, last_event_ts = {last_event_time}, session time_since_last_event={time_since_last_event}")
        if time_since_last_event > SESSION_LIFETIME:
            dispatcher.utter_template("utter_greet", tracker)
  "Restarting session since {time_since_last_event} is greater than session lifetime {SESSION_LIFETIME}")
            return [Restarted()]

You can create a reminder to schedule action_restarted(): Events

This is actually quite cool. Thanks!

why not use session_expiration_time?

I think I didnt know about the session_expiration_time at that point. I guess this should be the easy way out.