17
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DialogflowからFirebaseにWebhook

Last updated at Posted at 2018-06-08

簡単に制御するための覚え書き
20171118172831.png
前回の「まずはDialogflowを触ってみる」の返事をFirebaseにやらせる方法です。https://qiita.com/sanoh/items/efd99ebbdee294a7beb3
■受け渡しAPIにはV1とV2がある

最近V2をリリースしたので、V2使ってねという事だとおもいます、今回はV1とV2両方を書きます。
2018-06-08 (9).png
■V1 APIの場合

・設定で「V1 API」になっている事を確認してから「SAVE」を押します。
2018-06-08 (1).png
・Firebase設定
「Fulfilment」で他のサーバ設定ができます。
今回はFirebaseを使用するので「Inline Editor」を「ENABLED」してください
2018-06-08 (8).png
「index.js」のプログラムは以下のようにし、最後「DEPLOY」を押します(デプロイされるまでしばらくかかります)

index.js
'use strict';

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  function foodApp (agent) {
    var params = request.body.result.parameters;
    var rFoods = params['foods'];
    var rFeel = params['feel'];

    agent.add('私も' + rFoods + '' + rFeel + 'です');
  }
  let actionMap = new Map();
  actionMap.set('食べ物の好み!', foodApp);
  agent.handleRequest(actionMap);
});

・Intentの設定
最後に「食べ物の好み!」のIntentの設定で「Fulfillment」の「Enable webhook call this intent」をOnにし「SAVE」すれば終了です。
2018-06-08 (6).png
■V2 APIの場合

・設定で「V2 API」になっている事を確認してから「SAVE」を押します。
2018-06-08 (4).png
・Firebase設定
「Fulfilment」で他のサーバ設定ができます。
今回はFirebaseを使用するので「Inline Editor」を「ENABLED」してください
2018-06-08 (7).png
「index.js」のプログラムは以下のようにし、最後「DEPLOY」を押します(デプロイされるまでしばらくかかります)

index.js
'use strict';

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

const app = dialogflow();

app.intent('食べ物の好み!', (conv, params, confirmationGranted)  => {
    var rFoods = params['foods'];
    var rFeel = params['feel'];

    conv.ask('私も' + rFoods + '' + rFeel + 'です');
});

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

・Intentの設定
最後に「食べ物の好み!」のIntentの設定で「Fulfillment」の「Enable webhook call this intent」をOnにし「SAVE」すれば終了です。
2018-06-08 (6).png
■動作

V1,V2でも同じような動作になります、しかし、今後の事を考えるとV2のほうですかね!
2018-06-08 (3).png

(Botの場合、V1でないと動作が怪しいので要注意ですね)

17
24
0

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
17
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?