Commit 88a0da4b authored by Tammo Ronke's avatar Tammo Ronke

added gsearch

parent 656d950a
......@@ -67,23 +67,10 @@ topicPrompt.setup(bot, recognizer);
/*
* Dialogs
*/
<<<<<<< HEAD
bot.dialog("welcome", require("./dialogs/welcome"));
bot.dialog("join", require("./dialogs/join"));
bot.dialog("settings", require("./dialogs/settings")).triggerAction({
matches: "settings"
});
bot
.dialog("learning", require("./dialogs/learning"))
.triggerAction({ matches: "learn" });
=======
bot.dialog("/", rootDialog.dialog(recognizer));
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"));
......@@ -95,7 +82,6 @@ bot.dialog("join", require("./dialogs/join"));
});
*/
>>>>>>> 3334da3ad3af586a59cb31aab38e2d1f5d317f4c
bot.on("conversationUpdate", activity => {
if (activity.membersAdded) {
activity.membersAdded.forEach(identity => {
......
var builder = require("botbuilder");
module.exports = [(session, args, next) => {}];
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(), 100);
},
session => {
const hist = ["China", "Java", "Rustlang"];
const msg = joinCard(session, hist, GSearch.getImgs(hist));
session.send(msg);
}
];
const joinCard = (session, topics, imgUrls) => {
let topicCards = [];
topics.forEach((element, index) => {
topicCards.push(topicCard(session, element, imgUrls[index]));
});
const joinCard = session => {
return new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(cards);
.attachments(topicCards);
};
const topicCard = topic => {
const topicCard = (session, topic, img) => {
return new builder.HeroCard(session)
.title(topic)
.images([
builder.CardImage.create(
session,
"https://fat.gfycat.com/LightheartedSimilarGallinule.gif"
)
])
.images([builder.CardImage.create(session, img)])
.buttons([
builder.CardAction.postBack(session, "load." + topic, "More")
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,10 +2,7 @@ var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
const choices = [
"Confirm deletion of User",
"Confirm change of Name to"
];
const choices = ["Delete User", "Change Name"];
const reply = new builder.Message(session).addAttachment(
settingsCard(session)
);
......@@ -16,8 +13,15 @@ module.exports = [
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, results.response.entity)
confirmationCard(session, title())
);
builder.Prompts.choice(session, reply, choices);
} else {
......
......@@ -2,7 +2,7 @@ var builder = require("botbuilder");
module.exports = [
(session, args, next) => {
if (session.userData === {} || session.userData) {
if (session.userData.name === undefined) {
const msg = new builder.Message(session).addAttachment(
welcomeCard(session)
);
......
......@@ -6,8 +6,9 @@
"dependencies": {
"botbuilder": "^3.13.1",
"botbuilder-azure": "^3.0.4",
"free-google-image-search": "^1.0.0",
"restify": "^5.0.0"
"cheerio": "^1.0.0-rc.2",
"restify": "^5.0.0",
"sync-request": "^6.0.0"
},
"devDependencies": {
"request": "^2.81.0",
......
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 + " icon"
)}`
);
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