Commit 87dfc97f authored by Tammo Ronke's avatar Tammo Ronke

text

parent cd7b93ee
......@@ -69,20 +69,15 @@ topicPrompt.setup(bot, recognizer);
*/
bot.dialog("/", rootDialog.dialog(recognizer));
bot.dialog("delete", require("./dialogs/delete"));
bot.dialog("suggestions", require("./dialogs/suggestions"));
bot.dialog("name", require("./dialogs/name"));
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("recent", require("./dialogs/recent"));
/*bot.dialog("debug", session => {
session.beginDialog("welcome");
})
.triggerAction({
matches: "settings"
});
*/
bot.on("conversationUpdate", activity => {
if (activity.membersAdded) {
activity.membersAdded.forEach(identity => {
......@@ -91,9 +86,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");
}
);
}
......
var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
const choices = ["Bye Bye", "I changed my mind"];
const reply = new builder.Message(session).addAttachment(
confirmCard(session)
);
builder.Prompts.choice(session, reply, choices);
},
(session, results) => {
if (results.response.entity === "Bye Bye") {
session.userData = {};
session.replaceDialog("welcome");
} else {
session.endDialog();
}
}
];
const confirmCard = (session, topic, img) => {
return new builder.HeroCard(session)
.title("Are you sure about deleting you Account?")
.buttons([
builder.CardAction.imBack(session, "Bye Bye", "Of course"),
builder.CardAction.imBack(session, "I changed my mind", "Never")
]);
};
var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
builder.Prompts.text(session, "How should I call you?");
},
(session, results) => {
session.userData.name = results.response;
session.send(
"No problem, from now on I will call you " + session.userData.name
);
session.endDialog();
}
];
......@@ -6,10 +6,10 @@ module.exports = [
session.send(
"Give me a sec, \n\n I am currently looking through your history to get you started where you left of! 😨"
);
setTimeout(() => next(), 1000);
setTimeout(() => next(), 700);
},
session => {
const hist = ["China", "Java", "Rustlang", "goland", "car", "merkel"];
const hist = ["China", "Java", "Rustlang", "goland", "car", "muddi"];
const msg = joinCard(session, hist, GSearch.getImgs(hist));
session.send(msg);
session.endDialog();
......@@ -31,7 +31,5 @@ const topicCard = (session, topic, img) => {
return new builder.HeroCard(session)
.title(topic)
.images([builder.CardImage.create(session, img)])
.buttons([
builder.CardAction.postBack(session, "load." + "topic", "More")
]);
.buttons([builder.CardAction.postBack(session, topic, "Learn More")]);
};
......@@ -6,7 +6,14 @@ const dialog = recognizer => {
});
dialog.matches("settings", "settings");
dialog.matches("delete", "suggestions");
dialog.matches("changeName", "name");
dialog.matches("learn", "learning");
dialog.matches("None", [
session => {
session.send("I'm not quite sure what you meant");
}
]);
return dialog;
};
......
......@@ -2,72 +2,11 @@ var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
const choices = ["Delete User", "Change Name"];
const reply = new builder.Message(session).addAttachment(
const msg = new builder.Message(session).addAttachment(
settingsCard(session)
);
builder.Prompts.choice(session, reply, choices);
},
(session, results, next) => {
session.dialogData.confirm = results.response.entity;
if (results.response.entity !== "Change Name") {
const choices = ["true", "false"];
const title = () => {
switch (results.response.entity) {
case "Delete User": {
return " Confirm deletion of User!";
}
}
};
const reply = new builder.Message(session).addAttachment(
confirmationCard(session, title())
);
builder.Prompts.choice(session, reply, choices);
} else {
next();
}
},
(session, results, next) => {
if (results.response && results.response.entity === "true")
switch (session.dialogData.confirm) {
case "Delete User": {
session.userData = {};
session.replaceDialog("welcome");
break;
}
}
else {
switch (session.dialogData.confirm) {
case "Change Name": {
builder.Prompts.text(session, "How should I call you?");
break;
}
default: {
session.replaceDialog("settings");
}
}
}
},
(session, results, next) => {
session.dialogData.name = results.response;
const choices = ["true", "false"];
const reply = new builder.Message(session).addAttachment(
confirmationCard(session, `So, your name is ${results.response}?`)
);
builder.Prompts.choice(session, reply, choices);
},
(session, results, next) => {
if (results.response.entity === "true") {
session.send(
`Ok, from now on I will call you ${session.dialogData.name}.`
);
session.userData.name = session.dialogData.name;
session.endDialog();
}
session.replaceDialog("settings");
session.send(msg);
session.endDialog();
}
];
......@@ -76,24 +15,10 @@ const settingsCard = session => {
.title("Settings")
.text(`Name: ${session.userData.name}`)
.buttons([
builder.CardAction.postBack(
session,
"Confirm deletion of User",
"Delete User"
),
builder.CardAction.postBack(
builder.CardAction.imBack(
session,
"Confirm change of Name to",
"I would like to change my name",
"Change Name"
)
]);
};
const confirmationCard = (session, title) => {
return new builder.HeroCard(session)
.title(title)
.buttons([
builder.CardAction.postBack(session, "true", "Yes"),
builder.CardAction.postBack(session, "false", "No")
]);
};
var builder = require("botbuilder");
const GSearch = require("../utils/gsearch");
module.exports = [
(session, args, next) => {
args = [
{
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",
topic: "Ethereum"
},
{
url:
"https://media.consensys.net/programmable-blockchains-in-context-ethereum-s-future-cd8451eb421e",
title: "Programmable blockchains in context: Ethereum’s Future",
topic: "Future"
}
];
const msg = suggCards(session, args);
const choices = [];
args.forEach(element => {
choices.push(JSON.stringify(element));
});
builder.Prompts.choice(session, msg, choices);
},
(session, results, next) => {
session.replaceDialog("vote", JSON.parse(results.response.entity));
}
];
const suggCards = (session, args) => {
let cards = [];
args.forEach(element => {
cards.push(suggCard(session, element));
});
return new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(cards);
};
const suggCard = (session, sugg) => {
return new builder.ThumbnailCard(session)
.title(sugg.title)
.images([builder.CardImage.create(session, GSearch.getImg(sugg.title))])
.buttons([
builder.CardAction.openUrl(session, sugg.url, "Open Website"),
builder.CardAction.postBack(
session,
JSON.stringify(sugg),
"Rate Content"
)
]);
};
......@@ -2,43 +2,47 @@ 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 }
);
(session, args, next) => {
session.userData.vote = args;
next();
},
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?`
);
(session, next) => {
builder.Prompts.text(session, "hi");
},
(session, args, next) => {
switch (args.response.index) {
case 0: {
session.send(
`Sorry to hear. Do you want to read more about ${
session.dialogData.topic
} or learn about another topic?`
);
break;
}
case 1: {
session.send(
`Alright. Do you want to read some more about ${
session.dialogData.topic
} or some other topic?`
);
break;
}
case 2: {
session.send(
`Awesome, so you want to read more about ${
session.dialogData.topic
}?`
);
break;
}
}
suggestionStore.addAnalytic(
session.userData.currentArticle.topic,
session.userData.currentArticle.url,
args.topic,
args.url,
true,
args.response.index,
session.userData
);
session.userData.currentArticle = undefined;
next();
session.endDialog();
}
];
......@@ -19,7 +19,7 @@ module.exports = [
session.send(
`Ok, from now on I will call you ${
results.response
}. \n\n But you can change it all the time in the settings.`
}. \n\n Please be gentle... 😉`
);
session.userData.name = results.response;
session.endDialog();
......
......@@ -22,13 +22,8 @@ const getImg = imgTopic => {
let res = request(
"GET",
`https://www.google.com/search?tbs=iar%3As&tbm=isch&sa=1&q=${escape(
element
)}&oq=c%23`,
{
headers: {
"user-agent": "20100101"
}
}
imgTopic
)}`
);
const $ = cheerio.load(res.getBody("utf8"));
......
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