Commit df3c3292 authored by Eric Meier's avatar Eric Meier

voting works!

parent 3a67a983
......@@ -87,9 +87,7 @@ bot.on("conversationUpdate", activity => {
var session = bot.loadSession(
activity.address,
(error, session) => {
if (session.userData.currentArticle)
bot.beginDialog(activity.address, "vote");
else bot.beginDialog(activity.address, "welcome");
bot.beginDialog(activity.address, "welcome");
}
);
}
......@@ -112,7 +110,7 @@ server.get("/redirect/:address/:url", (req, res, next) => {
console.log(session.userData.recentQueries);
let suggestion = suggestionStore.getSuggestionByUrl(
address,
url,
session.userData
);
......@@ -122,6 +120,8 @@ server.get("/redirect/:address/:url", (req, res, next) => {
suggestion.rating,
session.userData
);
session.userData.currentArticle = suggestion;
});
res.setHeader("Content-Type", "text/html");
......
......@@ -12,14 +12,16 @@ var querySuggestions = (keyword, read_time, difficulty) => {
//Normalize data
if (data)
data = data.map(s => {
return {
title: s.name[0],
url: s.url[0],
keywords: s.keywords,
topic: keyword
};
});
data = data
.map(s => {
return {
title: s.name[0],
url: s.url[0],
keywords: s.keywords,
topic: keyword
};
})
.filter(s => s.url);
return data;
};
......@@ -35,7 +37,6 @@ var fetchJsonSync = url => {
try {
let body = res.getBody("utf8");
console.log("test:" + body);
return JSON.parse(body);
} catch (error) {
return null;
......
......@@ -62,7 +62,7 @@ module.exports = [
])
);
next();
setTimeout(() => next(), 500);
},
function(session, args, next) {
......
......@@ -6,7 +6,8 @@ const dialog = recognizer => {
recognizers: [recognizer]
});
dialog.matches("vote", "vote")
dialog.matches(/^vote:\[*.*\]/, "vote");
dialog.matches("settings", "settings");
dialog.matches("delete", "delete");
dialog.matches("changeName", "name");
......
......@@ -15,7 +15,7 @@ module.exports = [
}
//(session, results, next) => {
// session.replaceDialog("vote", JSON.parse(results.response.entity));
//}
//} vote : url
];
const suggCards = (session, args) => {
......@@ -48,7 +48,7 @@ const suggCard = (session, sugg, img) => {
),
builder.CardAction.postBack(
session,
JSON.stringify(sugg),
"vote:[" + sugg.url + "]",
"Rate Content"
)
]);
......
......@@ -4,21 +4,21 @@ var answers = require("../speech/answers");
module.exports = [
(session, args, next) => {
if (args.intends) {
var intent = builder.EntityRecognizer.findEntity(
args.intends,
"url"
);
if (/^vote:\[*.*\]/.test(session.message.text)) {
var url = session.message.text
.replace(/^vote:\[/, "")
.replace(/\]$/, "");
this.dialogData.suggestion = suggestionStore.getSuggestionByUrl(
intent.entity
session.dialogData.suggestion = suggestionStore.getSuggestionByUrl(
url,
session.userData
);
} else {
this.dialogData.suggestion = session.userData.currentArticle;
session.dialogData.suggestion = session.userData.currentArticle;
delete session.userData.currentArticle;
}
if (!this.dialogData.suggestion) session.endDialog();
if (!session.dialogData.suggestion) session.endDialog();
const choices = ["Not for me", "It was ok", "Loved it"];
const reply = new builder.Message(session).addAttachment(
......@@ -26,8 +26,8 @@ module.exports = [
.text(
answers.formatedRandomAnswer("vote.question", [
session.userData.name,
this.dialogData.suggestion.title,
this.dialogData.suggestion.topic
session.dialogData.suggestion.title,
session.dialogData.suggestion.topic
])
)
.buttons([
......@@ -53,8 +53,8 @@ module.exports = [
session.send(
answers.formatedRandomAnswer("vote.bad", [
session.userData.name,
this.dialogData.suggestion.title,
this.dialogData.suggestion.topic
session.dialogData.suggestion.title,
session.dialogData.suggestion.topic
])
);
break;
......@@ -63,8 +63,8 @@ module.exports = [
session.send(
answers.formatedRandomAnswer("vote.ok", [
session.userData.name,
this.dialogData.suggestion.title,
this.dialogData.suggestion.topic
session.dialogData.suggestion.title,
session.dialogData.suggestion.topic
])
);
break;
......@@ -73,22 +73,22 @@ module.exports = [
session.send(
answers.formatedRandomAnswer("vote.awesome", [
session.userData.name,
this.dialogData.suggestion.title,
this.dialogData.suggestion.topic
session.dialogData.suggestion.title,
session.dialogData.suggestion.topic
])
);
break;
}
}
suggestionStore.addAnalytic(
this.dialogData.suggestion.topic,
this.dialogData.suggestion.url,
suggestionStore.setAnalytic(
session.dialogData.suggestion.url,
true,
args.response.index,
session.userData
);
session.userData.contextArticle = session.dialogData.suggestion;
session.endDialog();
}
];
var speechData = require("./speechData.json");
["Beginner", "Intermediate", "Advanced"]
const formatedRandomAnswer = (path, format) => {
answers = getArray(path);
var answer = answers[Math.floor(Math.random() * answers.length)];
......
......@@ -27,7 +27,7 @@ var addHistory = (suggestions, userData) => {
var getSuggestionByUrl = (url, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
return userData.recentQueries.filter(value => value.url != url)[0];
return userData.recentQueries.find(value => value.url == url);
};
var addQuery = (query, userData) => {
......@@ -39,7 +39,6 @@ var addQuery = (query, userData) => {
var setAnalytic = (url, clicked, rating, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
let suggestion = getSuggestionByUrl(url, userData);
if (!suggestion) return;
......
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