Các chức năng của nền tảng (Dialogflow)

Khám phá trong Dialogflow

Nhấp vào Tiếp tục để nhập mẫu các chức năng của Surface 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!

Hành động của bạn có thể xuất hiện trên nhiều nền tảng, bao gồm cả các nền tảng chỉ phát âm thanh (loa thông minh) cũng như các nền tảng hiển thị và âm thanh (như màn hình thông minh và thiết bị di động).

Để thiết kế và xây dựng cuộc trò chuyện hoạt động hiệu quả trên mọi nền tảng, hãy sử dụng các tính năng nền tảng để kiểm soát và xác định phạm vi cuộc trò chuyện đúng cách.

Các chức năng của nền tảng cho Hành động

Actions on Google cho phép bạn kiểm soát việc người dùng có thể gọi Hành động của bạn hay không, dựa trên nền tảng mà họ đang sử dụng. Nếu người dùng cố gắng gọi Hành động của bạn trên một nền tảng không được hỗ trợ, thì họ sẽ nhận được thông báo lỗi cho biết thiết bị của họ không được hỗ trợ.

Bạn xác định chế độ hỗ trợ nền tảng cho Hành động trong dự án Actions (Hành động).

Hành động của bạn có thể xuất hiện trên nhiều nền tảng mà Trợ lý hỗ trợ, chẳng hạn như điện thoại thông minh (Android và iOS) và thiết bị Google Home.

Khả năng nền tảng trong thời gian chạy

Bạn có thể phục vụ trải nghiệm người dùng bằng chức năng nền tảng thời gian chạy theo hai cách chính:

  • Phân nhánh phản hồi – Đưa ra các câu trả lời khác nhau cho người dùng nhưng có cùng cấu trúc và quy trình cho cuộc trò chuyện của bạn trên nhiều nền tảng. Ví dụ: Hành động thời tiết có thể hiển thị một thẻ có hình ảnh trên điện thoại và phát tệp âm thanh trên Google Home, nhưng luồng trò chuyện sẽ giống nhau trên các nền tảng.
  • Phân nhánh cuộc trò chuyện – Mang đến cho người dùng những cuộc trò chuyện hoàn toàn khác nhau ở mỗi nền tảng. Ví dụ: nếu đang tạo một ứng dụng đặt món ăn, bạn nên cung cấp quy trình đặt hàng lại trên Google Home, nhưng có thể cung cấp quy trình tập hợp giỏ hàng đầy đủ trên điện thoại di động. Để phân nhánh cuộc trò chuyện, hãy xác định phạm vi kích hoạt ý định trong Dialogflow cho một số chức năng bề mặt nhất định theo ngữ cảnh Dialogflow. Các ý định thực tế trong Dialogflow sẽ không được kích hoạt trừ phi đáp ứng một khả năng cụ thể trên bề mặt.

  • Cuộc trò chuyện trên nhiều nền tảng – Trình bày cho người dùng một cuộc trò chuyện trên một nền tảng mà sẽ chuyển sang một nền tảng khác giữa cuộc trò chuyện. Ví dụ: nếu người dùng gọi Hành động của bạn bằng hình ảnh trên một nền tảng chỉ có âm thanh như Google Home, thì bạn có thể tạo Hành động để tìm một nền tảng khác có khả năng hình ảnh và di chuyển cuộc trò chuyện đến đó nếu có thể.

Phân nhánh phản hồi

Mỗi khi phương thức thực hiện của bạn nhận được yêu cầu từ Trợ lý Google, bạn có thể truy vấn các chức năng sau (ví dụ: Google Home hoặc điện thoại Android):

Node.js

const hasScreen =
  conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT');
  // OR conv.screen;
const hasAudio =
  conv.surface.capabilities.has('actions.capability.AUDIO_OUTPUT');
const hasMediaPlayback =
  conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO');
const hasWebBrowser =
  conv.surface.capabilities.has('actions.capability.WEB_BROWSER');
