A highly portable utility to post a message to a slack channel.
This utility, written in go, sends a message to a slack channel by constructing a message object containing all available slack incoming webhook API capabilities
slackpost https://slack.com/your-webhook "This is my message"
slackpost send
The default workdir is /tmp and the default message-id is the parent pid. This works great on linux but not on Windows. On Windows, manually specify these with the -m and -w flags
slackpost [options] [command] [arguments]
Command | Description |
---|---|
addfield | Add fields to the current attachment |
attach | Attach a text string to the message |
clean | Cleans up the message object |
help | Help about any command |
init | Initializes the message object |
send | Sends the message |
version | Show version |
Global flags are usable with any subcommand
Short | Long | Description |
---|---|---|
--config | config file (default is $HOME/.slackpost.json) | |
-m | --message-id | message id number. Can be anything. Defaults to PID of caller |
-v | --verbose | Enable verbose messages |
-w | --workdir | working directory to use to store message objects |
Initializes the message object
slackpost init <webhook> <message> [flags]
Name | Value |
---|---|
webhook | URL of slack channel incoming webook |
message | Message to send |
Short | Long | Description |
---|---|---|
-c | --channel | Name of channel to send to (ignored if passing a channel hook) |
-i | --icon | Icon name to post with the message |
-I | --icon-url | URL of Icon to post with the message |
-u | --username | User Name to associate with the message |
slackpost init https://slack.foo "This is my message"
Attach a text string to the message.
This function will add a string as an attachment to the message.
There can be unlimited attachments to a message, and each attachment has many
options available to customize how the attachment will appear.
slackpost attach <text> [flags]
Name | Value |
---|---|
text | string message to attach |
Short | Long | Description |
---|---|---|
-a | --author | Name of author |
-I | --author-icon | URL to a 16x16px icon to display by the author's name |
-A | --author-link | URL to hyperlink to the author's name |
-c | --color | Name of color to use with this attachment |
-B | --fallback | Fallback string to use for clients that can't display the message |
-f | --footer | Text that appears as a footer to the attachment. |
-F | --footer-icon | URL of an icon to display with the footer. |
-i | --image | URL of image to display inside the attachment. |
-p | --pretext | String to display above the message attachment block |
-b | --thumb | URL of a thumbnail to display to the top-right of the attachment. |
-d | --timestamp | Epoch-time date/time stamp for the attachment. |
-t | --title | String to display as the title of the attachment. Displays as larger, bolder text |
-T | --title-link | URL to hyperlink to the attachment title. |
slackpost attach "$(<logfile.txt)" -c "#abcdef" -a "yourname"
Add fields to the current attachment.
Message atachments can have multiple fields (see slack message documentation).
This function adds a few field to the most recently added attachment.
slackpost addfield <title> <value> [flags]
Name | Value |
---|---|
title | Title string associated with this field |
value | Value string associated with this field |
Short | Long | Description |
---|---|---|
-s | --short |
If set, indicates that the title/value pair is short enough to be displayed vertically with other fields |
slackpost addfield AssignedTo "Jane Doe"
Sends the constructed message to the slack channel
slackpost send [flags]
Cleans up the temporary file(s) used to create the message object.
This function is normally performed automatically after sending the object,
but in some cases you may need to clean up the message manually.
slackpost clean [flags]
Short | Long | Description |
---|---|---|
-a | --all | If set, will clean up any detected messages |
--force | When using -a |