Skip to content
Slack clients in golang
Go
Branch: master
Clone or download
ajm188 Merge pull request #33 from ajm188/plugins
adding interface and standardizing plugin workflow
Latest commit 042dd4d Feb 26, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
plugins/github closes #28. appends a message identifying who submitted the issue Feb 22, 2016
.codeclimate.yml set up codeclimate Feb 18, 2016
.travis.yml run all tests Feb 20, 2016
LICENSE Initial commit Jan 29, 2016
README.md all the badges Feb 18, 2016
api.go starting to add docs for Error and some functions Jan 31, 2016
api_test.go add tests for some private functions Feb 17, 2016
bot.go add struct to represent more info about users Feb 22, 2016
bot_action.go add comment for BotAction type Jan 31, 2016
bot_test.go store reconnect URL and reconnect when migration occurs. closes #17 Feb 18, 2016
direct_message.go handle case where user may not actually exist Feb 22, 2016
direct_message_test.go silence the logging from this test Feb 20, 2016
doc.go write a whole bunch of docs Feb 2, 2016
error.go starting to add docs for Error and some functions Jan 31, 2016
error_test.go move tests back into "slack" package, so coverage works Feb 17, 2016
event.go better slice usage, and implicit return. closes #21 Feb 19, 2016
event_test.go more handling tests Feb 18, 2016
listen.go remove more redundancy Feb 18, 2016
listen_test.go finally got internet, stop using integer value Feb 18, 2016
mention.go finish the rest of the docs Jan 31, 2016
mention_test.go slight refactoring, more helper functions for comparing messages Feb 17, 2016
message.go finish the rest of the docs Jan 31, 2016
message_test.go slight refactoring, more helper functions for comparing messages Feb 17, 2016
plugin.go adding interface and standardizing plugin workflow Feb 24, 2016
plugin_test.go adding interface and standardizing plugin workflow Feb 24, 2016
react.go finish the rest of the docs Jan 31, 2016
respond.go remove more redundancy Feb 18, 2016
respond_test.go finally got internet, stop using integer value Feb 18, 2016
status.go rename status enumeration according to golint; add docs for Status Jan 31, 2016
time.go flesh out more details of Messages Jan 31, 2016
user.go bugfix. docs say things inside "profile" may be not present or nil Feb 22, 2016
user_test.go add tests and fix minor bug in user FullName Feb 22, 2016

README.md

slack

Build Status Coverage Status GoDoc Go Report Card

Issue Stats Issue Stats

Installation

go get github.com/ajm188/slack

Usage

Starting the Bot

package main

import (
    "fmt"

    "github.com/ajm188/slack"
)

func main() {
    bot := slack.NewBot("my_slack_token")
    err := bot.Start()
    if err != nil {
        fmt.Println(err)
    }
}

Note that you need to pass your Slack token to the bot, so your bot can authenticate with the Slack API.

Simple Response

The design of slack is built around a handler pattern. The bot listens for incoming events from the Slack RTM API, and then invokes any handlers for that type of event.

A valid handler takes a reference to the bot and the event and returns a reference to a Message, and a Status, which tells the main loop whether or not to continue interacting with the RTM API.

slack has some factory methods for constructing handlers for common operations, such as responding to a message or posting a reaction to a message. If you need something more fine-grained, feel free to write your own.

There are also convenience methods for registering handlers specifically for "message" type events. The Bot defines instance methods Listen - which finds text that matches the given pattern - and Respond which finds text that first mentions the bot by name and then matches the given pattern. These helper methods have Regexp variants which can take a compiled regular expression directly instead of a string.

package main

// ... imports blah, blah

func main() {
    bot := slack.NewBot("")
    bot.Respond("hi!", slack.Respond("hi!"))
    bot.Start()
}

Adding a Reaction

package main

// imports

func main() {
    bot := slack.NewBot("")
    bot.Listen("ship ?it\\?", slack.React("shipit"))
    bot.Start()
}

Logging

slack uses logrus for logging. Feel free to set your log level appropriately in an init function.

You can’t perform that action at this time.