Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
merged some crap from @csell5
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Satrom committed May 18, 2016
1 parent 2379f0d commit 7c809cc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
46 changes: 8 additions & 38 deletions index.js
@@ -1,6 +1,7 @@
var http = require('http');
var https = require('https');
var querystring = require('querystring');
var Q = require('q');
var cognitiveServices = require('./scripts/cognitive-services');

var allContactTypes = ['direct_message', 'direct_mention', 'mention'];

Expand All @@ -21,43 +22,12 @@ var bot = controller.spawn({
token: process.env.token
}).startRTM();

controller.hears('cognitive test', ['ambient'], function(bot, message) {
bot.reply(message, 'on it, boss');

var responseData;
var postData = querystring.stringify({
'language' : 'en',
'analyzerIds' : ['08ea174b-bfdb-4e64-987e-602f85da7f72'],
'text' : 'Hi, Tom! How are you today?'
});

var options = {
host: 'api.projectoxford.ai',
path: '/linguistics/v1.0/analyze',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
'Ocp-Apim-Subscription-Key': '02829fac842a458d9fa90242754c6721', //replace with process.env.MSCSToken
}
};

var req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
bot.reply(message, responseData);
})
});

req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});

req.write(postData);
req.end();
controller.hears('(.*)', allContactTypes, function(bot, message) {
bot.reply(message, 'I am at your service');

cognitiveServices.analyzeText(message).then(function (analyzedText) {
bot.reply(message, analyzedText);
});
});

controller.hears(['that conference'], ['ambient'], function(bot, message) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -26,6 +26,7 @@
},
"homepage": "https://github.com/ThatConference/that-bot#readme",
"dependencies": {
"botkit": "^0.1.1"
"botkit": "^0.1.1",
"q": "^1.4.1"
}
}
47 changes: 47 additions & 0 deletions scripts/cognitive-services.js
@@ -0,0 +1,47 @@
var https = require('https');
var Q = require('q');

module.exports = {
analyzeText: function(message) {
var responseData = '';
var deferred = Q.defer();

var postData = JSON.stringify({
'language' : 'en',
'analyzerIds' : ['08ea174b-bfdb-4e64-987e-602f85da7f72'],
'text' : message.text
});

var options = {
host: 'api.projectoxford.ai',
path: '/linguistics/v1.0/analyze',
port: 443,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length,
'Cache-Control': 'no-cache',
'Ocp-Apim-Subscription-Key': '02829fac842a458d9fa90242754c6721', //replace with process.env.MSCSToken
}
};

var req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
deferred.resolve(responseData);
})
});

req.on('error', (e) => {
deferred.reject(new Error("problem with request: " + e.message));
});

req.write(postData);
req.end();

return deferred.promise;
}
};

0 comments on commit 7c809cc

Please sign in to comment.