Slash Command handler for Slack, written in Go.
Go
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ci
cmd/goulash
goulashfakes
manifests
slackapi
.cfignore
.gitignore
LICENSE
README.md
action.go
audit_log.go
auth_wrapper.go
command_server.go
errors.go
finder.go
glide.lock
glide.yaml
goulash_suite_test.go
groups.go
guestify.go
handler.go
handler_test.go
help.go
request_context.go
restrictify.go
user_converter.go

README.md

Goulash

Goulash is a way to drive Slack's API through Slash Commands.

Slack currently only has browser-based interface for inviting a single- or multi-channel guest to a channel. @levels.io did a write-up on how he solved the problem of programmatically inviting people to a channel. This project takes that idea and implements a similar solution using Slash Commands to perform specific levels of invites.

With this handler you can, through a Slash Command:

  • Invite someone as a single- or multi-channel guest your Slack team, with an initial channel
  • Find out if a user in your Slack team exists for a particular email address or username, and what type of user they are
  • Disable single- and multi-channel guests via email or username
  • List the private groups that the configured bot user is in
  • Convert a multi-channel guest to a single-channel guest
  • Convert a single-channel guest to a multi-channel guest

Requirements

Goulash is written in Go. See Go's Getting Started documentation if you don't already have it installed. Goulash has been tested in go1.4.2 darwin/amd64 and go1.4.2 linux/amd64.

Additionally, Goulash uses glide for dependency management. If you plan to deploy it to Cloud Foundry, you'll need glide:

$ curl https://glide.sh/get | sh

Usage

Get the source:

$ go get -t github.com/pivotalservices/goulash/...

// If you plan on deploying to Cloud Foundry
$ cd $GOPATH/src/github.com/pivotalservices/goulash
$ glide install

Configure a new Slash Command on Slack:

Create a new Slash Command.

This Slash Command should point at the endpoint Goulash is reachable at.

Set up your environment (or use the command line flags):

See descriptions below.

$ export SLACK_AUTH_TOKEN=xoxp-0000000000-0000000000-0000000000-000000
 
// Optional
$ export SLACK_AUDIT_LOG_CHANNEL_ID=G00000000
$ export UNINVITABLE_DOMAIN=example.com
$ export UNINVITABLE_DOMAIN_MESSAGE="Invites for this domain are forbidden."
$ export CONFIG_SERVICE_NAME=config-service

|Name|Required|Description| |---|---|---|---| |SLACK_AUTH_TOKEN|yes|The token of the user to use for inviting. This user must be an admin. |SLACK_SLASH_MESSAGE_TOKEN|yes|The token associated with the configured slash message. |PORT|no|The port to listen on. Defaults to 8080. |SLACK_AUDIT_LOG_CHANNEL_ID|no|ID of channel to use as audit log. See note below. |UNINVITABLE_DOMAIN|no|Email addresses with this domain will be prohibited from being invited. |UNINVITABLE_DOMAIN_MESSAGE|no|The message to show a user when they try to invite someone from an uninvitable domain. |CONFIG_SERVICE_NAME|no|The name of a Cloud Foundry User-Provided Service that will provide the Slack auth token and/or Slack slash message token.

You can get the ID of a channel by clicking its name from within Slack, and then choosing "Add a service integration". The ID is at the end of the URL.

Build and run Goulash:

$ cd $GOPATH/src/github.com/pivotalservices/goulash
$ go build -o goulash cmd/goulash/main.go
$ ./goulash

Running on Cloud Foundry

Goulash can be run on Cloud Foundry without making any changes as it is already set up to listen on PORT. Simply set your environment via cf set-env with all of the required environment variables above (except PORT, of course), and cf push the app:

$ cf push your-app-name -b https://github.com/cloudfoundry/go-buildpack.git

Don't have your own Cloud Foundry? Take a look at Pivotal Web Services.

Using a Cloud Foundry User-Provided Service for Slack Auth Token Storage

If you're using Cloud Foundry, you may choose to use a User-Provided Service to store your Slack auth token. Follow the same steps to configure the Slack slash message token, which will be used to validate incoming requests.

First, create the user-provided service and bind it to your app:

$ cf create-user-provided-service your-service-name -p "slack-auth-token, slack-slash-message-token"
$ cf bind-service your-app-name your-service-name

Create an app environment variable, CONFIG_SERVICE_NAME, that contains the name of the service, and remove the old ones:

$ cf set-env your-app-name CONFIG_SERVICE_NAME=your-service-name
$ cf unset-env your-app-name SLACK_AUTH_TOKEN
$ cf unset-env your-app-name SLACK_SLASH_MESSAGE_TOKEN

Restage the app to apply the changes:

$ cf restage your-app-name

Contributing

Pull requests are welcomed. Any PR must include test coverage.

$ cd $GOPATH/src/github.com/pivotalservices/goulash
$ ginkgo -r -p -randomizeAllSpecs

Before submitting a PR it is recommended to use Concourse and its fly tool to run tests in an isolated environment:

$ vagrant init concourse/lite
$ vagrant up
$ cd $GOPATH/src/github.com/pivotalservices/goulash
$ fly --target "http://192.168.100.4:8080" execute --config ci/unit.yml

Maintainers