Can the same entity be used twice in dialoglfow V2? - dialogflow-es

A number of my Intents respond to the same words - "yes" and "no".
I'm using the inline editor to handle requests/responses.
Because many of the intents respond to the same words "yes"/"no" I set up one entity called response.
So for Intent1 under the Action and parameters tab there is:
parameter: intent1response, entity: #response, value: $intent1response
For Intent2 there is:
parameter: intent2response, entity: #response, value: $intent2response
So basically i'm just changing the parameter and value for each intent but using the same entity.
But that doesn't seem to work and is messing around with contexts, etc. When I change the entity to be unique for each Intent things seem to work fine.
Just wondering if that's correct. I was also just hoping for clarification re: the input box under Actions and Parameters that says "Enter action name" - when an action name is entered here what happens with this action name in fulfilment? Can I just call it to get the parameter?

The short answer is yes, you can use the same Entity in multiple Intents.
The action you specify is passed along to your fulfillment. It isn't a parameter, but is a field that is included.

Related

DialogFlow: simple ways of passing parameters between intents and from previous context to the current context? (Without using fullfillment)

Hi I’m look in for simple solutions for passing values between intents and contexts.
I’ve tried to set output context (c1) for intent A, and use c1 as input context for intent B. However, I’m not able to access the parameters value within intent B. Do I have to use fullfillment to implement this ?
Besides, I also want to use the previous parameters’ value of intent A when intent A is triggered next time. Again, can we do this without using fullfillment?
If fullfillment is essential, can you give some guidance please?
Accessing parameter values from one intent to another where contexts are used can be done from the Console itself. Fulfillment Webhook response can also be used but for your use case this can be done from the Console itself.
You can refer to the below replication steps:
In the text response of Default Welcome Intent add Hi what is your name? and add an output context awaiting_name.
Create another Intent Get Name and in that pass “awaiting_name” as input context . Pass some training phrases like "john,sandeep,jacob" and map it with them to the #sys.given.name entity.
In the Get Name Intent the text response is Ok $name, what is your email address?. Add awaiting_email in the output context field of this intent.
Create another intent “Get Email” and add awaiting_email in the Input context. Add training phrases like "sandeep#abc.com","john#xyz.com" and map them with #sys.email entity.
When you want to fetch the parameter value from another intent to the present intent where context is used you need to call it by #context-name.parameter-name as per this doc.
My final output response is Thanks #awaiting_name.name we will contact you soon on $email

Add parameter to context without webhook in Dialogflow

Im wondering if it is possible to add set matched entity properties as context.
I am describing my use case which hopefully clarifies why I am trying to do this:
Imagine I have a entityType called "Animals" with the following properties -> synonyms mappings
{
Cow: ['Mammal','Moo'],
Frog: ['Amphibian','Croak']
Dog: ['Mammal','Bark']
}
I have an Intent("Intent1") which has Animals entityType as a parameter
Use case 1: If Intent1 is called I want to add the matched animal in context. For example if the user says "Bark", I want to add "Dog" in context. I would also like to have a follow up intent to intent1 (call it Intent2) which displays the matched animal from context.How can I make this work
Use case 2: I want to get matched with one and only one animal such that when Intent2 is invoked it only displays one matched animal not many. So for example if Intent1 is invoked with "mammal", I want to add "Cow" and "Dog" in context .Such that when intent1 is invoked again it only tries to create a match from the earlier matched entities. Thus if the user says Croak after having said Mammal then Frog should not get matched.
So the workflow should be:
Intent1 invoked with "Mammal" -> ["Cow","Dog"] put in context
Intent1 invoked with "Croak" -> ["Cow","Dog"] remain in context
Intent2 is invoked -> "Please narrow down to one animal"
Intent1 is invoked with "Dog" -> "Dog" is put in context
Intent2 is invoked -> Your matched animal is "Dog"
PS: I would prefer a solution without a Webhook
When you add a parameter to an intent that has a output context, the parameters are automatically added to the outputContext. As long as the context is available you should be retrieve the parameters in your follow-up intent by using #[ContextName].[ParameterName].
Intent1
Intent 2
Result
Usecase 2
Since you prefer an option without webhook, your options are a bit limited. It's not possible to narrow down on the available entity values based on what the user said. Dialogflow will always attempt to match the user input to all available values of an entity.
If you decided to use a webhook, you would have a second option. You could set "Dog" and "Cow" in the context and if the user gets invoked again, you check the user input against the values in your context. If the user says "Croak" you can return a no match response via code.

