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"); ...@@ -2,6 +2,9 @@ var restify = require("restify");
var builder = require("botbuilder"); var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure"); var botbuilder_azure = require("botbuilder-azure");
var durationPrompt = require("./prompts/durationPrompt");
var topicPrompt = require("./prompts/topicPrompt");
// Setup Restify Server // Setup Restify Server
var server = restify.createServer(); var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() { server.listen(process.env.port || process.env.PORT || 3978, function() {
...@@ -18,12 +21,6 @@ var connector = new builder.ChatConnector({ ...@@ -18,12 +21,6 @@ var connector = new builder.ChatConnector({
// Listen for messages from users // Listen for messages from users
server.post("/api/messages", connector.listen()); 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 tableName = "botdata";
var azureTableClient = new botbuilder_azure.AzureTableClient( var azureTableClient = new botbuilder_azure.AzureTableClient(
tableName, tableName,
...@@ -56,9 +53,15 @@ const LuisModelUrl = ...@@ -56,9 +53,15 @@ const LuisModelUrl =
luisAPIKey; luisAPIKey;
//Create a recognizer that gets intents from LUIS, and add it to the bot //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); bot.recognizer(recognizer);
/*
* Prompts
*/
durationPrompt.setup(bot, recognizer);
topicPrompt.setup(bot, recognizer);
/* /*
* Dialogs * Dialogs
*/ */
......
var builder = require("botbuilder"); var builder = require("botbuilder");
var durationPrompt = require("../prompts/durationPrompt");
var entityPrompt = require("../prompts/topicPrompt");
module.exports = [ module.exports = [
function(session, args, next) { function(session, args, next) {
const intent = args.intent; const intent = args.intent;
session.dialogData.duration = builder.EntityRecognizer.findEntity( var duration = builder.EntityRecognizer.findEntity(
intent.entities, intent.entities,
"builtin.datetimeV2.duration" "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, intent.entities,
"topic" "topic"
); );
if (topic && topic.entity) session.dialogData.topic = topic.entity;
session.dialogData.skillLevel = builder.EntityRecognizer.findEntity( session.dialogData.skillLevel = builder.EntityRecognizer.findEntity(
intent.entities, intent.entities,
"skillLevel" "skillLevel"
); );
next(); if (!session.dialogData.topic) {
entityPrompt.prompt(
session,
"What exactly do you want to learn about?"
);
} else next();
}, },
function(session, args, next) { function(session, args, next) {
if (session.dialogData.topic) { session.dialogData.topic = session.dialogData.topic || args.response;
next();
return; if (!session.dialogData.skillLevel) {
} builder.Prompts.choice(
session,
//session.send("What exactly do you want to learn about ?"); "How much do you already know about about " +
builder.Prompts.text( args.response +
session, "?",
"What exactly do you want to learn about ?" "nothing|something|much",
); { listStyle: 3 }
);
} else next();
}, },
function(session, args, next) { function(session, args, next) {
if (session.dialogData.skillLevel) { session.dialogData.skillLevel =
next(); session.dialogData.skillLevel || args.response;
return;
} if (!session.dialogData.duration) {
durationPrompt.prompt(
builder.Prompts.choice( session,
session, "Wohaa! I really found a lot of interesting articles for you. How much time do you want to invest learning about this topic?"
"How much do you already know about about " + args.response + "?", );
"nothing|something|much", } else next();
{ listStyle: 3 }
);
}, },
function(session, args, next) { function(session, args, next) {
if (session.dialogData.duration) { session.dialogData.duration =
next(); session.dialogData.duration || args.response;
return;
} session.send(JSON.stringify(args.dialogData));
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?"
);
} }
]; ];
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