LoginSignup
2
0

More than 5 years have passed since last update.

DialogflowのFulfillmentでユーザ入力のパラメータを取得するときにハマった

Last updated at Posted at 2018-04-07

Google Homeアプリを開発している時に、DialogflowのFulfillmentでユーザ入力のパラメータ(例. Aさん「◯◯を教えて」の◯◯の部分)を取得するときに悪戦苦闘したので、メモを残しておきます。

どこでハマったの?

index.js
...省略...

const App = require('actions-on-google').DialogflowApp;

...省略...

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const app = new App({request, response});

...省略...

});
Firebaseのログ
TypeError: App is not a constructor
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:11:15)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
    at /var/tmp/worker/worker.js:676:7
    at /var/tmp/worker/worker.js:660:9
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

どうやら、npmのactions-on-googleパッケージがうまく動作していない模様。ただindex.jsは以下公式サイトを参考に作成したので、スクリプト自体はあっているはず。。

Dialogflow で初めてのアプリをビルドする  |  Actions on Google  |  Google Developers

原因はpackage.jsonの中にありました

原因はpackage.jsonの中で定義しているactions-on-googleのバージョンでした。

FulfillmentのInline Editorにある、デフォルトのpackage.json内のactions-on-googleだとうまく動作しないようです。修正後のバージョンにすると動きました!

デフォルトのpackage.json
{

...省略...

  "dependencies": {
    "actions-on-google": "2.0.0-alpha.2",

...省略...

  }
}
修正後のpackage.json
{

...省略...

  "dependencies": {
    "actions-on-google": "^1.0.0",

...省略...

  }
}

まとめ

Google Homeアプリ開発はまだまだ情報が少ないのでよくつまづきます。もっともっと開発者が増えてこういったメモが増えると嬉しいですね。

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0