Phản hồi đơn giản (Dialogflow)

Khám phá trong Dialogflow

Nhấp vào Tiếp tục để nhập mẫu Phản hồi của chúng tôi vào Dialogflow. Sau đó, hãy làm theo các bước bên dưới để triển khai và kiểm thử mẫu:

  1. Nhập tên nhân viên hỗ trợ rồi tạo một nhân viên hỗ trợ Dialogflow mới cho mẫu.
  2. Sau khi nhập xong nhân viên hỗ trợ, hãy nhấp vào Chuyển đến nhân viên hỗ trợ.
  3. Trên trình đơn điều hướng chính, hãy chuyển đến mục Thực hiện đơn hàng.
  4. Bật Inline Editor (Trình chỉnh sửa cùng dòng), sau đó nhấp vào Deploy (Triển khai). Trình chỉnh sửa chứa mã mẫu.
  5. Trên trình đơn điều hướng chính, hãy chuyển đến phần Tích hợp, rồi nhấp vào Trợ lý Google.
  6. Trong cửa sổ phụ xuất hiện, hãy bật tính năng Auto-preview changes (Tự động xem trước các thay đổi) rồi nhấp vào Test (Kiểm thử) để mở Trình mô phỏng hành động.
  7. Trong trình mô phỏng, hãy nhập Talk to my test app để kiểm tra mẫu!

Các câu trả lời đơn giản sẽ có dạng bong bóng trò chuyện trực quan và sử dụng tính năng chuyển văn bản sang lời nói (TTS) hoặc Ngôn ngữ đánh dấu tổng hợp lời nói (SSML) cho âm thanh.

Theo mặc định, văn bản TTS được dùng làm nội dung bong bóng trò chuyện. Nếu khía cạnh hình ảnh của văn bản đó đáp ứng nhu cầu của bạn, thì bạn không cần chỉ định bất kỳ văn bản hiển thị nào cho bong bóng trò chuyện.

Bạn cũng có thể xem nguyên tắc thiết kế cuộc trò chuyện để tìm hiểu cách kết hợp những thành phần hình ảnh này vào Hành động của mình.

Thuộc tính

Hình 1. Ví dụ về câu trả lời đơn giản (điện thoại thông minh)

Phản hồi đơn giản có các yêu cầu và thuộc tính không bắt buộc sau đây mà bạn có thể định cấu hình:

  • Được hỗ trợ trên các nền tảng có tính năng actions.capability.AUDIO_OUTPUT hoặc actions.capability.SCREEN_OUTPUT.
  • Giới hạn 640 ký tự cho mỗi bong bóng trò chuyện. Các chuỗi dài hơn giới hạn sẽ bị cắt bớt ở ngắt từ đầu tiên (hoặc khoảng trắng) trước 640 ký tự.

  • Nội dung của bong bóng trò chuyện phải là một tập hợp con theo phiên âm hoặc bản chép lời hoàn chỉnh của đầu ra TTS/SSML. Điều này giúp người dùng xác định những điều bạn nói và tăng mức độ hiểu bài nói trong nhiều điều kiện.

  • Tối đa là 2 bong bóng trò chuyện mỗi lượt.

  • Đầu trò chuyện (biểu trưng) mà bạn gửi đến Google phải có kích thước 192 x 192 pixel và không được là ảnh động.

Hình 2. Ví dụ về câu trả lời đơn giản (màn hình thông minh)

Mã mẫu

Node.js

app.intent('Simple Response', (conv) => {
  conv.ask(new SimpleResponse({
    speech: `Here's an example of a simple response. ` +
      `Which type of response would you like to see next?`,
    text: `Here's a simple response. ` +
      `Which response would you like to see next?`,
  }));
});

Java

@ForIntent("Simple Response")
public ActionResponse welcome(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  responseBuilder.add(
      new SimpleResponse()
          .setTextToSpeech(
              "Here's an example of a simple response. "
                  + "Which type of response would you like to see next?")
          .setDisplayText(
              "Here's a simple response. Which response would you like to see next?"));
  return responseBuilder.build();
}

Node.js

conv.ask(new SimpleResponse({
  speech: `Here's an example of a simple response. ` +
    `Which type of response would you like to see next?`,
  text: `Here's a simple response. ` +
    `Which response would you like to see next?`,
}));

