- Overview
- Requirements
- Features
- Demo
- The Name
- Concepts
- Create Your Own Slackscot
- Contributing
- Some Credits
Slackscot
is a slack bot
core written in Go.
Think of it as the assembly kit to making your own friendly slack
bot
. It comes
with a set of plugins you might enjoy and a friendly API
for you to realize
your ambitious dreams (if you dreams include this sort of thing).
Go 1.11
or above is required, mostly for go module support.
-
Support for reactions to message updates.
slackscot
does the following:-
Keeps track of plugin action responses and the message that triggered them
-
On message updates:
-
Update responses for each triggered action
-
Delete responses that aren't triggering anymore (or result in errors during the message update)
-
-
On deletion of triggering messages, responses are also deleted
-
Limitation: Sending a
message
automatically splits it into multiple slack messages when it's too long. When updating messages, this spitting doesn't happen and results in anmessage too long
error. Effectively, the last message in the initial response might getdeleted
as a result. Handling of this could be better but that is the current limitation 😕
-
-
Support for threaded replies to user message with option to also
broadcast
on channels (disabled bydefault
). See configuration example below where both are enabled.- Plugin actions may also explicitely reply in threads with/without broadcasting via AnswerOption
-
Simple extensible storage
API
for persistence in two flavors:StringStorer
andBytesStorer
. Both are basickey:value
maps. A default file-based implementation is provided backed by leveldb -
Implementation of
StringStorer
backed by Google Cloud Datastore. See datastoredb's godoc for documentation, usage and example. -
In-memory implementation of
StringStorer
wrapping anyStringStorer
implementation to offer low-latency and potentially cost-saving storage implementation well-suited for small datasets. Plays well with cloud storage like the [datastoredb]((https://godoc.org/github.com/alexandre-normand/slackscot/store/datastoredb) See inmemorydb's godoc for documentation, usage and example. -
Support for various configuration sources/formats via viper
-
Support for various ways to implement functionality:
scheduled actions
: run something every second, minute, hour, week. Oh Monday is a plugin that demos this by sending aMonday
greeting every Monday at 10am (or the time you configure it to).commands
: respond to a command directed at yourslackscot
. That means something like@slackscot help
or a direct messagehelp
sent toslackscot
.hear actions
(aka "listeners"): actions that evaluated for a match on every message thatslackscot
hears. You'll want to make sure yourMatch
function isn't too heavy. An example is the "famous" finger quoter plugin
-
Experimental and subject to change: Testing functions to help validate plugin action behavior (see example in triggerer_test.go). Testing functions are found in assertplugin and assertanswer
-
Built-in
help
plugin supporting a decently formatted help message as a command listing all plugins' actions. If you'd like some actions to not be shown in the help, you can setHidden
totrue
in itsActionDefinition
(especially useful forhear actions
) -
The plugin interface as a logical grouping of one or many
commands
andhear actions
and/orscheduled actions
-
Support for injected services providing plugins easy access to an optionally caching
user info
and alogger
.
slackscot
deleting a triggered reaction after seeing a message updated that caused the first action to not trigger anymore and a new action to now trigger (it makes sense when you see it)
slackscot
updating a triggered reaction after seeing a triggering message being updated
slackscot
deleting a reaction after seeing the triggering message being deleted
slackscot
threaded replies enabled (withbroadcast => on
)
The first concrete bot implementation using this code was youppi, named after the great mascot of the Montreal Expos and, when the Expos left Montreal, the Montreal Canadiens.
Slackscot
is a variation on the expected theme of slackbot with the
implication that this is the core to more than just a regular bot
.
You know, a friendly company mascot that hangs out on your slack
.
-
Commands
: commands are well-defined actions with a format.Slackscot
handles all direct messages as implicit commands as well as@mention <command>
on channels. Responses to commands are directed to the person who invoked it. -
Hear actions
: those are listeners that can potentially match on any message sent on channels thatslackscot
is a member of. This can include actions that will randomly generate a response. Note that responses are not automatically directed to the person who authored the message triggering the response (although an implementation is free to use the user id of the triggering message if desired).
Slackscot
provides the pieces to make your mascot but you'll have to
assemble them for him/her to come alive. The easiest to get started is
to look at a real example: youppi.
The godoc is also a good reference especially if you're looking to implement something like a new implementation of the storer interfaces.
Here's an example of how youppi does it (apologies for the verbose and repetitive error handling when creating instances of plugins but it looks worse than it is):
package main
import (
"github.com/alexandre-normand/slackscot"
"github.com/alexandre-normand/slackscot/config"
"github.com/alexandre-normand/slackscot/plugins"
"github.com/alexandre-normand/slackscot/store"
"github.com/spf13/viper"
"gopkg.in/alecthomas/kingpin.v2"
"log"
"os"
)
var (
configurationPath = kingpin.Flag("configuration", "The path to the configuration file.").Required().String()
logfile = kingpin.Flag("log", "The path to the log file").OpenFile(os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
)
const (
storagePathKey = "storagePath" // Root directory for the file-based leveldb storage
name = "youppi"
)
func main() {
kingpin.Version(VERSION)
kingpin.Parse()
v := config.NewViperWithDefaults()
// Enable getting configuration from the environment, especially useful for the slack token
v.AutomaticEnv()
// Bind the token key config to the env variable SLACK_TOKEN (case sensitive)
v.BindEnv(config.TokenKey, "SLACK_TOKEN")
v.SetConfigFile(*configurationPath)
err := v.ReadInConfig()
if err != nil {
log.Fatalf("Error loading configuration file [%s]: %v", *configurationPath, err)
}
// Do this only so that we can get a global debug flag available to everything
viper.Set(config.DebugKey, v.GetBool(config.DebugKey))
options := make([]slackscot.Option, 0)
if *logfile != nil {
options = append(options, slackscot.OptionLogfile(*logfile))
}
youppi, err := slackscot.New("youppi", v, options...)
if err != nil {
log.Fatal(err)
}
if !v.IsSet(storagePathKey) {
log.Fatalf("Missing [%s] configuration key in the top value configuration", storagePathKey)
}
storagePath := v.GetString(storagePathKey)
strStorer, err := store.NewLevelDB(name, storagePath)
if err != nil {
log.Fatalf("Opening [%s] db failed with path [%s]", name, storagePath)
}
defer strStorer.Close()
karma := plugins.NewKarma(strStorer)
youppi.RegisterPlugin(&karma.Plugin)
fingerQuoterConf, err := config.GetPluginConfig(v, plugins.FingerQuoterPluginName)
if err != nil {
log.Fatalf("Error initializing finger quoter plugin: %v", err)
}
fingerQuoter, err := plugins.NewFingerQuoter(fingerQuoterConf)
if err != nil {
log.Fatalf("Error initializing finger quoter plugin: %v", err)
}
youppi.RegisterPlugin(&fingerQuoter.Plugin)
emojiBannerConf, err := config.GetPluginConfig(v, plugins.EmojiBannerPluginName)
if err != nil {
log.Fatalf("Error initializing emoji banner plugin: %v", err)
}
emojiBanner, err := plugins.NewEmojiBannerMaker(emojiBannerConf)
if err != nil {
log.Fatalf("Error initializing emoji banner plugin: %v", err)
}
defer emojiBanner.Close()
youppi.RegisterPlugin(&emojiBanner.Plugin)
ohMondayConf, err := config.GetPluginConfig(v, plugins.OhMondayPluginName)
if err != nil {
log.Fatalf("Error initializing oh monday plugin: %v", err)
}
ohMonday, err := plugins.NewOhMonday(ohMondayConf)
if err != nil {
log.Fatalf("Error initializing oh monday plugin: %v", err)
}
youppi.RegisterPlugin(&ohMonday.Plugin)
versioner := plugins.NewVersioner("youppi", VERSION)
youppi.RegisterPlugin(&versioner.Plugin)
err = youppi.Run()
if err != nil {
log.Fatal(err)
}
}
You'll also need to define your configuration for the core
, used
built-in plugins and any configuration required by your own custom plugins
(not shown here). Slackscot
uses
viper for loading configuration
which means that you are free to use a different file format
(yaml
, toml
, env variables
, etc.) as desired.
{
"token": "your-slack-bot-token",
"debug": false,
"responseCacheSize": 5000,
"timeLocation": "America/Los_Angeles",
"storagePath": "/your-path-to-bot-home",
"replyBehavior": {
"threadedReplies": true,
"broadcast": true
},
"plugins": {
"ohMonday": {
"channelIDs": ["slackChannelId"]
},
"fingerQuoter": {
"frequency": "100",
"channelIDs": []
},
"emojiBanner": {
"figletFontUrl": "http://www.figlet.org/fonts/banner.flf"
}
}
}
It might be best to look at examples in this repo to guide you through it:
- The simplest plugin with a single
command
is the versioner - One example of
scheduled actions
is oh monday - One example of a mix of
hear actions
/commands
that also uses thestore
api for persistence is the karma
- Fork it (preferrably, outside the
GOPATH
as per the new go modules guidelines) - Make your changes, commit them (don't forget to
go build ./...
andgo test ./...
) and push your branch to your fork - Open a PR and fill in the template (you don't have to but I'd appreciate context)
- Check the
code climate
andtravis
PR builds. You might have to fix things and there's no shame if you do. I probably won't merge something that doesn't passCI
build but I'm willing to help to get it to pass 🖖.
slackscot
uses Norberto Lopes's
Slack API Integration found at
https://github.com/nlopes/slack. The core
functionality of the bot is previously used
James Bowman's
Slack RTM API integration and
was heavily inspired by talbot,
also written by James Bowman.