Commit 5276fe57 authored by Tammo Ronke's avatar Tammo Ronke

redirect

parent 078125c1
const restify = require("restify");
const builder = require("botbuilder");
const botbuilder_azure = require("botbuilder-azure");
const suggestionStore = require("./store/suggestion");
const rootDialog = require("./dialogs/root");
......@@ -92,3 +93,26 @@ bot.on("conversationUpdate", activity => {
});
}
});
server.get("/redirect/:address/:url", (req, res, next) => {
const address = decodeURI(req.params.address);
const url = decodeURI(req.params.url);
bot.loadSession(address, (error, session) => {
let suggestion = suggestionStore.getSuggestionByUrl(
address,
session.userData
);
suggestionStore.addAnalytic(
address,
true,
suggestion.rating,
session.userData
);
});
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(`<script>window.location = '${url}';</script>`);
next();
});
const request = require("sync-request");
const cheerio = require("cheerio");
var fs = require("fs");
const randomTopic = () => {
let res = request("GET", "https://www.randomlists.com/topics/things.json");
const $ = cheerio.load(res.getBody("utf8"));
return $(".crux")[0].children[0].data;
};
const getSyns = base => {
let res = request(
"GET",
"https://www.powerthesaurus.org/" + base + "/synonyms"
);
const $ = cheerio.load(res.getBody("utf8"));
let syns = [];
const terms = $(".link--term");
terms.map(element => {
syns.push(terms[element].children[0].data);
});
return syns;
};
let out = "";
let syns = {};
syns["learn"] = getSyns("learn");
syns["want"] = getSyns("search");
syns["about"] = getSyns("about");
syns["like"] = getSyns("like");
syns["have"] = getSyns("know");
syns["some"] = getSyns("a lot");
syns["knowledge"] = getSyns("medium");
for (let index = 0; index < 25; index++) {
out +=
"I " +
syns["have"][index] +
" " +
syns["about"][index] +
" " +
randomTopic() +
" " +
randomTopic() +
" " +
randomTopic() +
" " +
randomTopic() +
" and " +
syns["have"][index] +
" " +
syns["knowledge"][index] +
" " +
syns["about"][index] +
"\n";
}
fs.writeFile("/home/tammo/out.txt", out, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
......@@ -7,7 +7,6 @@
"botbuilder": "^3.13.1",
"botbuilder-azure": "^3.0.4",
"cheerio": "^1.0.0-rc.2",
"imgix-core-js": "^1.1.1",
"restify": "^5.0.0",
"sync-request": "^6.0.0"
},
......@@ -17,7 +16,8 @@
},
"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"
......
......@@ -10,6 +10,11 @@ var getRecentQueries = (count, userData) => {
return userData.recentQueries.slice(0, count);
};
var getSuggestionByUrl = (url, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
return userData.recentQueries.find(s => s.url === url);
};
var addQuery = (query, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
......@@ -21,7 +26,7 @@ var addQuery = (query, userData) => {
userData.recentQueries = userData.recentQueries.slice(0, 150);
};
var addAnalytic = (queryString, url, clicked, rating, userData) => {
var addAnalytic = (url, clicked, rating, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
var query = userData.recentQueries.find(q => q.query == queryString);
......@@ -58,5 +63,6 @@ module.exports = {
generateSuggestions,
addQuery,
getRecentQueries,
getRecentQueryStrings
getRecentQueryStrings,
getSuggestionByUrl
};
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