// Interactive Canvas must be enabled in your project to see this
const hasInteractiveCanvas =
  conv.surface.capabilities.has('actions.capability.INTERACTIVE_CANVAS');

Java

boolean hasScreen = request.hasCapability(Capability.SCREEN_OUTPUT.getValue());
boolean hasAudio = request.hasCapability(Capability.AUDIO_OUTPUT.getValue());
boolean hasMediaPlayback = request.hasCapability(Capability.MEDIA_RESPONSE_AUDIO.getValue());
boolean hasWebBrowser = request.hasCapability(Capability.WEB_BROWSER.getValue());
// Interactive Canvas must be enabled in your project to see this
boolean hasInteractiveCanvas = request.hasCapability("INTERACTIVE_CANVAS");

Node.js

const hasScreen =
  conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT');
  // OR conv.screen;
const hasAudio =
  conv.surface.capabilities.has('actions.capability.AUDIO_OUTPUT');
const hasMediaPlayback =
  conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO');
const hasWebBrowser =
  conv.surface.capabilities.has('actions.capability.WEB_BROWSER');
// Interactive Canvas must be enabled in your project to see this
const hasInteractiveCanvas =
  conv.surface.capabilities.has('actions.capability.INTERACTIVE_CANVAS');

Java

boolean hasScreen = request.hasCapability(Capability.SCREEN_OUTPUT.getValue());
boolean hasAudio = request.hasCapability(Capability.AUDIO_OUTPUT.getValue());
boolean hasMediaPlayback = request.hasCapability(Capability.MEDIA_RESPONSE_AUDIO.getValue());
boolean hasWebBrowser = request.hasCapability(Capability.WEB_BROWSER.getValue());
// Interactive Canvas must be enabled in your project to see this
boolean hasInteractiveCanvas = request.hasCapability("INTERACTIVE_CANVAS");

JSON

Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

{
  "responseId": "206a66fb-a572-4cfc-9e41-8e2eb62fdf18-712767ed",
  "queryResult": {
    "queryText": "Current capabilities",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Webhook failed for intent: Current Capabilities",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Webhook failed for intent: Current Capabilities"
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_media_response_audio"
      },
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_audio_output"
      },
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_account_linking"
      },
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_web_browser"
      },
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_screen_output"
      },
      {
        "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/google_assistant_input_type_touch"
      }
    ],
    "intent": {
      "name": "projects/df-surface-caps-kohler/agent/intents/4e191eef-ba17-4f68-8a97-85a43cbc9ed1",
      "displayName": "Current Capabilities"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "source": "google",
    "version": "2",
    "payload": {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ",
        "type": "ACTIVE",
        "conversationToken": "[]"
      },
      "inputs": [
        {
          "intent": "actions.intent.TEXT",
          "rawInputs": [
            {
              "inputType": "TOUCH",
              "query": "Current capabilities"
            }
          ],
          "arguments": [
            {
              "name": "text",
              "rawText": "Current capabilities",
              "textValue": "Current capabilities"
            }
          ]
        }
      ],
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          },
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          },
          {
            "name": "actions.capability.ACCOUNT_LINKING"
          },
          {
            "name": "actions.capability.WEB_BROWSER"
          },
          {
            "name": "actions.capability.SCREEN_OUTPUT"
          }
        ]
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            },
            {
              "name": "actions.capability.WEB_BROWSER"
            }
          ]
        }
      ]
    }
  },
  "session": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ"
}

JSON

Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