Dialogflow fulfillment chose among options

I am writing you to ask a question about Dialogflow fulfillments.
I am trying to create an agent for Google Home and my backend is basically a web hook implemented in TypeScript.
In the conversation that I designed, the user requests to the agent to perform an action, providing a category as paramter. Now, the set of possible categories can vary through time, so I am using the entity type #sys.any to detect the parameter.
My problem is that, when on the fulfillment I try to identify the specific category on which the agent needs to take action, it may be the case that the requested paramter matches multiple cateogries, so I'd need a followup intent to ask the user to clarify which is the actual category it wants to select.
E.g. the conversation could be the following:
Agent: 'Welcome.'
User: 'Do action on **category**'
Agent: 'I have found **categoryA**, **categoryB** and **categoryC**. Please specify which one you want to select.'
User: 'Select the second || Select **categoryB**'
Agent: 'Great, action performed on **categoryB**'
Now, I was able to build this conversation using followup events and contexts: for example I created two followup events, one that detects the numbers and another that detects the text, so the user is driven on one or another depending on what it says (if the user says 'The first', a number is detected and in the backend I cycle the categories selecting the one that is associated to that index. I do a similar operation if the user says "categoryX", but inside a different intent).
What I want to understand is: what is the proper way to achieve that kind of conversation through the Node.js fulfillment API?
Thank you for any help.
From your description - you've done precisely the right thing (although you don't need followup intents).
When you reply with the options the user has, you include a Context that may contain the array of possible results. You then create Intents that have this as an Input Context, match either the index of the array (lets call this the match.index Intent) or by name (the match.name Intent).
In your webhook, the match.index Intent would determine which category was actually chosen, and then call a function that takes care of that category. Similarly, the webhook for match.name would take the parameter with the name and call the same function to take care of that category.

how can we pass the user original query across all followup intent in dialogflow

I have one intent named "search.category" which has user queries like "32gb phones" and it has a follow up intent to get_brand question like "do you have any specific brand? ".
This can have two type of answers that user can enter brand name or he can say "I don't know."
Is there any way to pass the whole user query in main intent to followup intents.
How can we pass the original user query(32gb phones) as a parameter across the intents?
In the second picture, you can see that two entities are selected, so is there any way to select the other text from user query ( I want the "show me some under 40000")
To do this, you would create a new Output Context on the first intent. Output contexts created as part of an intent contain the parameters that were set by the user when they were created and are available in subsequent intents (for as long as their lifespan is active). You can access the context's parameters either in the response or in your fulfillment webhook.
If you're trying to use values that aren't set in the parameters, then in the fulfillment of the original intent you can set any value you want as a parameter of an Output Context that you create in your webhook.

Followup intent with multiple parameters

I have an intent on Dialogflow where the user can ask something similar to this:
"What is the best price for shoes last month?"
Where translate to the parameters:
"What is the #case #metric for #item #date-period?"
So far so good. This intent outputs a context and works fine.
Now,
How do I create a follow-up context that allows the user to update one or more parameters keeping the remaining intact?
Eg:
"And what is the worse?" (only the case is updated)
"And what is the best for sandals?" (case and item are updated)
"And what is the worse last week?" (case and date-period are updated)
"And how about boots last week?" (item and date-period updated, )
etc.
I mean, I have four parameters, and I would like to provide to the user the ability to continue the conversation (context) changing one or more parameters.
There is any way to create some kind of "smart follow-up intent" or do I need to create all possible combinations follow-up intents?
Thank you in advance.
Start by adding an output context for your original intent, lets say "search". Make this intent calls your fulfillment and save the parameters, something like this:
app.data.case = app.getArgument('case');
app.data.metric = app.getArgument('metric');
app.data.item = app.getArgument('item');
app.data.date-period = app.getArgument('date-period');
Now create another intent and add some user says expressions that covers all parameters and have as input context the same context you put on the original intent. Make this intent also calls your fulfillment and from what parameters are filled you can realize what the user is trying to change so whatever the user has not provided you can get it back from what you had saved before:
let _case = app.data.case;

Resources