สำรวจใน Dialogflow
คลิก Continue เพื่อนำเข้าตัวอย่างการแสดงข้อความแจ้งของเราใน Dialogflow จากนั้นทำตามขั้นตอนด้านล่างเพื่อทำให้ใช้งานได้และทดสอบตัวอย่าง
- ป้อนชื่อตัวแทนและสร้าง Agent ใหม่ใน Dialogflow สำหรับตัวอย่าง
- หลังจากนำเข้า Agent เสร็จแล้ว ให้คลิกไปที่ Agent
- จากเมนูการนำทางหลัก ให้ไปที่การดำเนินการคำสั่งซื้อ
- เปิดใช้ตัวแก้ไขในบรรทัด แล้วคลิกทำให้ใช้งานได้ ซึ่งตัวแก้ไขจะมีโค้ดตัวอย่าง
- จากเมนูการนําทางหลัก ให้ไปที่ Integrations แล้วคลิก Google Assistant
- ในหน้าต่างโมดัลที่ปรากฏ ให้เปิดใช้แสดงตัวอย่างการเปลี่ยนแปลงอัตโนมัติ และคลิกทดสอบเพื่อเปิดเครื่องจำลองการดำเนินการ
- ในเครื่องจำลอง ให้ป้อน
Talk to my test app
เพื่อทดสอบตัวอย่าง
คุณสามารถใช้ฟีเจอร์ต่อไปนี้เพื่อจัดการกรณีที่ผู้ใช้ไม่ได้ระบุข้อมูลในการดําเนินการ (ข้อผิดพลาดที่ไม่มีการป้อนข้อมูล)
- การเตือนเริ่มต้นของระบบ - การเตือนผู้ใช้เหล่านี้ซ้ำโดยอัตโนมัติด้วยการเตือนล่วงหน้าที่เป็นคำทั่วไปสำหรับทุกกรณี
- การเตือนแบบไดนามิก - การประกาศว่าคุณต้องการจัดการการแสดงซ้ำด้วยตนเอง และรับ Intent (Actions SDK) หรือเหตุการณ์ (Dialogflow) ทุกครั้งที่ไม่มีการป้อนข้อมูล คุณจึงจัดการได้เป็นกรณีๆ ไป
ข้อความแจ้งเริ่มต้นของระบบ
โดยค่าเริ่มต้น เมื่อคุณตอบกลับ Assistant ระบบจะใช้ข้อความแจ้งเริ่มต้นเพื่อขอให้ผู้ใช้ทําซ้ำหรือพิมพ์อินพุตของตนเองอีกครั้ง
Dialogflow
Dialogflow บังคับใช้อินพุตที่ไม่จับคู่และไม่มีอินพุตรวมกันสูงสุด 3 รายการ เมื่อมีการพยายามเก็บรวบรวมการสนทนาถึง 3 ครั้ง ตัวแทน Dialogflow ของคุณ จะจบการสนทนาด้วยการตอบกลับเริ่มต้น อินพุตที่ไม่ตรงกันใน Dialogflow จะเกิดขึ้นเมื่อมีการทริกเกอร์ Intent สำรองรายการใดรายการหนึ่ง
แสดงข้อความแจ้งแบบไดนามิก
คุณสามารถรับ Intent หรือเหตุการณ์ Dialogflow ได้ทุกครั้งที่การดำเนินการของคุณไม่ได้รับอินพุตใดๆ วิธีนี้ช่วยให้คุณส่งคืนคำตอบที่แตกต่างกันได้โดยอิงตามตรรกะบางอย่าง หากจำเป็น และให้แสดงสิทธิ์แก่ผู้ใช้อีกครั้งได้อย่างเหมาะสม
Dialogflow
คุณสามารถสร้าง Intent ที่ไม่มีอินพุตได้ 2 ประเภทดังนี้
ความตั้งใจปกติ - วิธีนี้ไม่ได้ใช้บริบทใดๆ ดังนั้นระบบจะทริกเกอร์เมื่อไม่มีความตั้งใจตามบริบทรายการอื่นที่จะทริกเกอร์ วิธีนี้เป็นประโยชน์สำหรับ การแสดงข้อความแจ้งทั่วไปที่คุณต้องการนำไปใช้ในกรณีส่วนใหญ่
ความตั้งใจติดตามผล - จะมีการบังคับใช้ Intent ในการติดตามผลผ่านบริบท Dialogflow เพื่อให้มั่นใจว่าระบบจะทริกเกอร์แสดงการพูดซ้ำหลังการสนทนาจบลงแล้ว ซึ่งจะเป็นประโยชน์สำหรับการแสดงออกที่มีการปรับแต่งซึ่งคุณต้องการใช้กับสถานการณ์ที่เฉพาะเจาะจง
วิธีจัดการเหตุการณ์ที่ไม่มีการป้อนข้อมูล
- คลิกความตั้งใจในการนำทางด้านซ้าย
- สร้างความตั้งใจหรือความตั้งใจติดตามผลปกติ
- สำหรับ Intent ปกติ: คลิกไอคอน + ข้างรายการในเมนู Intent แล้วตั้งชื่อ Intent เช่น "Reprompt"
- สำหรับ Intent ติดตามผล: วางเมาส์เหนือ Intent ที่คุณต้องการปรับแต่งการแจ้งเตือนที่ไม่มีอินพุต แล้วคลิกเพิ่ม Intent ติดตามผล > กำหนดเอง ระบบจะสร้าง Intent ใหม่ให้ต่ำกว่า Intent เดิม
- คลิก Intent ที่สร้างขึ้นใหม่เพื่อเปิดเครื่องมือแก้ไข Intent
- คลิกส่วนเหตุการณ์ แล้วป้อน "actions_intent_NO_INPUT" ลงในช่องเพิ่มเหตุการณ์
- ในส่วนการดำเนินการ ให้ป้อนชื่อการดำเนินการหรือใช้ชื่อที่ระบบให้ไว้โดยค่าเริ่มต้น สำหรับตัวอย่างนี้ เราจะใช้ "no.input"
- คลิกบันทึก
- คลิกการผสานที่การนำทางด้านซ้าย
- เลือก Google Assistant แล้วคลิกทดสอบเพื่อให้แน่ใจว่าการเปลี่ยนแปลงนั้นแสดงในโปรเจ็กต์ Actions
เมื่อใดก็ตามที่ไม่มีการป้อนข้อมูลสำหรับ Intent นี้ คุณสามารถใช้ Fulfillment เพื่อส่งคืนคำตอบที่เหมาะสมหรือสร้างใน Dialogflow ก็ได้ ตัวอย่างเช่น ต่อไปนี้คือโค้ด Fulfillment ที่ใช้ไลบรารีของไคลเอ็นต์เพื่อจัดการ Intent ที่ไม่ต้องป้อนข้อมูลตามปกติที่เรียกว่า "Reprompt"
Node.js
const {dialogflow} = require('actions-on-google'); const functions = require('firebase-functions'); const app = dialogflow({debug: true}); app.intent('Reprompt', (conv) => { const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT')); if (repromptCount === 0) { conv.ask(`What was that?`); } else if (repromptCount === 1) { conv.ask(`Sorry I didn't catch that. Could you repeat yourself?`); } else if (conv.arguments.get('IS_FINAL_REPROMPT')) { conv.close(`Okay let's try this again later.`); } }); exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Java
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("Reprompt") public ActionResponse reprompt(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); int repromptCount = request.getRepromptCount(); String response; if (repromptCount == 0) { response = "What was that?"; } else if (repromptCount == 1) { response = "Sorry, I didn't catch that. Could you repeat yourself?"; } else { responseBuilder.endConversation(); response = "Okay let's try this again later."; } return responseBuilder.add(response).build(); } }
ขอ JSON
โปรดทราบว่า JSON ด้านล่างอธิบายคำขอเว็บฮุค
{ "responseId": "f26a9188-4998-42eb-ac16-d0e6e273b137-712767ed", "queryResult": { "queryText": "actions_intent_NO_INPUT", "parameters": {}, "allRequiredParamsPresent": true, "fulfillmentText": "Webhook failed for intent: Reprompt", "fulfillmentMessages": [ { "text": { "text": [ "Webhook failed for intent: Reprompt" ] } } ], "outputContexts": [ { "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_media_response_audio" }, { "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_account_linking" }, { "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_audio_output" }, { "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/google_assistant_input_type_voice" }, { "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_intent_no_input", "parameters": { "REPROMPT_COUNT": 2, "IS_FINAL_REPROMPT": true } } ], "intent": { "name": "projects/df-reprompts-kohler/agent/intents/75dfd97d-6368-4436-9533-70f05ae76c96", "displayName": "Reprompt" }, "intentDetectionConfidence": 1, "languageCode": "en" }, "originalDetectIntentRequest": { "source": "google", "version": "2", "payload": { "user": { "locale": "en-US", "userVerificationStatus": "VERIFIED" }, "conversation": { "conversationId": "ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA", "type": "ACTIVE", "conversationToken": "[]" }, "inputs": [ { "intent": "actions.intent.NO_INPUT", "rawInputs": [ { "inputType": "VOICE" } ], "arguments": [ { "name": "REPROMPT_COUNT", "intValue": "2" }, { "name": "IS_FINAL_REPROMPT", "boolValue": true } ] } ], "surface": { "capabilities": [ { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.ACCOUNT_LINKING" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] }, "availableSurfaces": [ { "capabilities": [ { "name": "actions.capability.AUDIO_OUTPUT" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.WEB_BROWSER" } ] } ] } }, "session": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA" }
JSON ของการตอบกลับ
โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค
{ "payload": { "google": { "expectUserResponse": false, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "Okay let's try this again later." } } ] } } } }
Actions SDK
วิธีจัดการ Intent ที่ไม่มีอินพุต
- ในออบเจ็กต์
conversations
ภายในแพ็กเกจการดำเนินการ ให้ประกาศว่าคุณต้องการรับ Intentactions.intent.NO_INPUT
เมื่อใดก็ตามที่ผู้ใช้ไม่ได้ระบุอินพุต{ "actions": [ { "description": "Default Welcome Intent", "name": "MAIN", "fulfillment": { "conversationName": "conversation_1" }, "intent": { "name": "actions.intent.MAIN" } } ], "conversations": { "conversation_1": { "name": "conversation_1", "url": "YOUR_FULFILLMENT_URL", "inDialogIntents": [ { "name": "actions.intent.NO_INPUT" } ] } } }
- เมื่อ Assistant ไม่ได้รับอินพุตใดๆ จากผู้ใช้ คุณจะได้รับ Intent ที่ไม่ต้องป้อนข้อมูลในคำขอถัดไปสำหรับการดำเนินการของคุณ จากนั้นคุณจึงประมวลผล Intent และส่งกลับการตอบสนองที่เหมาะสมได้ ตัวอย่างเช่น
Node.js
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 this sample on a speaker device, ` + `and stay silent when the mic is open. If trying ` + `on the Actions console simulator, click the no-input ` + `button next to the text input field.`); }); app.intent('actions.intent.TEXT', (conv, input) => { conv.ask(`You said ${input}`); conv.ask(`Try this sample on a speaker device, ` + `and stay silent when the mic is open. If trying ` + `on the Actions console simulator, click the no-input ` + `button next to the text input field.`); }); app.intent('actions.intent.NO_INPUT', (conv) => { const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT')); if (repromptCount === 0) { conv.ask(`What was that?`); } else if (repromptCount === 1) { conv.ask(`Sorry I didn't catch that. Could you repeat yourself?`); } else if (conv.arguments.get('IS_FINAL_REPROMPT')) { conv.close(`Okay let's try this again later.`); } }); exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Java
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 this sample on a speaker device, and stay silent when the mic is open. If trying on the Actions console simulator, click the no-input button next to the text input field."); 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 this sample on a speaker device, and stay silent when the mic is open. If trying on the Actions console simulator, click the no-input button next to the text input field."); return responseBuilder.build(); } @ForIntent("actions.intent.NO_INPUT") public ActionResponse reprompt(ActionRequest request) { ResponseBuilder responseBuilder = getResponseBuilder(request); int repromptCount = request.getRepromptCount(); String response; if (repromptCount == 0) { response = "What was that?"; } else if (repromptCount == 1) { response = "Sorry, I didn't catch that. Could you repeat yourself?"; } else { responseBuilder.endConversation(); response = "Okay let's try this again later."; } return responseBuilder.add(response).build(); } }
ขอ JSON
โปรดทราบว่า JSON ด้านล่างอธิบายคำขอเว็บฮุค
{ "user": { "locale": "en-US", "userVerificationStatus": "VERIFIED" }, "conversation": { "conversationId": "ABwppHEVDuKUPjdZ4Ud-F2yBXN5ssRg2funUp59hSHQheAi-B5Y3EzehAKFtVwMkduqMRWscUp77ScrDjYnYxISqAM-qOXuXEuCw", "type": "ACTIVE", "conversationToken": "{\"data\":{}}" }, "inputs": [ { "intent": "actions.intent.NO_INPUT", "rawInputs": [ { "inputType": "VOICE" } ], "arguments": [ { "name": "REPROMPT_COUNT", "intValue": "2" }, { "name": "IS_FINAL_REPROMPT", "boolValue": true } ] } ], "surface": { "capabilities": [ { "name": "actions.capability.AUDIO_OUTPUT" }, { "name": "actions.capability.ACCOUNT_LINKING" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" } ] }, "availableSurfaces": [ { "capabilities": [ { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } ] }
JSON ของการตอบกลับ
โปรดทราบว่า JSON ด้านล่างอธิบายการตอบสนองของเว็บฮุค
{ "expectUserResponse": false, "finalResponse": { "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "Okay let's try this again later." } } ] } } }