{
  "user": {
    "locale": "en-US",
    "userVerificationStatus": "VERIFIED"
  },
  "conversation": {
    "conversationId": "ABwppHENuB8dw7LgVquXnW5Bmy9hwu1Qz4bsaL7uIb9vDSBYPAFhFgsMWnMV6m4JEDgaUWz9FUVuIhQqWh1KZ_jjTwKEIlza",
    "type": "NEW"
  },
  "inputs": [
    {
      "intent": "actions.intent.TEXT",
      "rawInputs": [
        {
          "inputType": "TOUCH",
          "query": "Current capabilities"
        }
      ],
      "arguments": [
        {
          "name": "text",
          "rawText": "Current capabilities",
          "textValue": "Current capabilities"
        }
      ]
    }
  ],
  "surface": {
    "capabilities": [
      {
        "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
      },
      {
        "name": "actions.capability.SCREEN_OUTPUT"
      },
      {
        "name": "actions.capability.WEB_BROWSER"
      },
      {
        "name": "actions.capability.ACCOUNT_LINKING"
      },
      {
        "name": "actions.capability.AUDIO_OUTPUT"
      }
    ]
  },
  "availableSurfaces": [
    {
      "capabilities": [
        {
          "name": "actions.capability.WEB_BROWSER"
        },
        {
          "name": "actions.capability.AUDIO_OUTPUT"
        },
        {
          "name": "actions.capability.SCREEN_OUTPUT"
        }
      ]
    }
  ]
}

Phân nhánh cuộc trò chuyện

Bạn có thể thiết lập ý định Dialogflow để chỉ kích hoạt một số chức năng nhất định bằng bối cảnh Dialogflow được xác định trước. Mỗi khi có một ý định được so khớp, Dialogflow sẽ tự động tạo ngữ cảnh từ tập hợp chức năng nền tảng mà thiết bị có sẵn. Bạn có thể chỉ định một hoặc nhiều ngữ cảnh trong số này làm "bối cảnh đầu vào" cho ý định của mình. Điều này cho phép bạn kiểm soát việc kích hoạt ý định dựa trên phương thức.

Ví dụ: nếu chỉ muốn một ý định kích hoạt trên các thiết bị có đầu ra màn hình, bạn có thể đặt ngữ cảnh đầu vào cho ý định là actions_capability_screen_output.

Bạn có thể sử dụng các ngữ cảnh sau:

  • actions_capability_audio_output – Thiết bị có loa.
  • actions_capability_screen_output – Thiết bị có màn hình hiển thị đầu ra.
  • actions_capability_media_response_audio – Thiết bị hỗ trợ phát nội dung đa phương tiện.
  • actions_capability_web_browser – Thiết bị hỗ trợ trình duyệt web. (Tính năng này hiện chưa dùng được cho màn hình thông minh.)

Dưới đây là ví dụ về một ý định chỉ kích hoạt trên các nền tảng có màn hình:

Cuộc trò chuyện trên nhiều nền tảng

Tại bất kỳ thời điểm nào trong luồng Hành động, bạn có thể kiểm tra xem người dùng có nền tảng nào khác có khả năng cụ thể hay không. Nếu có nền tảng khác có chức năng được yêu cầu, bạn có thể chuyển cuộc trò chuyện hiện tại sang nền tảng mới đó.

