Dialogflow功能:无法读取属性'客户端'未定义的

时间:2018-06-01 06:50:57

标签: actions-on-google dialogflow

我终于让用户注册了这个云功能:

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"
  }
}

3 个答案:

答案 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。

这是屏幕截图:

enter image description here

答案 2 :(得分:0)

当我不想在我的测试项目中建立帐户链接时,我就遇到了这个问题,而我在进行测试时就一直保留帐户链接。当我在代码中连接没有任何clientID的webhook时,出现错误。我要做的就是清除Google项目中的accountlink设置,然后一切都解决了。

enter image description here