Oberflächenfunktionen (Dialogflow)

In Dialogflow ansehen

Klicken Sie auf Continue (Weiter), um unser Beispiel für Oberflächenfunktionen in Dialogflow zu importieren. Führen Sie dann die folgenden Schritte aus, um das Beispiel bereitzustellen und zu testen:

  1. Geben Sie einen Agent-Namen ein und erstellen Sie einen neuen Dialogflow-Agent für das Beispiel.
  2. Nachdem der Agent importiert wurde, klicken Sie auf Zum Agent.
  3. Klicken Sie im Hauptnavigationsmenü auf Fulfillment (Auftragsausführung).
  4. Aktivieren Sie den Inline-Editor und klicken Sie dann auf Bereitstellen. Der Editor enthält den Beispielcode.
  5. Klicken Sie im Hauptnavigationsmenü auf Integrations (Integrationen) und dann auf Google Assistant.
  6. Aktivieren Sie im angezeigten modalen Fenster die Option Änderungen automatisch in der Vorschau anzeigen und klicken Sie auf Testen, um den Actions-Simulator zu öffnen.
  7. Geben Sie im Simulator Talk to my test app ein, um das Beispiel zu testen.
Weiter

Deine Aktionen können auf verschiedenen Oberflächen angezeigt werden, darunter reine Audiooberflächen (intelligente Lautsprecher) und Audio- und Displayoberflächen (z. B. Smart Displays und Mobilgeräte).

Wenn Sie Unterhaltungen entwerfen und erstellen möchten, die auf allen Oberflächen gut funktionieren, verwenden Sie Oberflächenfunktionen, mit denen Sie Ihre Unterhaltungen richtig steuern und kontrollieren können.

Oberflächenfunktionen für Aktionen

Mit Actions on Google kannst du je nach verwendeter Oberfläche festlegen, ob Nutzer deine Aktion aufrufen können. Wenn Nutzer versuchen, deine Aktion auf einer nicht unterstützten Oberfläche auszuführen, erhalten sie eine Fehlermeldung, dass ihr Gerät nicht unterstützt wird.

Du legst die Unterstützung der Aktion in deinem Actions-Projekt fest.

Deine Aktion kann auf verschiedenen von Assistant unterstützten Oberflächen angezeigt werden, z. B. Smartphones (Android und iOS) und Google Home-Geräten.

Runtime-Oberflächen-Funktionen

Sie können die Nutzererfahrung mit Laufzeitfunktionen auf zwei Arten anpassen:

  • Antwortverzweigung: Sie können Nutzern unterschiedliche Antworten präsentieren, aber die gleiche Struktur und den gleichen Ablauf für Ihre Unterhaltung auf verschiedenen Oberflächen haben. Eine Wetter-Aktion kann beispielsweise eine Karte mit einem Bild auf einem Smartphone anzeigen und eine Audiodatei auf Google Home abspielen, der Unterhaltungsablauf ist jedoch auf allen Oberflächen gleich.
  • Unterhaltungsverzweigung: Sie können Nutzern auf jeder Oberfläche vollständig unterschiedliche Unterhaltungen präsentieren. Wenn Sie beispielsweise eine App für Essensbestellungen erstellen, möchten Sie vielleicht einen Neubestellvorgang auf Google Home und einen vollständigen Montageablauf für den Einkaufswagen auf Smartphones ermöglichen. Für die Verzweigung von Unterhaltungen müssen Sie das Auslösen des Intents in Dialogflow auf bestimmte Funktionen mit Dialogflow-Kontexten beschränken. Die tatsächlichen Dialogflow-Intents werden nur ausgelöst, wenn eine bestimmte Oberflächenfunktion erfüllt ist.

  • Unterhaltungen mit mehreren Oberflächen: Sie können Nutzern eine Unterhaltung auf einer Oberfläche präsentieren, die mitten in der Unterhaltung in eine andere übergeht. Wenn ein Nutzer deine Aktion beispielsweise mit Bildern auf einer reinen Audiooberfläche wie Google Home aufruft, kannst du deine Aktion so erstellen, dass sie nach einer anderen Oberfläche mit visuellen Funktionen sucht und die Unterhaltung dorthin verschieben kann.

