Commit 0a994819 authored by Eric Meier's avatar Eric Meier
parents cfc03df3 b782efef
......@@ -71,8 +71,9 @@ bot.dialog("/", rootDialog.dialog(recognizer));
bot.dialog("vote", require("./dialogs/vote"));
bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("openSettings", require("./dialogs/settings"));
bot.dialog("settings", require("./dialogs/settings"));
bot.dialog("learning", require("./dialogs/learning"));
bot.dialog("join", require("./dialogs/join"));
/*bot.dialog("debug", session => {
session.beginDialog("welcome");
......
var builder = require("botbuilder");
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 😨"
);
setTimeout(() => next(), 1000);
},
session => {
const hist = ["China", "Java", "Rustlang", "goland", "car", "merkel"];
const msg = joinCard(session, hist, GSearch.getImgs(hist));
session.send(msg);
session.endDialog();
}
];
const joinCard = (session, topics, imgUrls) => {
let topicCards = [];
topics.forEach((element, index) => {
topicCards.push(topicCard(session, element, imgUrls[index]));
});
return new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(topicCards);
};
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")
]);
};
......@@ -5,7 +5,7 @@ const dialog = recognizer => {
recognizers: [recognizer]
});
dialog.matches("settings", "welcome");
dialog.matches("settings", "settings");
dialog.matches("learn", "learning");
return dialog;
};
......
......@@ -2,35 +2,98 @@ var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
const choices = ["deleteUserData", "changeName"];
var reply = new builder.Message(session).addAttachment(
const choices = ["Delete User", "Change Name"];
const reply = new builder.Message(session).addAttachment(
settingsCard(session)
);
builder.Prompts.choice(session, reply, choices);
},
(session, results, next) => {
switch (results.response) {
case "deleteUserData": {
break;
session.dialogData.confirm = results.response.entity;
if (results.response.entity !== "Confirm change of Name to") {
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 "Confirm deletion of User": {
session.userData = {};
session.replaceDialog("welcome");
break;
}
}
case "changeName": {
break;
else {
switch (session.dialogData.confirm) {
case "Confirm change of Name to": {
builder.Prompts.text(session, "How should I call you?");
break;
}
default: {
session.replaceDialog("settings");
}
}
}
session.send(JSON.stringify(results));
},
(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");
}
];
const settingsCard = session => {
return new builder.HeroCard(session)
.title("Settings")
.text(`Name: ${session.userData.name}`)
.buttons([
builder.CardAction.postBack(
session,
"deleteUserData",
"Confirm deletion of User",
"Delete User"
),
builder.CardAction.postBack(session, "changeName", "Change Name")
builder.CardAction.postBack(
session,
"Confirm change of Name to",
"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");
module.exports = [
session => {
const msg = new builder.Message(session).addAttachment(
welcomeCard(session)
(session, args, next) => {
if (session.userData.name === undefined) {
const msg = new builder.Message(session).addAttachment(
welcomeCard(session)
);
session.send(msg);
setTimeout(() => next(), 800);
} else {
session.replaceDialog("join");
}
},
(session, results, next) => {
builder.Prompts.text(session, "How should I call you?");
},
(session, results, next) => {
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.`
);
session.send(msg);
session.userData.name = results.response;
session.endDialog();
}
];
......@@ -14,12 +30,12 @@ const welcomeCard = session => {
return new builder.HeroCard(session)
.title("Welcome to GlaDos!")
.text(
"I am GlaDos, if you want to learn anything, just ask me and I will try to provide you with useful information!"
"I am GlaDos, if you want to learn anything, just ask me and I will try to provide you with useful information! \n\n P.S. If you want to know what I can do just ask!"
)
.images([
builder.CardImage.create(
session,
"https://assets.gitlab-static.net/uploads/-/system/project/avatar/6142850/ezgif-4-9305c3684f.gif"
"https://fat.gfycat.com/LightheartedSimilarGallinule.gif"
)
]);
};
......@@ -6,7 +6,9 @@
"dependencies": {
"botbuilder": "^3.13.1",
"botbuilder-azure": "^3.0.4",
"restify": "^5.0.0"
"cheerio": "^1.0.0-rc.2",
"restify": "^5.0.0",
"sync-request": "^6.0.0"
},
"devDependencies": {
"request": "^2.81.0",
......@@ -14,8 +16,7 @@
},
"scripts": {
"bot": "node ./app.js",
"clean":
"rm -rf ./dist && rm -rf ./test && rm -rf ./node_modules && rm -f ./yarn.lock && rm -f ./package-lock.json && rm -rf ./yarn-error.log && clear && echo -e \"\\e[1;31mFinished cleaning!\\e[0m\""
"clean": "rm -rf ./dist && rm -rf ./test && rm -rf ./node_modules && rm -f ./yarn.lock && rm -f ./package-lock.json && rm -rf ./yarn-error.log && clear && echo -e \"\\e[1;31mFinished cleaning!\\e[0m\""
},
"author": "barbra",
"license": "ISC"
......
var request = require("sync-request");
const cheerio = require("cheerio");
const getImgs = imgTopics => {
let imgUrls = [];
imgTopics.forEach(element => {
let res = request(
"GET",
`https://www.google.com/search?tbs=iar%3As&tbm=isch&sa=1&q=${escape(
element
)}`
);
const $ = cheerio.load(res.getBody("utf8"));
imgUrls.push($("img").attr("src"));
});
return imgUrls;
};
const getImg = imgTopic => {
let res = request(
"GET",
`https://www.google.com/search?tbs=iar%3As&tbm=isch&sa=1&q=${escape(
element + " icon"
)}&oq=c%23`,
{
headers: {
"user-agent": "20100101"
}
}
);
const $ = cheerio.load(res.getBody("utf8"));
return $("img").attr("src");
};
module.exports = { getImgs, getImg };
This diff is collapsed.
This diff is collapsed.
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