我们希望保留持久的值(value)观。 我们使用以下简单代码进行了尝试,但该值未保留。 我们犯了什么错误?
index.js
'use strict';
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
app.intent('FirstIntent', conv => {
conv.user.storage.value = 'A';
conv.followup('SecondEvent');
});
app.intent('SecondIntent', conv => {
conv.close('value is ' + conv.user.storage.value);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.1"
}
}
FirstIntent 在启动时被调用。 将持久值保存在 FirstIntent 中并引发 SecondEvent。 SecondIntent 被调用。 读取 SecondIntent 中的持久值以创建响应。 显示“值未定义”。
我们发现了以下日志。
Billing account not configured.
External network is not accessible and quotas are severely limited.
Configure billing account to remove these restrictions
我们升级到flame,确认日志没有显示,但是持久值还没有保存。我们可以在不充电的情况下解决这个问题吗?
最佳答案
此行为(即设置为 user.storage
的值未通过 followup()
函数传递)是 actions-on-google- 的规范Nodejs SDK。
实际上,这不仅仅是SDK的规范,也是由于user.storage
功能与followup()使用的Dialogflow followup events功能不兼容造成的
函数。调用 followup()
函数时,“followupEventInput”响应将从履行返回到 Dialogflow。收到响应后,Dialogflow 决定一个可以处理指定事件的 Intent,并直接触发该 Intent,而不向 Actions on Google 返回任何响应。 user.storage
是 Actions on Google 的一项功能,因此,Dialogflow 必须将新值返回到 Actions on Google 来更新 user.storage
值,以便Actions on Google 将新值发送到下一个请求。但是,在调用 followup()
时,Dialogflow 不会将控制权传递给 Actions on Google。因此,即使将值设置为 user.storage
,不幸的是这些值也会被忽略。
相反,SDK 可以临时存储新的 user.storage
值,以便将这些值返回到下一个 Webhook 的 Actions on Google。但是,后续事件触发的 Intent 并不总是调用 Webhook。因此,这个想法并不能涵盖所有情况。经过讨论,目前的SDK不支持这个想法。
以下 API 引用中描述了此规范。
此外,您可以在以下位置阅读决定此规范的讨论:
https://github.com/actions-on-google/actions-on-google-nodejs/pull/211#issuecomment-412942410
关于dialogflow-es - 想要保留持久的值(value)观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52779346/