Search code examples
dialogflow-es

In Dialogflow ES, how to save parameter value from one intent to another?


I have one intent "Buy-Car" where I ask some basic information like color, size, region. These are saved in parameter. Then I trigger another intent called "TriggerBot" which will call my backend process to fulfill the order via fulfillment. How do I pass the parameter information from one intent to the other one?

Here I define the parameters in Buy-Car intent: enter image description here

Here I define the TriggerBot intent: enter image description here

Here is my code for fulfillment:

function TriggerBot(agent) {
    console.log("Parameters: "+JSON.stringify(agent.parameters));
    const color = agent.parameters.color;
    const size = agent.parameters.size;
    const region = agent.parameters.region;
}
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
    console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
    console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
    let intentMap = new Map();
    intentMap.set('Default Welcome Intent', Welcome);
    intentMap.set('Default Fallback Intent', Fallback);
    intentMap.set('Trigger Bot', TriggerBot);
    agent.handleRequest(intentMap);
}

Everything is undefined in this case, however if I use just one intent, it works fine. So the value is lost when transferring from one intent to another.


Solution

  • There are 3 main ways to pass parameters between intents in Dialogflow ES

    1. Followup Intents

    You can use follow-up intents to automatically set contexts for pairs of intents. A follow-up intent is a child of its associated parent intent.

    Followup intents are helpful for keeping track of what happened in the conversation. They also help you pass parameters between intents.

    1. Use session variables

    Declare something called a session variable in each of your Dialogflow entry intents.

    This has the added benefit of being able to pass parameters between intents even if the conversation takes an unexpected turn.

    1. Use Context

    It was described in another stackoverflow thread - How to save data between conversations in Dialogflow?.

    In addition I think you could also find some additional information in the below links