Implementing Wit.Ai with Azure for faster responses.
Wit.Ai and sign into singaporeis and Azure.
Credentials for singaporeis and Azure. Node.js.
Start by typing the sentence. Add the intent where it says add new entity. Create a new Value by typing the name.
Start by typing the sentence. Highlight a part of a sentence or a word which will be used to understand the context. Start by creating a unique name for the entity and then just confirm.
Enter bot_setup.js and the following code allows to match the query to the correct intent.
bot.dialog('doSomeIntent', [dialog_intent.Query, dialog_intent.Results]).triggerAction({
matches: 'intent_name'
});
Enter the working dialog file or create a new one.
Basic starting requirements.
var builder = require('botbuilder');
var functions_refined = require('../functions_refined/code');
var fs = require('fs');
Use module.exports.Query to match entities in Azure.
module.exports.Query = function (session, args, next) {
fs.readFile('./static/qnamaker.txt', 'utf8', function (err, data) { //If you are using qnamaker.txt
if (err) throw err;
list = data.split('\n');
list.forEach(function (value) {
splitlist.push(value.split("[;]"));
});
var entityReception = builder.EntityRecognizer.findEntity(args.intent.entities, 'visitor');
next({ entityReception: entityReception});
var entityDepartmentReception = builder.EntityRecognizer.findEntity(args.intent.entities, 'department');
}
Use module.exports.Requests to respond to the query.
module.exports.Results = function (session, results) {
//Incase visitorReception is empty.
var visitorReception = '';
try {
console.log(results.entityReception);
if (results.entityReception == null) {
visitorReception = results.response;
console.log(results.response);
}
else {
visitorReception = results.entityReception.rawEntity.value.toLowerCase();
}
new Promise((resolve, reject) => {
splitlist.forEach(function (value) { //If using qnamaker.txt
if (session.message.text == value[0] || value[0].includes(visitorReception)) {
sendMessage(session, value[1]);
resolve(true);
throw new Error("Done");
}
else if (!(departmentReception == undefined)) {
sendMessage(session, `To get to ${departmentReception}. You can fill out the Virtual Management System on my touch screen or you will have to contact the reception with the number 6592 2727 ${departmentReception}`);
resolve(true);
throw new Error("Done");
}
});
reject(false);
}).then((res) => {
console.log(res);
}).catch((err) => {
sendMessage(session, "Default Reception Faliure Message");
});
}
catch (err) {
//do nothing for now
session.endDialog();
session.clearDialogStack();
}
}