Slack notifier with support of Slack's BlockKit
2.3K
https://github.com/trestini/slack-notify
Slack-Notify is a very simple tool for sending a Slack notification via a Slack Incoming Webhook.
It is designed to function as a 12-factor app, receiving configuration via environment variables. To keep things simple, it is rigid in what it allows you to set. More complex slackbots might want to customize this a little more.
This is a fork of https://github.com/krom/slack-notify
This tool uses Slack Incoming Webhooks to send a message to your slack channel.
Before you can use this tool, you need to log into your Slack account and configure this.
Note: Webhooks configured through Slack Apps cannot override some parameters as Channel, Icon, color or User name. These will be inherrited from the slack app.
Instead using plain text messages, is possible to use variable SLACK_BLOCKS and pass the blocks to compose a more user friendly message. Blocks can be built using Slack's block kit builder, on
https://app.slack.com/block-kit-builder.
Running slack-notify in a shell prompt goes like this:
$ export SLACK_WEBHOOK=https://hooks.slack.com/services/Txxxxxx/Bxxxxxx/xxxxxxxx
$ export SLACK_BLOCKS="[{\"type\": \"header\",\"text\": {\"type\": \"plain_text\",\"text\": \"This is a title\"}},{\"type\": \"divider\"},{\"type\": \"section\",\"text\": {\"type\": \"mrkdwn\",\"text\": \"This is the text body"}}]"
$ slack-notify
Running the Docker container goes like this:
$ export SLACK_WEBHOOK=https://hooks.slack.com/services/Txxxxxx/Bxxxxxx/xxxxxxxx
$ docker run -e SLACK_WEBHOOK=$SLACK_WEBHOOK -e SLACK_MESSAGE="plain text hello" -e SLACK_CHANNEL=acid trestini/slack-notify
.gitlab-ci.yml
You may to setup variables via CI/CD variables
stages:
- notify
variables:
SLACK_WEBHOOK: https://hooks.slack.com/services/Txxxxxx/Bxxxxxx/xxxxxxxx
notify:
stage: notify
image: trestini/slack-notify:latest
script:
- 'SLACK_MESSAGE="Message" slack-notify'
# The Slack-assigned webhook
SLACK_WEBHOOK=https://hooks.slack.com/services/Txxxxxx/Bxxxxxx/xxxxxxxx
# A URL to an icon
SLACK_ICON=http://example.com/icon.png
# The channel to send the message to (if omitted, use Slack-configured default)
SLACK_CHANNEL=example
# The title of the message
SLACK_TITLE="Hello World"
# The body of the message
SLACK_MESSAGE="Today is a fine day"
# RGB color to for message formatting. (Slack determines what is colored by this)
SLACK_COLOR="#efefef"
# The name of the sender of the message. Does not need to be a "real" username
SLACK_USERNAME="Bot"
# Body message based on BlockKit instead a plain message. It should be a escaped JSON string with the `blocks` array, not `blocks` object.
SLACK_BLOCKS="[{\"type\": \"header\",\"text\": {\"type\": \"plain_text\",\"text\": \"This is a title\"}},{\"type\": \"divider\"},{\"type\": \"section\",\"text\": {\"type\": \"mrkdwn\",\"text\": \"This is the text body"}}]"
Compile:
make build
Publish to DockerHub
make docker-build docker-push
Content type
Image
Digest
Size
4.8 MB
Last updated
about 5 years ago
docker pull trestini/slack-notify