Commit 656d950a authored by Tammo Ronke's avatar Tammo Ronke

merged

parents 10ab3ccc 3334da3a
......@@ -2,6 +2,11 @@ var restify = require("restify");
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
var rootDialog = require("./dialogs/root");
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 +23,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,12 +55,19 @@ 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
*/
<<<<<<< HEAD
bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("join", require("./dialogs/join"));
......@@ -73,6 +79,23 @@ bot
.dialog("learning", require("./dialogs/learning"))
.triggerAction({ matches: "learn" });
=======
bot.dialog("/", rootDialog.dialog(recognizer));
bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("openSettings", require("./dialogs/settings"));
bot.dialog("learning", require("./dialogs/learning"));
bot.dialog("join", require("./dialogs/join"));
/*bot.dialog("debug", session => {
session.beginDialog("welcome");
})
.triggerAction({
matches: "settings"
});
*/
>>>>>>> 3334da3ad3af586a59cb31aab38e2d1f5d317f4c
bot.on("conversationUpdate", activity => {
if (activity.membersAdded) {
activity.membersAdded.forEach(identity => {
......@@ -83,7 +106,3 @@ bot.on("conversationUpdate", activity => {
});
}
});
bot.dialog("/", session => {
session.send("nothing implemented");
});
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 builder = require("botbuilder");
const dialog = recognizer => {
var dialog = new builder.IntentDialog({
recognizers: [recognizer]
});
dialog.matches("settings", "welcome");
dialog.matches("learn", "learning");
return dialog;
};
module.exports = { dialog };
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