我使用api.ai在node.js客戶端庫下面進行測試,我複製了本頁給出示例的確切代碼。ApiAiApp不是構造函數
https://developers.google.com/actions/reference/nodejs/ApiAiApp
但每次我得到
TypeError: ApiAiApp is not a constructor
at /app/index.js:9:15
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
這是我的index.js文件:
var express = require('express');
var request = require('request');
var exps = express();
const ApiAiApp = require('actions-on-google').ApiAiApp;
exps.post('/hook', function(request, response) {
const app = new ApiAiApp({request, response});
response.status(200)
response.json({
speech: "Hello from hook",
displayText: "Hello from hook",
source: 'HOOK'
})
console.log("RESPONSE :::: \n");
console.log(response);
});
exps.listen((process.env.PORT || 8000), function() {
console.log("App up and running, listening.")
})
的package.json
{
"name": "googleActionNode",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Sukhvinder Singh",
"dependencies": {
"actions-on-google": "1.2.0",
"body-parser": "^1.15.0",
"express": "^4.13.4"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/sukhvinder1/googleActionNode.git"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/sukhvinder1/googleActionNode/issues"
},
"homepage": "https://github.com/sukhvinder1/googleActionNode#readme"
}
如果我commnent出在線以下,一切工作正常。
const app = new ApiAiApp({request: request, response: response});
任何人都可以幫我嗎?
就在你嘗試調用new之前,看看你是否可以做一個console.log(ApiAiApp);和console.log(typeof ApiAiApp); – Prisoner
同時發佈您的package.json以及您正在使用的谷歌操作版本 – Prisoner
由於@Prisoner將我指向了正確的文檔,我刪除了我的答案。我會根據他的想法來了解如何進行調試以使其工作。 –