How to save data between conversation in Dialogflow?

不问归期 提交于 2019-12-17 05:15:12

问题


I don't understand how you're supposed to save data. I tried using

let conv = agent.conv()
conv.data.data1=mydata //to save
mydata = conv.data.data1 //to load
agent.add(conv)

but it crash my app. I saw that you could put info in

var token = JSON.stringify(request.body.originalDetectIntentRequest.payload.conversation.conversationToken);

but how do you put data in conversationToken in the response?

What is your method? Thanks


回答1:


Use the output context to save parameters

{  
  "fulfillmentText":"This is a text response",
  "fulfillmentMessages":[  ],
  "source":"example.com",
  "payload":{  
    "google":{  },
    "facebook":{  },
    "slack":{  }
  },
  "outputContexts":[  
    {  
      "name":"<Context Name>",
      "lifespanCount":5,
      "parameters":{  
        "<param name>":"<param value>"
      }
    }
  ],
  "followupEventInput":{  }
}

If you are using NodeJS client

You can save context with parameters like

let param1 = [];
let param2 = {};
let ctx = {'name': '<context name>', 'lifespan': 5, 'parameters': {'param1':param1, 'param2': param2}};
agent.setContext(ctx);

and get it like

let params = agent.getContext("<context name>").parameters;
let param1 = params.param1;
let param2 = params.param2; 

You can store arrays, JSON obj but there is a limit to the total payload the response can save. check for more details here. For large data, use DB.

Also, if you are using standalone actions-on-google, then you can simply add key-value pair to the data object. See the link where they are storing a count




回答2:


Also if you want to mark those parameters as required and use slot filling, that will automatically generate your output contexts during fulfillment. You can see this through a basic sample here: https://github.com/dialogflow/fulfillment-slot-filling-nodejs



来源:https://stackoverflow.com/questions/51521454/how-to-save-data-between-conversation-in-dialogflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!