Extend Session Timeout for Dialogflow Chatbot

Pragnakalp Techlabs
Chatbots Life
Published in
3 min readJun 24, 2022

--

In Dialogflow, the session for agents is maintained by Dialogflow itself. Session continuous the conversation flow between the agent and the user.

Why is it necessary to extend the Dialogflow session?

In the conversation with the chatbot, if a user takes longer than 30 minutes to respond to the agent then the session between the user and the Dialogflow agent will expire. In such cases, the user will have to restart the conversation with the agent from the beginning. So to overcome this problem we need to extend the session for Dialogflow.

Problem statement

Suppose the user is talking to a chatbot regarding fashion. During the conversion, the bot asks the user about the size he prefers wearing, for which the user is unsure. So the user confirms his size with his wife and responds after 30 minutes but as the session has expired the flow for the bot will not be continued and the user will have to restart the conversion. And will have to go through the flow once again to reach the previous stopping point.

Here is a conversational example:

Bot: Hello Welcome to shopify What would you like to wear.
User: Tshirts.
Bot: So, tell me what is your prefered style?
- Polo
- Casual
- Dyed
- Dry-fit
User: Casual
Bot: Okay, What size do you wear ?
User: ( After 45 minutes ) XL
Bot: Sorry, could you say that again?

What is the session deadline for Dialogflow?

In Dialogflow, agent responses can be set in two ways from Dialogflow itself for basic responses and another is to set dynamic responses using webhooks. Complex conversation can be created using webhook services.

The Dialogflow session is only maintained for 30 minutes. The user must respond within 30 mins to continue the flow of the agent. After that chatbot will not continue the flow and we can say the session deadline occurs. Any response given after 30 mins will set the agent back to Dialogflow fallback intent.

How to extend the session timeout for Dialogflow Agent?

To resolve the above issue, we need to extend the session deadline. The following are steps to extend the session timeout:

Step 1: We need to access our Dialogflow agent with Dialogflow API. In the Dialogflow API, we need to pass one unique user id to identify the user.

Step 2: We manually create a session name consisting of the user id such that every user has their own unique session Id.

Step 3: We then create a Database (DB) to store the user id and currently active context of Dialogflow intent.

Step 4: When a user inputs the data we take the data as query text and create an API call to Dialogflow, which detects the intents from the context and sends a response. The user id and the relative context are stored in the Database (DB).

Step 5: After some time when the user enters another input a similar request is made to Dialogflow and responses are displayed. Keeping the session active even though it has been some time since the last input.

Step 6: Contexts and parameters will keep on changing in DB on every query input given by the user.

If we consider the above same conversation as an example, then after extending the session timeout in Dialogflow, the conversation with the bot should be:

Bot: Hello Welcome to shopify What would you like to wear.
User: Tshirts.
Bot: So, tell me what is your prefered style?
- Polo
- Casual
- Dyed
- Dry-fit
User: Casual
Bot: Okay, What size do you wear ?
User: ( After Infinite amount of time ) XL
Bot: Okay , What colour would you prefer?

You can extend the session indefinitely by following the procedures above. Hope it will be useful in resolving the significant session time increase problem in Dialogflow ES. If you face any problems when implementing this functionality, kindly comment below.

Originally published at Extend Session Timeout For Dialogflow Chatbot on June 24, 2022.

--

--

Chatbots Development, Python Programming, Natural Language Processing (NLP), Machine Learning Solutions. https://www.pragnakalp.com