Skip to content

Instantly share code, notes, and snippets.

@RedRussianBear
Created December 14, 2018 00:08
Show Gist options
  • Save RedRussianBear/3deeccddf5b439d083067e765a3c6d17 to your computer and use it in GitHub Desktop.
Save RedRussianBear/3deeccddf5b439d083067e765a3c6d17 to your computer and use it in GitHub Desktop.
const response_emoji = ['😭', '😒', '😞', '😐', 'πŸ™‚', 'πŸ˜ƒ', 'πŸ˜„'];
controller.on('direct_mention,direct_message', function(bot, message) {
if(message.text) {
const document = {
content: message.text,
type: 'PLAIN_TEXT',
};
client.analyzeSentiment({document: document})
.then(results => {
const sentiment = results[0].documentSentiment;
if(sentiment.magnitude > 0.2)
bot.reply(message, `${response_emoji[Math.round(sentiment.score/.3) + 3]}`);
else
bot.reply(message, '😢');
})
.catch(err => {
console.error('ERROR:', err);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment