Reputation: 11
I am new to Dialogflow and I have created a bot that queries different user information through different intents (e.g. first name, name, birthdate etc.). Now I am using a function in fulfillment where I need the parameter values from different intents.
const {last_name, street, house_no,
zip_code, birthdate,
email} = agent.parameters;
In the output of the function the parameters are labeled "undefined". I guess because agent.parameters only refers to the intent that triggers the webhook, it does not capture the parameter values from all the other intents. Is there a way how to get the parameter values from the other intents?
Upvotes: 1
Views: 391
Reputation: 3271
If you want to use paramter values from a different intent, you first have to save them in your webhook. Dialogflow has a feature called Context to help you do this. Context's have a parameter field in which you can store values. So in your first intent you can store them by creating a context and adding the values to this context.
1st Intent
const {last_name, street, house_no,
zip_code, birthdate,
email} = agent.parameters;
agent.context.set('context_name', 5, {'lastName' : last_name, 'street': street});
In the above example 5 is used to indicate the lifespan of the context. So the values will be available for 5 turns of the conversation. Next up, in the second intent you need to get the context that you just set to use the values. After that you can get values from the paramter field of the context.
2nd Intent
const context = agent.context.get('context_name');
const lastName = context.parameters.lastName;
const street = context.parameters.street;
Upvotes: 0