Home / DialogFlow ES / How to use session variables to save user input in Dialogflow ES
DialogFlow ES

How to use session variables to save user input in Dialogflow ES

In the previous article I explained how you can mimic the behavior of follow up intents to move to the next intent.

One disadvantage of this approach is that you cannot access the information collected from 2 or more steps prior in the current response.

The way around this is to use the concept of session variables.

What are session variables?

In the entry intent (that is one which does not have an input context), add an output context which has a very large lifespan, like 50 or 100. You can now use this output context for the next 50 (or 100) steps in your conversation flow and access user input values

Example

Let us take the example of the lead capture bot, and extend it to use session variables.

Add an intent called add.website.chatbot intent with the following details. Add an output context called session-vars with a context lifespan of 50

Add an intent called user.provides.name with the following details

Add an intent called user.provides.email with the following information

Add an intent called user.provides.url with the following information

The user.provides.url intent ends the conversation. So we display a thank you message and also summarize the user’s input.

Notice that I use the prefix #session-vars followed by the parameter name. That is how you can access parameters stored in the session-vars context.

However, the last parameter $url will only be added into the session-vars in the next step. So you need to just access it via the regular parameter name.

Now test the bot using the Dialogflow Messenger integration

<— End of article —>


This website contains affiliate links. See the disclosure page for more details. 
"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth
"Much clearer than the official documentation to be honest"

Thanks a lot for the advice (of buying and following your videos)! They helped a lot indeed. Everything is very clear when you explain, much clearer than the official documentation to be honest 🙂

Neuraz T
Review for Learn Dialogflow CX
"I will strongly recommend this course because even I can learn how to design chatbot (no programming background)"

I think Aravind really did a great job to introduce dialogflow to people like me, without programming background. He organizes his course in very clear manner since I have been a college professor for 20 years. It is very easy for me to recognize how great Aravind’s course is! Very use-friend and very easy to follow. He doesn’t have any strong accent when he gives the lectures. It is so easy for me to understand. Really appreciate it.

Yes, I will strongly recommend this course because even I can learn how to design chatbot (no programming background) after studying Avarind’s course, you definitely can!

Ann Cai
Review for Learn Dialogflow ES

Similar Posts