Kemampuan permukaan (Dialogflow)

Jelajahi di Dialogflow

Klik Continue untuk mengimpor contoh kemampuan Surface di Dialogflow. Kemudian, ikuti langkah-langkah di bawah ini untuk men-deploy dan menguji contoh:

  1. Masukkan nama agen dan buat agen Dialogflow baru untuk contoh.
  2. Setelah agen selesai diimpor, klik Go to agent.
  3. Dari menu navigasi utama, buka Fulfillment.
  4. Aktifkan Inline Editor, lalu klik Deploy. Editor berisi contoh tersebut pada kode sumber.
  5. Dari menu navigasi utama, buka Integrations, lalu klik Google Asisten.
  6. Di jendela modal yang muncul, aktifkan Pratinjau perubahan secara otomatis, lalu klik Uji untuk membuka simulator Actions.
  7. Dalam simulator, masukkan Talk to my test app untuk menguji sampel.
Lanjutkan

Action Anda dapat muncul di berbagai platform, termasuk hanya audio platform (smart speaker) dan audio & platform tampilan (seperti layar smart dan perangkat seluler).

Untuk mendesain dan membangun percakapan yang berfungsi dengan baik di semua platform, gunakan platform untuk mengontrol dan mencakup percakapan Anda dengan benar.

Menampilkan kemampuan untuk Actions

Actions on Google memungkinkan Anda mengontrol apakah pengguna bisa memanggil Action Anda atau tidak, berdasarkan di platform yang mereka gunakan. Jika pengguna mencoba memanggil Action Anda pada platform yang tidak didukung, mereka akan menerima pesan error yang memberi tahu bahwa perangkat mereka tidak didukung.

Anda menentukan dukungan platform Action di project Action Anda.

Action Anda dapat muncul di berbagai platform yang yang didukung Asisten, seperti smartphone (Android dan iOS) dan Perangkat Google Home.

Kemampuan platform runtime

Anda dapat menghadirkan pengalaman pengguna dengan kemampuan platform runtime melalui dua cara utama:

  • Percabangan respons - Menyajikan respons yang berbeda kepada pengguna, tetapi memiliki struktur dan alur yang sama untuk percakapan Anda di berbagai platform. Sebagai contoh, {i>weather Action<i} mungkin menampilkan kartu dengan gambar di ponsel dan memutar file audio di Google Home, tetapi alur percakapannya sama di berbagai platform.
  • Percabangan percakapan - Menampilkan tampilan yang benar-benar berbeda kepada pengguna percakapan di setiap platform. Misalnya, jika Anda membuat layanan pemesanan makanan Anda mungkin ingin memberikan alur pemesanan ulang di Google Home, tetapi dalam alur perakitan keranjang di ponsel. Untuk melakukan percabangan percakapan, ruang lingkup pemicu intent di Dialogflow ke kemampuan platform tertentu dengan Dialogflow konteks tambahan. Intent Dialogflow yang sebenarnya tidak dipicu kecuali jika kemampuan platform terpenuhi.

  • Percakapan multi-platform - Menyajikan percakapan kepada pengguna memunculkan platform lain di tengah percakapan. Misalnya, jika pengguna memanggil Action Anda dengan gambar di platform khusus audio seperti Google Beranda, Anda dapat membangun Action untuk mencari platform lain dengan dan memindahkan percakapan ke sana jika memungkinkan.

Percabangan respons

Setiap kali fulfillment Anda menerima permintaan dari Asisten Google, Anda dapat mengkueri platform berikut (misalnya, Google Home atau ponsel Android) kemampuan:

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

Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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

Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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"
        }
      ]
    }
  ]
}

Cabang percakapan

Anda dapat menyiapkan intent Dialogflow agar hanya dipicu pada kemampuan tertentu dengan konteks Dialogflow standar. Setiap kali intent dicocokkan, Dialogflow otomatis membuat konteks dari serangkaian kemampuan platform yang perangkat tersedia. Anda dapat menentukan satu atau beberapa konteks ini sebagai "konteks input" untuk intent Anda. Hal ini memungkinkan Anda membatasi pemicuan intent berdasarkan modalitas.

Misalnya, jika Anda ingin intent hanya terpicu pada perangkat dengan {i>output<i} layar, Anda dapat menetapkan konteks input pada intent menjadi actions_capability_screen_output.

Tersedia konteks berikut:

  • actions_capability_audio_output - Perangkat memiliki speaker.
  • actions_capability_screen_output - Perangkat memiliki layar tampilan output.
  • actions_capability_media_response_audio - Perangkat mendukung pemutaran konten media.
  • actions_capability_web_browser - Perangkat mendukung browser web. (Ini saat ini tidak tersedia untuk layar smart.)

Berikut adalah contoh intent yang hanya akan dipicu pada permukaan dengan layar:

Percakapan multi-platform

Kapan saja selama alur Action, Anda dapat memeriksa apakah pengguna memiliki platform dengan kemampuan tertentu. Jika platform lain dengan tersedia, Anda kemudian dapat mentransfer percakapan ke platform baru tersebut.

Alur untuk transfer platform akan berfungsi sebagai berikut:

  1. Memeriksa apakah pengguna memiliki platform yang tersedia

    Di pengendali webhook, Anda dapat mengkueri apakah pengguna memiliki platform yang tersedia dengan kemampuan tertentu. Perhatikan bahwa platform ini harus dikaitkan dengan Akun Google yang sama dengan platform sumber.

    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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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. Meminta untuk mentransfer pengguna ke platform baru

    Jika ada platform yang tersedia dengan kemampuan yang diperlukan, Action Anda akan perlu bertanya kepada pengguna apakah mereka ingin mentransfer percakapan itu.

    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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan respons 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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan respons 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. Menangani respons pengguna

    Berdasarkan respons pengguna terhadap permintaan Anda, Action Anda akan memfasilitasi pengalihan atau mengembalikan kontrol percakapan ke platform asal. Apa pun pilihan Anda, permintaan berikutnya ke endpoint akan berisi actions.intent.NEW_SURFACE sehingga Anda harus membangun intent yang memicu peristiwa tersebut dengan yang sesuai di webhook Anda. Dalam kode pengendali, Anda harus memeriksa apakah transfer berhasil atau tidak.

    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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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

    Perlu diperhatikan bahwa JSON di bawah mendeskripsikan permintaan 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"
            }
          ]
        }
      ]
    }