แสดงข้อความแจ้ง (Dialogflow)

สำรวจใน Dialogflow

คลิกต่อไปเพื่อนำเข้าตัวอย่างการแสดงซ้ำใน Dialogflow จากนั้นทำตาม ด้านล่างเพื่อปรับใช้และทดสอบตัวอย่าง

  1. ป้อนชื่อ Agent และสร้าง Agent ใหม่ของ Dialogflow สำหรับตัวอย่าง
  2. หลังจากนำเข้าตัวแทนเสร็จแล้ว ให้คลิกไปที่ตัวแทน
  3. จากเมนูการนำทางหลัก ให้ไปที่การดำเนินการตามคำสั่งซื้อ
  4. เปิดใช้เครื่องมือแก้ไขในบรรทัด แล้วคลิกทำให้ใช้งานได้ เครื่องมือแก้ไขมีตัวอย่าง โค้ด
  5. จากเมนูการนำทางหลัก ให้ไปที่ Integrations แล้วคลิก Google Assistant
  6. ในหน้าต่างโมดัลที่ปรากฏขึ้น ให้เปิดใช้แสดงตัวอย่างการเปลี่ยนแปลงอัตโนมัติ แล้วคลิกทดสอบ เพื่อเปิดเครื่องมือจำลอง Actions
  7. ในเครื่องมือจำลอง ให้ป้อน Talk to my test app เพื่อทดสอบตัวอย่าง

คุณสามารถใช้ฟีเจอร์ต่อไปนี้เพื่อจัดการกรณีที่ผู้ใช้ไม่ให้ ป้อนการดำเนินการของคุณ (ข้อผิดพลาดที่ไม่ต้องป้อนข้อมูล):

  • การแสดงซ้ำเริ่มต้นของระบบ - ระบบจะแจ้งเตือนผู้ใช้อีกครั้งโดยอัตโนมัติ โดยใช้ข้อความซ้ำที่กำหนดไว้ล่วงหน้า ซึ่งเป็นข้อความทั่วไปสำหรับทุกกรณี
  • การแสดงข้อความแจ้งแบบไดนามิก - การประกาศว่าคุณต้องการจัดการการแสดงข้อความแจ้งซ้ำใน เอง และรับ Intent (Actions SDK) หรือเหตุการณ์ (Dialogflow) ทุกครั้ง ไม่ป้อนข้อมูลใดๆ เพื่อให้คุณจัดการได้เป็นกรณีๆ ไป

การแสดงซ้ำตามค่าเริ่มต้นของระบบ

โดยค่าเริ่มต้น เมื่อคุณตอบกลับไปยัง Assistant ระบบจะใช้ แสดงข้อความเริ่มต้นซ้ำเพื่อขอให้ผู้ใช้พิมพ์คำตอบซ้ำหรือพิมพ์ซ้ำ

Dialogflow

Dialogflow บังคับใช้อินพุตที่ไม่มีการจับคู่และไม่มีอินพุตรวมกันสูงสุด 3 รายการ เมื่อการสนทนาเก็บรวบรวมภาพถึง 3 ครั้งแล้ว ตัวแทน Dialogflow จะจบการสนทนาด้วยคำตอบเริ่มต้น ข้อมูลที่ไม่ตรงกันใน Dialogflow เมื่อมีการทริกเกอร์ Intent สำรองรายการใดรายการหนึ่งของคุณ

การแสดงซ้ำแบบไดนามิก

คุณสามารถรับเหตุการณ์ Intent หรือ Dialogflow ได้ทุกครั้งที่การดำเนินการล้มเหลว รับข้อมูลใดก็ได้ ทำให้คุณสามารถส่งคืนการตอบกลับที่แตกต่างกัน ซึ่งขึ้นอยู่กับ หากจำเป็นและแสดงผลผู้ใช้อีกครั้งอย่างเหมาะสม

Dialogflow

