A simple bot that can listen for reactions with specific emoji in Slack.
To install this package in your existing Go project, run:
go get -u github.com/jordanleven/reaction-bot
Then install additional dependences:
go get -t
Import into your file:
import "github.com/jordanleven/reaction-bot/reactionbot"
To initialize Reaction Bot, run reactionbot.New()
with the your options.
func main() {
registrationOptions := reactionbot.RegistrationOptions{
SlackTokenApp: slackTokenApp,
SlackTokenBot: slackTokenBot,
RegisteredEmoji: registeredReactions,
}
reactionbot.New(registrationOptions)
}
SlackTokenApp
: The Slack app token obtained from Slack.SlackTokenBot
: The Slack bot token obtained from Slack.RegisteredEmoji
: The list of emoji to register reactions to (see Registering Reactions below).
Although you may retrieve the tokens from your env file yourself, you may also use the GetSlackTokenApp
and GetSlackTokenBot
functions retrieve them (see example above). Each of these functions accepts the name of the environmental variable to retrieve the tokens from, and will subsequently check the formatting of the tokens to confirm they are the correct ones.
slackTokenApp := reactionbot.GetSlackTokenApp("SLACK_TOKEN_APP")
slackTokenBot := reactionbot.GetSlackTokenBot("SLACK_TOKEN_BOT")
You may register an unlimited number of emoji reactions in RegisteredEmoji
. When the emoji identified as the key is used in any channel where Reaction Bot is added, the message will be posted to the identified channel.
// The name of the bot reaction. This is only used when logging reactions on the server.
Name string
// The channel to post the reaction to.
Channel string
When registered in RegisteredEmoji
, a bot named "Mr. Randomness" with that will post messages to the "random" channel when reacted to with the "laughing" emoji would look like this.
var registeredReactions = reactionbot.RegisteredReactions{
"laughing": {
Name: "Randomness",
Channel: "random",
},
}