Reset Context in DialogFlow V2 - node.js

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.

Related

Is there a way to specify which intents are active at specific points in a conversation using DialogFlow?

I am creating an interactive fiction game for the Google Assistant, and I want to move the story on after each choice the user makes.
I have created new intents to deal with each new scene, which look to see which choices have been made. I also want some other general intents to look for questions like, "What are my options?"
The problem I've encountered is that, when a user has moved on to a follow-up intent, they can still say a key word linked to a previous intent, and that intent provides an unwanted fulfilment.
What is the easiest way to disable certain intents from providing fulfilments in certain scenes, or of specifying which intents should be active at any time?
To get some control on which intents can be triggered by the user your can use Dialogflow's context to set which intent can and cannot be triggered. You can set an Output Context on an intent, once that intent is triggered the output context will be active. While any contexts are active, Dialogflow will only match intents that are configured with input contexts that match the currently active contexts.
In the above image you can see an example, the CheckingBalance intent can only be triggered once an active context has been set in the CheckingInfo intent and while the context is active, Dialogflow will first look for any intents matching the context. For more info about setting input and output context. Have a look at the docs.

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.

Is there a way to create an intent that eliminate all the context in dialogflow?

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.

Dialogflow webhook - First fulfill the current Intent and then trigger another Intent

Lets say I have two Intents QuotationIntent and SalesRepresentativeIntent.
The QuotationIntent, gets some input from the user and returns appropriate result through web-hook. After successful fulfillment, I want to trigger the SalesRepresentativeIntent to check with the user if they want our sales representative to call them. I am able to trigger the Intent through events. But the problem is QuotationIntent fulfillment message is skipped.
I don't want to add a follow up intent directly to QuotationIntent, as there are many intents from which I will have to trigger SalesRepresentativeIntent.
Can you please tell me how to achieve this? Thanks in advance.
You may use context here. Add output context say "QuotationDone" in your QuotationIntent. Use the same context as the input context for SalesRepresentativeIntent. This way SalesRepresentativeIntent will be triggered only when QuotationIntent is completed.
To trigger SalesRepresentativeIntent you need to add either "user says" phrases and train your agent or add EVENTS to your intent.
This way your SalesRepresentativeIntent will only be triggered when the following condition met:
if((inputContext is present) AND (event is triggered OR user says phrase is present)){
trigger `SalesRepresentativeIntent`
} else {
fallback intent called
}
The other way you can do your task is to use SLOTS. Here in single intent, you can have multiple parameters collected. Add parameters that you want to collect. In your case whatever you are collecting in QuotationIntent you can collect it in first few parameters and make them as required and then the things you need to collect in SalesRepresentativeIntent you can collect in other parameters in the same intent. Arrange the order of the parameters in the order you want your bot asks from your users. This way your responses will be asked automatically depending on the parameters are collected from the user or not.

Optional Input Context in dialogflow

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

Resources