Richieste (Dialogflow)

Esplora in Dialogflow

Fai clic su Continua per importare il nostro campione di Reprompt in Dialogflow. Poi segui le passaggi di seguito per eseguire il deployment e testare l'esempio:

  1. Inserisci il nome di un agente e crea un nuovo agente Dialogflow per il campione.
  2. Al termine dell'importazione, fai clic su Vai all'agente.
  3. Nel menu di navigazione principale, vai a Fulfillment.
  4. Attiva l'editor incorporato e fai clic su Esegui il deployment. L'editor contiene l'esempio le API nel tuo codice.
  5. Nel menu di navigazione principale, vai a Integrazioni, quindi fai clic su Google Assistente.
  6. Nella finestra modale che viene visualizzata, attiva Anteprima automatica delle modifiche e fai clic su Test. per aprire il simulatore delle azioni.
  7. Nel simulatore, inserisci Talk to my test app per testare il campione.
Continua

Puoi utilizzare le seguenti funzionalità per gestire i casi in cui gli utenti non forniscono input per le tue Azioni (errori senza input):

  • Ripetizioni predefinite di sistema: le richieste all'utente vengono riproposte automaticamente. con ripetizioni preconfigurate e generiche per tutti i casi.
  • Ripetizioni dinamiche: dichiara che vuoi gestire la replica sul tuo e riceve un intent (SDK Actions) o un evento (Dialogflow) ogni volta non avviene alcun input, quindi potrai gestirli caso per caso.
di Gemini Advanced.

Ripetizioni predefinite di sistema

Per impostazione predefinita, quando restituisci una risposta all'assistente, il sistema utilizza richieste predefinite per chiedere agli utenti di ripetere o digitare nuovamente l'input.

Dialogflow

Dialogflow applica un massimo combinato di tre input senza corrispondenza e senza input. Quando una conversazione raggiunge tre tentativi di raccolta, l'agente Dialogflow termina la conversazione con una risposta predefinita. Un input senza corrispondenza in Dialogflow si verifica quando viene attivato uno degli intent di fallback.

Ripetizioni dinamiche

Puoi ricevere un intent o un evento Dialogflow ogni volta che l'azione non riesce ricevere qualsiasi input. Ciò ti consente di restituire una risposta diversa in base a della logica, se necessario, e ripetere la richiesta all'utente in modo appropriato.

Dialogflow

Puoi creare due tipi di intent senza input:

  • Intent normale: questo metodo non si applica ad alcun contesto e verrà quindi attivato quando non c'è un altro intento più contestuale da attivare. È utile per i prompt generici che vuoi applicare nella maggior parte dei casi.

  • Intent di follow-up: gli intent di follow-up vengono applicati tramite Dialogflow in ogni contesto, assicurandosi che i reprompt vengano attivati solo dopo alcuni passaggi conversazione. È utile per i prompt personalizzati a cui vuoi applicare situazioni specifiche.

Per gestire gli eventi senza input:

  1. Nel menu di navigazione a sinistra, fai clic su Intent.
  2. Crea un intent normale o un intento di follow-up.
    • Per gli intent normali: fai clic sull'icona + accanto al menu Intent. e assegna un nome all'intent, ad esempio "Reprompt".

    • Per gli intent di follow-up: passa il mouse sopra l'intent che vuoi personalizza la richiesta senza input e fai clic su Aggiungi intent di follow-up > personalizzata. Viene creato un nuovo intent sotto l'intent originale.

  3. Fai clic sull'intent appena creato per aprire l'editor degli intent.
  4. Fai clic sulla sezione Eventi e inserisci "actions_intent_NO_INPUT" nel Campo Aggiungi evento.
  5. Nella sezione Azioni, inserisci un nome per l'azione o utilizza quello fornito per impostazione predefinita. Per questo esempio utilizzeremo "no.input".

  6. Fai clic su Salva.
  7. Nel menu di navigazione a sinistra, fai clic su Integrazioni.
  8. Scegli Assistente Google e fai clic su Prova per effettuare per assicurarti che le modifiche si riflettano nel progetto Actions.

Ogni volta che non si verifica alcun input per questo intent, puoi utilizzare il tuo fulfillment per restituire una risposta appropriata o crearne una in Dialogflow. Ad esempio, ecco un codice di completamento che utilizza la libreria client per gestire un normale intent senza input denominato "Reprompt".

Node.js

const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');

const app = dialogflow({debug: true});

