Extracting entity in the middle of conversation - node.js

I have an intent in LUIS called ChangeFlight. I can extract the date entity when user input some kind of date format initially. When the user forgets to input some date, it will ask the user to input a date.
However, I don't want to just get the results of the response, instead, I want it to extract the date entity such as the initial step. I have bot.dialog('askForDate') which asks for date from user but I am not sure how to extract the builtin date entity in the middle of the conversation.
How should I handle this?
Thanks.

You can use the Prompt dedicated for time resolution, it will allow a user to input a time or date/time. doc is here.
For example:
function (session, results, next) {
if (results.response) {
session.dialogData.name = results.response;
builder.Prompts.time(session, "What time would you like to set an alarm for?");
} else {
next();
}
},
function (session, results) {
if (results.response) {
session.dialogData.time = builder.EntityRecognizer.resolveTime([results.response]);
}
// TO DO : add here what you want to do with the value
}

Related

Find user dynamically

** I want to create a function that accepts any data like id, email, etc., and finds the user based on the input passed to it. **
ex:
const user = async(input)=>{
const result = data.findOne({input}); //whatever the input I passed I want the user
return result;
}
should I Pass the key with input like (input, key)??
so I need one common function to find the user data dynamically
Assuming you know ahead of time what fields the data might be found in, use $or to check them all:
data.findOne({$or: [
{id: input},
{email: input},
{username: input}
]})

how to save value of formarray in mysql with nodejs

I have a problem and I want someone to help me.
My English is not that good, I'm sorry about that I'll try my best to explain the problem to you hopefully u can help me and thank you.
I'm working on an activity management platform where an employee login to his account and chose a project, then a table contains the days of a certain month under each day there is an input where he enters 1 or 0 if he worked that day or not this is how the UI looks:
When he clicks the button VALIDER (Validate in French) the data entered should be saved in mysql database.
to collect the data I used FormBuilder in angling, I defined as a form group that contains a form control that should get the name of the project, a form control that gets the month, and one for the year, and a form array that should get the values of the 3 inputs, when I console.log the value of the form I get this:
when I try to save the data in my database, I get the message successful, but when I look at my database nothing gets stored,
my database contain a table with :
projectName: varchar(45),
month: number,
year: number,
days: JSON
I think that the problem is that days are an array and not of type Jason because I tried saving an array, but I did like this: insert into project (projectName, days) values ('nomProjet', '['0', '0', '0']') and it gets saved but my days Array doesn't.
my node js code for the backend :
app.post('/cra/add', function (req, res) {
let nomProjet = req.body.projet;
let year = req.body.year;
let month = req.body.month;
let days = req.body.days;
if (nomProjet && year && month && days) {
connection.query('INSERT INTO projetcra2 ( nomProjet, month, year, days ) SET ( ? , ? , ? , ?) ',
[nomProjet, month, year, days],
function (error, results, fields) {
res.send({ status: 'success' , days});
res.end();
});
} else {
res.send({ status: 'failed', message: 'some data are required', loggedin: false });
res.end();
}
});
my formbuilder :
my save function to save to the database :
addDaysWorked() {
this.api.cra(this.form.value).subscribe(
(data: any) => {
console.log(data);
}, (error: HttpErrorResponse) => {
console.log(error);
}
)
}
when i test with postman :
my database :
I hope my problem is explained, if u think I can help with anything else let me know and thank you.
I'm not an expert at backend stuff by any means. However, I believe storing items as an array is inside of a single column in a database is not ideal. You should consider creating a new, separate table, for just days worked.
In the table, you could have a column that specified the date, whether or not he/she worked, and link obviously link this using a foreign key (like userId) to the users table or the main table in this case.
This would allow you to more easily insert the data. Since each day would just be a simple row, querying would also be simpler as you would just query data given a Timeframe (example: from beginning of August - End of August), a user (unique user ID).
Here are a couple other generic stack questions that might clarify as well.
Hope this helps!
Check out this resource as well

Need to store parameter values that I get from previous conversation into a variable and merge it dialogflow

