0

In Dialogflow Fulfillment I simply want to pass data from the Welcome Intent to the help Intent using conv.user.storage as seen in the code below. I can add it in the welcome intent but when I try to retrieve it in the help intent it is always undefined meaning data is NOT passed to the help intent. I have spent several hours on something I thought was straight forward and played around without any success. I would really appreciate a real world example on how to fix it and understand what I'm doing wrong.

function welcome(agent) {
   agent.add(request.body.queryResult.fulfillmentMessages[0].text.text[0]);
    var entity = 'media_getreq?message=volume';
    getData(entity).then(result => {
        let conv = agent.conv();
        conv.user.storage["devicedata"] = result;
        console.log(conv.user.storage["devicedata"]); //WORKS
    });
}

function help(agent) {              
        agent.add(request.body.queryResult.fulfillmentMessages[0].text.text[0]);
        let conv = agent.conv();
        console.log(conv.user.storage["devicedata"]); //ALWAYS EMPTY
}

1 Answers1

0

You have missed out Contexts a critical componet required to link intents. Contexts represent the current state of a user's request and allow your agent to transport conversation information from one intent to another. You can use combinations of input and output contexts to control the conversational path the user traverses through your dialog sequence.

In summary, The intent that collects your Welcome input uses an output context to "remember" what you said. The same context is used as the input context to the next intent, which collects input into the HelpIntent.

You need to update your code accordingly. Please see for details:

https://dialogflow.com/docs/contexts

https://dialogflow.com/docs/contexts/contexts-api

Terungwa
  • 61
  • 1
  • 6