An HTTP gateway for posting to Slack.
2.3K
With a single HTTP request, you can post a message, creating the channel first if it doesn't exist and invite people and groups.
Runs as a server, listening for an HTTP request. Upon receipt of a message, the gateway:
This removes the complexity of orchestrating many Slack API calls behind a simple endpoint.
If you'd like to run Slack Gateway yourself as a Docker container, you can do the following:
docker run -d \
--env SLACK_USER_TOKEN="CHANGEME" \
--env SLACK_CHANNEL_MEMBERS="jsmith,mjones" \
--publish 8080:8080 \
outofcoffee/slack-gateway
Note: See the Environment variables section for the available configuration settings.
Send a message to a channel:
curl http://localhost:8080/messages/raw \
--header "Content-Type: application/json" \
--data '{"channel":"general", text":"Hello World!"}'
Send a message with attachments:
curl http://localhost:8080/messages/raw \
--header "Content-Type: application/json" \
--data '{"channel":"general", text":"Hello World!","attachments":[{"text":"More info","color":"#33ee33"}]}'
For more information on the Slack post message format, see https://api.slack.com/
If you don't want to compose the JSON yourself, you can use a simpler, but slightly more limited, key-value format instead.
Send a message to a channel:
curl http://localhost:8080/messages/text \
--data 'channel=general' \
--data 'text=Hello%20World!'
Send a message as an attachment:
curl http://localhost:8080/messages/text \
--data 'channel=general' \
--data 'text=Hello%20World!' \
--data 'title=Attachment' \
--data 'attachment=true' \
--data 'color=00ff00'
The example above will send the text message as an attachment, with a particular colour and title.
The available options for the key-value format are:
| Key | Required | Type | Purpose |
|---|---|---|---|
| channel | Yes | String | Channel name |
| text | Yes, unless additional message keys used | String | Literal message text |
| attachment | No | Boolean | Whether to send in attachment mode |
| title | No | String | Attachment title |
| color | No | String | Attachment color |
| author_name | No | String | Attachment author name |
| title_link | No | String | Attachment title link URL |
| footer | No | String | Attachment footer text |
| footer_icon | No | String | Attachment footer icon URL |
| Additional message keys | No, unless text is empty | String | See below |
When using the key-value format, any additional keys are appended to the text message. For example:
curl http://localhost:8080/messages/text \
--data 'channel=general' \
--data 'key_one=foo' \
--data 'key_two=bar' \
--data 'key_three=baz'
This will result in message text such as the following:
key one: *foo* | key two: *bar* | key three: *baz*
Note that underscores in key names are replaced with spaces, and the values are emboldened.
You can specify the channel type as public or private. This will be used when creating channels, or posting messages.
Set the channel_type query parameter in the HTTP request, or use the DEFAULT_CREATE_CHANNEL_TYPE environment variable.
Valid values:
Example using the query parameter:
curl http://localhost:8080/messages/text \
--data 'channel=some-private-channel' \
--data 'text=Hello%20world' \
--data 'channel_type=private'
As a Slack admin, create a Slack app: https://api.slack.com/apps/new
Add a bot user in the 'Bot Users' section:
https://api.slack.com/apps/<your app ID>/bots
Add the required scopes in the 'OAuth & Permissions' section:
https://api.slack.com/apps/<your app ID>/oauth
The scopes are:
chat:write:bot
channels:read
channels:write
groups:read
groups:write
users:read
usergroups:read
Don't forget to save changes after adding scopes.
Install your app to your workspace. This will generate two tokens.
Copy the 'OAuth Access Token' and set it as the SLACK_USER_TOKEN. It should look like this:
xoxp-123456789012-123456789012-123456789012-abcdef1234567890abcdef1234567890
Copy the 'Bot User OAuth Access Token' and set it as the SLACK_BOT_TOKEN. It should look like this:
xoxb-123456789012-123456789012-abcdef1234567890abcdef1234567890
Don't forget to invite your app to any existing private channels, using:
/invite @YourAppName
Slack doesn't permit apps to post to channels unless they have permissions.
Configure the bot using the following environment variables.
Content type
Image
Digest
sha256:b644ba5a4…
Size
102.4 MB
Last updated
over 3 years ago
docker pull outofcoffee/slack-gateway