Google Assistant webhook slot filling customize - actions-on-google

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?

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 .

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.

Related

Chain ADF pipe line with feeding output

I would like to chain 2 Azure Data Factory pipelines A -> B so that the pipeline B consumes the output of the Pipe line A.
So, basically A is a authorization pipeline that has few activities, the last of which produces the authentication token. Now that token I want use in the Pipeline B (and C, and D.. etc...). So, basically I want to reuse pipe line A.
I used Execute Pipleline activity but, its output is NOT what I expect .. How can use the actual output of A in B ?
Create Pipeline B
Click on Parameters
Add a parameter value ->inputfromA and give Default value as blank
Create a variable fromA and in the value,click on add dynamic content->#pipeline().parameters.inputfromA
Create Pipeline A
Store the value of authorization token in some variable
Add a execute pipeline and on InvokedPipeline->add pipelineB
Then it will ask to input the value of inputfromA ->click add dynamic content and then you can add the token value there.
So, I figured out how to solve this, for my case at least.
Since, I am dealing with (in the particular case) with the authentication token, I made use of the Azure Key Vault. Where, in the last activity of a pipe line A I POST the acquired token to the Azure key vault as a named secret.
In the pipeline B - what I do is I call 'execute Pipeline' activity - executing pipe line A. After that on completion, calling the web activity to read the token acquired in 'A'. And as a next activity in "B" I am using that token in API.

DialogFlow CX how to declare parameters in the start page?

I need to declare a parameter to store username as input in the first message of dialogflow session, "My name is John" will be the first message the user type to dialogflow cx,
I noticed it's not possible to create a parameter on the Start page, is there is a way to detect parameters using EntityType from the first message of the session ?
To detect parameter values from the first end-user input, you can use intent parameters.
First, create an intent and add training phrases like "My name is John" and similar. See how the intent may look like.
Then, add an intent route on the Start page and define agent response in fulfillment. See how the route and a simulator test may look like.
You can also check the general agent design best practices for more information.

How to trigger multiple Intent in Webhook api.ai?

I am developing an api.ai bot that will search for the Vendor name in the database.
a ) if vendor exist -> provide username -> provide password
b) if vendor doesn't exist -> (add vendor -> yes ) or (add vendor -> No)
I have a webhook which is checking the vendor exist in database or not .
Bot Scenario: (Example )
Case1:
User: Do Alpha exist as a vendor?
Bot: yes, Alpha exist in Database. Please Provide User Name.
User: abc#gmail.com
Bot: Please Provide Password?
User: abcdef
Bot : Welcome
Case 2:
User: Do Beta exist as a vendor ?
Bot: No Beta is not a vendor. Do you want to Register?
Case 1:
User: Yes
Bot: Please fill this Form.
Case 2:
User: No
Bot: Is there any other way I can help
One thing I have figured out, I have to use output context to trigger the intent. But how can I do it in this complex case? and how can I call multiple to follow up intent using Output Context?
I might be using a bad approach, Is there any other way to solve this ?
I do have a follow-up question.
when we pass the fulfillment response back to dialogue flow. The response print on bot console will be the default text response, how can I get "fulfillmentText" to be the Response.
Thank you Guys. This is the followup Intent scenario.
This is not complex, you are doing it wrong by having two intents for collecting username/password.
Try the following way
When you detect that your vendor is present - set the context in webhook, as say, "vendor-present"
When the vendor is not present - set the context in webhook, as say, "vendor-new"
Use lifespan (the number at the left side of the context) to set the lifetime or validity of the context.
Create a separate intent for existing vendor - say "Vendor Data Collection" for collecting username and password. Set input context as "vendor-present" in the Dialogflow. Here you will collect these as parameters in the same intent (see image below). Mark these parameters as 'required' so that they must be collected by your bot. Use the Prompt section to put your response question for collecting information like "Please provide username".
If the vendor is not present, use existing intents and set input context as "vendor-new" in the Dialogflow.
Now, few things to note - the username parameter can be collected using the system entity #sys.given-name. But it is not very accurate with the Non-American/English names. I am not sure if this is improved or not. Secondly, there is no system entity to collect passwords, so you need to set the entity as #sys.any and in the webhook, you need to use regex to extract passwords on your own. BTW - you are not supposed to share passwords!
Hope this helped you!

How to perform slot validation in webhook in Dialogflow?

How to perform slot validation in an intent using backend code (webhook).
I have seen how to perform slot filling using the webhooks but I want to know how to validate the slot data and re-prompt the user if validation fails.
Example:
User: I want to know the your services in London.
Bot: We do not provide service in London, please enter some other city name.
In short: If validation fails, reset the dialog contexts, trigger your intent again, and optionally use default values to keep other parameters that were actually valid (so you don't need to re-prompt the user for those again).
You don't need to declare an incoming context on that intent to achieve this. Note that you can use contexts in intents, even though they are not declared as incoming/outgoing contexts on that intent.
In this example, I'm requesting 2 parameters from the user (car make and model). Of course, Enable webhook call for slot filling needs to be set in your intent.
Steps:
On Dialogflow, in the intent, declare an Event. This can be used to trigger this intent from your fulfillment code:
In your parameters, declare a Default Value for each parameter you want to be able to keep after resetting the intent:
Set the Default Value to a parameter in a helper context. If this helper context does exist, the default value will be set, otherwise, it'll be kept empty. This will allow you to reset the intent and keep other parameters you already had. In this example, I'm using the context show-car-details-data, and setting the default value of parameter model to _model in that incoming context:
In your slot-filling fulfillment method, you can validate your parameter and re-prompt the user by reseting the intent. To do that, you need to 1) clear the current dialog contexts, 2) call setFollowupEvent to trigger your intent again, and 3) optionally set up some helper context you can use to assign default values (so you don't need to re-prompt user for those that were valid).
I'm using Dialogflow Fulfillment Node.js Library:
// clear dialog contexts:
agent.contexts.forEach( e => {
if ( e.name.endsWith('_id_dialog_context') ) agent.context.delete(e.name);
});
// workaround bug: https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/160
agent.add('');
// set follow up event: this triggers your intent again
agent.setFollowupEvent('show-car-details');
// optionally set helper context to set default values and avoid re-prompt of already valid values
// in this example, keep make since it was a valid parameter
// clear model because it was invalid. User will be prompted again on model, but not on make
agent.context.set('show-car-details-data', 1, { '_make': make, '_model': '' });
Steps
Enable webhook for slot filing in Dialog flow with Entity set as "Required".
Get entity from arguments.
Programmatically check if it is not null and as per your requirement.
If it is correct, proceed further.
Else, RESET THE CONTEXT and ask the question as per the wrong slot input. Programmatically, set the output context same as input so that user can again respond back slot/entity. If the correct context is not present, the slot will not get captured. When a slot is captured as per set Entity, the context for that slot captured is finished and to recapture it you need to increase the lifespan or create it again.

Watson Conversation Service - Quit Parameter for Slots/ Entities

There is a new feature in the conversation service where you can define slots/ entities for specific intents to extract the relevant information from the user input like currencies or specific string inputs. Those slots can be set mandatory in case you need them to proceed and the user will be asked for missing slots until he provides them.
Is it possible to define sth. like quit parameter so I can easily interrupt this conversation? The general documentation does not provide any information regarding this problem.
https://console.bluemix.net/docs/services/conversation/entities.html#defining-entities
You can do it by adding node-level handler which will listen to your cancellation intent and fill the slots with dummy values.
You can read more about this approach in the documentation: https://console.bluemix.net/docs/services/conversation/dialog-build.html (paragraph "Handle requests to exit the process")