Giter VIP home page Giter VIP logo

slack-cli's Introduction

slack-cli | Powerful Slack CLI via pure bash

version versioning branching license pm chat circleci

A pure bash, pipe friendly, feature rich, command line interface for Slack. Richly formatted messages are a first class concept, helping you send beautiful messages with ease. 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.

Basic message example:

$ slack chat send hi @slackbot

Richly formatted message example:

$ slack chat send \
  --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 \
  --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'
  --timestamp 123456789
  --title 'title'
  --title-link 'https://github.com/rockymadden/slack-cli'

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

Installation

Via brew:

$ brew tap rockymadden/rockymadden
$ brew install 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 stedolan/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 stedolan/jq on your PATH.

Configuration

Ensure you have a Slack API token and use said token one of the following ways:

Via init:

$ slack init

Via environment variable:

export SLACK_CLI_TOKEN='token'

Usage

$ slack --help
Usage:
  slack chat delete [<timestamp> [channel]]
    [--channel|-ch <channel>] [--compact|-c] [--filter|-f <filter>] [--monochrome|-m]
    [--timestamp|-ts <timestamp>] [--trace|-x]

  slack chat send [<text> [channel]]
    [--author|-at <author>] [--author-icon|-ai <author-icon-url>]
    [--author-link|-al <author-link>] [--channel|-ch <channel>] [--color|-cl <color>]
    [--compact|-cp] [--filter|-f <filter>] [--footer|-ft <footer>]
    [--footer-icon|-fi <footer-icon-url>] [--image|-im <image-url>] [--monochrome|-m]
    [--pretext|-pt <pretext>] [--text|-tx <text>] [--thumbnail|-th <thumbnail-url>]
    [--title|-ti <title>] [--title-link|-tl <title-link>] [--trace|-x]

  slack chat update [<text> [<timestamp> [channel]]]
    [--author|-at <author>] [--author-icon|-ai <author-icon-url>]
    [--author-link|-al <author-link>] [--channel|-ch <channel>] [--color|-cl <color>]
    [--compact|-cp] [--filter|-f <filter>] [--footer|-ft <footer>]
    [--footer-icon|-fi <footer-icon-url>] [--image|-im <image-url>] [--monochrome|-m]
    [--pretext|-pt <pretext>] [--text|-tx <text>] [--thumbnail|-th <thumbnail-url>]
    [--timestamp|-ts <timestamp>] [--title|-ti <title>] [--title-link|-tl <title-link>]
    [--trace|-x]

  slack init
    [--compact|-c] [--filter|-f <filter>] [--monochrome|-m] [--token|-tk <token>]
    [--trace|-x]

  slack file delete [file]
    [--compact|-c] [--file|-fl <file>] [--filter|-f <filter>] [--monochrome|-m]
    [--trace|-x]

  slack file info [file]
    [--count|-cn <count>] [--compact|-c] [--file|-fl <file>] [--filter|-f <filter>]
    [--monochrome|-m] [--page|-pg <page>] [--trace|-x]

  slack file list
    [--channel|-ch <channel>] [--count|-cn <count>] [--compact|-c] [--filter|-f <filter>]
    [--monochrome|-m] [--page|-pg <page>] [--timestamp-from|-tf <timetamp>]
    [--timestamp-to|-tt <timestamp>] [--trace|-x] [--types|-ty <types>]
    [--user|-ur <user>]

  slack file upload [<file> [channels]]
    [--channels|-chs <channels>] [--comment|-cm <comment>] [--compact|-c]
    [--file|fl <file>] [--filename|-fn <filename>] [--filter|-f <filter>]
    [--monochrome|-m] [--title|-ti <title>] [--trace|-x]

  slack snooze end
    [--compact|-c] [--filter|-f <filter>] [--monochrome|-m] [--trace|-x]

  slack snooze info [user]
    [--compact|-c] [--filter|-f <filter>] [--monochrome|-m] [--trace|-x]
    [--user|-ur <user>]

  slack snooze start [minutes]
    [--compact|-c] [--filter|-f <filter>] [--minutes|-mn <minutes>] [--monochrome|-m]
    [--trace|-x]

Configuration Commands:
  init    Initialize

Chat Commands:
  chat delete    Delete chat message
  chat send      Send chat message
  chat update    Update chat message

File Commands:
  file delete    Delete file
  file info      Info about file
  file list      List files
  file upload    Upload file

Snooze Commands:
  snooze end      End snooze
  snooze info     Info about snooze
  snooze start    Start snooze

More Information:
  chat    https://rockymadden-slack.herokuapp.com
  repo    https://github.com/rockymadden/slack-cli

PROTIPS:

  • The --compact option is a wrapper around the jq --compact-output option
  • The --filter option is passed directly to jq as a filter
  • The --monochrome option a wrapper around the jq --monochrome-output option
  • All commands prompt for required arguments which were not provided via options or arguments. This allows for both traditional usage and prompt-based usage.

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'

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

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

Coverage

  • channels
  • chat
  • files
  • groups
  • pins
  • search
  • snooze
  • usergroups
  • users

License

The MIT License (MIT)

Copyright (c) 2016 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

rockymadden avatar

Stargazers

Alan Stebbens avatar

Watchers

Alan Stebbens avatar James Cloos avatar

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.