Quy trình chuyển giao bề mặt sẽ diễn ra như sau:

  1. Kiểm tra xem người dùng có nền tảng hiện có hay không

    Trong trình xử lý webhook, bạn có thể truy vấn xem người dùng có một nền tảng có khả năng cụ thể hay không. Lưu ý rằng nền tảng này phải được liên kết với cùng một Tài khoản Google như nền tảng nguồn.

    Node.js

    const screenAvailable =
      conv.available.surfaces.capabilities.has(
        'actions.capability.SCREEN_OUTPUT');

    Java

    String screen = Capability.SCREEN_OUTPUT.getValue();
    boolean screenAvailable = false;
    for (Surface surface : request.getAvailableSurfaces()) {
      for (com.google.api.services.actions_fulfillment.v2.model.Capability capability :
          surface.getCapabilities()) {
        if (capability.getName().equals(screen)) {
          screenAvailable = true;
          break;
        }
      }
    }

    Node.js

    const screenAvailable =
      conv.available.surfaces.capabilities.has(
        'actions.capability.SCREEN_OUTPUT');

    Java

    String screen = Capability.SCREEN_OUTPUT.getValue();
    boolean screenAvailable = false;
    for (Surface surface : request.getAvailableSurfaces()) {
      for (com.google.api.services.actions_fulfillment.v2.model.Capability capability :
          surface.getCapabilities()) {
        if (capability.getName().equals(screen)) {
          screenAvailable = true;
          break;
        }
      }
    }

    JSON

    Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

    {
      "responseId": "206a66fb-a572-4cfc-9e41-8e2eb62fdf18-712767ed",
      "queryResult": {
        "queryText": "Current capabilities",
        "parameters": {},
        "allRequiredParamsPresent": true,
        "fulfillmentText": "Webhook failed for intent: Current Capabilities",
        "fulfillmentMessages": [
          {
            "text": {
              "text": [
                "Webhook failed for intent: Current Capabilities"
              ]
            }
          }
        ],
        "outputContexts": [
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_media_response_audio"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_audio_output"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_account_linking"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_web_browser"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/actions_capability_screen_output"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ/contexts/google_assistant_input_type_touch"
          }
        ],
        "intent": {
          "name": "projects/df-surface-caps-kohler/agent/intents/4e191eef-ba17-4f68-8a97-85a43cbc9ed1",
          "displayName": "Current Capabilities"
        },
        "intentDetectionConfidence": 1,
        "languageCode": "en"
      },
      "originalDetectIntentRequest": {
        "source": "google",
        "version": "2",
        "payload": {
          "user": {
            "locale": "en-US",
            "userVerificationStatus": "VERIFIED"
          },
          "conversation": {
            "conversationId": "ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ",
            "type": "ACTIVE",
            "conversationToken": "[]"
          },
          "inputs": [
            {
              "intent": "actions.intent.TEXT",
              "rawInputs": [
                {
                  "inputType": "TOUCH",
                  "query": "Current capabilities"
                }
              ],
              "arguments": [
                {
                  "name": "text",
                  "rawText": "Current capabilities",
                  "textValue": "Current capabilities"
                }
              ]
            }
          ],
          "surface": {
            "capabilities": [
              {
                "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
              },
              {
                "name": "actions.capability.AUDIO_OUTPUT"
              },
              {
                "name": "actions.capability.ACCOUNT_LINKING"
              },
              {
                "name": "actions.capability.WEB_BROWSER"
              },
              {
                "name": "actions.capability.SCREEN_OUTPUT"
              }
            ]
          },
          "availableSurfaces": [
            {
              "capabilities": [
                {
                  "name": "actions.capability.AUDIO_OUTPUT"
                },
                {
                  "name": "actions.capability.SCREEN_OUTPUT"
                },
                {
                  "name": "actions.capability.WEB_BROWSER"
                }
              ]
            }
          ]
        }
      },
      "session": "projects/df-surface-caps-kohler/agent/sessions/ABwppHG7pYytu-kJGJApvrFTk2iNkshy-NLsjlzJg2ntVbxZkoz-rdFch3Fd8Vmlgf0VxmNSK1woelx1otayGwCnE8gzAQ"
    }

    JSON

    Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

    {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHENuB8dw7LgVquXnW5Bmy9hwu1Qz4bsaL7uIb9vDSBYPAFhFgsMWnMV6m4JEDgaUWz9FUVuIhQqWh1KZ_jjTwKEIlza",
        "type": "NEW"
      },
      "inputs": [
        {
          "intent": "actions.intent.TEXT",
          "rawInputs": [
            {
              "inputType": "TOUCH",
              "query": "Current capabilities"
            }
          ],
          "arguments": [
            {
              "name": "text",
              "rawText": "Current capabilities",
              "textValue": "Current capabilities"
            }
          ]
        }
      ],
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          },
          {
            "name": "actions.capability.SCREEN_OUTPUT"
          },
          {
            "name": "actions.capability.WEB_BROWSER"
          },
          {
            "name": "actions.capability.ACCOUNT_LINKING"
          },
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          }
        ]
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.WEB_BROWSER"
            },
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            }
          ]
        }
      ]
    }
  2. Yêu cầu chuyển người dùng sang nền tảng mới

    Nếu có một nền tảng với những chức năng cần thiết, thì Hành động của bạn sẽ cần hỏi người dùng xem họ có muốn chuyển cuộc trò chuyện hay không.

    Node.js

    if (conv.screen) {
      conv.ask(`You're already on a screen device.`);
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Current Capabilities',
        'Check Audio Capability',
        'Check Screen Capability',
        'Check Media Capability',
        'Check Web Capability',
      ]));
      return;
    } else if (screenAvailable) {
      const context =
        `Let's move you to a screen device for cards and other visual responses`;
      const notification = 'Try your Action here!';
      const capabilities = ['actions.capability.SCREEN_OUTPUT'];
      return conv.ask(new NewSurface({context, notification, capabilities}));
    } else {
      conv.ask('It looks like there is no screen device ' +
        'associated with this user.');
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Current Capabilities',
        'Check Audio Capability',
        'Check Screen Capability',
        'Check Media Capability',
        'Check Web Capability',
      ]));
    };

    Java

    ResponseBuilder responseBuilder = getResponseBuilder(request);
    if (request.hasCapability(Capability.SCREEN_OUTPUT.getValue())) {
      responseBuilder.add("You're already on a screen device");
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Transfer surface",
            "Check Audio Capability",
            "Check Screen Capability",
            "Check Media Capability",
            "Check Web Capability",
          });
      return responseBuilder.build();
    } else if (screenAvailable) {
      responseBuilder.add(
          new NewSurface()
              .setContext("Let's move you to a screen device for cards and other visual responses")
              .setNotificationTitle("Try your Action here!")
              .setCapabilities(Collections.singletonList(screen)));
      return responseBuilder.build();
    } else {
      responseBuilder.add("It looks like there is no screen device associated with this user.");
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Transfer surface",
            "Check Audio Capability",
            "Check Screen Capability",
            "Check Media Capability",
            "Check Web Capability",
          });
      return responseBuilder.build();
    }

    Node.js

    if (conv.screen) {
      conv.ask(`You're already on a screen device.`);
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Transfer surface',
        'Current capabilities',
      ]));
      return;
    } else if (screenAvailable) {
      const context =
        `Let's move you to a screen device for cards and other visual responses`;
      const notification = 'Try your Action here!';
      const capabilities = ['actions.capability.SCREEN_OUTPUT'];
      return conv.ask(new NewSurface({context, notification, capabilities}));
    } else {
      conv.ask('It looks like there is no screen device ' +
        'associated with this user.');
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Transfer surface',
        'Current capabilities',
      ]));
    };

    Java

    ResponseBuilder responseBuilder = getResponseBuilder(request);
    if (request.hasCapability(Capability.SCREEN_OUTPUT.getValue())) {
      responseBuilder.add("You're already on a screen device");
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Current capabilities", "Transfer surface",
          });
      return responseBuilder.build();
    } else if (screenAvailable) {
      responseBuilder.add(
          new NewSurface()
              .setContext("Let's move you to a screen device for cards and other visual responses")
              .setNotificationTitle("Try your Action here!")
              .setCapabilities(Collections.singletonList(screen)));
      return responseBuilder.build();
    } else {
      responseBuilder.add("It looks like there is no screen device associated with this user.");
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Current capabilities", "Transfer surface",
          });
      return responseBuilder.build();
    }

    JSON

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

    {
      "payload": {
        "google": {
          "expectUserResponse": true,
          "systemIntent": {
            "intent": "actions.intent.NEW_SURFACE",
            "data": {
              "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
              "capabilities": [
                "actions.capability.SCREEN_OUTPUT"
              ],
              "context": "Let's move you to a screen device for cards and other visual responses",
              "notificationTitle": "Try your Action here!"
            }
          }
        }
      }
    }

    JSON

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

    {
      "expectUserResponse": true,
      "expectedInputs": [
        {
          "possibleIntents": [
            {
              "intent": "actions.intent.NEW_SURFACE",
              "inputValueData": {
                "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValueSpec",
                "capabilities": [
                  "actions.capability.SCREEN_OUTPUT"
                ],
                "context": "Let's move you to a screen device for cards and other visual responses",
                "notificationTitle": "Try your Action here!"
              }
            }
          ]
        }
      ]
    }
  3. Xử lý phản hồi của người dùng

    Dựa trên phản hồi của người dùng đối với yêu cầu của bạn, Hành động của bạn sẽ tạo điều kiện cho việc chuyển giao hoặc đưa quyền kiểm soát cuộc trò chuyện trở lại nền tảng ban đầu. Dù bằng cách nào, yêu cầu tiếp theo đến điểm cuối sẽ chứa ý định actions.intent.NEW_SURFACE. Vì vậy, bạn nên tạo một ý định kích hoạt sự kiện đó bằng một trình xử lý tương ứng trong webhook. Trong mã trình xử lý, bạn nên kiểm tra xem quá trình chuyển có thành công hay không.

    Node.js

    app.intent('Transfer Surface - NEW_SURFACE', (conv, input, newSurface) => {
      if (newSurface.status === 'OK') {
        conv.ask('Welcome to a screen device!');
        conv.ask(new BasicCard({
          title: `You're on a screen device!`,
          text: `Screen devices support basic cards and other visual responses!`,
        }));
      } else {
        conv.ask(`Ok, no problem.`);
      }
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Current Capabilities',
        'Check Audio Capability',
        'Check Screen Capability',
        'Check Media Capability',
        'Check Web Capability',
      ]));
    });

    Java

    @ForIntent("Transfer Surface - NEW_SURFACE")
    public ActionResponse newSurface(ActionRequest request) {
      ResponseBuilder responseBuilder = getResponseBuilder(request);
      Map<String, Object> newSurfaceStatus = request.getArgument("NEW_SURFACE").getExtension();
      if (newSurfaceStatus.get("status").equals("OK")) {
        responseBuilder.add("Welcome to a screen device!");
        responseBuilder.add(
            new BasicCard()
                .setTitle("You're on a screened device!")
                .setFormattedText("Screen devices support basic cards and other visual responses!"));
      } else {
        responseBuilder.add("Ok, no problem.");
      }
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Transfer surface",
            "Check Audio Capability",
            "Check Screen Capability",
            "Check Media Capability",
            "Check Web Capability",
          });
      return responseBuilder.build();
    }

    Node.js

    app.intent('actions.intent.NEW_SURFACE', (conv) => {
      if (conv.arguments.get('NEW_SURFACE').status === 'OK') {
        conv.ask('Welcome to a screen device!');
        conv.ask(new BasicCard({
          title: `You're on a screen device!`,
          text: `Screen devices support basic cards and other visual responses!`,
        }));
      } else {
        conv.ask(`Ok, no problem.`);
      }
      conv.ask('What else would you like to try?');
      conv.ask(new Suggestions([
        'Transfer surface',
        'Current capabilities',
      ]));
    });

    Java

    @ForIntent("actions.intent.NEW_SURFACE")
    public ActionResponse newSurface(ActionRequest request) {
      ResponseBuilder responseBuilder = getResponseBuilder(request);
      Map<String, Object> newSurfaceStatus = request.getArgument("NEW_SURFACE").getExtension();
      if (newSurfaceStatus.get("status").equals("OK")) {
        responseBuilder.add("Welcome to a screen device!");
        responseBuilder.add(
            new BasicCard()
                .setTitle("You're on a screened device!")
                .setFormattedText("Screen devices support basic cards and other visual responses!"));
      } else {
        responseBuilder.add("Ok, no problem.");
      }
      responseBuilder.add("What else would you like to try?");
      responseBuilder.addSuggestions(
          new String[] {
            "Current capabilities", "Transfer surface",
          });
      return responseBuilder.build();
    }

    JSON

    Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

    {
      "responseId": "94b74485-cd7a-4b3b-b96a-fec15f3a496c-712767ed",
      "queryResult": {
        "queryText": "actions_intent_NEW_SURFACE",
        "parameters": {},
        "allRequiredParamsPresent": true,
        "fulfillmentText": "Webhook failed for intent: Transfer Surface - NEW_SURFACE",
        "fulfillmentMessages": [
          {
            "text": {
              "text": [
                "Webhook failed for intent: Transfer Surface - NEW_SURFACE"
              ]
            }
          }
        ],
        "outputContexts": [
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_capability_screen_output"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_capability_web_browser"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_capability_audio_output"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_capability_media_response_audio"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_capability_account_linking"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/google_assistant_input_type_voice"
          },
          {
            "name": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q/contexts/actions_intent_new_surface",
            "parameters": {
              "NEW_SURFACE": {
                "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValue",
                "status": "OK"
              },
              "text": ""
            }
          }
        ],
        "intent": {
          "name": "projects/df-surface-caps-kohler/agent/intents/9db3798d-bdac-4dc8-a8e7-52349a3af0e8",
          "displayName": "Transfer Surface - NEW_SURFACE"
        },
        "intentDetectionConfidence": 1,
        "languageCode": "en"
      },
      "originalDetectIntentRequest": {
        "source": "google",
        "version": "2",
        "payload": {
          "user": {
            "locale": "en-US",
            "userVerificationStatus": "VERIFIED"
          },
          "conversation": {
            "conversationId": "ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q",
            "type": "ACTIVE",
            "conversationToken": "[]"
          },
          "inputs": [
            {
              "intent": "actions.intent.NEW_SURFACE",
              "rawInputs": [
                {
                  "inputType": "VOICE"
                }
              ],
              "arguments": [
                {
                  "name": "NEW_SURFACE",
                  "extension": {
                    "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValue",
                    "status": "OK"
                  }
                },
                {
                  "name": "text"
                }
              ]
            }
          ],
          "surface": {
            "capabilities": [
              {
                "name": "actions.capability.SCREEN_OUTPUT"
              },
              {
                "name": "actions.capability.WEB_BROWSER"
              },
              {
                "name": "actions.capability.AUDIO_OUTPUT"
              },
              {
                "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
              },
              {
                "name": "actions.capability.ACCOUNT_LINKING"
              }
            ]
          },
          "availableSurfaces": [
            {
              "capabilities": [
                {
                  "name": "actions.capability.SCREEN_OUTPUT"
                },
                {
                  "name": "actions.capability.WEB_BROWSER"
                },
                {
                  "name": "actions.capability.AUDIO_OUTPUT"
                }
              ]
            }
          ]
        }
      },
      "session": "projects/df-surface-caps-kohler/agent/sessions/ABwppHEfQy-JgH7nmiW5gHWiDEyvqNRSPv9zkd3qTVF7F8G8YXJFI2_yal335Co0Z-_N5oUBTmVO_DJUlQONqd5lUgZz-Q"
    }

    JSON

    Xin lưu ý rằng JSON ở bên dưới mô tả một yêu cầu webhook.

    {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHENAOzBH5swn9iKb5QgUliTw4JLu5f86gS373tGtNvYcz1C3qHdorjcIb77o_PUleXGzIEFdPsl3-kmIAARvx67A7Ym",
        "type": "NEW"
      },
      "inputs": [
        {
          "intent": "actions.intent.NEW_SURFACE",
          "rawInputs": [
            {
              "inputType": "VOICE"
            }
          ],
          "arguments": [
            {
              "name": "NEW_SURFACE",
              "extension": {
                "@type": "type.googleapis.com/google.actions.v2.NewSurfaceValue",
                "status": "OK"
              }
            },
            {
              "name": "text"
            }
          ]
        }
      ],
      "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.WEB_BROWSER"
            },
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            }
          ]
        }
      ]
    }