对话流 v2 代码不是 运行

dialog flow v2 code not running

我正在根据 v2 测试新代码。 Link: Build Your First App with Dialogflow 代码:

'use strict';

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

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

app.intent('Default Welcome Intent', conv => {
  console.log("-----welcome intent-----");
  conv.ask('Welcome');
});

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

但是我模拟的时候显示:

MalformedResponse
'final_response' must be set.

我能做什么? 虽然启用了 Fulfillment,但请求未到达函数。

--------更新------------

现在我在尝试将函数部署到 firebase 时遇到此错误:

Function load error: Code in file index.js can't be loaded
Is there a syntax error in your code?
Detailed stack trace: TypeError: dialogflow is not a funct
    at Object.<anonymous> (/user_code/index.js:6:13)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at getUserFunction (/var/tmp/worker/worker.js:388:24)
    at loadUserCode (/var/tmp/worker/worker.js:444:18)

我看不懂???

这是我的 package.json:

{
  "name": "some name",
  "description": "some desc",
  "version": "0.0.1",
  "author": "Google Inc.",
  "engines": {
    "node": "~4.2"
  },
  "dependencies": {
    "actions-on-google": "^1.0.0",
    "firebase-admin": "^5.11.0",
    "firebase-functions": "^1.0.0",
    "dialogflow": "^0.3.0",
    "request": "^2.85.0",
    "uuid": "^3.0.1"
  }
}

------更新2------ 我已将节点更改为:

"engines": {
        "node": "~6.0"

还是一样的问题

-----更新3--------

部署完成,但是当请求到达它时,它显示:

确保 fulfillment 在 Dialogflow 仪表板中启用并且 API 的 v2 开启 ?还要检查您在实现中使用的意图名称是否与 Dialogflow 中的名称相匹配。

我觉得你的代码不错。可能是配置问题。

检查您使用的节点版本。 package.json 建议您使用节点 4,如果您使用 =>.

,则至少需要使用节点 6

由于 Firebase Cloud Functions 也是节点 6,您也应该切换到它来进行本地开发。 (Node 本身的 LTS 版本为 8,并且正在使用版本 9,因此您当然应该考虑更新。)

确认您使用的是哪个版本的 actions-on-google 库。 "actions-on-google": "^1.0.0" 的依赖项指定了库的 1.x 版本,但其余的用法是通过 2.0.0 语法。报错提示没有dialogflow对象,库2版本也有提供,1版本没有

要使用 2.0.0 及更高版本,您需要将 package.json 中的行更改为

"actions-on-google": "^2.0.0"

然后是运行

npm update

正在尝试将 conv.ask('Welcome') 更改为 conv.close('Welcome');

同时删除 console.log("-----welcome intent-----"); 行以进行测试

更改了 package.json:

"engines": {
    "node": "~6.11.1"
  },
  "dependencies": {
    "actions-on-google": "^2.0.0",
    "firebase-admin": "^5.11.0",
    "firebase-functions": "^1.0.0",
    "dialogflow": "^0.3.0",
    "request": "^2.85.0",
    "uuid": "^3.0.1"
  }

这行得通