scope of questions in api.ai - bots

Can anyone suggest me , how to allowed scope of questions in api.ai? i.e. I want to ask user "how many book can you carry at a time ?" : user can reply any positive integer number. Then my bot reply: "good , you can still better than others!". now, without any reference if user directly write "any positive integer number" at starting then also bot reply : "good , you can still better than others!" , instead of "I didn't get"(or default response.). This answer come only when previous question has been asked.How can I do this?
==== case : 1 ====
Bot: how many book can you carry at a time ?
User:5
Bot:good , you can still better than others!
=== case : 2 ===
(without any reference if users gives inputs at very starting of conversation)
User: 5
Bot: good , you can still better than others!
Thanks In Advance.

You should make a required parameter instead of putting numbers in User says:
In your intent configure your action to have one required parameter numBooks. Have the prompt for that parameter be "how many book can you carry at a time ?". Then for that intent, have the response be, "good , you can still better than others!". Finally, in the User says section, add anything you want the user to say to trigger the intent, for example: "hi". Save your intent. Now whenever a user says "hi" the bot will ask the question and the conversation will begin. But if the user randomly sends a number, it will respond with fallback intent.

Related

Can i put Many Pictures links in dialogflow and send only one Randomly

I am new to dialogflow. I learned some things the previous month, but I am still searching for how to put a lot of pictures in intent and sending only one to the user, not all of them, and randomly, such as text responses as a kind of entertainment inside the Agent ...
Note :
I linked the client to Facebook Messenger and I want to send the photo there
Can i do this?
Assuming you're using Dialogflow-fulfillment library to respond to webhook requests this should do the trick.
You can store whatever type of response that you want to send in an array...
For example, I'll choose an array of plain text responses
const responses = [
"I didn't get that. Can you say it again?",
'I missed what you said. What was that?',
'Sorry, could you say that again?',
'Sorry, can you say that again?',
'Can you say that again?',
"Sorry, I didn't get that. Can you rephrase?",
'Sorry, what was that?',
'One more time?',
'What was that?',
'Say that one more time?',
"I didn't get that. Can you repeat?",
'I missed that, say that again?'
]
Given the array you can generate a random number between 0 (most programming languages index from 0) and the length of the array.
const index = Math.floor((Math.random() * responses.length) + 1)
In the above case, index is assigned to any number between 0 and 11. You can then pass this index into the array to randomly choose 1 value.
agent.add(responses[index])
You can take this concept and apply it to any response type you want.
Hope this does the trick for you!

Requesting a parameter from the user or triggering an event from fulfillment

In some intents in dialogflow I want to evaluate some parameters (that are required) and then, if they do not meet some criteria, request them again.
More specifically, I ask the user a date an event happened and in case he just provides me with e.g. "june" the #sys.date-period entity that's associated with the parameter translates this to "01/06/2019 to 30/6/2019", a date that has not been past yet and cannot be accepted. Therefore I want to check if the date is valid, and if not, ask the user again to provide it (erase the previous parameter and "reprompt").
The date can have many forms, month, year, period defined by start and end dates, so the automatic entities of google are really helpful. At the beginning I tried to create my own entities (like months, seasons), but because this procedure must be implemented for multiple different intents in the project, I do not want to end up with 100+ intents solely for the date retrieval. For the same reason, I want to do this through my webhook and not through intents that can be triggered if the date is not valid etc.
So I want to say to the user "You date is invalid, please retry." and then wait for a date, which will be evaluated and depending on the result of the evaluation, the procedure will either proceed or ask again for a valid parameter.
I read about this and I didn't find anything to indicate that this can be done (if anyone knows a way, please share it with me). So now I am trying to trigger an event(eventToTrigger), that I entered in this intent (that needs the date), but without success.
var bool1=isDateInValid(startDate);
var bool2=isDateInValid(endDate);
if (bool1 && bool2) {
agent.add("This date is invalid: "+startDate+ " to "+endDate+". Please retry");
return {
"followupEventInput": {
"name": "eventToTrigger"
}
};
}
It prints "This date is invalid: 2019-06-01 to 2019-06-30. Please retry", which was expected, but nothing else.
Apart from the above message, I wanted to also ask the user "give me a period", which is the response of the bot when entered in the specific intent without the user having provided a date, which is required as I said above.
How can I do this?
Thanks in advance!
Edit:
I implemented the advice #sid8491 gave me. I made an intent with input context wrongDate and I added to my fulfillment code the following:
if (bool1 && bool2) {
agent.add("This date is invalid: "+startDate+ " to "+endDate+". Please retry");
const context=agent.session+"/contexts/wrongDate";
console.log("Follow up intent with context: "+context);
return {
"outputContexts": [
{
"name": context,
"lifespanCount": 1
}
]
};
}
I also related this new intent with the same function through intentMap. When I give (as a user) an invalid date (e.g. "may") the bot responds "This date is invalid: 2019-05-01 to 2019-05-31. Please retry". After that I type "may" or "may 2018" and the bot enters the fallback intent, as if I did not send the output context (which is similar to my problem with the event, I could not be sure if the message was just ignored or if I did not send it in a correct form/way).
In your condition when the date is wrong, instead of invoking an event you can simply return a message with the error prompt along with an extra context.
Here's what you need to do:
Evaluate the condition for wrong date
If the date is wrong, set response message. In your case it's This
date is invalid: "+startDate+ " to "+endDate+". Please retry
Set an output-context with some lifeSpan. e.g. wrong-date Make
one more intent which will handle date input, and set input-context
to wrong-date
In the parameters section of this intent, give all the parameters
which you expect and set default value to
#output-context.parameter_name (replace output-context with
wrong-date and parameter_name with your exact name of parameter)
Do not set default value for the date parameter for which you are
expecting correct reply from user, so that it does not take older
value
Give some sample utterances for this intent i.e dates
Hope it helps.

