Context array in api.ai - dialogflow-es

Why does api.ai have context array, that creates contexts with some arbitrary names which live until the intent is complete?
When the intent is complete if a context is created it is retained rest others are removed, what is the significance of it

I assume you are referring to cases when you are in the middle of resolving an intent, you get context names that look like this: 72e79993-...-10dc7db59a93_id_dialog_context
This is happening because the intent has not yet been resolved, and the system creates a sort of temporary, interim context for any exchanges happening in this middle point, before the intent is resolved and export contexts are triggered.
In the cases you see it, you'll probably notice they're when the user has not filled in a required parameter values and API.ai has to respond with a prompt for the user to input their desired value. This 'prompt response' is a response but not a resolution of the intent. So to store/mark this temporary state as being different from a full response and resolved intent state (and to help interpret what the user says in this hyper-specific context of clarifying a specific parameter value given a specific intent), API.ai inserts these 'hyper-specific' interim context names.
You'll notice the context names in these cases match the metadata's intentID, for this very reason.

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

Global variable or context between Intent - Dialogflow

I'm new to Dialogflow and trying to figure out about Context and different Intent.
Basically my need would be to be able to trigger the same Intent with or without a context. But it's seem that it's with or without but not in between.
Here is what I'd like to be able to do:
Imagine a user that ask about Events in a specific Region, then we could give him a response saying : "Don't miss the XYZ Festival in Quebec this Weekend!".
Then, just after, the user asks about the Weather : "How will be the weather this Weekend?"
I'd like to be able to give him the answer for Quebec, because the Event is there and as human we would understand that the second question is about the first.
This is possible with context set as Output Context in EventIntent and Input Context in the WeatherIntent. But inverse could happen.
User can ask about the Weather in a specific region and then ask for Events there. If I set the Input Context in Weather, then it will never be triggered without that context. And if I don't set the Context, then it will ask for the region again.
How do I manage this?
You're on the right track using Contexts, but you're missing how Input Contexts are used.
Setting an Input Context on an Intent means that Intent can be triggered only when that Context is valid. If no Input Context is listed, however, then it will be valid at any time - and you can still use the Context as long as it is valid (ie - as long as it hasn't timed out).
So you can set the location parameter by setting an Output Context (either in the Intent description or, better, in your webhook). Then have phrases for your "EventIntent" and "WeatherIntent" that both take the (optional) location parameter and not. In your fulfillment you might use logic such as this:
If the location parameter comes from the phrase, then return answers based on it and save it in the Context for future use.
Otherwise, try to get the location from the Context and return answers based on that.
If you can't get a location at all - ask for it, and then return answers based on that reply.

Dialogflow prevent repeating intent

I'm bulding an agent with a lot of top level intents. Sometimes users ask a question which has not been added as an intent and it gets triggered by a wrong intent. Usually they try to ask the very same question again in a little different way. They get the same (wrong) intent again.
Is there a way I can avoid triggering the same intent multiple times in a row? It'd be cool to call the default fallback at the second time it is triggered. I'd like to apply this to all of the top level intents.
The way I would achieve this without fulfillment is a little clunky, but it will do the job. All you do is for every top-level intent, create a duplicate (with the same training phrases), named something like [original_intent_name]_repeat and put a input context required of [original_intent_name]_asked. Then for all your original top-level intents, add an output context of [original_intent_name]_asked with a lifespan of 1.
That way what happens is the following:
User: What's your name?
Bot: It's Dave! [intent `name`, output context `name_asked:1`
User: What's your name?
Bot: It appears you've already asked me my name! Try something else. [intent `name_repeat`]
This works because Dialogflow priorities intents with input context requirements over ones that do not.

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.

Dialogflow required parameters

In my dialogflow chatbot i am creating i have a scenario where a user can ask what are the available vacancies you have or they can directly ask i want to join as a project manager or something. Both are in the same intent called "jobs" and the position they want is a required parameter. If user don't mention the position (eg - "what are the available vacancies you have" ) it will list all available vacancies and minimum qualifications need for that vacancy and ask user to pick one (done with slotfilling for webhook.). Now since the intent is waiting for the parameter when user enter the position they like it will provide the details regarding that position. But even when user is trying to ask for something else (trying to call to a another intent or they don't have enough qualifications for that vacancy or the needed job is not listed with the available job list) since that parameter (the Job position) is not provided it ask again and again what is the position you want.
how do i call to another intent when the chatbot is waiting for a required parameter
There is a separate intent for "The job i want is not here". If i typed the exact same one i used to train that intent then i works. but if it is slightly different then it won't work
Try this:
make your parameter as "NOT" required by unchecking the required checkbox.
keep webhook for slot filling.
in the webhook, keep a track if the parameter is provided or not.
if the intent is triggered, check programmatically for parameter and ask the user to provide it by playing with the contexts.
if the user said something else, then there will be no "required" parameter as per Dialogflow and it will not ask repeatedly to provide the parameter.
Let me know if this helped.

Resources