-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalchemy.js
35 lines (34 loc) · 1.44 KB
/
alchemy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Create the AlchemyAPI object
var AlchemyAPI = require('./alchemyapi');
var alchemyapi = new AlchemyAPI();
var sendmessage = require('./sendmsg');
var Promise = require("bluebird");
module.exports = function(text, sender, callback) {
if (text.length < 1) {
callback(false, undefined); // Nothing in text, don't even send to alchemy.
return;
}
console.log("Text: " + text);
alchemyapi.entities('text', text, {
'sentiment': 1
}, function(response) {
console.log("Hit alchemy " + JSON.stringify(response));
Promise.filter(response.entities, function(item) { // Only want companies
console.log("Item.type: " + item.type);
if (item.type === "Company") {
return true;
} else {
return false;
}
}).map(function(companyArray) {
return companyArray.text
}).then(function(companyArray) { // Array of companies.
console.log("CompanyArray: " + companyArray);
if (companyArray.length < 1) {
callback(false, undefined);
} else {
callback(true, companyArray)
}
})
});
}