0

I am trying to get all the parameters at once in dialogflow using dialogflow-fulfillment library instead of using action-google.

Is it possible to do so?

My code is like -:

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 conv= agent.conv();

function welcome(agent) {

let date = new Date();
var curHr = date.getHours();

if(curHr.toString() < 12)
{
  agent.add('Hello, Good Morning!');

}
else{
    agent.add('Hello, Hope you are having good day!');
}
}

function fein(agent){
const fein = agent.parameters.fein;
const name = agent.parameters['business-name'];
conv.user.storage = {
     fein: fein
  };


agent.add(conv.user.storage.fein.toString());
}

But not able to fetch the output.

I am not sure I am doing it the right way, Please help how to get it done.

Ridhima Garg
  • 67
  • 11

1 Answers1

0

Before you use the user.storage objects you should check if you need the saved data to last between conversations. If you only need the data to be available within the current conversation it is easier to use conv.data.

If you need the information to persist between multiple conversations use conv.user.storage. When you use conv.user.storage make sure you users enable the Web & App Activity setting and the Include Chrome history checkbox in the activity controls.

enter image description here

These settings are required if you want to use user storage to save data between conversations. If you don't enable them, your data won't be saved in the user storage at all.

Jordi
  • 3,041
  • 5
  • 17
  • 36
  • Okay, but my agent object in the above code is of webhookClient, not of action-on-google library. Will conv.data work for agent object? – Ridhima Garg Nov 13 '19 at 09:02
  • I am pretty sure conv.data works for Dialogflow aswell, aslong as you call agent.conv(); – Jordi Nov 13 '19 at 09:03
  • I tried conv.data.fein = fein, but its not able to prompt any message. – Ridhima Garg Nov 13 '19 at 09:11
  • I am able to see the output in https://console.actions.google.com/ but not in test console, also not on the integrated website. I have integrated the chatbot using kommunicate. – Ridhima Garg Nov 13 '19 at 09:59
  • Ah okay I'm not sure if it works for other integrations, looking at the documentation it looks like agent.conv is a build in integration with Google Assistant. So that would explain why it isn't working for kommunicate. https://dialogflow.com/docs/reference/fulfillment-library/webhook-client#webhookclientconv_%E2%87%92_dialogflowconversation_null – Jordi Nov 13 '19 at 10:10
  • I am still not able to figure out, what steps need to be taken. Please suggest if anything. – Ridhima Garg Nov 14 '19 at 06:25