我终于让用户注册了这个云功能:
const functions = require('firebase-functions');
const {
dialogflow,
Image,
} = require('actions-on-google')
// Create an app instance
const app = dialogflow()
// Register handlers for Actions SDK intents
app.intent('test', conv => {
conv.ask(new SignIn());
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
但在那之后我得到了同样的错误:
TypeError: Cannot read property 'client' of undefined
at Function.<anonymous> (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:120:71)
at next (native)
at /user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71
at __awaiter (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12)
at Function.handler (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:84:16)
at Object.<anonymous> (/user_code/node_modules/actions-on-google/dist/assistant.js:55:32)
at next (native)
at /user_code/node_modules/actions-on-google/dist/assistant.js:22:71
at __awaiter (/user_code/node_modules/actions-on-google/dist/assistant.js:18:12)
at standard (/user_code/node_modules/actions-on-google/dist/assistant.js:51:41)
它甚至无法进入console.log('test')
:
const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google')
// Create an app instance
const app = dialogflow()
// Register handlers for Actions SDK intents
app.intent('test', conv => {
console.log('test')
conv.ask(`response`)
})
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": "~6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "2.1.3",
"firebase-admin": "5.12.1",
"firebase-functions": "1.0.3",
"dialogflow": "0.5.0",
"dialogflow-fulfillment": "0.4.0"
}
}
答案 0 :(得分:9)
在
中初始化您的应用时const app = dialogflow();
通过链接客户端ID
的Google帐户传递您的操作对象您的代码应如下所示:
const app = dialogflow({
clientId : YOUR_APPS_CLIENT_ID
})
这将解决此问题。
要获取YOUR_APPS_CLIENT_ID,请转到Google控制台上的操作,在左侧导航菜单上,在高级选项下,转到帐户关联并展开第三张卡片以获取您的ID。
希望它有所帮助。
答案 1 :(得分:0)
2019年9月更新
如果找不到您的客户ID (就像我这样,因为Google似乎不再在“ Google登录客户信息”卡中显示该客户ID),请转到在您的 Google Cloud Platform 控制台中,并在 API和服务菜单下,打开凭据屏幕。
然后滚动到 OAuth 2.0客户端ID 部分,然后找到“ Google App上的新操作”。最后一列的值是您在Google项目上执行操作的客户ID。
这是屏幕截图:
答案 2 :(得分:0)