Inquirer.js: ask multiple questions if one prompt is true

I'm writing an account creator using Inquirer.js, and wanted to ask for the user's e-mail and password only if the user asked for such protection. It goes like this:
inquirer.prompt([
{type:'input', name:'username', message:'Choose an username:'},
{type:'confirm', name:'protect_ask', message:'Do you want to password-protect your game list?'},
{type:'input', name:'email', message:'E-mail (for password recovering):', when:function(answers){return answers.protect_ask}},
{type:'password', name:'password', message:'Password:', when:function(answers){return answers.protect_ask}},
{type:'password', name:'confirm_password', message:'Confirm you password:', when:function(answers){return answers.protect_ask}}
]
As you can see, I'm running the exact same when statement three times, for it verifies if the password-protection was chosen or not. I want to know if there's a more intelligent, pragmatic way to do so, this is, to run this verification without repeating the when function.
Maybe nesting the three questions would do it, but how to do so without breaking the prompt flow?

How to set conditional parameters? I would like to prompt user for 3 symptoms but if user types 'end' then intent is finished

I'm trying to make a medical diagnosis chatbot. The general idea is that the bot prompts the user for symptoms.
The user must input at least 1 symptom and a maximum of 3 symptoms.
The end of conversation is reached when user does one of the following:
Inputs 3 symptoms OR
Types 'end' after inputting at least 1 symptom
Example 1 (3 symptoms):
Bot: Hello! Diagnosis Bot at your service here. Please type in the symptoms you are having.
User: Cough
Bot: Gotcha! Please type in another symptom.
User: Fever
Bot: Roger that. Please type in another symptom.
User: Phlegm
Bot: I have received the following symptoms: Cough, Fever, Phlegm. Give me a few seconds to calculate your diagnosis.....
// This part will connect to a custom built AI engine
Example 2 (2 symptoms):
Bot: Hello! Diagnosis Bot at your service here. Please type in the symptoms you are having.
User: Chest pain
Bot: Gotcha! Please type in another symptom.
User: Dizziness
Bot: Roger that. Please type in another symptom.
User: End
Bot: I have received the following symptoms: Chest pain, Dizziness. Give me a few seconds to calculate your diagnosis.....
To design this chat bot, I have setup the following:
A 'symptom' entity
A 'Get Started' intent
A 'symptom-input' intent which requires 3 symptom parameters.
Question:
I would like to set it up so that at any point the user types 'end' to any of the prompts then it finishes the symptom-input intent and invokes the symptom-end intent. How do I do so?
Symptom entity:
Get Started intent:
symptom-input intent:
symptom-end intent:
This doesn't seem like a good design, how would the user know that he can finish the input with the 'end' keyword? It would be better if your agent would simply accept a list of symptoms like so:
Bot: Hello! Diagnosis Bot at your service here. Please tell me what symptoms you are having.
User: I'm having fever, dizziness and chest pain.
Bot: Ok, give me a few seconds to calculate your diagnosis.....
All you have to do for that is to check the list box next to the symptom parameter in the parameter table of your symptom-input intent. This would make your dialog shorter and more intuitive and save you the need for a separate symptom-end intent. See the documentation on parameters for details.

Wit.ai differences between Trait - Free Text - Keyword and Intent/entities

It's a mess in my head right now. I've seen this video tutorial to understand Wit.ai logic : https://www.youtube.com/watch?v=yLAHVPaHWFA
It's a really good video for basic training. But I can't still understand the logic.
I want to create a story like that Human(H) / Robot(R):
(H) Hello
(R) Hello human, you can choose A action or B action
(H) A action
(R) Ok human, this is A action
It's really simple but I don't know what to declare in "understanding" section.
1 - Do I have to create a "Say Hello" intent
2 - If yes, Do I have to create an "hello" entity and feed it with other salutations like "Hi", "yo", "What's up?", ...
3 - Do I have to create a "choose action" intent or it's just one intent for one story ? This is exactly what I don't understand.
4 - If yes, A&B action are free-text like ("An hotel", "a restaurant"). How can I teach the bot to recognized them ?
I just need some enlightening about those points ! It's really hard for me to translate and understand correctly. Thank you for you help !
You may declare a "greeting" intent(Intents are just user-created entities). After that, you can validate(feed) it with many other words like "Hey buddy, Sup bud, Hellloooo, Hi bot, etc". Also, you can give values to that intent such as Negative or Positive values.
For instance:
" Hey dumb f* " >> "greeting" Intent + Negative value ❌
" Hi brother! " >> "greeting" Intent + Positive value ✅
So that you can decide between:
"Language, please... Anyway. Hey {user_name}"
or
"Hey {user_name} ! :) Really nice to see you here ! "
to respond to the user's simple hi text.
Other than that:
(R) Hello human, you can choose A action or B action
(H) A action
(R) Ok human, this is A action
This type of interaction needs the usage of /converse API
https://wit.ai/docs/recipes#converse-link
In this above link go down to the "Handle yes/no answers" section.
Also, you can use Quick Replies for letting the user choose between the A Action or B Action. Quick Replies are really useful for this type of interactions.
https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies

Resources