Last active
November 29, 2022 16:21
-
-
Save danielravina/364d4d59d78d5b960426d702fa47df87 to your computer and use it in GitHub Desktop.
A friendly Slack Bot that responds and reacts to everyone with emojis 🗣
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 rp = require('request-promise') | |
const Botkit = require('botkit'); | |
const emojiDict = require("emoji-dictionary"); | |
const shuffle = require('shuffle-array') | |
const getRandomInt = (min, max) => { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
const controller = Botkit.slackbot(); | |
controller.spawn({ | |
token: process.env.SLACK_BOT_TOKEN, | |
}).startRTM() | |
// Direct messaging and mentions | |
controller.hears('.*',['direct_message','direct_mention','mention'], (bot,message) => { | |
let text = message.text | |
text = text.replace(/[^\w\s]/gi, '') | |
rp(`https://emoji.getdango.com/api/emoji?q=${text}`).then(response => { | |
const emojiList = JSON.parse(response).results | |
const picks = shuffle([emojiList[0], emojiList[1]]) | |
const replyMessage = picks.map(emoji => emoji.text).join(''); | |
bot.replyWithTyping(message, replyMessage); | |
}) | |
}); | |
// Reactions in channels | |
controller.on('ambient', (bot, message) => { | |
let text = message.text | |
text = text.replace(/[^\w\s]/gi, '') | |
rp(`https://emoji.getdango.com/api/emoji?q=${text}`).then(response => { | |
const results = JSON.parse(response).results | |
if (results[0].score > 0.03) { | |
const = emojiName1 = emojiDict.getName(results[0].text) | |
bot.api.reactions.add({ | |
timestamp: message.ts, | |
channel: message.channel, | |
name: emojiName1, | |
}); | |
} | |
if (results[0].score - results[1].score < 0.03 && results[1].score > 0.01) { | |
const emojiName2 = emojiDict.getName(results[1].text) | |
bot.api.reactions.add({ | |
timestamp: message.ts, | |
channel: message.channel, | |
name: emojiName2, | |
}); | |
} | |
}) | |
}); |
Hey @danielravina ! This is great! A long time has passed since this but do you know if it's possible for the bot to comment on a message based on a specific reaction emoji?
Nevermind, I think this reaction.get
method API is perfect :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plug in your SLACK_BOT_TOKEN, run
node emoji-bot.js
.After inviting the bot to a channel, with the power of AI, it will respond to
@mentions
and add reactions to messages.You can also talk to it privately if that's your thing!