Search code examples
dialogflow-esactions-on-googlegoogle-homefulfillment

Want to preserve persistent values


We want to preserve persistent values. We tried it with the following simple code, but the value was not preserved. What did we make a mistake?

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 is called at startup. Save the persistent value in FirstIntent and raise a SecondEvent. SecondIntent is called. Read a persistent value in SecondIntent to create a response. "Value is undefined" is displayed.

We found the following log.

Billing account not configured. 
External network is not accessible and quotas are severely limited. 
Configure billing account to remove these restrictions

We upgraded to flame and confirmed that the log is not displayed, but the persistent value has not been saved yet. Can we solve this problem without charging?


Solution

  • This behavior (that is, the value set to the user.storage is not passed via followup() function) is a specification of actions-on-google-nodejs SDK.

    Actually, this is not only the specification of the SDK, but this also is caused by incompatible between the user.storage feature and the Dialogflow followup events feature used by the followup() function. When calling the followup() function, the "followupEventInput" response is returned from the fulfillment to Dialogflow. After receiving the response, Dialogflow decides an intent that can handle the specified event and triggers the intent directly without returning any response to the Actions on Google. The user.storage is a feature of Actions on Google, therefore, the Dialogflow has to return the new values to the Actions on Google to update the user.storage values so that the Actions on Google sends the new values to the next request. However, the Dialogflow doesn't pass the control to the Actions on Google when calling the followup(). As the result, even if setting the values to the user.storage, unfortunately these values are ignored.

    Instead, the SDK can store the new user.storage values temporarily to return the values to the Actions on Google at the next webhook. However, the intent triggered by the followup event does not always call a webhook. Therefore, this idea cannot cover all cases. As the result of a discussion, the current SDK does not support this idea.

    This specification is described at the following API reference.

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

    Also, you can read the discussion at deciding this specification at the following:

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