app.intent('Reprompt', (conv) => {
  const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
  if (repromptCount === 0) {
  conv.ask(`What was that?`);
  } else if (repromptCount === 1) {
  conv.ask(`Sorry I didn't catch that. Could you repeat yourself?`);
  } else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
  conv.close(`Okay let's try this again later.`);
  }
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Java

package com.example;

import com.google.actions.api.ActionRequest;
import com.google.actions.api.ActionResponse;
import com.google.actions.api.DialogflowApp;
import com.google.actions.api.ForIntent;
import com.google.actions.api.response.ResponseBuilder;

public class MyActionsApp extends DialogflowApp {

  @ForIntent("Reprompt")
  public ActionResponse reprompt(ActionRequest request) {
    ResponseBuilder responseBuilder = getResponseBuilder(request);
    int repromptCount = request.getRepromptCount();
    String response;
    if (repromptCount == 0) {
      response = "What was that?";
    } else if (repromptCount == 1) {
      response = "Sorry, I didn't catch that. Could you repeat yourself?";
    } else {
      responseBuilder.endConversation();
      response = "Okay let's try this again later.";
    }
    return responseBuilder.add(response).build();
  }
}

Richiedi JSON

Tieni presente che il codice JSON seguente descrive una richiesta webhook.

{
  "responseId": "f26a9188-4998-42eb-ac16-d0e6e273b137-712767ed",
  "queryResult": {
    "queryText": "actions_intent_NO_INPUT",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Webhook failed for intent: Reprompt",
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            "Webhook failed for intent: Reprompt"
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_media_response_audio"
      },
      {
        "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_account_linking"
      },
      {
        "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_capability_audio_output"
      },
      {
        "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/google_assistant_input_type_voice"
      },
      {
        "name": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA/contexts/actions_intent_no_input",
        "parameters": {
          "REPROMPT_COUNT": 2,
          "IS_FINAL_REPROMPT": true
        }
      }
    ],
    "intent": {
      "name": "projects/df-reprompts-kohler/agent/intents/75dfd97d-6368-4436-9533-70f05ae76c96",
      "displayName": "Reprompt"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "source": "google",
    "version": "2",
    "payload": {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA",
        "type": "ACTIVE",
        "conversationToken": "[]"
      },
      "inputs": [
        {
          "intent": "actions.intent.NO_INPUT",
          "rawInputs": [
            {
              "inputType": "VOICE"
            }
          ],
          "arguments": [
            {
              "name": "REPROMPT_COUNT",
              "intValue": "2"
            },
            {
              "name": "IS_FINAL_REPROMPT",
              "boolValue": true
            }
          ]
        }
      ],
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          },
          {
            "name": "actions.capability.ACCOUNT_LINKING"
          },
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          }
        ]
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            },
            {
              "name": "actions.capability.WEB_BROWSER"
            }
          ]
        }
      ]
    }
  },
  "session": "projects/df-reprompts-kohler/agent/sessions/ABwppHFi9Dpwy6KiEtS0UIPDNVfa7mlkrPIEZRlikFkjuN_4SGPixgX8OCatpXu38ln7VG43-nk-7veZWhds3nLljA"
}

JSON di risposta

Tieni presente che il codice JSON seguente descrive una risposta webhook.

{
  "payload": {
    "google": {
      "expectUserResponse": false,
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "Okay let's try this again later."
            }
          }
        ]
      }
    }
  }
}

SDK Actions

