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 tính 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à thử nghiệm mẫu:

  1. Nhập tên nhân viên hỗ trợ và tạo một nhân viên hỗ trợ Dialogflow mới cho mẫu.
  2. Sau khi nhân viên hỗ trợ nhập xong, hãy nhấp vào Chuyển đến nhân viên hỗ trợ.
  3. Trong trình đơn điều hướng chính, hãy chuyển đến phần Fulfillment (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ẫu .
  5. Trong trình đơn điều hướng chính, hãy chuyển đến mục Tích hợp, rồi nhấp vào Google Trợ lý Google.
  6. Trong cửa sổ phụ xuất hiện, hãy bật tuỳ chọn Tự động xem trước các thay đổi rồi nhấp vào Kiểm tra để mở Trình mô phỏng thao tác.
  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, trong đó có nền tảng chỉ phát âm thanh bề mặt (Loa thông minh), âm thanh và nền tảng hiển thị (như màn hình thông minh và thiết bị di động).

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

Giới thiệu các chức năng cho Thao tác

Actions on Google cho phép bạn kiểm soát việc người dùng có thể gọi ra Hành động của bạn hay không, dựa trên 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ợ, 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 nền tảng hỗ trợ cho Hành động trong dự án Actions.

Hành động của bạn có thể xuất hiện trên nhiều nền tảng mà 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 của 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 các chức năng của giao diện trong thời gian chạy theo hai cách chính:

  • Phân nhánh phản hồi – Trình bày các câu trả lời khác nhau cho người dùng nhưng vẫn có cùng một cấu trúc và luồng trò chuyện cho cuộc trò chuyện trên nhiều nền tảng. Cho Ví dụ: một 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 một tệp âm thanh trên Google Home, nhưng luồng trò chuyện vẫn giữ nguyên trên các nền tảng.
  • Phân nhánh cuộc trò chuyện - Trình bày người dùng với kiểu hoàn toàn khác cuộc trò chuyện trên mỗi nền tảng. Ví dụ: nếu bạn đang xây dựng một cửa hàng đặt đồ ăn bạn có thể muốn cung cấp một quy trình sắp xếp lại trên Google Home, nhưng quy trình lắp ráp giỏ hàng 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 ý định kích hoạt trong Dialogflow cho một số khả năng hiển thị nhất định bằng Dialogflow ngữ cảnh. Ý định Dialogflow thực tế không được kích hoạt trừ phi một ý định cụ thể đã đáp ứng được chức năng 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 cuộc trò chuyện trên một nền tảng nền tảng chuyển đổi 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 nền tảng chỉ có âm thanh như Google Màn hình chính, bạn có thể tạo Hành động để tìm một giao diện khác bằng hình ảnh và chuyển cuộc trò chuyện đến đó nếu có thể.

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

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

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 tệp 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 tệp 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 hội thoại

Bạn có thể thiết lập ý định Dialogflow để chỉ kích hoạt một số chức năng bằng ngữ cảnh Dialogflow xác định trước. Mỗi khi có ý định được so khớp, Dialogflow tự động tạo bối cảnh từ tập hợp khả năng bề mặt của thiết bị đã có. 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" phù hợp với ý định của bạn. Đ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 bạn 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.

Có các bối 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 nghe nhìn.
  • actions_capability_web_browser – Thiết bị hỗ trợ một trình duyệt web. (Kết quả này hiện chưa hỗ trợ màn hình thông minh.)

Dưới đây là ví dụ về một ý định sẽ 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 của mình, bạn có thể kiểm tra xem người dùng có bất kỳ các nền tảng có chức năng cụ thể. Nếu một nền tảng khác có thông tin được yêu cầu có sẵn, sau đó bạn có thể chuyển trò chuyện sang nền tảng mới đó.

Quy trình chuyển nền tảng sẽ hoạt động như sau:

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

    Trong trình xử lý webhook, bạn có thể truy vấn xem người dùng có nền tảng hay không với một khả năng cụ thể. Lưu ý rằng bề mặt này phải được liên kết với cùng một Tài khoản Google làm 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 tệp 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 tệp 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ó sẵn nền tảng có các tính năng cần thiết, 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 bên dưới 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 bên dưới 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ý câu trả lờ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ẽ hỗ trợ quyền chuyển giao hoặc trả lại quyền kiểm soát cuộc trò chuyện về vị trí ban đầu. Dù bằng cách nào, yêu cầu tiếp theo đến điểm cuối của bạn sẽ chứa actions.intent.NEW_SURFACE ý định, 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 của bạn. Trong mã 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 tệp 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 tệp 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"
            }
          ]
        }
      ]
    }