Dialogflow で探索
[続行] をクリックして、Dialogflow の会話の終了サンプルをインポートします。次に、 サンプルをデプロイしてテストする手順は次のとおりです。
- エージェント名を入力し、サンプルの新しい Dialogflow エージェントを作成します。
- エージェントのインポートが完了したら、[Go to agent] をクリックします。
- メインのナビゲーション メニューから [Fulfillment] に移動します。
- [Inline Editor] を有効にして、[Deploy] をクリックします。エディタにはサンプルが含まれています。 説明します。
- メイン ナビゲーション メニューから [Integrations] に移動し、[Google] をクリックします アシスタント。
- 表示されたモーダル ウィンドウで、[変更の自動プレビュー] を有効にして [テスト] をクリックします。 Actions シミュレータを開きます
- シミュレータで「
Talk to my test app
」と入力して、サンプルをテストします。
会話を途中で終了するには、次のように言います。
- "exit"
- 「キャンセル」
- 「停止」
- 「気にしない」
- 「さようなら」
デフォルトでは、アシスタントは会話を終了してイアコンを再生します。
この動作をオーバーライドするには、
を使用してフルフィルメント ロジックをクリーンアップし、最後にもう一度ユーザーに返信できます。
最終的なレスポンスは、単一のシンプルなレスポンスにする必要があります。
textToSpeech
と displayText
の値は 60 文字以内にする必要があります。
会話終了リクエストに許容される最大実行時間は 2 秒です。「いいえ」の場合 レスポンスを受信しないと、デフォルトの終了イアコンで会話が終了します。 カスタムのキャンセル応答が失敗した場合(文字数制限を超えているため 不適切な応答タイプなど)がある場合、会話もデフォルトの終了イアコンで終了します。
Dialogflow
会話終了イベントを受け取るには:
- 画面左のナビゲーションで、[Intents](インテント)メニュー項目の横にある + アイコンをクリックします。
- インテントに名前(
Exit Conversation
など)を付けて、[Events] セクションをクリックします。 - [イベントを追加] フィールドに「
actions_intent_CANCEL
」と入力します。 - [レスポンス] でレスポンスを指定します。あるいは、Webhook コードでこのインテントに独自のレスポンスを設定します。
- [このインテントを会話の終わりに設定する] を有効にします。
- [保存] をクリックします。
- 画面左のナビゲーションで [Integrations] をクリックします。
- [Google Assistant] を選択し、[Update draft] をクリックしてから [Test] をクリックします。 変更がプロジェクトに反映されていることを確認します。
ユーザーが会話の終了をリクエストすると、作成したインテントがトリガーされ、 レスポンスがユーザーに返されます。対象 クライアント ライブラリを使用して インテントをキャンセルしてレスポンスを返します。
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
app.intent('Exit Conversation', (conv) => {
conv.close(`Okay, talk to you next time!`);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
package com.example;
import com.google.actions.api.ActionRequest;
import com.google.actions.api.ActionResponse;
import com.google.actions.api.DialogflowApp;
import com.google.actions.api.ForIntent;
import com.google.actions.api.response.ResponseBuilder;
public class MyActionsApp extends DialogflowApp {
@ForIntent("Exit Conversation")
public ActionResponse exit(ActionRequest request) {
ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add("Okay, talk to you next time!");
responseBuilder.endConversation();
return responseBuilder.build();
}
}
下記の JSON は Webhook リクエストを示します。
{
"responseId": "e0c9d47f-aa99-4d03-bd48-a64c79e9c2a2-712767ed",
"queryResult": {
"queryText": "actions_intent_CANCEL",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Webhook failed for intent: Exit Conversation",
"fulfillmentMessages": [
{
"text": {
"text": [
"Webhook failed for intent: Exit Conversation"
]
}
}
],
"outputContexts": [
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_capability_audio_output"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_capability_media_response_audio"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_capability_account_linking"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_capability_screen_output"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_capability_web_browser"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/google_assistant_input_type_keyboard"
},
{
"name": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0/contexts/actions_intent_cancel"
}
],
"intent": {
"name": "projects/df-exits-kohler/agent/intents/b506991f-ad7a-4c4b-8adc-5e6c62727381",
"displayName": "Exit Conversation"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"user": {
"locale": "en-US",
"userVerificationStatus": "VERIFIED"
},
"conversation": {
"conversationId": "ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0",
"type": "ACTIVE",
"conversationToken": "[]"
},
"inputs": [
{
"intent": "actions.intent.CANCEL",
"rawInputs": [
{
"inputType": "KEYBOARD",
"query": "cancel"
}
]
}
],
"surface": {
"capabilities": [
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.ACCOUNT_LINKING"
},
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
}
]
}
},
"session": "projects/df-exits-kohler/agent/sessions/ABwppHGVnlRtMz1RhGGmDOSlCFAbc2QaM12xYtw0raWvv-R5GYM6tkqiVOpIOexm_LTBCvmARwpbZ_onRuX0"
}
下記の JSON は Webhook レスポンスを示します。
{
"payload": {
"google": {
"expectUserResponse": false,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Okay, talk to you next time!"
}
}
]
}
}
}
}
Actions SDK
会話終了インテントを受け取るには:
-
アクション パッケージ内の
conversations
オブジェクトで、 リクエスト対象の値をactions.intent.CANCEL
ユーザーが会話の途中で終了しようとするたびに 発生します
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "conversation_1"
},
"intent": {
"name": "actions.intent.MAIN"
}
}
],
"conversations": {
"conversation_1": {
"name": "conversation_1",
"url": "YOUR_ENDPOINT_URL",
"inDialogIntents": [
{
"name": "actions.intent.CANCEL"
}
]
}
}
} -
actions.intent.CANCEL
でリクエストを受け取ったとき 必要なフルフィルメント ロジックをクリーンアップして、 適切な終了フレーズをユーザーに提示しますたとえば、このフルフィルメント コードは次のようになります。 これは、クライアント ライブラリを使用してキャンセル インテントを処理するものです。const {actionssdk} = require('actions-on-google');
const functions = require('firebase-functions');
const app = actionssdk({debug: true});
app.intent('actions.intent.MAIN', (conv) => {
conv.ask(`Hi! Try saying 'exit' or 'cancel'`);
});
app.intent('actions.intent.TEXT', (conv, input) => {
conv.ask(`You said ${input}`);
conv.ask(`Try saying 'exit' or 'cancel'`);
});
app.intent('actions.intent.CANCEL', (conv) => {
conv.close(`Okay, talk to you next time!`);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);package com.example;
import com.google.actions.api.ActionRequest;
import com.google.actions.api.ActionResponse;
import com.google.actions.api.ActionsSdkApp;
import com.google.actions.api.ConstantsKt;
import com.google.actions.api.ForIntent;
import com.google.actions.api.response.ResponseBuilder;
import com.google.actions.api.response.helperintent.Confirmation;
import com.google.actions.api.response.helperintent.DateTimePrompt;
import com.google.actions.api.response.helperintent.Permission;
import com.google.actions.api.response.helperintent.Place;
import com.google.api.services.actions_fulfillment.v2.model.DateTime;
import com.google.api.services.actions_fulfillment.v2.model.Location;
public class MyActionsApp extends ActionsSdkApp {
@ForIntent("actions.intent.MAIN")
public ActionResponse welcome(ActionRequest request) {
ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add("Hi! Try saying 'exit' or 'cancel'");
return responseBuilder.build();
}
@ForIntent("actions.intent.TEXT")
public ActionResponse fallback(ActionRequest request) {
ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add("You said " + request.getRawInput().getQuery());
responseBuilder.add("Try saying 'exit' or 'cancel'");
return responseBuilder.build();
}
@ForIntent("actions.intent.CANCEL")
public ActionResponse exit(ActionRequest request) {
ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add("Okay, talk to you next time!");
responseBuilder.endConversation();
return responseBuilder.build();
}
}下記の JSON は Webhook リクエストを示します。
{
"user": {
"locale": "en-US",
"userVerificationStatus": "VERIFIED"
},
"conversation": {
"conversationId": "ABwppHEtH6XptryyLGWDBOVnLgy8EkOclTPETd4lcLh_f6ghQAzzg0seUuq3YocyFT8B17N6AGD6YPPjQw5CXBM",
"type": "NEW"
},
"inputs": [
{
"intent": "actions.intent.CANCEL",
"rawInputs": [
{
"inputType": "KEYBOARD",
"query": "exit"
}
]
}
],
"surface": {
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.ACCOUNT_LINKING"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
}
]
}下記の JSON は Webhook レスポンスを示します。
{
"expectUserResponse": false,
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Okay, talk to you next time!"
}
}
]
}
}
}