Awesome Open Source
Awesome Open Source

slack-webhook-cli

The easiest way to send messages to a Slack channel or user through an Incoming Webhook.

TL;DR

Watch this video

Installation

Using pip:

$ pip install slack-webhook-cli

From source:

$ git clone https://github.com/philippbosch/slack-webhook-cli.git
$ cd slack-webhook-cli
$ python setup.py install

Prerequisites

You need to create and configure an incoming webhook here. Grab the URL from the Webhook URL field.

Usage

I'll let the script speak for itself:

$ slack -h

usage: slack [-h] [-w WEBHOOK_URL] [-c CHANNEL] [-u USERNAME] [-i ICON_URL]
             [-e ICON_EMOJI] [-a] [-C COLOR] [-t TITLE] [-d]
             text

positional arguments:
  text                  message you want to get delivered. wrap in quotes if
                        it contains spaces.

optional arguments:
  -h, --help            show this help message and exit
  -w WEBHOOK_URL, --webhook-url WEBHOOK_URL
                        webhook URL to use. if not given, the
                        SLACK_WEBHOOK_URL environment variable needs to be set
  -c CHANNEL, --channel CHANNEL
                        channel the message should be sent to. can also be set
                        using the SLACK_CHANNEL environment variable. if not
                        given, the channel configured for this webhook URL
                        will be used.
  -u USERNAME, --username USERNAME
                        username that should be used as the sender. can also
                        be set using the SLACK_USERNAME environment variable.
                        if not given, the username configured for this webhook
                        URL will be used.
  -i ICON_URL, --icon-url ICON_URL
                        URL of an icon image to use. can also be set using the
                        SLACK_ICON_URL environment variable.
  -e ICON_EMOJI, --icon-emoji ICON_EMOJI
                        Slack emoji to use as the icon, e.g. `👻`. can
                        also be set using the SLACK_ICON_EMOJI environment
                        variable.
  -a, --attachment      send message as a rich attachment
  -C COLOR, --color COLOR
                        set the attachment color
  -t TITLE, --title TITLE
                        set the attachment title
  -d, --dump-json       do not post request but just print json body and exit

Examples

$ slack "Hello from the command line"
$ slack -c \#random "something totally random"
$ slack -u hamlet "to be or not to be"
$ slack -e 👻 "boo"

You can also pass in the message through stdin like this:

$ echo Hello there | slack
$ uptime | slack
$ slack < /path/to/file.txt

License

MIT



Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (840,414
Command Line (131,806
Slack (13,009
Webhook (8,958