Per gestire gli intent senza input:

  1. In un oggetto conversations all'interno del tuo pacchetto di azioni, dichiara che vuoi per ricevere l'intent actions.intent.NO_INPUT ogni volta che un utente non fornisce di testo.
    {
      a"ctions:" [
        {
          d"escription:" D"efault Welcome Intent,"
          n"ame:" M"AIN,"
          f"ulfillment:" {
            c"onversationName:" c"onversation_1
    "      },
          i"ntent:" {
            n"ame:" a"ctions.intent.MAIN
    "      }
        }
      ],
      c"onversations:" {
        c"onversation_1:" {
          n"ame:" c"onversation_1,"
          u"rl:" Y"OUR_FULFILLMENT_URL,"
          i"nDialogIntents:" [
            {
              n"ame:" a"ctions.intent.NO_INPUT
    "        }
          ]
        }
      }
    }a
  2. Quando l'assistente non riceve alcun input dall'utente, ricevi l'intent senza intervento nella successiva richiesta di completamento. Puoi quindi Elaborare l'intento e restituire una risposta appropriata. Ecco un esempio:

    Node.js

    const {actionssdk} = require('actions-on-google');
    const functions = require('firebase-functions');
    
    const app = actionssdk({debug: true});
    
    app.intent('actions.intent.MAIN', (conv) => {
      conv.ask(`Hi! Try this sample on a speaker device, ` +
        `and stay silent when the mic is open. If trying ` +
        `on the Actions console simulator, click the no-input ` +
        `button next to the text input field.`);
    });
    
    app.intent('actions.intent.TEXT', (conv, input) => {
      conv.ask(`You said ${input}`);
      conv.ask(`Try this sample on a speaker device, ` +
        `and stay silent when the mic is open. If trying ` +
        `on the Actions console simulator, click the no-input ` +
        `button next to the text input field.`);
    });
    
    app.intent('actions.intent.NO_INPUT', (conv) => {
      const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
      if (repromptCount === 0) {
        conv.ask(`What was that?`);
      } else if (repromptCount === 1) {
        conv.ask(`Sorry I didn't catch that. Could you repeat yourself?`);
      } else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
        conv.close(`Okay let's try this again later.`);
      }
    });
    
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

    Java

    package com.example;
    
    import com.google.actions.api.ActionRequest;
    import com.google.actions.api.ActionResponse;
    import com.google.actions.api.ActionsSdkApp;
    import com.google.actions.api.ConstantsKt;
    import com.google.actions.api.ForIntent;
    import com.google.actions.api.response.ResponseBuilder;
    import com.google.actions.api.response.helperintent.Confirmation;
    import com.google.actions.api.response.helperintent.DateTimePrompt;
    import com.google.actions.api.response.helperintent.Permission;
    import com.google.actions.api.response.helperintent.Place;
    import com.google.api.services.actions_fulfillment.v2.model.DateTime;
    import com.google.api.services.actions_fulfillment.v2.model.Location;
    
    public class MyActionsApp extends ActionsSdkApp {
    
      @ForIntent("actions.intent.MAIN")
      public ActionResponse welcome(ActionRequest request) {
        ResponseBuilder responseBuilder = getResponseBuilder(request);
        responseBuilder.add("Hi! Try this sample on a speaker device, and stay silent when the mic is open. If trying on the Actions console simulator, click the no-input button next to the text input field.");
        return responseBuilder.build();
      }
    
      @ForIntent("actions.intent.TEXT")
      public ActionResponse fallback(ActionRequest request) {
        ResponseBuilder responseBuilder = getResponseBuilder(request);
        responseBuilder.add("You said " + request.getRawInput().getQuery());
        responseBuilder.add("Try this sample on a speaker device, and stay silent when the mic is open. If trying on the Actions console simulator, click the no-input button next to the text input field.");
        return responseBuilder.build();
      }
    
      @ForIntent("actions.intent.NO_INPUT")
      public ActionResponse reprompt(ActionRequest request) {
        ResponseBuilder responseBuilder = getResponseBuilder(request);
        int repromptCount = request.getRepromptCount();
        String response;
        if (repromptCount == 0) {
          response = "What was that?";
        } else if (repromptCount == 1) {
          response = "Sorry, I didn't catch that. Could you repeat yourself?";
        } else {
          responseBuilder.endConversation();
          response = "Okay let's try this again later.";
        }
        return responseBuilder.add(response).build();
      }
    
    }

    Richiedi JSON

    Tieni presente che il codice JSON seguente descrive una richiesta webhook.

    {
      "user": {
        "locale": "en-US",
        "userVerificationStatus": "VERIFIED"
      },
      "conversation": {
        "conversationId": "ABwppHEVDuKUPjdZ4Ud-F2yBXN5ssRg2funUp59hSHQheAi-B5Y3EzehAKFtVwMkduqMRWscUp77ScrDjYnYxISqAM-qOXuXEuCw",
        "type": "ACTIVE",
        "conversationToken": "{\"data\":{}}"
      },
      "inputs": [
        {
          "intent": "actions.intent.NO_INPUT",
          "rawInputs": [
            {
              "inputType": "VOICE"
            }
          ],
          "arguments": [
            {
              "name": "REPROMPT_COUNT",
              "intValue": "2"
            },
            {
              "name": "IS_FINAL_REPROMPT",
              "boolValue": true
            }
          ]
        }
      ],
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          },
          {
            "name": "actions.capability.ACCOUNT_LINKING"
          },
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          }
        ]
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            },
            {
              "name": "actions.capability.WEB_BROWSER"
            },
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            }
          ]
        }
      ]
    }

    JSON di risposta

    Tieni presente che il codice JSON seguente descrive una risposta webhook.

    {
      "expectUserResponse": false,
      "finalResponse": {
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Okay let's try this again later."
              }
            }
          ]
        }
      }
    }