- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个 dialogflow 机器人来询问用户一些问题,我需要保存输入到 Firestore 数据库中的所有答案,我使用的是 api v1 机器人!我可以通过在 Dialogflow 上下文中保存文档的名称来添加字段 name 和 answer1,
index.js:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(
(request, response) => {
// console.log("function happening");
let action = request.body.result.action;
var Name = request.body.result.parameters.Name;
let params = request.body.result.parameters;
var Answer1 = request.body.result.parameters.Answer1;
var Answer2 = request.body.result.parameters.Answer2;
var Answer3 = request.body.result.parameters.Answer3;
var Answer4 = request.body.result.parameters.Answer4;
var Answer5 = request.body.result.parameters.Answer5;
var Answer6 = request.body.result.parameters.Answer6;
var Answer7 = request.body.result.parameters.Answer7;
var Answer8 = request.body.result.parameters.Answer8;
var Answer9 = request.body.result.parameters.Answer9;
var Answer10 = request.body.result.parameters.Answer10;
var Answer11 = request.body.result.parameters.Answer11;
var Answer12 = request.body.result.parameters.Answer12;
let query = request.body.result.resolvedQuery;
const parameters = request.body.result.parameters;
const inputContexts = request.body.result.contexts;
console.log("Parameters is" + params);
console.log("Answer1 is " + Answer1);
console.log("Helllo");
console.log("action is " + action);
console.log("name is:", Name);
if (action == "save.name") {
admin
.firestore()
.collection("users")
.doc(Name)
.set({
name: Name,
answer1: "",
answer2: "",
})
.then(ref => {
console.log("name saving function");
console.log("Name is added successfully", +Name);
console.log("Added new user");
});
}
if (action == "save.answer1") {
var Name;
for (
var co = 0;
inputContexts && co < inputContexts.length && !Name;
co++
) {
var context = inputContexts[co];
console.log('The input context here is ', +inputContexts[co]);
if (context.name == "question1") {
console.log("The name of the document is", +context.parameters.Name);
Name = context.parameters.Name;
}
}
console.log("name in save.answer1", Name);
admin
.firestore()
.collection("users")
.doc(Name)
.update({
answer1: Answer1
})
.then(ref => {
console.log("Updated user");
console.log("Name is " + Name);
console.log("ref id is:" + ref.id);
});
}
if (action == "save.answer2") {
var Name;
for (
var co = 0;
inputContexts && co < inputContexts.length && !Name;
co++
) {
var context = inputContexts[co];
console.log('The input context here is ', +context.name);
if (context.name == "question2") {
console.log("The context name here is", +context.name);
console.log("The name of the document is", +context.parameters.Name);
Name = context.parameters.Name;
console.log('Name inside if', +Name);
}
}
console.log("name in save.answer2", Name);
admin
.firestore()
.collection("users")
.doc(Name)
.update({
answer2: Answer2
})
.then(ref => {
console.log("Updated user");
console.log("Name is " + Name);
console.log("ref id is:" + ref.id);
});
}
}
);
我在 dialogflow 上下文中保存文档的名称,这样我就可以将字段 name 和 answer1 保存到文档中,但我不能能够通过遵循相同的技术来保存 answer2,它会抛出如下错误:
Argument "documentPath" is not a valid ResourcePath. Path must be a non-empty string.
保存 answer1 后我在 dialogflow 中的 json 如下所示:
{
"id": "da818283-f8bf-44ee-8c86-80a69cf8128a",
"timestamp": "2018-07-18T07:33:51.743Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "I am fine",
"action": "save.answer1",
"actionIncomplete": false,
"parameters": {
"Answer1": "I am fine"
},
"contexts": [
{
"name": "question2",
"parameters": {
"Answer1": "I am fine",
"Answer1.original": "I am fine"
},
"lifespan": 1
}
],
"metadata": {
"intentId": "cf4c0b5e-b848-402a-be22-62ca26ec1d00",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"isFallbackIntent": "false",
"webhookResponseTime": 10000,
"intentName": "Q-1"
},
"fulfillment": {
"speech": "Oh Well, Can you tell What is the best thing about your Companion?",
"messages": [
{
"type": 0,
"speech": "Oh Well, Can you tell What is the best thing about your Companion?"
}
]
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Request timeout."
},
"sessionId": "4967cb18-a192-0796-63ed-5ce3ec03acf9"
}
输入answer2后的json:
{
"id": "9a9425dc-44a0-4cf6-8fa5-8d483d552c74",
"timestamp": "2018-07-18T08:40:10.86Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "I love to watch movies",
"action": "save.answer2",
"actionIncomplete": false,
"parameters": {
"Answer2": "I love to watch movies"
},
"contexts": [
{
"name": "question3",
"parameters": {
"Answer2": "I love to watch movies",
"Answer2.original": "I love to watch movies"
},
"lifespan": 1
}
],
"metadata": {
"isFallbackIntent": "false",
"webhookResponseTime": 339,
"intentName": "Q-2",
"intentId": "d15366cc-93f0-4178-975b-af8b0e182498",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false"
},
"fulfillment": {
"speech": "Oh that's cool! What is the worst thing about your partner?",
"messages": [
{
"type": 0,
"speech": "Oh that's cool! What is the worst thing about your partner?"
}
]
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: 500 Internal Server Error"
},
"sessionId": "4967cb18-a192-0796-63ed-5ce3ec03acf9"
}
最佳答案
问题是您没有在任何上下文中存储 name
,而是试图在下一次从上下文中读取它。这些上下文是在调用您的 webhook 之间存储信息的内容,因此您需要添加下次需要的任何信息。
由于文档的名称是您需要在以后的响应中使用的内容,因此您需要保存它。
您没有显示您是如何创建或发送响应的,但请确保您创建了一个上下文并将 name
作为参数之一包含在内。
关于javascript - 无法通过将文档名称保存在对话流上下文中来向文档添加多个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51396250/
我知道 Jobs 可以通过 flink 或 flink.bat 提交给 JobManager。我想知道Flink有没有提供Java API给JobManager提交作业? 最佳答案 是的。根据您要连接
我已经将 GCM 的演示代码应用于 appache 服务器的服务器端和 android 设备的客户端,并且运行良好;但我需要在我的应用程序中激活此服务,如下所示:我在 SqlServer 上有一个数据
我需要将自定义 header 添加到 WebView 中加载的页面,但它不起作用, header 未设置: @Override public WebResourceResponse shouldInt
我是一名优秀的程序员,十分优秀!