Java

ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add(
    new SimpleResponse()
        .setTextToSpeech(
            "Here's an example of a simple response. "
                + "Which type of response would you like to see next?")
        .setDisplayText(
            "Here's a simple response. Which response would you like to see next?"));
return responseBuilder.build();

JSON

Xin lưu ý rằng JSON dưới đây mô tả phản hồi webhook.

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Here's an example of a simple response. Which type of response would you like to see next?",
              "displayText": "Here's a simple response. Which response would you like to see next?"
            }
          }
        ]
      }
    }
  }
}

JSON

Xin lưu ý rằng JSON dưới đây mô tả phản hồi webhook.

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ],
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Here's an example of a simple response. Which type of response would you like to see next?",
                "displayText": "Here's a simple response. Which response would you like to see next?"
              }
            }
          ]
        }
      }
    }
  ]
}

SSML và âm thanh

Việc sử dụng SSML và âm thanh trong câu trả lời giúp các câu trả lời này hay hơn và nâng cao trải nghiệm người dùng. Các đoạn mã sau đây cho bạn biết cách tạo phản hồi sử dụng SSML:

Node.js

app.intent('SSML', (conv) => {
  conv.ask(`<speak>` +
    `Here are <say-as interpet-as="characters">SSML</say-as> examples.` +
    `Here is a buzzing fly ` +
    `<audio src="https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg"></audio>` +
    `and here's a short pause <break time="800ms"/>` +
    `</speak>`);
  conv.ask('Which response would you like to see next?');
});

Java

@ForIntent("SSML")
public ActionResponse ssml(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  responseBuilder.add(
      "<speak>"
          + "Here are <say-as interpet-as=\"characters\">SSML</say-as> examples."
          + "Here is a buzzing fly "
          + "<audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>"
          + "and here's a short pause <break time=\"800ms\"/>"
          + "</speak>");
  return responseBuilder.build();
}

Node.js

conv.ask(`<speak>` +
  `Here are <say-as interpet-as="characters">SSML</say-as> examples.` +
  `Here is a buzzing fly ` +
  `<audio src="https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg"></audio>` +
  `and here's a short pause <break time="800ms"/>` +
  `</speak>`);
conv.ask('Which response would you like to see next?');

Java

ResponseBuilder responseBuilder = getResponseBuilder(request);
responseBuilder.add(
    "<speak>"
        + "Here are <say-as interpet-as=\"characters\">SSML</say-as> examples."
        + "Here is a buzzing fly "
        + "<audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>"
        + "and here's a short pause <break time=\"800ms\"/>"
        + "</speak>");
return responseBuilder.build();

JSON

Xin lưu ý rằng JSON dưới đây mô tả phản hồi webhook.

{
  "payload": {
    "google": {
      "expectUserResponse": true,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "<speak>Here are <say-as interpet-as=\"characters\">SSML</say-as> examples.Here is a buzzing fly <audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>and here's a short pause <break time=\"800ms\"/></speak>"
            }
          },
          {
            "simpleResponse": {
              "textToSpeech": "Which response would you like to see next?"
            }
          }
        ]
      }
    }
  }
}

JSON

Xin lưu ý rằng JSON dưới đây mô tả phản hồi webhook.

{
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "possibleIntents": [
        {
          "intent": "actions.intent.TEXT"
        }
      ],
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "<speak>Here are <say-as interpet-as=\"characters\">SSML</say-as> examples.Here is a buzzing fly <audio src=\"https://actions.google.com/sounds/v1/animals/buzzing_fly.ogg\"></audio>and here's a short pause <break time=\"800ms\"/></speak>"
              }
            },
            {
              "simpleResponse": {
                "textToSpeech": "Which response would you like to see next?"
              }
            }
          ]
        }
      }
    }
  ]
}

Hãy xem tài liệu tham khảo về SSML để biết thêm thông tin.

Thư viện âm thanh

Chúng tôi cung cấp nhiều âm thanh ngắn, miễn phí trong thư viện âm thanh. Những âm thanh này được lưu trữ cho bạn, vì vậy bạn chỉ cần đưa chúng vào tệp SSML.