What is the right approach for handling direct and contextual questions in dialogflow? - dialogflow-es

I am creating a HR chatbot using Dialogflow. I am unable to figure out the right approach to have the bot handle both direct questions and questions asked in a contextual manner. For example:
Contextual case:
User: I want to know how many leaves i can get in a year
Bot: You get x number of leaves
User: Ok cool how do i apply for one then?
Bot: Follow this process to apply for a leave
Direct case (2 separate conversations with direct questions):
Conversation 1:
User: I want to know how many leaves i can get in a year
Bot: You get x number of leaves
Conversation 2:
User: I want to know how to apply for leave
Bot: Follow this process to apply for a leave
Approaches I have tried:
1) Adding input and output contexts to handle contextual cases and add direct questions to knowledge base.
The issue with this approach is that since we cannot give multiple phrases in knowledge base, most direct questions do not match
2) Have 2 intents, one with input and output contexts and one to handle direct questions. (For example: One intent would be leaves.apply.context which would have both input and output context set and would have training phrases like how do i apply for this and another intent leaves.apply.direct which would have training phrases like how do i apply for a leave and no context). I'm not convinced that this is the right way as I am essentially creating two intents for the same question with the same response.
So is there a recommended approach to solve this problem?

I don't think there is a recommended approach to this, it is a matter of taste. Your solutions are a nice way of approaching this, but I don't think you will get around the fact that you will have to make an extra intent with the same response if you want to allow a follow-up question to also be approachable directly due to the context.
If you really don't like to create two intents for the same response, I think you would be able to workout this scenario by creating two intents and dropping the contextual flow. Just create a HowManyLeavesAvailableIntent and a HowToApplyForLeaveIntent without any context and train the HowToApplyForLeaveIntent to trigger on phrases that would follow-up HowManyLeavesAvailableIntent and direct questions for HowToApplyForLeaveIntent. Due to the missing context, this might not be ideal because it can create weird mappings to intents, but it would allow you to have just one intent for how to apply for leave.

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.

How to create a search form with dialogflow

