Reputation: 88
I am using Dialogflow API v1 for this project and using Node.js as my webhook language. Currently, I am able to save a value in a context and access the value in the intent following the initial question. Is it possible to access that same value 3-4 levels deep of intents after saving it initially?
As an example, I can access a variable stored in such way: Intent A -> Intent B
However, I am trying to access a variable stored in this way: Intent A -> Intent B -> Intent C -> Intent D
I am able to access the value in intent B however, every time I get to Intent C or Intent D, the context variable is null. Is there a way to store a variable across multiple intents and not just one in Dialogflow? I am passing the same context across multiple intents.
Upvotes: 0
Views: 1323
Reputation: 50701
Yup! The way you'd handle this is in Intent A, set the output context (I'll call it Context_A) with the value you want, and set the lifespan of it to at least 3. That means that the context will exist for at least 3 rounds of conversation between your user and Dialogflow.
You can set it for longer if you wish, of course. If you set it lower, you may also wish to just extend its lifespan in some later Intent by re-sending it in an output context with a larger lifespan value.
If you have additional information in, for example, Intent B, you could either set it in Context_B or add to the properties set in Context_A and make sure its lifespan is still sufficient.
Upvotes: 2
Reputation: 11970
If you are using the AoG client library, you can persist data across multiple steps of a conversation by using app.data
.
app.data.datum1 = "Hello";
app.data.datum2 = "world";
These data will be cleared after the user exits the conversation.
Upvotes: 2