Can we create a conversation loop in Google Dialogflow - dialogflow-es

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.

Related

Two different intents with the same training phrases - DialogFlow. How to ensure both intents get used

Hi so I have a problem.
In Dialogflow, when I get a response to end the chat, I would like to ask the user for ratings.
so I've created 2 intents, "endchat" and "endchat2."
They both have the same training phrases, but it appears only endchat2 is being used (the most recently created intent)
How do I ensure that the chatbot randomly chooses an intent after a given response, instead of only using one intent? They have the same training phrases.
An alternate idea is in the attachments. The problem lies that I want the custom payload to only to appear after one of the text responses, (that being text response #1,) but not appear, if the chatbot decides to use text response #2. This is the reason I decide to make two separate intents, but it looks like that's not helping out because the bot is only using one intent.
Remember, Intents represent what the user says and does and not how you respond to that. So there is no way to "randomly choose an Intent" to use to respond.
What you can do, however, is setup a webhook for that Intent and determine how you wish to respond to what the user says. In some cases, you can thank them and end the conversation, while in others you can thank them, ask them the followup question, and set a Context so you can expect their reply.
Having the same / similar training phrase in multiple intents is an anti-pattern of bot design. Ultimately this confuses the bot and it leads to undefined behavior.
This should also trigger an warning in "Validation" with something like "Multiple intents share training phrases which are too similar:..." on the intents.

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!

DialogFlow I search how to jump an intent

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.

Resources