Commit 31e3559b authored by Eric Meier's avatar Eric Meier

merge

parents a9842971 5276fe57
[ignore]
[include]
[libs]
[lints]
[options]
[strict]
var restify = require("restify");
var builder = require("botbuilder");
var botbuilder_azure = require("botbuilder-azure");
const restify = require("restify");
const builder = require("botbuilder");
const botbuilder_azure = require("botbuilder-azure");
const suggestionStore = require("./store/suggestion");
var rootDialog = require("./dialogs/root");
const rootDialog = require("./dialogs/root");
var durationPrompt = require("./prompts/durationPrompt");
var topicPrompt = require("./prompts/topicPrompt");
const durationPrompt = require("./prompts/durationPrompt");
const topicPrompt = require("./prompts/topicPrompt");
// Setup Restify Server
var server = restify.createServer();
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log("%s listening to %s", server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
let connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
......@@ -23,17 +24,16 @@ var connector = new builder.ChatConnector({
// Listen for messages from users
server.post("/api/messages", connector.listen());
var tableName = "botdata";
var azureTableClient = new botbuilder_azure.AzureTableClient(
let tableName = "botdata";
let azureTableClient = new botbuilder_azure.AzureTableClient(
tableName,
process.env["AzureWebJobsStorage"]
);
var tableStorage = new botbuilder_azure.AzureBotStorage(
let tableStorage = new botbuilder_azure.AzureBotStorage(
{ gzipData: false },
azureTableClient
);
var bot = new builder.UniversalBot(connector);
let bot = new builder.UniversalBot(connector);
server.post("/api/messages", connector.listen());
/*
......@@ -94,3 +94,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();
});
......@@ -2,7 +2,7 @@ var builder = require("botbuilder");
var answers = require("../speech/answers");
const dialog = recognizer => {
var dialog = new builder.IntentDialog({
let dialog = new builder.IntentDialog({
recognizers: [recognizer]
});
......
var builder = require("botbuilder");
const builder = require("botbuilder");
const GSearch = require("../utils/gsearch");
module.exports = [
......
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",
"xmlhttprequest": "^1.8.0"
......@@ -18,7 +17,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"
......
......@@ -19,13 +19,22 @@ var getRecentQueries = (count, userData) => {
};
var addHistory = (suggestions, userData) => {
userData = userData.concat(suggestions).slice(0, 150);
};
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 = [];
userData.recentQueries = userData.recentQueries
.concat(suggestions)
.slice(0, 150);
};
var setAnalytic = (url, clicked, rating, userData) => {
var addAnalytic = (url, clicked, rating, userData) => {
if (!userData.recentQueries) userData.recentQueries = [];
let query = userData.recentQueries.find(q => q.url == url);
......@@ -40,5 +49,6 @@ module.exports = {
getRecentTopics,
getWithTopic,
setAnalytic,
addHistory
addHistory,
getSuggestionByUrl
};
var request = require("sync-request");
const request = require("sync-request");
const cheerio = require("cheerio");
const getImgs = imgTopics => {
......
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