How to trigger "invalid parameter event"

1,676 views
Skip to first unread message

Haoyan Sue

unread,
May 14, 2021, 1:36:35 PM5/14/21
to Dialogflow CX Edition users
Hi,
I tried to use webhook to check if user's utterance is valid. For example, in the financial service, the agent will ask users for getting their credit card numbers. I set a form parameter called "card_number", and set it to be required. When I get the card number from user's utterance, I want to use webhook to check its validation. If I find the card number is invalid, I send "INVALID" enum number back to the agent by using webhook Response. 
According to the documentation, this "INVALID" enum number should trigger the "invalid parameter event". However, I couldn't trigger this event even though I have set it under the parameter "card_number".

屏幕快照 2021-05-15 上午1.02.49.png

Miguel Lorenzo Baticados

unread,
May 18, 2021, 4:47:13 PM5/18/21
to Dialogflow CX Edition users

Note that the webhook you set on the parameter is called before the parameter is collected.

In order to have a webhook called after the parameter value gets collected, you should add a transition route with a condition  "$page.params.xxx.status = "UPDATED"" and enable webhook for validating the parameter. Below is an example where it loops on the page if the required parameter is not met.

invalid-param.png

Also, in your webhook response, add the field 'required': true under the ParameterInfo object. Below is a sample code snippet:

{

   "fulfillmentResponse":{

      "messages":[

         {

            "text":{

               "text":[

                  "Response from Webhook"

               ]

            }

         }

      ]

   },

   "pageInfo":{

      "formInfo":{

         "parameterInfo":[

            {

               "displayName": "parameter-name",

               "required": true,

               "value": "<optional>",

               "state":"INVALID"

            }

         ]

      }

   }

}


Note that any additional validation will depend on how you design your backend.



Haoyan Sue

unread,
May 19, 2021, 1:38:20 PM5/19/21
to Dialogflow CX Edition users
hi Miguel,
Thank you for your help. I appreciated your sample code which help me a lot in my coding part. 
However, there's a concept that I want to discuss further. You mentioned that "the webhook you set on the parameter is called before the parameter is collected". I don't think so. The webhook is inside of the fulfillment part. In your case, the fulfillment can only be called when the condition requirement is satisfied. I think it means that the page parameters have been filled at that moment, and then the webhook along with the condition fulfillment is called. 

Miguel Lorenzo Baticados

unread,
May 20, 2021, 8:47:37 PM5/20/21
to Dialogflow CX Edition users
Based on the description in your first email, I understand that you have set the webhook in the Parameters section to validate the user input, hence I mentioned this statement: “Note that the webhook you set on the parameter is called before the parameter is collected”

However, as seen above, yes, the page parameters need to be filled first. Once filled, you may call the condition route and add the webhook there to validate the input and send the INVALID enum if the value is invalid in your webhook response. This will then trigger the Invalid Parameter event handler defined in your Parameters section. See screenshot below:

invalid-parameter.png

Haoyan Sue

unread,
May 25, 2021, 2:32:17 AM5/25/21
to Dialogflow CX Edition users
Thank you so much, I got your point now.

Shanmugavel V

unread,
Jun 22, 2021, 2:22:59 PM6/22/21
to Dialogflow CX Edition users
Hi,

I'm trying to achieve the same validation operations from fulfillment. In my case, while user entering the PIN, I need to validate that and proceed to next page, if the PIN was right or else stay with the same page until the user enters the correct PIN. As you said, I kept the parameters and routes accordingly. But it doesn't work like as mentioned. So I think I'm missing something on transition part in form parameters. Please find the below the screenshots of my setup. Thanks in advance.

1. Created the form parameters and its configurations.
validation1.PNG


2. The query here is, in the form parameter do I need to call the webhook for validation or else the webhook should be called inside the Routes handler. (i.e., Can I able to do the validation within parameters itself or else in the Routes)

                      Dialogflow-CX-Console.png           Dialogflow-CX-Console (1).png

3. In the event handlers under the form parameters, do I need to configure the transition page? If yes means which page I need to configure current page or target page. Same doubt in the Routes as well.
 
Dialogflow-CX-Console (2).png            Dialogflow-CX-Console (3).png 

4. Finally the JSON response I'm trying to send from the Routes fulfillment when the parameter is invalid. Do I need send any specific response, if the parameter is valid.

validation2.PNG

Marianne Lerin

unread,
Jun 23, 2021, 5:50:25 PM6/23/21
to Dialogflow CX Edition users

Hi,

Please see answers to the following queries:

1. “The query here is, in the form parameter do I need to call the webhook for validation or else the webhook should be called inside the Routes handler. (i.e., Can I able to do the validation within parameters itself or else in the Routes)

The webhook should be called inside the routes. In the condition route, $page.params.authCheck.status = “UPDATED”, add a webhook to validate the input and send the INVALID enum if the value is invalid in your webhook response.

2. “In the event handlers under the form parameters, do I need to configure the transition page? If yes means which page I need to configure current page or target page. Same doubt in the Routes as well.” 

Since the validation is happening on the webhook, you need to transition to the target page or target flow by adding the transition in your webhook response if the input is valid. If the input is invalid, the Invalid Parameter event handler should be triggered. Depending on your agent design, you may add a transition on the Invalid Parameter event handler.

3. “Finally the JSON response I'm trying to send from the Routes fulfillment when the parameter is invalid. Do I need send any specific response, if the parameter is valid.”

It depends on how you will design your agent. However, it is better if you have a response if the parameter is valid. This will also help you determine that validating the input is successful.

Reply all
Reply to author
Forward
0 new messages