I'm using a cloud function to respond to webhooks as described in the documentation. On DialogFlow, I made all the parameters optional, and instead I want to control which parameters are required dynamically. Is it possible to set allRequiredParamsPresent dynamically? Secondly, how can we bias the next input / response to fill a certain parameter?
The user can input a date or a date range, both of which are different parameters. One or the other is required, but not both.
Unfortunately, in the console if I set both as required, the dialogue does not end (which is why I wanted to override when it ends), and if I don't make them required, the dialogue ends without all required params being present.
Moreover, depending on the follow-up question the agent is made to ask from the web hook, I want to bias the user's next answer to fill a specific @sys.any
parameter, since it keeps filling the wrong parameters.
Dialogflow sends a webhook request message to your webhook service. This message contains information about the matched intent, the action, the parameters, and the response defined for the intent. Your service performs actions as needed, like database queries or external API calls.
Steps to receive webhooksCreate a webhook endpoint as an HTTP endpoint (URL) on your local server. Handle requests from Stripe by parsing each event object and returning 2xx response status codes. Test that your webhook endpoint is working properly using the Stripe CLI.
Here is the challenge: You want to use the text response you write in your Dialogflow console to be available to the webhook code. Here are three reasons for doing this (there may be others too): maintain the WYSIWYG (what you see is what you get) for your copy editors, who are usually not programmers.
The request message from Dialogflow contains data in the Dialogflow webhook format. This object includes Actions on Google-specific information, as summarized below: The originalDetectIntentRequest.source value is "google".
The Dialogflow CX documentation explains that you can set session parameters from your webhook in the Webhook response object. Let us take a look at the Webhook response object. There are two fields you need to set: the session string (which you get from the Webhook request object) and the parameters map (i.e. another JSON object).
If your webhook service encounters an error while handling a webhook request, your webhook code should return one of the following HTTP status codes: In any of the following error situations, Dialogflow invokes a webhook error or timeout built-in event and continues processing as usual: Response timeout exceeded. Error status code received.
I would suggest you to use intents for each parameter that you require rather than using entities. That would solve two problems:
Suppose you require 3 parameters to buy a watch : color, date/date-time, cost
Your agent will have these intents:
For each of the intent you will have all 3 parameters optional.
Also, you will nee to set default value of the param to the $entity
for self intent, and #context.entity
for other params.
For example, in the intent get_color
, you will have these params and default values:
color = $color
date = #buy_watch.date
cost = #buy_watch.cost
Lastly, you will have to call webhook for all the above intents.
In the webhook, you will have to check the params of incoming intent and set output_context + response_message according to the missing param.
params = intent_request["query_result"]["parameters"]
case 1 --> if not params["color"]: set output_context = color and response = what color do you want
case 2 --> if not params["date"]: set output_context = date and response = when do you want to buy
case 3 --> if not params["cost"]: set output_context = cost and response = what is your budget
case 4 --> if you get all params: call event e_got_all_details
Intent got_all_details
will be called through event when you get all the params, regardless of in what order you get them.
Depending on the output_context of the response and input_context which you have configured in your intent, correct intent will be triggered and you will be able to get the correct values.
I had similar problem, and this was the most efficient way to handle it in my opinion for validation of params and handling when you get unexpected values (using intent specific follow-up fallback intents).
Edit 1: One extra logic will be there to assign value to date depending on you got it from date or date range entity.
if params["date"] or params["date-range"]:
date = params["date"] if params["date"] else params["date-range"]
All the intents will have training phrases which will try to capture params without any order, but do not mark them required.
So, if the user says i want to buy a watch tomorrow, buy_watch
intent will be triggered with param date. The code will check color and cost are missing and will prompt for that after setting appropriate output_context
.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With