Antwortverzweigung

Jedes Mal, wenn Ihre Auftragsausführung eine Anfrage von Google Assistant erhält, können Sie die folgenden Funktionen (z. B. Google Home oder ein Android-Smartphone) abfragen:

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

Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

{
  "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

Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

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

Unterhaltungsverzweigung

Sie können Dialogflow-Intents so einrichten, dass sie nur bei bestimmten Funktionen mit vordefinierten Dialogflow-Kontexten ausgelöst werden. Bei jeder Zuordnung eines Intents generiert Dialogflow automatisch Kontexte aus den Oberflächenfunktionen, die das Gerät zur Verfügung hat. Sie können einen oder mehrere dieser Kontexte als "Eingabekontexte" für Ihre Intents angeben. So können Sie Intent-Trigger modalitätenabhängig steuern.

Wenn ein Intent beispielsweise nur auf Geräten mit Bildschirmausgabe ausgelöst werden soll, können Sie actions_capability_screen_output als Eingabekontext für den Intent festlegen.

Folgende Kontexte sind verfügbar:

  • actions_capability_audio_output: Das Gerät hat einen Lautsprecher.
  • actions_capability_screen_output: Das Gerät hat einen Ausgabebildschirm.
  • actions_capability_media_response_audio: Das Gerät unterstützt die Wiedergabe von Medieninhalten.
  • actions_capability_web_browser: Das Gerät unterstützt einen Webbrowser. Diese Funktion ist derzeit für Smart Displays nicht verfügbar.

Hier ein Beispiel für einen Intent, der nur auf Oberflächen mit Bildschirmen ausgelöst wird:

Unterhaltungen über mehrere Oberflächen

Während des Ablaufs deiner Aktion kannst du jederzeit prüfen, ob der Nutzer andere Oberflächen mit einer bestimmten Fähigkeit hat. Wenn eine andere Oberfläche mit der angeforderten Funktion verfügbar ist, können Sie die aktuelle Unterhaltung auf diese neue Oberfläche übertragen.

Der Ablauf für eine Oberflächenübertragung läuft so ab:

  1. Prüfen, ob der Nutzer eine verfügbare Oberfläche hat

    Im Webhook-Handler können Sie abfragen, ob der Nutzer eine Oberfläche mit einer bestimmten Funktion hat. Diese Oberfläche muss mit demselben Google-Konto wie die Quelloberfläche verknüpft sein.

    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

    Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

    {
      "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

    Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

    {
      "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. Übertragung des Nutzers auf die neue Oberfläche anfordern

    Wenn eine Oberfläche mit den erforderlichen Funktionen vorhanden ist, muss deine Aktion den Nutzer fragen, ob er die Unterhaltung übertragen möchte.

    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

    Beachten Sie, dass der folgende JSON-Code eine Webhook-Antwort beschreibt.

    {
      "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

    Beachten Sie, dass der folgende JSON-Code eine Webhook-Antwort beschreibt.

    {
      "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. Antwort des Nutzers verarbeiten

    Basierend auf der Antwort des Nutzers auf deine Anfrage ermöglicht deine Aktion entweder die Übergabe oder gibt die Kontrolle der Unterhaltung an die ursprüngliche Oberfläche zurück. In beiden Fällen enthält die nächste Anfrage an den Endpunkt den Intent actions.intent.NEW_SURFACE. Sie sollten also einen Intent erstellen, der bei diesem Ereignis mit einem entsprechenden Handler im Webhook ausgelöst wird. Prüfen Sie im Handler-Code, ob die Übertragung erfolgreich war.

    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

    Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

    {
      "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

    Der folgende JSON-Code beschreibt eine Webhook-Anfrage.

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