Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFlow - set allRequiredParamsPresent from webhook?

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.

like image 726
arao6 Avatar asked Feb 15 '19 15:02

arao6


People also ask

What message Dialogflow sends to the webhook service?

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.

How do I get webhook response?

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.

Can I use Dialogflow console responses in the webhook code?

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.

What data is included in the Dialogflow webhook request message?

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

How do I set session parameters in Dialogflow CX?

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).

What happens when Dialogflow receives a webhook error or timeout?

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.


1 Answers

I would suggest you to use intents for each parameter that you require rather than using entities. That would solve two problems:

  • If user does not give correct value for required param, dialogflow will not keep on asking same question again and again in loop
  • You can control which parameter to fill next

Suppose you require 3 parameters to buy a watch : color, date/date-time, cost
Your agent will have these intents:

  • buy_watch -> input_context = None, output_context = buy_watch
    I want to buy a watch
    I want to buy watch in black color
    ...
  • get_color -> input_context = color, output_context = buy_watch
    Black
    i want it in black
    ...
  • get_date -> input_context = date, output_context = buy_watch
    i want it tomorrow
    i want it next week
    (that will capture both date and date-range and not on anything else, you can have logic to assign the value to param if you get any of them)
  • get_cost -> input_context = cost, output_context = buy_watch
    around 10000
    budget is 15k
  • got_all_details --> event = e_got_all_details

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.

like image 68
sid8491 Avatar answered Oct 10 '22 14:10

sid8491