คุณสร้าง Intent ที่ไม่มีอินพุตได้ 2 ประเภท ดังนี้

  • Intent ปกติ - วิธีนี้ไม่ใช้บริบทใดๆ ระบบจึงจะทริกเกอร์ เมื่อไม่มี Intent ตามบริบทอื่น ที่จะทริกเกอร์มากกว่า มีประโยชน์ สำหรับการแสดงข้อความซ้ำทั่วไปที่คุณต้องการใช้ในกรณีส่วนใหญ่

  • ความตั้งใจในการติดตามผล - ระบบจะบังคับใช้ความตั้งใจสำหรับการติดตามผลผ่าน Dialogflow เพื่อให้มั่นใจว่าการแสดงซ้ำถูกเรียกหลังจากเล่นจบเฉพาะช่วงเวลาเท่านั้น การสนทนา ซึ่งมีประโยชน์สำหรับการแสดงซ้ำที่ปรับแต่งมาตามที่คุณต้องการ สถานการณ์เฉพาะ

วิธีจัดการเหตุการณ์ที่ไม่มีการป้อนข้อมูล

  1. คลิก Intent ในการนำทางด้านซ้าย
  2. สร้างความตั้งใจปกติหรือความตั้งใจติดตามผล
    • สำหรับ Intent ปกติ: คลิกไอคอน + ข้างเมนู Intent และตั้งชื่อ Intent เช่น "Reprompt"

    • สำหรับ Intent ติดตามผล: วางเมาส์เหนือ Intent ที่ต้องการ ปรับแต่งข้อความแจ้งแบบไม่ป้อนข้อมูล แล้วคลิกเพิ่มความตั้งใจในการติดตามผล > กำหนดเอง ระบบจะสร้าง Intent ใหม่ต่ำกว่า Intent เดิม

  3. คลิก Intent ที่สร้างขึ้นใหม่เพื่อเปิดตัวแก้ไข Intent
  4. คลิกส่วนเหตุการณ์ แล้วป้อน "actions_intent_NO_INPUT" ลงใน เพิ่มเหตุการณ์
  5. ป้อนชื่อการดำเนินการหรือใช้ชื่อที่ให้มาในส่วนการดำเนินการ โดยค่าเริ่มต้น สำหรับตัวอย่างนี้ เราจะใช้ "no.input"

  6. คลิกบันทึก
  7. คลิกการผสานที่การนำทางด้านซ้าย
  8. เลือก Google Assistant แล้วคลิกทดสอบเพื่อดำเนินการ ตรวจดูว่าการเปลี่ยนแปลงแสดงในโปรเจ็กต์ Actions

เมื่อใดก็ตามที่ไม่มีการป้อนข้อมูลสำหรับ Intent นี้ คุณสามารถใช้ Fulfillment ของคุณเพื่อแสดงการตอบสนองที่เหมาะสมหรือสร้างการตอบสนองใน Dialogflow ลองดูตัวอย่างโค้ดการดำเนินการตามคำสั่งซื้อที่ใช้ไลบรารีของไคลเอ็นต์เพื่อ จัดการ 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 ที่ไม่มีการป้อนข้อมูล

  1. ในออบเจ็กต์ conversations ภายในแพ็กเกจการดำเนินการ ให้ประกาศว่าคุณต้องการ เพื่อรับ Intent actions.intent.NO_INPUT เมื่อใดก็ตามที่ผู้ใช้ไม่ได้ระบุ อินพุต
    {
      a"ctions:" [
        {
          d"escription:" D"efault Welcome Intent,"
          n"ame:" M"AIN,"
          f"ulfillment:" {
            c"onversationName:" c"onversation_1
    "      },
          i"ntent:" {
            n"ame:" a"ctions.intent.MAIN
    "      }
        }
      ],
      c"onversations:" {
        c"onversation_1:" {
          n"ame:" c"onversation_1,"
          u"rl:" Y"OUR_FULFILLMENT_URL,"
          i"nDialogIntents:" [
            {
              n"ame:" a"ctions.intent.NO_INPUT
    "        }
          ]
        }
      }
    }a
  2. เมื่อ Assistant ไม่ได้รับข้อมูลใดๆ จากผู้ใช้ คุณจะได้รับ ที่ไม่ต้องป้อนข้อมูลในคำขอถัดไปที่จะส่งไปยัง Fulfillment จากนั้นคุณจะสามารถ ประมวลผลความตั้งใจและแสดงผลการตอบกลับที่เหมาะสม นี่คือ ตัวอย่าง:

    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."
              }
            }
          ]
        }
      }
    }