Commit 57a732b2 authored by Tammo Ronke's avatar Tammo Ronke
parents 7faa9205 57807ebb
......@@ -69,10 +69,11 @@ topicPrompt.setup(bot, recognizer);
*/
bot.dialog("/", rootDialog.dialog(recognizer));
bot.dialog("vote", require("./dialogs/vote"));
bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("settings", require("./dialogs/settings"));
bot.dialog("learning", require("./dialogs/learning"));
bot.dialog("join", require("./dialogs/join"));
bot.dialog("recent", require("./dialogs/recent"));
/*bot.dialog("debug", session => {
session.beginDialog("welcome");
......@@ -87,7 +88,14 @@ bot.on("conversationUpdate", activity => {
activity.membersAdded.forEach(identity => {
// say hello only when bot joins and not when user joins
if (identity.id === activity.address.bot.id) {
bot.beginDialog(activity.address, "welcome");
var session = bot.loadSession(
activity.address,
(error, session) => {
if (session.userData.currentArticle)
bot.beginDialog(activity.address, "vote");
else bot.beginDialog(activity.address, "recent");
}
);
}
});
}
......
var builder = require("botbuilder");
var durationPrompt = require("../prompts/durationPrompt");
var entityPrompt = require("../prompts/topicPrompt");
var luisUtils = require("../utils/luis");
const skillLevels = ["low", "medium", "high"];
module.exports = [
function(session, args, next) {
const intent = args.intent;
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;
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"
);
session.dialogData.skillLevel = getSkillLevel(args.entities);
session.dialogData.topic = getTopic(args.entities);
session.dialogData.duration = getDuration(args.entities);
if (!session.dialogData.topic) {
entityPrompt.prompt(
......@@ -39,9 +26,9 @@ module.exports = [
builder.Prompts.choice(
session,
"How much do you already know about about " +
args.response +
session.dialogData.topic +
"?",
"nothing|something|much",
"nothing|something|a lot",
{ listStyle: 3 }
);
} else next();
......@@ -49,7 +36,7 @@ module.exports = [
function(session, args, next) {
session.dialogData.skillLevel =
session.dialogData.skillLevel || args.response;
session.dialogData.skillLevel || skillLevels[args.response.index];
if (!session.dialogData.duration) {
durationPrompt.prompt(
......@@ -63,6 +50,42 @@ module.exports = [
session.dialogData.duration =
session.dialogData.duration || args.response;
session.send(JSON.stringify(args.dialogData));
session.send(JSON.stringify(session.dialogData));
session.userData.currentArticle = {
url: "test",
title: "some title",
topic: "a topic"
};
next();
}
];
const getSkillLevel = entities => {
var skillLevel = luisUtils.findBestMatch(entities, [
"skillLevel::low",
"skillLevel::medium",
"skillLevel::high"
]);
if (skillLevel) return skillLevel.type.replace("skillLevel::", "");
return null;
};
const getTopic = entities => {
var topic = builder.EntityRecognizer.findEntity(entities, "topic");
if (topic) return topic.entity;
return null;
};
const getDuration = entities => {
var duration = builder.EntityRecognizer.findEntity(
entities,
"builtin.datetimeV2.duration"
);
if (duration && duration.resolution.values.length > 0)
return duration.resolution.values[0].value;
return null;
};
......@@ -4,7 +4,7 @@ const GSearch = require("../utils/gsearch");
module.exports = [
(session, args, next) => {
session.send(
"Give me a sec, \n\n I am currently looking through your history 😨"
"Give me a sec, \n\n I am currently looking through your history to get you started where you left of! 😨"
);
setTimeout(() => next(), 1000);
},
......
var builder = require("botbuilder");
var suggestionStore = require("../store/suggestion");
module.exports = [
function(session, args, next) {
if (!session.userData.currentArticle) session.endDialog();
builder.Prompts.choice(
session,
`How did you like the article ${
session.userData.currentArticle.title
} about ${session.userData.currentArticle.topic}?`,
"Not for me|It was ok|Loved it!",
{ listStyle: 3 }
);
},
function(session, args, next) {
if (args.response.index == 0)
session.send(
`Sorry to hear. Do you want to read more about ${
session.userData.currentArticle.topic
} or learn about another topic?`
);
else
session.send(
`Alright. Do you want to read some more about ${
session.userData.currentArticle.topic
} or some other topic?`
);
suggestionStore.addAnalytic(
session.userData.currentArticle.topic,
session.userData.currentArticle.url,
true,
args.response.index,
session.userData
);
session.userData.currentArticle = undefined;
next();
}
];
......@@ -5,7 +5,7 @@ var recognizer;
const dialog = new builder.Prompt({
defaultRetryPrompt:
"Sorry, but I didn't understand you! Try entering something like 30 minutes."
"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(
......
......@@ -12,7 +12,7 @@ const dialog = new builder.Prompt({
"topic"
);
if (!topic) callback(null, 0.0);
if (!topic) callback(null, 0.5, context.message.text);
else {
callback(null, 1, topic.entity);
}
......
var getRecentQueryStrings = (count, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
return userData.recentQueries
.slice(0, count)
.map(query => query.queryString);
};
var getRecentQueries = (count, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
return userData.recentQueries.slice(0, count);
};
var addQuery = (query, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
userData.recentQueries.push({
query: queryString,
suggestions: suggestions
});
userData.recentQueries = userData.recentQueries.slice(0, 150);
};
var addAnalytic = (queryString, url, clicked, rating, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
var query = userData.recentQueries.find(q => q.query == queryString);
if (!query) return;
suggestion = query.suggestions.find(suggestion => suggestion.url == url);
suggestion.clicked = clicked;
suggestion.rating = rating;
};
var generateSuggestions = query => {
query = {
query: [
{
url:
"https://medium.com/financial-times/ethereums-vitalik-buterin-on-the-bitcoin-bubble-and-running-a-125bn-blockchain-4ce5f25e7046",
title:
"Ethereum’s Vitalik Buterin on the Bitcoin Bubble and Running a $125bn Blockchain"
},
{
url:
"https://media.consensys.net/programmable-blockchains-in-context-ethereum-s-future-cd8451eb421e",
title: "Programmable blockchains in context: Ethereum’s Future"
}
]
};
addQuery(query);
};
module.exports = {
addAnalytic,
generateSuggestions,
addQuery,
getRecentQueries,
getRecentQueryStrings
};
var builder = require("botbuilder");
findBestMatch = (entities, types) => {
return types
.map(element => builder.EntityRecognizer.findEntity(entities, element))
.filter(element => element)
.sort((a, b) => a.score - b.score)[0];
};
module.exports = { findBestMatch };
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