尝试在语音助手中测试 google 操作时出现执行错误

Fulfillment error occurred when trying to test google action in voice assistant

我正在尝试创建一个 webhook,它将获取 Intent 和当前状态,更改状态,并使用 node.js 的 actions-on-google 库发回回复。

index.js如下:

'use strict';

const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});

app.intent('welcome', conv => {
  let replyState = setReplyState( conv, 'prompt' );
  let intent = getIntentName( conv );
  sendReply( conv, intent, replyState );
});


function getReplyState( conv ){
  return conv.data['replyState'];
}

function setReplyState( conv, state ){
  conv.data['replyState'] = state;
  return state;
}

function getIntentName( conv ){
  return conv.intent;
}

const welcomeReplies = [
  "Welcome!"
];


const allReplies = {
  welcome: welcomeReplies,
};

function sendReply( conv, intent, replyState ){

  let repliesNamed = replyState;
  let replies = allReplies[repliesNamed];
  conv.add( reply );
}

exports.fulfillment = functions.https.onRequest(action);

package.json如下:

{
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
        "node": "8"
      },
  "dependencies": {
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.3",
    "actions-on-google": "~2.5.0"
  },
  "private": true
}

发生错误:

MalformedResponse Failed to parse Dialogflow response into AppResponse because of invalid platform response: Could not find a RichResponse or SystemIntent in the platform response for agentId: ab93fe46-9eb1-4a6c-aea7-1699d67d7369 and intentId: 1ec758db-d03a-40b7-85fe-189d9245e6e2.

我提到了 https://github.com/afirstenberg/examples/tree/master/conversation-to-code-2-aog

您没有显示函数执行日志,但看起来 action 未在任何地方定义,因此调用 functions.https.onRequest(action); returns 出错。

在您使用的源代码中,action 定义为

const action = dialogflow();

并且所有 Intent Handlers 都注册了

action.intent(...)

虽然你有类似的定义

const app = dialogflow({debug: true});

因此您可以将定义函数的行更改为

exports.fulfillment = functions.https.onRequest(app);

解决您眼前的问题。