This simple script aims to ease the sending of Slack messages from CLI, and specially from (scripted) automated processes.
post_to_slack --text="This is a test!" --botname="My bot" --icon="robot_face" --channel="#general"
- A Slack team, of course
- Bash
- curl
- Clone this repository to your computer
git clone [email protected]:elamperti/shlack.git
- Go to your Slack team's Apps & Integrations and add "Incoming WebHooks".
- Add a configuration for Incoming WebHooks. You can override some of this settings later (see Syntax).
- In the following page, copy the Webhook URL (
https://hooks.slack.com/services/…
) and paste it into a file named.slack-hook
in the folder from where Shlack will be called. - See Usage section to learn how to post messages.
The .slack-hook
will be read from the current directory, which may be different from where Shlack is sourced.
This enables you to use different URLs for different teams or situations according to the context (the directory) where it's being used.
The script can be sourced or called directly (e.g. $ shlack.sh --text "Hello world"
).
If you source it, use post_to_slack
to post messages to Slack.
The following options are available:
--text
: The message to post. If omitted will try to use stdin.--hook
: Slack hook URL. Overrides theSLACK_URL
environment variable and.slack-hook
file.--channel
: Channel or username. Defaults to the channel defined in the hook configuration.--botname
: The displayed nickname for the bot. Defaults to the name defined in the hook configuration.--icon_url
: URL to an image to use as icon for the message.--icon
: Emoji to use as icon; colons around it aren't required. Overridesicon_url
. Defaults to the icon defined in the hook configuration.--debug
: Prints hook URL and payload to stdout instead of posting to Slack.--silent
: Response won't be printed to stdout.--no-markdown
: Tells Slack the message must not be formatted as Markdown.
If a message wasn't defined using --text
, Shlack will wait for input on stdin only for 2 seconds, otherwise the script would hang forever when stdin is empty.
Tests are written in Bats, run bats test
to execute them.
Copyright (C) 2016 Enrico Lamperti GNU GPL v2, see LICENSE file for more information.