Every time I add new output context in Google dialogflow it sets its lifespan to '5'
I am following certain design pattern where I set output context lifespan to '1' only. Couldn't found any setting to change this behavior.
Is there any other way to make output context default life span as '1'
No, 5 is the API default, if you want something different you have to set it manually (it is not documented as the default anymore, but afair it used be and has been this way forever).
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.
Currently I am creating a bot using API.AI, but I was questioning if there is a way to clean all the contexts of the intents, in a intent that receive a message like "Clean memory" or "Cancel Creation" .
For example:
I have context-1, context-2, context-3; and I want to clean/eliminate all those contexts and start fresh.
Yes. In general, you can set the Output Contexts to include all the contexts that you want to clear and set their lifespan to 0.
The easiest way to do this is through a webhook, where you can look at all the contexts that are set and, if their lifespan isn't already 0, create an output context with the same name and set the lifespan to 0.
If you don't want to use a webhook, you can include this in the output context field when editing an Intent, but you need to list each context individually and set the lifespan to 0.
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.
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
What's the difference between NSLocale currentLocale vs autoupdatingCurrentLocale? It's not obvious from reading the documentation.
When the user changes their system locale settings, the autoupdating one automatically updates to the new locale.
The currentLocale only retrieve an locale object one time from the current user's settings. autoupdatingCurrentLocale updates the locale object on the fly so you don't need to validate. You might think autoupdateingCurrentLocale is the prefer way, it is per Apple documentation; however, since the returned object may be cached, you don't really need to hold on to it indefinitely when using currentLocale, verse autoupdateingCurrentLocale.
If you are using autoupdatingCurrentLocale, note that this API do not cache the locale object, so you will need a way to compute cache upon receipt. One way is to use notification such as NSCurrentLocaleDidChangeNotification method call.