Commit 33bc65ff authored by Eric Meier's avatar Eric Meier

learning dialog is now luis enabled

parent 41a92cd8
......@@ -2,6 +2,9 @@ var restify = require("restify");
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
var durationPrompt = require("./prompts/durationPrompt");
var topicPrompt = require("./prompts/topicPrompt");
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
......@@ -18,12 +21,6 @@ var connector = new builder.ChatConnector({
// Listen for messages from users
server.post("/api/messages", connector.listen());
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
var tableName = "botdata";
var azureTableClient = new botbuilder_azure.AzureTableClient(
tableName,
......@@ -56,9 +53,15 @@ const LuisModelUrl =
luisAPIKey;
//Create a recognizer that gets intents from LUIS, and add it to the bot
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
const recognizer = new builder.LuisRecognizer(LuisModelUrl);
bot.recognizer(recognizer);
/*
* Prompts
*/
durationPrompt.setup(bot, recognizer);
topicPrompt.setup(bot, recognizer);
/*
* Dialogs
*/
......
var builder = require("botbuilder");
var durationPrompt = require("../prompts/durationPrompt");
var entityPrompt = require("../prompts/topicPrompt");
module.exports = [
function(session, args, next) {
const intent = args.intent;
session.dialogData.duration = builder.EntityRecognizer.findEntity(
var duration = builder.EntityRecognizer.findEntity(
intent.entities,
"builtin.datetimeV2.duration"
);
if (duration && len(duration.resolution.values) > 0)
session.dialogData.duration = duration.resolution.values[0].value;
session.dialogData.topic = builder.EntityRecognizer.findEntity(
var topic = builder.EntityRecognizer.findEntity(
intent.entities,
"topic"
);
if (topic && topic.entity) session.dialogData.topic = topic.entity;
session.dialogData.skillLevel = builder.EntityRecognizer.findEntity(
intent.entities,
"skillLevel"
);
next();
if (!session.dialogData.topic) {
entityPrompt.prompt(
session,
"What exactly do you want to learn about?"
);
} else next();
},
function(session, args, next) {
if (session.dialogData.topic) {
next();
return;
}
//session.send("What exactly do you want to learn about ?");
builder.Prompts.text(
session,
"What exactly do you want to learn about ?"
);
session.dialogData.topic = session.dialogData.topic || args.response;
if (!session.dialogData.skillLevel) {
builder.Prompts.choice(
session,
"How much do you already know about about " +
args.response +
"?",
"nothing|something|much",
{ listStyle: 3 }
);
} else next();
},
function(session, args, next) {
if (session.dialogData.skillLevel) {
next();
return;
}
builder.Prompts.choice(
session,
"How much do you already know about about " + args.response + "?",
"nothing|something|much",
{ listStyle: 3 }
);
session.dialogData.skillLevel =
session.dialogData.skillLevel || args.response;
if (!session.dialogData.duration) {
durationPrompt.prompt(
session,
"Wohaa! I really found a lot of interesting articles for you. How much time do you want to invest learning about this topic?"
);
} else next();
},
function(session, args, next) {
if (session.dialogData.duration) {
next();
return;
}
builder.Prompts.time(
session,
"Wohaa! I really found a lot of interesting articles for you. How much time do you want to invest learning about this topic?"
);
session.dialogData.duration =
session.dialogData.duration || args.response;
session.send(JSON.stringify(args.dialogData));
}
];
var app = require("../app");
var builder = require("botbuilder");
var recognizer;
const dialog = new builder.Prompt({
defaultRetryPrompt:
"Sorry, but I didn't understand you! Try entering something like 30 minutes."
}).onRecognize((context, callback) => {
recognizer.recognize(context, (err, result) => {
var duration = builder.EntityRecognizer.findEntity(
result.entities,
"builtin.datetimeV2.duration"
);
if (!duration || !duration.resolution.values[0].value)
callback(null, 0.0);
else {
callback(null, 1, duration.resolution.values[0].value);
}
});
});
const prompt = (session, prompt, options) => {
var args = options || {};
args.prompt = prompt || options.prompt;
session.beginDialog("durationPrompt", args);
};
const setup = (bot, rec) => {
bot.dialog("durationPrompt", dialog);
recognizer = rec;
};
module.exports = { prompt, dialog, setup };
var app = require("../app");
var builder = require("botbuilder");
var recognizer;
const dialog = new builder.Prompt({
defaultRetryPrompt: "Sorry, but I didn't understand you!"
}).onRecognize((context, callback) => {
recognizer.recognize(context, (err, result) => {
var topic = builder.EntityRecognizer.findEntity(
result.entities,
"topic"
);
if (!topic) callback(null, 0.0);
else {
callback(null, 1, topic.entity);
}
});
});
const prompt = (session, prompt, options) => {
var args = options || {};
args.prompt = prompt || options.prompt;
session.beginDialog("topicPrompt", args);
};
const setup = (bot, rec) => {
bot.dialog("topicPrompt", dialog);
recognizer = rec;
};
module.exports = { prompt, dialog, setup };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment