Created
October 26, 2016 12:00
-
-
Save sunnygleason/3512ac02ab018e4c902651982d061e04 to your computer and use it in GitHub Desktop.
PubNub Sentiment Analysis with IBM Watson BLOCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xhr = require('xhr'); | |
const qs = require('codec/query_string'); | |
export default (request) => { | |
const apiUrl = 'https://gateway-a.watsonplatform.net/calls/text/TextGetTextSentiment'; | |
const apiKey = '0000000000000000000000000000000000000000'; | |
const querystring = qs.stringify({ | |
outputMode: 'json', | |
showSourceText: false, | |
text: request.message.text, | |
apikey: apiKey | |
}); | |
return xhr.fetch(apiUrl + '?' + querystring) | |
.then(function (r) { | |
const body = JSON.parse(r.body); | |
request.message.sentiment_score = body.docSentiment.score; | |
request.message.sentiment_type = body.docSentiment.type; | |
return request.ok(); | |
}) | |
.catch(function (e){ | |
console.error(e); | |
return request.ok(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment