Git Product home page Git Product logo

slack-cli's Introduction

slack-cli | Powerful Slack CLI via pure bash

version versioning branching license circleci

A pure bash, pipe friendly, feature rich, command line interface for Slack. Richly formatted messages, file uploads, and even creating Slack posts are first class constructs. Deep integration with jq allows for the ability to perform advanced operations upon JSON responses, helping you perform complex queries and pipe chaining with ease.

Simple chat example:

$ slack chat send hi @slackbot

100% Slack-based pomodoro example:

$ alias pomodoro='f() { slack status edit --text="Pomodoro" --emoji=":tomato:" && slack snooze start --minutes="${1-60}" && slack reminder add "Pomodoro done!" $(date -v +${1-60}M "+%s") }; f'
$ pomodoro 60

Pipe chaining example:

$ # Send a message, update the message, and finally delete the message:
$ slack chat send hello @slackbot --filter '.ts + "\n" + .channel' |
  xargs -n2 slack chat update goodbye --filter '.ts + "\n" + .channel' |
  xargs -n2 slack chat delete

Richly formatted chat example:

$ slack chat send \
  --actions '{"type": "button", "style": "primary", "text": "See results", "url": "http://example.com"}' \
  --author 'author' \
  --author-icon 'https://assets-cdn.github.com/images/modules/logos_page/Octocat.png' \
  --author-link 'https://github.com/rockymadden/slack-cli' \
  --channel '#channel' \
  --color good \
  --fields '{"title": "Environment", "value": "snapshot", "short": true}' \
  --footer 'footer' \
  --footer-icon 'https://assets-cdn.github.com/images/modules/logos_page/Octocat.png' \
  --image 'https://assets-cdn.github.com/images/modules/logos_page/Octocat.png' \
  --pretext 'pretext' \
  --text 'text' \
  --time 123456789 \
  --title 'title' \
  --title-link 'https://github.com/rockymadden/slack-cli'

Installation

Via brew

$ brew tap rockymadden/rockymadden
$ brew install rockymadden/rockymadden/slack-cli

Via curl

$ curl -O https://raw.githubusercontent.com/rockymadden/slack-cli/master/src/slack
$ chmod +x slack

PROTIP: You are responsible for having curl and jq on your PATH.

Via make

$ git clone [email protected]:rockymadden/slack-cli.git
$ cd slack-cli
$ make install bindir=/path/to/bin etcdir=/path/to/etc

PROTIP: You are responsible for having curl and jq on your PATH.

Configuration

If you want to post from your own account, you need a legacy API token which can be found here. If you want to post from a slackbot, create one here. Otherwise, you can create an app with a Slack API token and use said API token one of the following ways:

Via init

$ slack init

Via environment variable

$ export SLACK_CLI_TOKEN='token'

Examples and Recipes

chat send

$ # Send message via prompts:
$ slack chat send
$
$ # Send message via arguments:
$ slack chat send 'Hello world!' '#channel'
$
$ # Send message via options:
$ slack chat send --text 'Hello world!' --channel '#channel'
$
$ # Send message via short form options:
$ slack chat send -tx 'Hello world!' -ch '#channel'
$
$ # Send message via pipe:
$ ls -al | slack chat send --channel '#channel' --pretext 'Directory:' --color good
$
$ # Send message and returning just the timestamp via filter option:
$ slack chat send 'Hello world!' '#channel' --filter '.ts'

PROTIP: See the Slack attachments documentation for more information about option meanings.

chat update

$ # Update message via prompts:
$ slack chat update
$
$ # Update message via arguments:
$ slack chat update 'Hello world, again!' 1405894322.002768 '#channel'
$
$ # Update message via options:
$ slack chat update --text 'Hello world, again!' --timestamp 1405894322.002768 --channel '#channel'
$
$ # Update message via short form options:
$ slack chat update -tx 'Hello world, again!' -ts 1405894322.002768 -ch '#channel'
$
$ # Send message and immediately update:
$ slack chat send 'Hello world!' '#channel' --filter '.ts + "\n" + .channel' |
  xargs -n2 slack chat update 'Goodbye world!'

PROTIP: See the Slack attachments documentation for more information about option meanings.

chat delete

$ # Delete message via prompts:
$ slack chat delete
$
$ # Delete message via arguments:
$ slack chat delete 1405894322.002768 '#channel'
$
$ # Delete message via options:
$ slack chat delete --timestamp 1405894322.002768 --channel '#channel'
$
$ # Delete message via short form options:
$ slack chat delete -ts 1405894322.002768 -ch '#channel'
$
$ # Send message and immediately delete:
$ slack chat send 'Hello world!' '#channel' --filter '.ts + "\n" + .channel' |
  xargs -n2 slack chat delete

file upload

$ # Upload file via prompts:
$ slack file upload
$
$ # Upload file via arguments:
$ slack file upload README.md '#channel'
$
$ # Upload file via options:
$ slack file upload --file README.md --channels '#channel'
$
$ # Upload file via pipe:
$ ls -al | slack file upload --channels '#channel'
$
$ # Upload file with rich formatting:
$ slack file upload README.md '#channel' --comment 'Comment' --title 'Title'
$
$ # Create a Slack post, noting the filetype option:
$ slack file upload --file post.md --filetype post --title 'Post Title' --channels '#channel'

file list

$ # List files:
$ slack file list
$
$ # List files and output only ID and size:
$ slack file list --filter '[.files[] | {id, size}]'

file info

$ # Info about file via prompts:
$ slack file info
$
$ # Info about file via arguments:
$ slack file info F2147483862
$
$ # Info about file via options:
$ slack file info --file F2147483862

file delete

$ # Delete file via prompts:
$ slack file delete
$
$ # Delete file via arguments:
$ slack file delete F2147483862
$
$ # Delete file via options:
$ slack file delete --file F2147483862

presence active

$ # Active presence:
$ slack presence active

reminder list

$ # List reminders:
$ slack reminder list

reminder add

$ # Add reminder via prompts:
$ slack reminder add
$
$ # Add reminder via arguments:
$ slack reminder add 'lunch' 1526995300
$
$ # Add reminder in 10 minutes, via date on macOS, via arguments:
$ slack reminder add 'lunch' $(date -v +10M "+%s")
$
$ # Add reminder via options:
$ slack reminder add --text="lunch" --time=1526995300

reminder complete

$ # Complete reminder via prompts:
$ slack reminder complete
$
$ # Complete reminder via arguments:
$ slack reminder complete Rm7MGABKT6
$
$ # Complete reminder via options:
$ slack reminder complete --reminder="Rm7MGABKT6"

reminder delete

$ # Complete reminder via prompts:
$ slack reminder delete
$
$ # Complete reminder via arguments:
$ slack reminder delete "Rm7MGABKT6"
$
$ # Complete reminder via options:
$ slack reminder delete --reminder="Rm7MGABKT6"

reminder info

$ # Info about reminder via prompts:
$ slack reminder info
$
$ # Info about reminder via arguments:
$ slack reminder info "Rm7MGABKT6"
$
$ # Info about reminder via options:
$ slack reminder info --reminder="Rm7MGABKT6"

presence away

$ # Away presence:
$ slack presence away

snooze start

$ # Start snooze via prompts:
$ slack snooze start
$
$ # Start snooze via arguments:
$ slack snooze start 60
$
$ # Start snooze via options:
$ slack snooze start --minutes 60
$
$ # Start snooze via short form options:
$ slack snooze start -mn 60

snooze info

$ # Info about your own snooze:
$ slack snooze info
$
$ # Info about another user's snooze via argument:
$ slack snooze info @slackbot
$
$ # Info about another user's snooze via options:
$ slack snooze info --user @slackbot
$
$ # Info about another user's snooze via short form options:
$ slack snooze info -ur @slackbot

snooze end

$ # End snooze:
$ slack snooze end

status edit

$ # Edit status:
$ slack status edit
$
$ # Edit status via arguments:
$ slack status edit lunch :hamburger:
$
$ # Edit status via options:
$ slack status edit --text lunch --emoji :hamburger:
$
$ # Edit status via short form options:
$ slack status edit --tx lunch -em :hamburger:

Contributors

A big thank you to the following contributors who have helped add features and/or fixes:

License

The MIT License (MIT)

Copyright (c) 2018 Rocky Madden (https://rockymadden.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

slack-cli's People

Contributors

alyssais avatar bertag avatar funky-monkey avatar haalcala avatar leehuffman avatar nharsch avatar raine avatar rockymadden avatar travismcchesney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-cli's Issues

Error on delete function

Hi,

I'm trying to delete messages with your great script but it saying channel_not_found.

./slack chat delete "1546300800" "#test"

I confirm that the follow command is working perfectly...

./slack chat send "hi" "#test"

Any idea why?

Thanks

Is this project maintained anymore

Hello, This is a great tool. I found it to be very useful. But, the project appears to have stalled. I see 14 PRs still open as of now. Also, I think the tool is currently using a deprecated way of sending messages.

Is this project still active or is there another fork/copy that is actively maintained?

Add support for passing token as argument

We're trying to set up slack-cli as a status updater for all members on our remote team.
For this, we need to pass everyone's token to the CLI, preferably via argument.

What we would like to do:

  • Set up a crontab manager like Cronkeep on our team server
  • Everyone puts her work hours in the crontab
  • We save everyone's token in .env, like SLACK_TOKEN_EMAILALIAS
  • The command for the auto status update would for example be slack status edit --text="Pomodoro" --emoji=":tomato:" --token="SLACK_TOKEN_TEST"

If there is any chance for this to be implemented, we would work on a PR.
Happy for direction where in the script to add the part (At the beginning where you check for the token? Or rather at the command level?)

Load .slack from homedir.

Would be nice to have a .slack file in my home dir.

On our production boxes we could then have slack automatically configured easily by automation and easily send messages.

We could use .bashrc but that's kind of hacky IMO

Hanging in pipe friendliness code on Bamboo CI machines

Hi,

In our Bamboo environment, we are seeing slack ci hang while trying to read from /dev/stdin. I was able to work around this by piping a space into the slack cli command, but was wondering if there is a better solution.

Here are some logs:

16-Nov-2018 00:11:23 + bash -x bin/slack chat send -x -tx 'testing this thing' -ch '#mcore_tools_basement'
16-Nov-2018 00:11:23 +++ dirname bin/slack
16-Nov-2018 00:11:23 ++ cd bin
16-Nov-2018 00:11:23 ++ pwd
16-Nov-2018 00:11:23 + bindir=/Users/bambooagent/AgentHome/xml-data/build-dir/MTS-AS0-JOB1/bin
16-Nov-2018 00:11:23 +++ dirname bin/slack
16-Nov-2018 00:11:23 ++ cd bin
16-Nov-2018 00:11:23 ++ pwd
16-Nov-2018 00:11:23 + etcdir=/Users/bambooagent/AgentHome/xml-data/build-dir/MTS-AS0-JOB1/bin
16-Nov-2018 00:11:23 + '[' -n ******** ']'
16-Nov-2018 00:11:23 + token=********
16-Nov-2018 00:11:23 + cmd=chat
16-Nov-2018 00:11:23 + shift
16-Nov-2018 00:11:23 + case "${cmd}${1}" in
16-Nov-2018 00:11:23 + sub=send
16-Nov-2018 00:11:23 + shift
16-Nov-2018 00:11:23 + case "${cmd}${sub}" in
16-Nov-2018 00:11:23 + '[' -p /dev/stdin ']'
16-Nov-2018 00:11:23 ++ cat
16-Nov-2018 00:31:55 Force Stop build feature is enabled for current plan. Either Bamboo has detected the build has hung or it has been manually stopped.

Status clear command

There seems to be no easy way to script clearing your status from the command line without requiring some user interaction

The following command goes into interactive mode

slack status edit --text '' --emoji ''

The best workaround I have so far is pretty unintuitive and brittle:

printf "\n\n" | slack status edit

Sending private message

Hi, I tried sending a private message but I keep getting a 'channel_not_found' error using the following command:

slack chat send 'Hello world!' @Adel

Note: I can successfully send messages to channel, however i need to send private messages now

Complete error message:
jq: error (at <stdin>:0): Cannot iterate over null (null)
jq: error (at <stdin>:0): Cannot iterate over null (null)
{ "ok": false, "error": "channel_not_found" }

Unable to run via bash shell

I am able to initialize just fine, but I always get Sending: fail when it runs in a bash shell. The same command works fine from the command line, just not from a bash shell. The script I am kicking off is below, including the full output I get...

SCRIPT
export PATH=/usr/local/bin:$PATH;
slack init --channel='sickbeard-results' --token=
slack send 'Starting Sickbeard'

OUTPUT
Initializing: done
Sending: fail

Feature Request: Channel Feed

I very much want a way to keep an important Slack channel open without running a browser or the desktop client. I'm thinking you could invoke something like slack live "#channel" and the CLI would take over the terminal, letting you type new messages in while loading messages at some interval. This may be achievable with standard bash, or could require use of something like ncurses.

I'd be totally excited to help on something like this, if there's interest.

slack-cli autocomplete

I would like to know if there is any autocomplete in this project or if it would be in development

$ slack-cli chat <tab><tab>
send update delete

Send message with different username and/or icon

Hi,

is there any possibility to get a behavior similar to this other slack CLI-tool (https://www.npmjs.com/package/slack-cli), where a message can be sent with a different username and even with a different user-icon?
I think this would be a nice addition, so if I wanted to have a script post something to my slack channel, it would be easier to spot for the other users...
See also this youtube-video for clarification:
https://www.youtube.com/watch?v=WWljTSHRmmU&amp;t=38s

Thank you for your help!

status clearing

within the native client to clear status you can just "/status "

i've tried a bunch of variations with the cli but it seems i need to set a specific emoji?

also, i was trying to use the cli to delete messages but am not sure how to get the timestamp (since it includes finer detail info than what is displayed on the client)

thanks Rocky!

Escaping char on pipe input is inconsistent. Double quotes are not escaped but newlines are.

When you pipe contents to slack cli it will do the proper escaping for newlines yet does not for ".

For now I'm using a sed script to remove it but I'm probably missing other characters?

#try.txt has newlines and some " (double quotes)
 cat try.txt | sed 's/"/\\"/g' | slack chat send --channel '#engineering' --pretext 'Blah:'

I saw #62 where someone explained you have to do the escaping yourself but if that is the case how come newline is handled but double quote is not? Its really confusing because I'm not sure what chars are handled and what isn't.

Feature Request: Add support for threaded conversations

It would be great if a user (me) could send threaded messages

In its simplest form, i believe that it would simply be a case of allowing the user (me) to pass a 'thread_ts' value when posting a message, which would make the message a child of the first message in the thread (assuming that I passed the correct ts) and the thread_broadcast boolean, which (for my use case I would set to true).

I have a slack channel that receives updates from out CI system (using slack-cli). Builds run a series of tests, but as up to 30 builds can be running at once, it would be awesome if I could thread them...

Question: Reading Channels not possible?

Hi, sorry to misuse an issue for a question but didn't see another way in the README.

Is it correct that I can't use this to read messages from a channel? Reading other people's responses would only be possible via private message chats and im.list?

Feature Request: Set Channel Topic

Is it possible to set the channel topic? I can't find it if it is.
I tried
slack chat send "/topic test topic"
but that sends the literal text.

Don't put .slack in 'etcdir'

I just looked at the source you're putting the configuration file in the installation dir of the script.

Is this a bug?

My .slack shouldn't be in /usr/bin...

if anything it should be in /etc/ for system wide installs.

slack init errors out on my mac

When I try to run slack init with my slack bot token I get the following output:
/usr/local/bin/slack: line 522: /usr/local/etc/slack-cli/.slack: No such file or directory { "ok": false, "error": "not_writable" }

Feature Request: custom ${bin}

The binary name 'slack' clobbers with the GUI slack application.
I can customize the via Makefile the bindir, but not the bin name.
Can this be customized?

Number of unread messages

Apologies if I am missing the obvious, but I am wondering if there is a way to obtain the number of unread messages in a given channel.

Many thanks

Presence and status changes

Does setting/changing my own presence/status require me to use a Legacy token or can it be done using one of the other auth methods?

Non-ZIP file upload

Is it possible to upload files not as ZIPs? This seems to be the default behavior, and I can't seem to figure out how to turn it off.

Teams equivalent of slack-cli

Hi all, I've been using slack-cli for many years now, and I love it.

One organization I've worked with though, only wants to deal with Microsoft Teams. Does anybody know of an equivalent of slack-cli for MS Teams? Thx.

Add support for getting token from password managers?

Hey, I wanted to send some messages to Slack programmatically and this script seems to do the job nicely. Thanks!

I didn't see how to store the Slack API token securely, though, instead of just leaving it in plaintext on disk. I generally use pass to do this job.

So, in my dotfiles I added support for a SLACK_CLI_TOKEN_CMD environment variable. It just contains a command that will print the token to standard output.

Any interest in a PR to support password managers? If yes, does the above seem like a reasonable basis for one?

Feature Request: Plaintext messages

Is it possible to send messages only containing text using the text attribute of the slack api rather than defaulting to using attachments? I would like to use this to interact with a slack bot but the slack bot only understands simple messages.

Feature Request: Add ability to set expire time on statuses

It'd be really useful to be able to set an expire time when updating a status.

Edit status via arguments:
slack status edit lunch :hamburger: 60

Edit status via options:
slack status edit --text lunch --emoji :hamburger: --expire 60

Edit status via short form options:
slack status edit --tx lunch -em :hamburger: -ex 60

It appears this could be easily done by adding status_expiration.

I would implement myself and make a pull request but my bash skills are not so hot.

Slash commands

Hello,

I'm wondering if i can use the slash command '/remind' also with this CLI? (I'd like to run a script that reminds me for a bunch of stuff so I dont need to do this manually everytime)

Cheers,
Sidney

unable to send strings containing quotes

It doesn't seem possible to send strings which include quotes.

To reproduce:

$ echo \"this is a string with quotes which can\'t be sent\"
"this is a string with quotes which can't be sent"


$ echo \"this is a string with quotes which can\'t be sent\" | ./slack chat send --channel '#testchannel'
{
  "ok": false,
  "error": "no_text"
}


$ echo this is a string without quotes which can be sent | ./slack chat send --channel '#testchannel'
{
  "ok": true,
  "channel": "CASLS2A87",
  "ts": "1526569175.000785",
  "message": {
    "type": "message",
    "user": "U04PC8VG1",
    "text": "",
    "bot_id": "BARC5MV6Y",
    "attachments": [
      {
        "fallback": "```this is a string without quotes which can be sent```",
        "pretext": "```this is a string without quotes which can be sent```",
        "id": 1,
        "mrkdwn_in": [
          "pretext"
        ]
      }
    ],
    "ts": "1526569175.000785"
  }
}

How to message a user in a channel ?

I was looking at the Slack docs, and they mention using <@UserName> to mention a user and notify them as part of the API, but I can't seem to get it to work? Any thoughts?

Status update cannot include spaces

I was just trying to script together a simple status updater for pomodoros and noticed what appears to be a bug in the argument parsing:

slack status edit --text "Pomodoro until DATE" --emoji :tomato:

Under the hood it appears to run this invalid CURL command

curl -s -X POST https://slack.com/api/users.profile.set --data-urlencode 'profile={"status_text":"Pomodoro' until 'DATE", "status_emoji":":tomato:"}' --data-urlencode token=<redacted>

and you get back this from the Slack API:

{
  "ok": false,
  "error": "invalid_profile"
}

Problem formatting piped output

I'm trying to pipe a url to a channel and it always ends up formatted with backticks.

For example:

echo "http://github.com" | slack chat send -ch @mark 

I receive the message but it looks like this:
image

Is there a way to format piped output?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.