DialogFlow I search how to jump an intent - dialogflow-es

I search how to jump an intent, i have one topic with several context, i would like for my agent, he can give an answer to question 3 and get the context of the question 1 and 2, without ask the question 2, like this
Is this possible?

What isn't clear from your example is how you expect the conversation to "jump over" the second question. But keep this in mind:
Intents represent what the user says, and not how you reply.
Your fulfillment can handle input any way that makes sense at that moment and keep track of the state of your conversation. Based on what the user says and the current state, you can reply and prompt for something else.
If you have Input Context set for an Intent, that Intent will only be valid if all the Input Contexts are currently active. You can't have an Intent that will trigger if only one of them is.
The workaround for this is to have more than one Intent, each with the same training phrase, but with different Input Contexts. Then, in your fulfillment, you can either register the same Intent Handler for both, or have both Intent Handlers call the same function to actually do the work.

Related

Can we create a conversation loop in Google Dialogflow

Consider a small task where we ask the user to add fruits to the basket one by one in a loop
I have created a small agent for this task with the following intents
Intent: basket
Intent: basket-yes (follow up)
Intent: basket-no (follow up)
In the intent basket user have to provide a fruit name and quantity. Then
If the user says "no" then basket-no (follow up) intent is triggered and the cart is finished
If the user says "yes" then basket-yes (follow up) intent is triggered which should trigger basket intent to allow the user to add more fruits
I have set the input/output context for intents as per the above requirement but the conversation is not moving towards basket intent. I don't know if it's the correct way to do it or even if it's possible to do it with Dialogflow.
First, remember that the Input and Output Contexts don't indicate which Intents will be triggered, they indicate which Intents can be triggered. Intents are only triggered based on what the user says or does. So you never "trigger" an Intent by changing the Context - you can just evaluate which Intents may be valid at any time.
Intents can only be triggered if all of their Input Contexts are currently valid and the user says something that matches a training phrase. So your "basket" Intent will only be triggered if the basket-repeat Context is currently valid and the user says one of the phrases (which you did not show in your screen shots).
Intents are not like state machines, although the Contexts sometimes help you model them that way.
You can do "loops", of a sort, although the user is ultimately in control of how you advance through those loops. While you can't loop through Intents, you can loop through Contexts or state, which influence which Intents may be acceptable at a given moment. And your prompts should certainly reflect the looping nature of what you expect from the user.
I think what is happening is that the basket-repeat Context is never set in the first place, so the basket Intent can never be matched.

Redirecting from one intent to another in dialogflow

I am trying to transition between intents. I have welcome intent and based on user response, I want to either redirect to Search intent or to CheckInternet intent.
I have given output context as search and interconnection in Welcome intent and then given them as input context in relevant intents. But still not able to chain them together.
Unfortunately, I don't have knowledge of Dialogflow yet, as using this for hackathon first time to check its capabilities. Any help would be great
Intents in Dialogflow aren't nodes in a state machine. You don't "transition" between them. Intents reflect what the user says or does.
So, to give your example:
When they start the agent, the welcome Intent is triggered based on the welcome event.
If, at any point, they say "search", then the training phrases in the Search Intent might match, so the webhook or responses for it would be triggered.
Or, if they said "check", then the training phrases in the CheckIntent Intent might match, so the webhook or responses for it would be triggered instead.
If you need to limit under what circumstances these phrases would be accepted by an Intent, you can add a Context and make sure that Context is valid. But you usually only want to add that once you get it responding in the more general case.
You would have to add both Search and CheckInternet as "Follow-up Intents". To do so, create two new Intents and assign the contexts search and interconnection to them respectively as Input Context.
When the user says something that should lead to Search, set search as output context and for the next utterance Search Intent will be considered (if sample utterance match).
I hope that's clear enough, I'm happy to explain that in detail, too. This way I configured a nicely working Chatbot with 20+ Intents once :)

Getting the output context from the fallback intent in fulfillment

I've got a few intents. They all just use a single fallback intent and this fallback intent has the webhook enabled.
In the fallback function what I was hoping to do is switch on the output context and then determine what should happen next depending on which intent the fallback came from.
But the line
var context = request.body.queryResult.outputContexts;
When debugged to the console gets output:
[ { name: 'projects/xxxxproj-xxxx/agent/sessions/xxxxxx-xxxxxx-xxxxx-xxxxx/contexts/xxxxxxx-context' } ]
For the switch statement i just want the last bit with the xxxxx-context. Am I going to have to split that up to get the output context?
In the "Diagnostic Info" section I am a bit surprised there is no reference to the intent from which the fallback came and the only way to work it out seems to be using the outputcontext but as show above that is quite a long string.
Thanks
Yes, the context name is just the last part of that path. Most libraries will take care of that for you, but if you're working with the JSON directly, you need to do this yourself.
There is no reference to "the Intent from which the fallback came" because this isn't quite the model of what an Intent is. Intents represent what the user has said or done, not the current state of the conversation or where you are in the conversation. That current state is represented by Contexts, should you choose to set them.
In that sense, how you use the contexts can vary. They can store parameters, so are a good way to keep information between rounds of a conversation, and you can use them the way you are - to see what state the conversation is in general. But they also take on additional uses when defining Intents.
In an Intent definition, the Intent will only be triggered if all the Contexts listed in the Input Context field are set (ie - have a lifespan greater than 0). Dialogflow uses this when it makes followup Intents, for example, and it is common so you can do things such as have "help" trigger different Intents based on Context. In an Output Context, it will automatically capture all of the parameters specified in the Intent, including those filled in by the user's response, so this can be an easy way to remember what the user has said from round to round.
To answer your question in the comments - it doesn't specifically say which Intents were previously triggered, or which most recently, although if you're consistent in how you use your Output Contexts and what lifespan you give them, you can use it this way. What it does say is in what state your conversation is in, which is generally much better anyway.
Remember - Intents represent what a user has said or done. It doesn't represent anything else about the conversation. Only the state of the system represents that, and one tool we have to control that state is through Contexts.

