Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
/ shlack Public archive

Simple tool to post messages to Slack from Bash 📮💨

License

Notifications You must be signed in to change notification settings

elamperti/shlack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shlack Build Status

This simple script aims to ease the sending of Slack messages from CLI, and specially from (scripted) automated processes.

Demo

Slack message sent with custom bot name and emoji icon

post_to_slack --text="This is a test!" --botname="My bot" --icon="robot_face" --channel="#general"

Requirements

  • A Slack team, of course
  • Bash
  • curl

Setup

  1. Clone this repository to your computer git clone [email protected]:elamperti/shlack.git
  2. Go to your Slack team's Apps & Integrations and add "Incoming WebHooks".
  3. Add a configuration for Incoming WebHooks. You can override some of this settings later (see Syntax).
  4. 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.
  5. See Usage section to learn how to post messages.

A note on .slack-hook

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.

Usage

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.

Options

The following options are available:

  • --text: The message to post. If omitted will try to use stdin.
  • --hook: Slack hook URL. Overrides the SLACK_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. Overrides icon_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.

Caveats

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.

Testing

Tests are written in Bats, run bats test to execute them.

License

Copyright (C) 2016 Enrico Lamperti GNU GPL v2, see LICENSE file for more information.

About

Simple tool to post messages to Slack from Bash 📮💨

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages