Commit a9842971 authored by Eric Meier's avatar Eric Meier

Messages are now dynmaic and not hard coded

parent 0d6f3606
......@@ -77,6 +77,7 @@ bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("settings", require("./dialogs/settings"));
bot.dialog("learning", require("./dialogs/learning"));
bot.dialog("recent", require("./dialogs/recent"));
bot.dialog("greet", require("./dialogs/greet"));
bot.on("conversationUpdate", activity => {
if (activity.membersAdded) {
......
var request = require("sync-request");
//const HOST = "https://evil-octopus-34.localtunnel.me/";
const HOST = "https://suggestions32435342.localtunnel.me";
var querySuggestions = (keyword, read_time, difficulty) => {
var url = `${HOST}suggestions?keyword=${normalize(
keyword
)}&difficulty=${normalize(difficulty)}&read_time=${normalize(read_time)}`;
data = fetchJsonSync(url);
//Normalize data
if (data)
data = data.map(s => {
return {
title: s.name[0],
url: s.url[0],
keywords: s.keywords,
topic: keyword
};
});
return data;
};
var normalize = string => {
string.replace(" ", "-");
};
var fetchJsonSync = url => {
console.log(url);
let res = request("GET", url);
try {
let body = res.getBody("utf8");
console.log("test:" + body);
return JSON.parse(body);
} catch (error) {
return null;
}
};
module.exports = { querySuggestions };
var builder = require("botbuilder");
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
......@@ -21,7 +22,11 @@ module.exports = [
const confirmCard = (session, topic, img) => {
return new builder.HeroCard(session)
.title("Are you sure about deleting you Account?")
.text(
answers.formatedRandomAnswer("delete_account.confirm", [
session.userData.name
])
)
.buttons([
builder.CardAction.imBack(session, "Bye Bye", "Of course"),
builder.CardAction.imBack(session, "I changed my mind", "Never")
......
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
session.send(
answers.formatedRandomAnswer("greet.greetings", [
session.userData.name
])
);
session.endDialog();
}
];
......@@ -2,6 +2,9 @@ var builder = require("botbuilder");
var durationPrompt = require("../prompts/durationPrompt");
var entityPrompt = require("../prompts/topicPrompt");
var luisUtils = require("../utils/luis");
var client = require("../backend/client");
var suggestionStore = require("../store/suggestion");
var answers = require("../speech/answers");
const skillLevels = ["low", "medium", "high"];
......@@ -14,7 +17,9 @@ module.exports = [
if (!session.dialogData.topic) {
entityPrompt.prompt(
session,
"What exactly do you want to learn about?"
answers.formatedRandomAnswer("learn.topic", [
session.userData.name
])
);
} else next();
},
......@@ -25,9 +30,10 @@ module.exports = [
if (!session.dialogData.skillLevel) {
builder.Prompts.choice(
session,
"How much do you already know about about " +
session.dialogData.topic +
"?",
answers.formatedRandomAnswer("learn.skill", [
session.userData.name,
session.dialogData.topic
]),
"nothing|something|a lot",
{ listStyle: 3 }
);
......@@ -41,7 +47,9 @@ module.exports = [
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?"
answers.formatedRandomAnswer("learn.time", [
session.userData.name
])
);
} else next();
},
......@@ -50,14 +58,14 @@ module.exports = [
session.dialogData.duration =
session.dialogData.duration || args.response;
session.send(JSON.stringify(session.dialogData));
session.userData.currentArticle = {
url: "test",
title: "some title",
topic: "a topic"
};
const suggestions = client.querySuggestions(
session.dialogData.topic,
session.dialogData.duration,
session.dialogData.skillLevel
);
suggestionStore.addHistory(suggestions);
session.replaceDialog("suggestions", suggestions);
next();
}
];
......
var builder = require("botbuilder");
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
builder.Prompts.text(session, "How should I call you?");
builder.Prompts.text(
session,
answers.formatedRandomAnswer("name.question", [])
);
},
(session, results) => {
session.userData.name = results.response;
session.send(
"No problem, from now on I will call you " + session.userData.name
answers.formatedRandomAnswer("name.update", [session.userData.name])
);
session.endDialog();
}
......
var builder = require("botbuilder");
const GSearch = require("../utils/gsearch");
var GSearch = require("../utils/gsearch");
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
session.send(
"Give me a sec, \n\n I am currently looking through your history to get you started where you left of! 😨"
answers.formatedRandomAnswer("recent.loading", [session.userData.name])
);
setTimeout(() => next(), 700);
},
......
var builder = require("botbuilder");
var answers = require("../speech/answers");
const dialog = recognizer => {
var dialog = new builder.IntentDialog({
......@@ -6,12 +7,15 @@ const dialog = recognizer => {
});
dialog.matches("settings", "settings");
dialog.matches("delete", "suggestions");
dialog.matches("delete", "delete");
dialog.matches("changeName", "name");
dialog.matches("learn", "learning");
dialog.matches("greet", "greet");
dialog.matches("None", [
session => {
session.send("I'm not quite sure what you meant");
session.send(
answers.formatedRandomAnswer("unknown", [session.userData.name])
);
}
]);
return dialog;
......
var builder = require("botbuilder");
var suggestionStore = require("../store/suggestion");
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
......@@ -9,9 +10,11 @@ module.exports = [
const reply = new builder.Message(session).addAttachment(
new builder.HeroCard(session)
.text(
`How did you like the article: **${args.title}** about **${
args.topic
}**?`
answers.formatedRandomAnswer("vote.question", [
session.userData.name,
session.userData.currentArticle.title,
session.userData.currentArticle.topic
])
)
.buttons([
builder.CardAction.postBack(
......@@ -34,25 +37,31 @@ module.exports = [
switch (args.response.index) {
case 0: {
session.send(
`Sorry to hear. Do you want to read more about ${
session.dialogData.vote.topic
} or learn about another topic?`
answers.formatedRandomAnswer("vote.bad", [
session.userData.name,
session.userData.currentArticle.title,
session.userData.currentArticle.topic
])
);
break;
}
case 1: {
session.send(
`Alright. Do you want to read some more about ${
session.dialogData.vote.topic
} or some other topic?`
answers.formatedRandomAnswer("vote.ok", [
session.userData.name,
session.userData.currentArticle.title,
session.userData.currentArticle.topic
])
);
break;
}
case 2: {
session.send(
`Awesome, so you want to read more about ${
session.dialogData.vote.topic
}?`
answers.formatedRandomAnswer("vote.awesome", [
session.userData.name,
session.userData.currentArticle.title,
session.userData.currentArticle.topic
])
);
break;
}
......
var builder = require("botbuilder");
var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
......@@ -13,13 +14,14 @@ module.exports = [
}
},
(session, results, next) => {
builder.Prompts.text(session, "How should I call you?");
builder.Prompts.text(
session,
answers.formatedRandomAnswer("name.question", [])
);
},
(session, results, next) => {
session.send(
`Ok, from now on I will call you ${
results.response
}. \n\n Please be gentle... 😉`
answers.formatedRandomAnswer("name.update", [results.response])
);
session.userData.name = results.response;
session.endDialog();
......
......@@ -9,7 +9,8 @@
"cheerio": "^1.0.0-rc.2",
"imgix-core-js": "^1.1.1",
"restify": "^5.0.0",
"sync-request": "^6.0.0"
"sync-request": "^6.0.0",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"request": "^2.81.0",
......
var speechData = require("./speechData.json");
const formatedRandomAnswer = (path, format) => {
answers = getArray(path);
var answer = answers[Math.floor(Math.random() * answers.length)];
format.forEach((s, i) => {
answer = answer.replace("[" + i + "]", s);
});
return answer;
};
const getArray = key => {
let res = speechData;
key.split(".").forEach(v => {
res = res[v];
});
return res;
};
module.exports = { formatedRandomAnswer };
{
"greet": {
"greetings": ["hi [0]!", "heyho ^^", "hi there!", "hola [0] :)"]
},
"delete_account": {
"confirm": [
"**Do you really want to leave me [0]?**",
"**Are you 100% sure you want to delete your account ?**",
"**I will miss you! Are you sure you want to continue?**",
"**I will change, things can go back to where they where! Are you sure?**"
]
},
"learn": {
"topic": [
"What exactly do you want to learn about?",
"Could you specify what you want to learn about ?",
"It would be nice to know what exactly you wanna learn about [0]!"
],
"skill": [
"From 100 to 4569, who much do you already know about **[1]** [0] ?",
"How much do you know about **[1]**",
"How would you rate your knowledge about **[1]**"
],
"time": [
"How much time to you have to spear?",
"How much spare time do you have?",
"How much time can you invest [0]?"
]
},
"name": {
"question": [
"How should I call you?",
"How do you want to be called?",
"What's ya name?"
],
"update": [
"No problem, from now on I will call you [0]",
"Nice to meet you [0]",
"[0], what a beautiful name!",
"From now on I will call you [0]. Please be gentle... 😉"
]
},
"recent": {
"loading": [
"[0] please give me a sec, \n\n I am currently looking through your history to get you started where you left of! 😨",
"Please stand by you content will (hopefully) (sooner or later) (more likely later) be loaded",
"I'm currently fetching you content so you can start right away! Please stand by :)"
]
},
"unknown": [
"I'm not quite sure what you meant",
"I have literally no idea what to say :)",
"I didn't go ya!"
],
"vote": {
"question": [
"How did you like the article: **[1]** about **[2]**?",
"Could you tell me your impression of the article **[1]** about **[2]** [0]?"
],
"bad": [
"Sorry to hear. Do you want to read more about **[2]** or learn about another topic?"
],
"ok": [
"Alright. Do you want to read some more about **[2]** or some other topic?"
],
"awesome": [
"Awesome! Do you want to read some more about **[2]** or some other topic?"
]
}
}
var getRecentQueryStrings = (count, userData) => {
var getRecentTopics = (count, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
return userData.recentQueries
.map(q => q.topic)
.filter((v, i, s) => s.indexOf(v) === i)
.slice(0, count);
};
var getWithTopic = (count, topic, userData) => {
return userData.recentQueries
.slice(0, count)
.map(query => query.queryString);
.filter(s => s.topic === topic)
.slice(0, count);
};
var getRecentQueries = (count, userData) => {
......@@ -10,53 +18,27 @@ var getRecentQueries = (count, userData) => {
return userData.recentQueries.slice(0, count);
};
var addQuery = (query, userData) => {
var addHistory = (suggestions, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
userData.recentQueries.push({
query: queryString,
suggestions: suggestions
});
userData.recentQueries = userData.recentQueries.slice(0, 150);
userData.recentQueries = userData.recentQueries
.concat(suggestions)
.slice(0, 150);
};
var addAnalytic = (queryString, url, clicked, rating, userData) => {
var setAnalytic = (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);
let query = userData.recentQueries.find(q => q.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);
if (!query) return;
query.clicked = clicked;
query.rating = rating;
};
module.exports = {
addAnalytic,
generateSuggestions,
addQuery,
getRecentQueries,
getRecentQueryStrings
getRecentTopics,
getWithTopic,
setAnalytic,
addHistory
};
......@@ -1479,6 +1479,10 @@ xmlbuilder@0.4.3:
version "0.4.3"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-0.4.3.tgz#c4614ba74e0ad196e609c9272cd9e1ddb28a8a58"
xmlhttprequest@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
xtend@^4.0.0, xtend@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
......
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