Is there a way i can avoid triggering an intent for the second time?

I'm a newbie in need of certain help in Dialogflow.
I have three intents (they're actually way more than this) with both of them having follow-ups, allow me sketch below.
I will call the 1st Intent - "Head" , 2nd Intent "Chest" , 3rd Intent "Back"
Say 1st intent is triggered when someone says "I have a head rush",
a couple of follow ups will come along that line like "how long does this take", "when did this start" ...... and more till the last follow up of this intent, thereafter the agent will ask if the user has problems with "Chest" hence triggering the 2nd intent or could as well ask if the user has problems with the "Back" triggering the 3rd intent.
Moving on, say the agent asked about "Chest" which triggers 2nd Intent which as well has its own follow ups and also i set it up to ask about the other problems as i did for the 1st Intent (in this case "Head" or "Back").
My question is how do i let the agent not ask about "Head" (which was already asked in the 1st instance) and only go for the remaining instance which is "Back"?
I hope i have phrased this in an understandable way.
Any workarounds will really be appreciated, thanks in advance
You may want to look into contexts.
https://dialogflow.com/docs/contexts
https://dialogflow.com/docs/contexts/input-output-contexts
So how it works essentially is, if you have an intent with an input context, it won't trigger unless that specific context is active. You can create and set the duration of a context in an intent, in the output context section.
So if you're in the middle of the conversation for chest is, you don't want to have the input context for chest or back active so their related intents won't trigger.
Only after the last step of chest is handled, you can start the input context for Back and in the output context, set the lifespan of the chest context to 0, so it ends. This ensures that Chest related intents will not trigger again.
This is assuming you want to handle these conversations in a sequential, if you want it to be more dynamic, where the order of questions doesn't matter. It's going to be a lot more difficult.
Hope this helps!

How do I set context and followup event in one intent?

I am trying to jump to a random question with followup event, and at the same time store the question number in the context. But dialogflow only jumps to the event without storing the question number. Is there a way to do followup event and store a context in one intent?
app.intent('Quiz - random', (conv) => {
let rand = Math.floor(Math.random() * quiz_len) + 1;
conv.data.current_qns = rand;
conv.followup(`quiz-question${rand}`);
});
Not really. The point of using conv.followup() is to make it as if the new Intent is the one that was actually triggered by the user. Remember - Intents represent what the user is saying not what you're replying with. You can include a parameter with the redirect, which I guess you can use to send the question, but this still would be the equivalent of a parameter sent by the user.
It isn't entirely clear why you feel you need to direct to a different Intent. Is it just to ask the question as part of the reply? Go ahead and ask it in the Intent handler you're in and store the number in the context directly.
Update
You've indicated in the comments that you want to structure things so you have a "random dispatcher" that then redirects to an Intent to ask a question, and that Intent has a Followup Intent that accepts the right answer (and possibly ones that deal with wrong answers).
This requires you to build a lot of extra Intents for all the various questions, and then the conditions on each question. This requires you to re-build this structure every time you want to add a new question.
Dialogflow works very well to navigate the structure of a conversation - so you don't need to use it to navigate specific questions, answers, and responses. Remember - Intents model what a user says in broad terms, not how our agent responds.
Here is a structure that might work better:
There is an Intent that handles the user asking for a random question. The Intent fulfillment for this (ie - the handler function in your webhook) does the following:
Selects a question
Sets a context to indicate which question is being asked
Sends the context and the question to the user
There is another Intent that handles user responses. All user responses. If this is a multiple choice question, you can set very specific phrases, but otherwise you may need to make this a Fallback Intent that has the context specified above as an Input Context.
Your handler for this compares the answer.
If correct, you clear the context, say so, and ask if they want another question. (Which would then loop to the Intent specified in step 1.)
If incorrect, you make sure the context is still valid and tell them they're wrong. Possibly increase a counter so you don't let them guess indefinitely.
This means you're only building two Intents that handle the question itself. You should add a few more. Here are a few to think about:
What happens if the user doesn't say anything at all? The "No Input" scenario should be handled differently than a bad answer.
If you're asking a multiple choice question, perhaps you'll use a list and need to handle a list response.
Finally, if you're using a list, you may want to do something fancy and use Dialogflow's API to set a Session Entity Type for just that question. This allows you to set what you're expecting (with some aliases) for what is correct and incorrect, and then use a Fallback Intent for the context to say that what the user said didn't make sense.

Resources