I am trying to make a search algorithm with dialogflow that could take any combination of: first name, address, phone number, zip code or city as input to a search algorithm. The user does not need all of them, but we will refine our search with each additional answer until we only have one result. Basically we are trying to identify which customer we are talking to.
How should this type of intent (or set of intents) be structured? We have tried one intent with multiple parameters, but we do not need all of them to be required. We have also written a JavaScript function for fulfillment but how can we communicate back to dialogflow as to whether we need more information?
Thank you very much for your help.
Slot filling is designed for this purpose.
Hope that helps.
Please post more code/details to help answers be more specific.
First, keep in mind that Intents reflect what the user is saying, and not typically what you're replying with or what other information you need. Slot filling sometimes bends this rule, but only if you have required slots.
Since you don't - you need a different approach.
This can be done with a single intent, although you may find that multiple intents make it easier in some ways. The approach is broadly the same:
When you ask the question, make sure you set an Outgoing Context with a relatively short lifespan (2-3 is good) to indicate you are collecting user info.
Create an Intent (or Intents) that have sample phrases that capture the information you need.
Some of these will have obvious entity types (phone number and zip code) while others will be more difficult (First name has a system entity type, but it doesn't include all possible first names).
You will need to create sample phrases that collect the parameters by themselves, along with phrases that make sense. You're the best judge of this, and you should probably write some sample conversations before you write the phrases.
In your fulfillment, you'll figure out if you have enough information.
If you do, you can reply and clear the Context that was set. (Clearing it is important so Dialogflow doesn't match the information collecting Intent again.)
If you do not, you can add the information you have as parameters to the Context so you can save it for later processing, make sure you reset the Context lifespan (so it doesn't expire), and prompt the user for additional information. Again, having a conversation mocked out ahead of time will help here.

What is the best practice to create a Q&A Alexa app?

I want to make a simple Q&A Alexa app similar to Alexa's custom Q&A blueprint app. I don't want to use blueprints because I need additional functionality. What is the best practice for creating the Alexa app? Should I create a separate intent for each question or should I somehow use utterances?
The best way depends upon what the questions are and how it will be asked.
1. If the questions has a simple structure
Consider these examples:
what is a black hole
define supernova
tell me about milkyway
what is a dwarf star
then it can be configured like this in an intent:
what is a {space}
define {space}
tell me about {space}
and the slot {space} -> black hole, supernova, milkyway, dwarf star.
From the slot value, you can understand what the question is and respond. Since Alexa will also fill slots with values other than those configured, you will be able to accommodate more questions which follows this sentence structure.
2. If the question structure is little complex
what is the temperature of sun
temperature to boil water
number of eyes of a spider
what is the weight of an elephant
then it can be configured like this in an intent:
what is the {unit} of {item}
{unit} to boil {item}
{unit} of eyes of a {item}
what is the {unit} of an {item}
Here,
{unit} -> temperature, number, weight, height etc.
{item} -> sun, moon, water, spider etc
With proper validation of slots you will be able to provide the right answer to the user.
Also, you will be able to provide suggestions if the user asks a question partially.
Ex:
user: what is the temperature
[slots filled: "unit"="temperature","item":""]
Now, you know that the user asked about temperature but the item is missing, so you respond back with a suggestion like this
"Sorry I didn't understand. Do you want to know the temperature of the sun?"
3. If the questions has totally different structure
How to deal with an annoying neighbor
What are the types of man made debris in space
Recommend few good Nickelback songs
Can I jump out of a running train
If your questions are like this, with total random structure, you can focus on certain keywords or crust of the question and group them. Even if you can't group them, find out the required fields or mandatory words.
IntentA: How to deal with an annoying {person}
IntentB: What are the types of man made {item} in {place}
IntentC: Recommend few good {person} songs
IntentD: Can I {action} out of a running {vehicle}
The advantage of using slots here is that even if the user asks a partial question and an associated intent is triggered, you will be able to identify it and respond back with an answer/suggestion or error message.
Ex:
user: what are the types of man made mangoes in space
[IntentB will be triggered]
If you have configured this without a mandatory slot, your backend will be focusing on the intent triggered and will respond with the right answer (man made debris in space), which in this case won't make any sense to the user.
Now, with proper usage of slots and validation you can find that instead of debris your backend received "mangoes" which is not valid. And therefore you can respond back with a suggestion or error message like
"Sorry, I don't know that. Do you want to know about the man made debris found in space"
Grouping questions will help you to add other similar questions later with ease. You can use one intent per question if it is too difficult to group. But remember to validate it with a slot if you want to avoid the situation mentioned right above.
While naming question-intents use a prefix. This might help you to group handlers in your backend code depending on your backend design. This is not mandatory, just a suggestion.
Summary:
Group questions with similar structure.
Use slots appropriately and validate them.
Use predefined slots wherever possible.
Don't just depend on intents alone, because intents can be mapped if its the closest match. But the question might be entirely different or might not make any sense. So use slots appropriately and validate them.
If possible provide suggestion for partial questions.
Test thoroughly and make sure it wont break your interaction model.
You should check Alexa Dialog Interface that allow you to make Q/A or QUIZZ.
https://developer.amazon.com/fr/docs/custom-skills/dialog-interface-reference.html

How to structure many questions intent in dialogflow

I am making a chat bot to answer questions on a particular subject(example, physics). How would you structure all the possible questions as intent in dialogflow?
I am considering the following 2 methods,
Methods:
make each question as an unique intent.
group all the questions into one "asking questions" intent and use entity to identify the specific question being asked.
Pros:
Dialogflow can easily match users input to the specific questions using low confidence score threshold, and can give multiple training phrases per question.
Only need one "asking questions" intent, neater and maintaining it is easier.
Cons:
There will be tons of intents, and maintaining it might be a nightmare. Might also reach the max number of intents.
Detecting entity might be more strict and less robust.
I would suggest you to try Knowledge Base feature of DialogFlow.
You can give multiple web-page links from where it can gather all the questions, or you can manually prepare a list and upload it to DialogFlow.
That way you don't need to make it in separate intents, it will try to match it automatically.
Let me know if you have any confusion.
This looks like an FAQ type chatbot. You can develop the chatbot in 2 ways:
Use Prebuilt Agents - Go to prebuilt agent and select and import FAQ and add your intents.
Use Knowledge Base approach - This is in Beta mode right now, but super easy to build.
a. You need to enable Beta Features from the agent settings
b. Go to Knowledge Base on the left menu, create a new document and upload CSV file (Q and A). You can also provide a link for Q/A if you have.
Check out the documentation for more details.
Knowledge Base seems to be the best way, but it only supports English content

Resources