How can I make the content response rely on multiple intents - dialogflow-es

I know the question might sounds confusing, but basically my agent asks the user 3 yes-or-no questions and the user answer after each one, note that each question is an intent by itself, anyhow I managed to accomplish that successfully.
Now after the questions were asked and answered by the user, I want the agent to to give a final response, but it must be dependent on the answers which were given by the user..!
For example, if the user's answers were (yes-yes-no) then it gives a specific response and so on for each combination I set.!
Can this be done..!?

You can do this with API.AI using follow-up intents. You will have to track the user responses for each matched intent in fulfillment and then provide a final response.

Related

How to implement a binary decision tree on google actions using dialogflow fulfillment node.js?

I want to ask the users a few questions in my welcome intent and depending on their answers give them a particular output.
My problem is that, once the user answers the first question, the agent exits my welcome intent and tries to match with the next intent.
I thought I could solve this by matching it back to the welcome intent.
So ideally it should have gone like this :
Welcome intent -> 1st question -> user answer -> Welcome intent ->2nd question -> and so on
But actually this happens :
Welcome intent -> 1st question -> user answer ->Welcome intent -> 1st question
It will keep asking the first question.
To solve this , I started maintaining a flag for each question.
If question 1 was answered I would set its flag true and then use it to skip the first question when the welcome intent is matched for the second time.
This is a very convoluted way to do it and probably far from the best way to do it.
Can anyone point me in the right direction to implement it?
Thank you.
Edit : I have given up my old method. Let me explain what I want to do and then I can get guidance on the way I should implement it.
I have 16 different outputs and I would like to show one of them to the user depending on their answer to 4 questions. Each question will only have two answers as options and depending on the option chosen by the user for each question , I will pick one of the 16 outputs and display it to the user.
How do I accomplish this using diaglogflow node.js?
First of all remember that an Intent captures what the user says or does and not what you do with that information or how you reply to it. That part is best handled by your fulfillment. While we can use Contexts to limit which Intents will be considered for a user response they are probably most useful in this case to store your state and keep track of which questions have been asked and answered.
Under this scheme, your Intents remain responsible for capturing input and your fulfillment examines this input, changes state based on this input, and sends a reply based on the new state (what it needs to ask next). If the user's responses will be mostly the same (free form, or from the same set of phrases), you can even use the same Intent to capture this input and the fulfillment would use the state and input to determine what logic to execute. If you need different types of input, and thus different Intents, their handlers can still call common functions to do the processing and change the state/reply.
This is further discussed in Thinking for Code: Design conversations not logic
You can use the concept of the follow-up intents in Dialogflow Console to create a chain of questions/answers.
Here is an example of my chain of questions/answers:
Though I still strongly advise you to study also how input/output context works. Especially if you want to collect all user reply parameters in the one final fulfillment of the last step to avoid storing the user inputs in fulfillments attached to every intent of the chain.

Google Action Intent with multiple input parameters

I'm looking to POC a small Google Action that gives a decision based on a few yes/no answers the user must answer first. Effectively I need to:
Ask a question
Store the result
Ask the next question
Store results
* Repeat until all yes/no answers given then end the conversation with a decision using saved values in the conversation.
Ongoing though I would like to add help to any of the questions. So the user could say "I don't understand", "Can you give an example", "Help" and it would give an example to help the user answer yes or no to the question they are up to.
After playing around through the labs it looks like I would do this by creating an Intent for my end decision and then nest a bunch of follow up intents within to gather all my yes/no answers. I feel this would get messy though as it would be a huge chain of them.
Is there a better way to design it?
Yes, using Followup Intents would be messy. It is almost never the right approach to the problem. Remember that Intents capture what the user has said and not what you are doing with what they have said.
If the questions are truly just yes/no, I would setup six Intents:
However you trigger the start of the questioning. This might be your Welcome Intent, or it may be something else.
Saying "yes" and equivalent
Saying "no" and equivalent
Asking for help
Asking to repeat the question
A fallback Intent that handles other unexpected input
When questioning begins, your fulfillment would setup a Context that contains the current question being asked and the responses for the questions so far. Answering yes or no would update the responses, determine what question to ask next, save this in the context, and ask it. Help, repeat, and the fallback Intent would respond with appropriate information based on the current question.

Google dialogflow how use dynamic response strings?

I'm trying to make a simple dialogflow conversation. I have made a simple conversation to ask a person who they are trying to call and then says if a person is available / unavailable, which is just a text reply. When a person is unavailable I have potentially 3 actions the user can do, leave a voicemail, redirect to a colleague or wait until the person is available.
The message I would return is
"I'm sorry nameOfPerson is not available, would you like to leave a voicemail message, redirect to a colleague or wait until nameOfPerson is available?"
Which works, but how can I make it so that lets say there is no voicemail the intent only response with, "I'm sorry nameOfPerson is not available, would you like to redirect to a colleague or wait until nameOfPerson is available?"
Currently the only way I see to fix this is making 7 intents with all different contexts like:
Intent1: voicemailContext
Intent2: redirectContext
Intent3: voicemailContext, redirectContext
Intent4: waitingContext
Intent5: WaitingContext, redirectContext
Intent6: waitingContext, voicemailContext
intent7: waitingContext,redirectContext, voicemailContext
All that work for just a small adjustment seems way to complicated. Also currently I'm sending those options in a call which I would much rather not since people could also just say those options and get a match
Dialogflow is very poor at handling logic. You can sorta do it, as you've seen, but this does lead to overly complicated models. One thing to remember that might help with this is that Intents are good at modeling what the user says, but that you're still responsible for what you do with that.
Better in many cases is to put the logic in a fulfillment webhook. This lets your code determine what the best response is and send that response. Depending how you want to structure your replies, you have a few other options:
You can send a context back in the reply. This would limit which Intents can get triggered when the user replies.
Another approach is to only have one Intent for the reply, but to use Entities to represent what sorts of things they can do. Then have your fulfillment, again, determine if they have given you a valid or invalid reply and respond accordingly.

DIALOGFLOW! How to create a followup intent that is provoked when 3 previous intents have been answered in a certain way?

I’m working on a memory game with multiple levels on Dialogflow. Each correctly guessed question is a separate intent and all 3 questions need to be answered correctly to proceed to the next level. How do I create the game so that the second level (which will be the follow up intent) is only provoked when all 3 questions from the 1st level are answered correctly? Thank you in advance!
Instead of having the followup intent, you can maintain a counter in a parameter (see my answer here for storing parameters).
Enable webhook in all the intents.
Whenever a question is answered, check the validity and if correct increment the counter.
When the counter reaches 3, you can respond back with the response of your choice.
If you want to go by your way then, after answering 3 question correctly you will need to generate an event dynamically via webhook. And the fourth intent should be triggered using that event.

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