Dialogflow CX -- User Switches Topic -- Switching Flows - dialogflow-es

Let's say a user switches topics in the middle of a flow. Is there a way to have Dialogflow CX route to the new flow (based on the intent recognition), finish that flow, and come back to where we were before?
I know I can set up Route groups, but that's not robust enough.
In theory, I could set up every permutation of every page (i.e. ever intent be included as a route on every single page), but that seems unmanageable.
Am I missing something?

To transition to the start of another flow, at the bottom of the intent definition in the CX control panel, where you are choosing the transition target, choose "Flow" instead of "Page", and then any page can branch to another flow. I'm not sure but I think you always transition to the start of the new flow.
When that flow is to finish, transition to the END_FLOW page. That will return you to where you were in the original flow.
Described in the Handler Call Stack documentation.

Related

How to get IBM Watson's intents / dialog nodes to work in tandem with actions

At a high level, I am trying to build a Watson Assistant that:
(1) Follows a fixed conversation structure (currently containing 25 steps)
(2) At each step, evaluates whether the user is saying anything that might be considered as a safety issue / 'red flag' and, if so, present emergency info and end the conversation, otherwise continue with the next conversation step in the fixed sequence referred to above
I have implemented the fixed conversation structure (item 1 above) using Watson's actions steps. Works well.
I have also defined an intent I call 'RedFlag' and provided 5 examples so far (will be adding more) of what users may say to trigger this. I also have a dialogue node which detects this intent and presents emergency info. Works well.
Issues I am struggling with:
a) I am not sure how to end the conversation once the RedFlag intent is detected and the assistant presents the emergency info
b) I am not able to get the conversation actions sequence to work in parallel with intent detection and activation of the related dialogue node, basically my conversation structure works only if there are no defined intents / dialogue nodes. As soon as I have an intent (in this case the RedFlag one) the assistant ignores the conversation actions / steps and simply waits for the user to say something that matches the defined intent. Its like an either / or situation - either I step through the conversation without any intents or I'm stuck within the intent detection and none of the fixed conversation sequence / steps get activated.
Essentially, I am trying to have a fixed conversation structure while also having a number of 'waiting' intents / dialogue nodes that can be activated at any point during the fixed conversation steps, depending on what the user says.
This is a crucial point for us - I need to keep the fixed conversation flow going and only interrupt it if a specific intent is detected, then either exit (in the case of the RedFlag intent) or activate the appropriate response from the related dialogue / action node and then return to the next question in the fixed sequence.
You should consider adding the Red Flag intent as a Topic change, or in classical Assistant terms a not returnable digression.
See:
https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-change-topic
The easiest way to do this is to have your orchestration layer (Dialog) or your pre-webhook (Actions Watson Plus) do the work.
After that two options.
Have the red flags checked directly in the code.
Create an entity of red flags and then check if the entity was triggered in your code.

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.

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