Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to set session timeout to 30 seconds

Hi,
I use Google Dialogflow CX.
If there is no user activity in 30 seconds I want to terminate chatbot session.
There are examples or documentation as below, I tried somethings 
but didn't work. 
https://cloud.google.com/dialogflow/cx/docs/concept/session#long-lasting

If you have a concrete example which is work, please share with me.

Thanks.

0 1 479
1 REPLY 1

Hi @oozturkplus,

Welcome to Google Cloud Community!

Dialogflow CX does not have a built-in mechanism to automatically terminate a session after 30 seconds of inactivity. The documentation you referenced discusses extending session lifespan, not shortening it. To implement a 30-second inactivity timeout, you will need to create a custom solution outside of Dialogflow CX. This involves integrating your Dialogflow CX agent with a custom application (such as a web application or serverless function) that handles the session timeout logic. Here are some approaches you can consider:

  1. Client-Side Timer: Your client application (the chatbot interface) should implement a timer that starts when the user last interacts with the chatbot (e.g., sends a message).
  2. Inactivity Detection: Once the timer reaches 30 seconds, the client application triggers a custom event, such as SESSION_TIMEOUT, to your Dialogflow CX agent.
  3. Dialogflow CX Event Handler: You’ll need to set up an event handler in your Dialogflow CX agent to capture the SESSION_TIMEOUT event. This handler should handle the action of ending the session, possibly by transitioning to an "End Session" page.
  4. Session Termination: The "End Session" page in Dialogflow CX should be configured to properly close the session, providing an appropriate message to the user if needed.
  5. Webhook with session timer:

  • Develop a webhook that tracks the last user activity time.
  • When a new user interaction is received, reset the timer.
  • If the timer elapses without any user activity (set to 30 seconds in your case), send a predefined message (e.g., "session expired") and terminate the session from your webhook.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.