Webhook フルフィルメントを作成したら、本番環境にデプロイしてアクションに接続します。次の手順では、本番環境のホスティング用に Cloud Functions for Firebase にデプロイする環境を設定する方法について説明します。ただし、フルフィルメントをホストするために、HTTPS リクエストとレスポンスをサポートする任意のウェブ ホスティング プラットフォームを選択できます。
Webhook をすでにウェブ ホスティング プラットフォームにデプロイしている場合は、Webhook をアクションに接続するに進んでください。以下のプロセスの最後の手順は、Dialogflow と Actions SDK のどちらを使用するかによって異なります。
Cloud Functions for Firebase にデプロイする
- Node.js をダウンロードしてインストールします。
Firebase CLI を設定して初期化します。次のコマンドが
EACCES
エラーで失敗した場合は、npm アクセス権の変更が必要になる場合があります。npm install -g firebase-tools
Google アカウントで Firebase ツールを認証します。
firebase login
Actions プロジェクト ディレクトリに移動して、Firebase を初期化します。Actions プロジェクトに設定する Firebase CLI 機能を選択するよう求められます。
Functions
と、Firestore などの他の使用する機能を選択し、Enter キーを押して確定して続行します。cd <cloud_function_dir> firebase init
矢印キーを使用してプロジェクト リストを移動し、Firebase ツールを Actions プロジェクトに関連付けます。
を使用してこの関連付けを行う必要があります。 プロジェクトを選択すると、Firebase ツールが Functions の設定を開始し、使用する言語を尋ねます。続行するには、矢印キーを使用して選択し、Enter キーを押してください。
=== Functions Setup
A functions directory will be created in your project with a Node.js package pre-configured. Functions can be deployed with firebase deploy. ? What language would you like to use to write Cloud Functions? (Use arrow keys) > JavaScript TypeScriptESLint を使用して潜在的なバグを捕捉し、
Y
またはN
入力によるスタイルを適用するかどうかを選択します。? Do you want to use ESLint to catch probable bugs and enforce style? (Y/n)
プロンプトに対して「
Y
」と入力して、プロジェクトの依存関係を取得します。? Do you want to install dependencies with npm now? (Y/n)
設定が完了すると、次のような出力が表示されます。
✔ Firebase initialization complete!
actions-on-google 依存関係をインストールします。
cd <cloud_function_dir>/functions npm install actions-on-google
フルフィルメント依存関係を取得し、フルフィルメント関数をデプロイします。
npm install firebase deploy --only functions
デプロイには数分かかります。完了すると、次のような出力が表示されます。Dialogflow にアクセスするには、Function URL が必要です。
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/exampleproject-123/overview Function URL (cloudFunctionName): https://us-central1-exampleproject-123.cloudfunctions.net/cloudFunctionName
Webhook をアクションに接続する
Dialogflow を使用している場合: Dialogflow コンソールで [Fulfillment] に移動し、[Webhook] ボタンを [ENABLED] に切り替えて、[URL] フィールドの URL を Function URL に置き換えます。
Actions SDK を使用している場合: conversations
オブジェクト内にオブジェクトを作成して、アクション パッケージでフルフィルメントを宣言します。
{ "actions": [ { "description": "Default Welcome Intent", "name": "MAIN", "fulfillment": { "conversationName": "myFulfillmentFunction" }, "intent": { "name": "actions.intent.MAIN", "trigger": { "queryPatterns": [ "talk to myFulfillmentFunction" ] } } } ], "conversations": { "myFulfillmentFunction": { "name": "myFulfillmentFunction", "url": "https://us-central1-myprojectname-ab123.cloudfunctions.net/cloudFunctionName" } }, "locale": "en" }