The flow :
User: Hi.
Bot: Spell the characters.
User: joh.
Bot: continue.
User: ny.
Bot: continue.
User: thats it.
Bot: Thank you ,johny(joh+ny)
Here, how can I store all the uservalues into a variable and merge them and display to user?I tried using context. I created a globalparameter context that has the values displayed.
For this,I have created 2 intents
First intent: firstnameletters
Second intent: Thank you
In Firstintent,
const first_name_letters = async (df,globalParameter) =>{
let name=df._request.queryResult.parameters.alphabets;//slot values like joh
df.setResponseText(("name").replace("name",name).split('').join(' ')+"\n\n"+"continue");
}
The code below when I print globalparameter:
const first_name_letters = async (df,globalParameter) =>{
console.log("globalparametr ",globalParameter);
let name=df._request.queryResult.parameters.alphabets;
console.log("alphabets",globalParameter.alphabets);
}
//output of global parameter when I pass "suchi" in the DF console.
globalparametr {
alphabets: 'suchi',
reqIntent: 'first_name_letters',
languageCode: 'en',
'alphabets.original': 'suchi'
}
alphabets suchi
//output of globalparameter during next time when I pass "itra"
globalparametr before {
alphabets: 'itra',
reqIntent: 'first_name_letters',
languageCode: 'en',
'alphabets.original': 'itra'
}
alphabets itra
Dialogflow:
Now,I want to combine "suchitra" and want the bot to display "Thank you suchitra" in the thank you intent.
As confirmed by #lakshmi, to be able to combine the user inputs in an ongoing conversation you can:
Store values of name in a list every time the user provides an input.
Concatenate the values in the list when user is done providing inputs.
Use the concatenated value as response to the user.

Interactive conversation implementation in Bixby

I am new to Bixby, facing trouble in Interactive conversation implementation.
Something like below :
User: "Hi Bixby, book me a table at Flemings Steakhouse."
Okay, for what day?
User: "Tomorrow."
Okay, for what time?
User: "6:00pm."
Okay, for how many people?
User: "Four."
Okay, booking a table for 4 people at Flemings Steakhouse tomorrow at 6:00pm.
If any suggestion , please help.
This isn't too hard with Bixby. What you'll want to do is create an action that will collect all the input from the user. It could look similar to this
Your action
action (BookReservaton) {
type(Search)
description (Book a reservation)
collect {
// Ask for the user's reservation date
input (reservationDate) {
type (time.DateTimeExpression)
min (Required) max (One)
}
// Prompt for number of guests, but also allow them to confirm 2
input (numberOfGuests) {
type (NumberOfGuests)
min (Required) max (One)
default-init {
intent {
goal: NumberOfGuests
value: NumberOfGuest(2)
}
}
prompt-behavior (AlwaysSelection)
}
}
output (Reservation)
}
In your case, you're going to need to collect input from the user when they don't provide your required input from their utterance. This is a good example of collecting dates, etc. You can also support someone saying 'Book a table for 4 this Tuesday at 7PM' without needing to prompt them for input. Bixby will only prompt the user when it doesn't have a required input.

After the entity and intent recognition in LUIS, what can be the bot's logic in order to provide the response to the user?

for example, If a user asks the bot "whats the weather", and the luis will recognize the entity and the bot will ask for location. After that, the bot has to pick an answer from a point and has to reply back to the user with an answer. I am not able to do the 'reply back with the answer' to the user.
Thanks in advance.
Are you using a standard waterfall methodology in your dialog? For example, the following code is pulled from a demo I built (written in TypeScript):
bot.dialog("location", [
(sess, args, next) => {
builder.Prompts.choice(sess, "We are showing multiple results. Please choose one:", getEntities(builder, args));
},
(sess, results) => {
sess.send(new builder.Message(sess).addAttachment(dialogs.createHeroCard(sess, parser.findExact("title", results.response.entity))));
}
]).triggerAction({
matches: "location"
});
In this example, the intent in LUIS is labeled "location", so the triggerAction matches against that. The dialog has two functions. The first is called when LUIS returns, and it displays a choice dialog with multiple options. When the user chooses one of those options, the result ends up in the second function. So this encompasses two questions. First, the user asks where a particular speaking engagement is being held, and the bot returns a few items that match the intent (maybe there are three presentations on "bots" at a conference). It displays a choice dialog with the elements, and the user's choice pings back to the dialog (but in the second function), and sends a hero card of the presentation chosen.
In the first instance, the bot uses builder.Prompts.choice() to ask for the choice information, and the second response uses session.send() to display the result.
In your example, you could use builder.Prompts.text() to ask for the user's location, and upon receiving the response (available in the second function of the waterfall as results.response, if your function parameters are session and results), you'd parse that data, and then use session.send() to display the results.
So if this were translated to your example, you could probably do something like:
bot.dialog("weather", [
(sess, args, next) => {
builder.Prompts.text(sess, "What location do you want weather for?");
},
(sess, results) => {
//Do something with the results
sess.send("Here's the weather!");
}
]).triggerAction({
matches: "weather"
});

Resources