Package: slack-cli
⚠️ THIS PROJECT IS IN MAINTENANCE MODE. I have lost interest in Slack – actually, the less I use Slack the better I feel. Thus I do not have the time nor the energy to make slack-cli compatible with the new Slack authentication mechanism. I will happily review and merge pull requests, though 🙂 If a contributor would like to step forward and start fixing issues, I could then transfer ownership of the project (after they have demonstrated proficiency and integrity).Effectively interact withSlackfrom the command line: send messages, upload files, send command output, pipe content… all from the confort of your terminal.Member of dozens of Slack teams? No worries, withslack-cliyou can easily switch from one team to another.Quickstart$ pip install slack-cli
$ slack-cli -d general "Hello everyone!"You will be asked to provide a Slack API token. It’s easy, check out theTokenssection for a quickstart.Usage$ slack-cli -h
usage: slack-cli [-h] [-t TOKEN] [-T TEAM] [-d DST] [-f FILE] [--pre] [--run]
                 [-u USER] [-s SRC] [-l LAST]
                 [messages [messages ...]]

Send, pipe, upload and receive Slack messages from the CLI

optional arguments:
  -h, --help            show this help message and exit
  -t TOKEN, --token TOKEN
                        Explicitly specify Slack API token which will be
                        saved to /home/user/.config/slack-cli/slack_token.
  -T TEAM, --team TEAM  Team domain to interact with. This is the name that
                        appears in the Slack url: https://xxx.slack.com. Use
                        this option to interact with different teams. If
                        unspecified, default to the team that was last used.

Send messages:
  -d DST, --dst DST     Send message to a Slack channel, group or username
  -f FILE, --file FILE  Upload file
  --pre                 Send as verbatim `message`
  --run                 Run the message as a shell command and send both the
                        message and the command output
  -u USER, --user USER  Send message not as the current user, but as a bot
                        with the specified user name
  messages              Messages to send (messages can also be sent from
                        standard input)

Receive messages:
  -s SRC, --src SRC     Receive messages from a Slack channel, group or
                        username. This option can be specified multiple times.
                        When streaming, use 'all' to stream from all sources.
  -l LAST, --last LAST  Print the last N messages. If this option is not
                        specified, messages will be streamed from the
                        requested sources.Sending messagesThe destination argument may be any user, group or channel:$ slack-cli -d general "Hello everyone!"
$ slack-cli -d slackbot "Hello!"Send message with a different username:$ slack-cli -d general -u terminator "I'll be back"Update status$ slack-cli -d general "/status :office: In the office"
$ slack-cli -d general "/status :house: At home"
$ slack-cli -d general "/status Just chillin'"
$ slack-cli -d general "/status clear"Pipe content from stdin$ cat /etc/hosts | slack-cli -d devteamUsually you will want to format piped content as verbatim content with triple backticks (”```”). This is achieved with the--preoption:$ tail -f /var/log/nginx/access.log | slack-cli -d devteam --preUpload file$ slack-cli -f /etc/nginx/sites-available/default.conf -d aliceRun command and send outputThis is really convenient for showing both the result of a command and the command itself:$ slack-cli -d john --run "git log -1"will send to userjohn:$ git log -1
commit 013798f5c85043d31f0221a9a32b39298e97fb08
Author: Régis Behmo <regis@behmo.com>
Date:   Thu Jun 22 15:20:36 2017 +0200

    Replace all commands by a single command

    Our first 1.0 release!Receiving messagesStream to stdoutStream the content of a channel:$ slack-cli -s generalMonitor all conversations:$ slack-cli -s allDump (backup) the content of a channel$ slack-cli -s general --last 10000 > general.log
$ slack-cli -s myboss --last 10000 > covermyass.logAuthenticationSwitch to a different teamSwitch to a different team anytime with the-Tflag:$ slack-cli -T family -d general "I'll be home in an hour"The new team will become the new default team.Token managementNote that the Slack token may optionally be stored in an environment variable (although it is not recommendedfor security reasons):$ export SLACK_TOKEN="slack_token_string"Theslack-cliconfiguration is stored in a generic configuration directory – by default, this is ~/.config/slack-cli on Linux. You can check the path of this directory by running:python3 -c "from slackcli.token import CONFIG_ROOT; print(CONFIG_ROOT)"This directory can be modified by setting theSLACK_CLI_CONFIG_ROOTenvironment variable. For instance:export SLACK_CLI_CONFIG_ROOT=~/slackcliBells and Whistles ᕕ(⌐■_■)ᕗ ♪♬AutocompleteChannel, group and user names can be autocompleted from the command line forbashusers. Add the following line to~/.bashrc:eval "$(register-python-argcomplete slack-cli)"Then, try autocompletion with:$ slack -s gene<tab>or:$ slack -d <tab><tab>Unfortunately, I did not manage to get autocompletion to work withzsh¯\_( ͡° ͜ʖ ͡°)_/¯ Please let me know if you have more success.ColorsColor output is activated by default in compatible terminals. To deactivate colors, define theSLACK_CLI_NO_COLORenvironment variable:export SLACK_CLI_NO_COLORS=1EmojisEmoji short codes will be automatically replaced by their corresponding unicode value. For instance,:smile:will become 😄. However,these characters will display properly only if your terminal supports them!I stronly encourage you to download patched fonts fromNerd Fontsand to configure your terminal to use them. For instance, in Ubuntu this is how I downloaded the DejaVuSansMono fonts:wget -O ~/.fonts/DejaVuSansMono.zip https://github.com/ryanoasis/nerd-fonts/releases/download/v2.0.0/DejaVuSansMono.zip
cd ~/.fonts
unzip DejaVuSansMono.zip
fc-cache -vf ~/.fontsIf emojis are not your thing, you can disable them globally with theSLACK_CLI_NO_EMOJIenvironment variable:export SLACK_CLI_NO_EMOJI=1TokensTo generate a token, create anew Slack Appand add it to your workspace.Grant API Permissions to your App, select all that apply (you probably want “chat:write”):This is an example of how it could look like:Now hit the greenInstall App to workspacebutton, and you will be presented with a token you can use for authentication.DevelopmentContributionsI am very much open to comments! Please don’t be afraid toraise issuesoropen pull requests.This work is licensed under the terms of theMIT LicenseNote that this project was initially a fork ofslacker-clibut the two projects have now considerably diverged.TestsInstall the development requirements:pip install -e .[development]Run all tests:make testFormat your code withblack:make formatUpdate emojispython -c "from slackcli.emoji import Emojis; Emojis.download()"