I have a voice commands such as
- turn on lights in the lounge
- turn on lights in the kitchen
The room (lounge, kitchen) and is a mandatory parameter is stored as a context variable.
My question is - is there a way to have an optional input context for an intent. If context exists, use data from it, otherwise get the user to specify the context via slot filling.
Without this feature, it seems I need to have two intents which are almost identical.
- TurnOnLights_WithContext
- TurnOnLights_WithoutContext
The solution is to set the default value for the parameter from the context. If the value exists in the context it will be set. If not, the user will have to specify the value via slot-filling.
See screenshots below
Related
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.
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.
I would like to know how to reset contexts in DialogFlow V2. I m currently using V2 and writing the backend codes in node.js.
Got the Solution Myself:-
There are several ways to clear contexts:
In a detectIntent query, you can set resetContexts to "true".
To reset contexts when testing in the Dialogflow test console, click the 'RESET CONTEXTS' button.
In order to reset all contexts in an intent, click on the 'X' button in the 'Contexts' section below the intent name. The contexts will be cleared after the intent completion.
If you want to reset an individual context in the intent, set the context lifespan value to 0.
You can also use our /contexts endpoint to perform these operations programmatically: https://dialogflow.com/docs/reference/api-v2/rest/v2/projects.agent.sessions.contexts.
For resetting contexts via webhook, use the "outputContexts" field in the response from the web service: https://dialogflow.com/docs/reference/v1-v2-migration-guide-fulfillment#webhook_responses. Note that the contexts will be updated after the intent completion.
It depends exactly what you mean by "reset contexts", but if you want to remove a context from being considered during the next user statement, you can set the context's lifespan to 0.
For a simple parameter, I can easily set the default value, However I want to mark the parameter as "is list" and then set a default value to it. How can I achieve this?
It was much needed feature for me and I have asked this to Dialoglflow support team. But they said for list value, they have no such support right now. So I have created one workaround.
Let's say "location" is list entity. So you need to create another entity i.e. "location_default" ( can be any name convention).
Value of "location" entity will always be taken from parameter i.e $Location.
Value of "location_default" entity will be #search-context.location where "search-context" is the context maintained between different intents and values are passed through this context.
Hence, everytime you have one extra parameter carrying default value. So, at any step, where "location" entity is empty and "location_default" is not, just assign it back i.e assign value of "location_default" to "location"
Value can be assigned via "context api" mentioned in Reference link of Dialogflow Forums.
Hope this solution works for you, as its working like a charm for me.
I'd suggest adding the "default" value as context when you send the initial request to api.ai - that might do it (I'm not sure if the user provides the parameter in their request if it will override, but I would expect it to).
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.