首页 > 解决方案 > 想要保留持久值

问题描述

我们希望保留持久的价值观。我们使用以下简单代码进行了尝试,但没有保留该值。我们犯了什么错误?

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);

包.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,确认日志没有显示,但是持久值还没有保存。不收费能解决这个问题吗?

标签: dialogflow-esactions-on-googlegoogle-homefulfillment

解决方案


这种行为(即设置为 的值user.storage不是通过followup()函数传递的)是 actions-on-google-nodejs SDK 的规范。

实际上,这不仅是 SDK 的规范,也是由于该user.storage功能与该功能使用的 Dialogflow 后续事件功能不兼容造成的followup()。调用该followup()函数时,“followupEventInput”响应从履行返回到 Dialogflow。收到响应后,Dialogflow 会决定一个可以处理指定事件的 Intent 并直接触发 Intent,而不向 Actions on Google 返回任何响应。这user.storage是 Actions on Google 的一项功能,因此,Dialogflow 必须将新值返回到 Actions on Google 以更新user.storage值,以便 Actions on Google 将新值发送到下一个请求。但是,Dialogflow 在调用followup(). 结果,即使将值设置为user.storage,不幸的是这些值也会被忽略。

相反,SDK 可以临时存储新user.storage值,以便在下一个 webhook 处将这些值返回给 Actions on Google。但是,后续事件触发的意图并不总是调用 webhook。因此,这个想法不能涵盖所有情况。经过讨论,目前的 SDK 不支持这种想法。

该规范在以下 API 参考中进行了描述。

https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#followup

此外,您可以在以下位置阅读有关决定此规范的讨论:

https://github.com/actions-on-google/actions-on-google-nodejs/pull/211#issuecomment-412942410


推荐阅读