简体   繁体   中英

Google Assistant webhook slot filling customize

I am using Google Assistant integrated webhook with spring boot application.

I have created 3 slots in agent dialogflow, all are required. a1, a2, a3.

Suppose a2's value depends on a1's value.

If a1 > 100, I want to skip a2 and ask for a3. So when user speak something that should be populated in a3, instead of a2.

If a1<=100 then ask a2 and then a3.

How to tell the google agent which slot needs to be filled?

In cases like this (where parameters are optionally required), you can't use slot filling or mark them as required.

The solution is to manage this yourself using contexts and additional intents. So while you might design your Intent to accept answers that include all the parameters, but not mark any of them as required. You then build your webhook to determine if a parameter is necessary and missing and, if so, ask for it. Store the parameters you collect in a context so you have them all available once you have everything you need - you may need to use a different parameter name so they are not overwritten. You may also want to set a context when prompting for a value so you can narrow which Intents make sense when answering the question.

You can set parameters programmatically in your fulfillment webhook by setting the needed context's and their parameters. Note that this is not the intended use of slot filling.

Dialogflow by default creates 3 output contexts when filling in parameters

  • <intentId>_id_dialog_context
  • <intentname>_dialog_context
  • <intentname>_dialog_params_<parameterName>

You can find these contexts by using Webhookclient.contexts

Note that the context containing the parameterName will change according to which parameter is being asked for by Dialogflow. For instance, if you fill in parameter a1, dialog will ask for a2. The context will be <intentname>_dialog_params_a2

All of these contexts contain the parameters needed for the intent. You can programmatically set these parameters using this approach:

  • Users fills in a1
  • In your webhook, determine if a2 should be asked or skipped
  • if it should be asked, do nothing or send in a different prompt using webhookClient.add(responses)

if it should be skipped:

  • set both _dialog_context contexts using webhookClient.setContext(context)
  • while setting them, send in the parameter a2 as something being not null
  • remove the context _params_a2
  • set context _params_a3, with the same parameters

Probably your parameters now look something like:

{a1 : 'someUserValue', a2 : 'someValueByWebhook', a3 : ''}

By doing this Dialogflow already has a value for a2, and won't ask for it again

You have to use webhooks for slot fullfilment and mark all the slots as not required in dialog flow console. After getting request in webhook after user interacted with google assistant you can set output context in response to specifically load other slots .

For example user says I want 100 item where 100 is value of slot a1 Then from webhook you can create a response with fulfilment text Please provide slot a2 and also you need to set output context as a2 . To accept slot value for a2 create a dialogflow intent which has an input context a2 , so that dialogflow is biased while resolving slot a2. Similarly To accept slot value for a3 create a dialogflow intent which has an input context a3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM