Skip to content

A simple installable package to register bots that can listen for reactions with specific emoji in Slack and post the message to channels.

Notifications You must be signed in to change notification settings

jordanleven/reaction-bot

Repository files navigation

banner

Reaction Bot

A simple bot that can listen for reactions with specific emoji in Slack.

Installing Reaction Bot

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"

Initializing Reaction Bot

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)
}

Configuration

  1. SlackTokenApp: The Slack app token obtained from Slack.
  2. SlackTokenBot: The Slack bot token obtained from Slack.
  3. RegisteredEmoji: The list of emoji to register reactions to (see Registering Reactions below).

Retrieving the authentication credentials

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")

Registering Emoji

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",
  },
}

About

A simple installable package to register bots that can listen for reactions with specific emoji in Slack and post the message to channels.

Topics

Resources

Stars

Watchers

Forks

Languages