slack-cli

Crates.ioslack-cli
lib.rsslack-cli
version0.1.1
created_at2024-12-18 23:37:21.206267+00
updated_at2024-12-19 01:31:29.600389+00
descriptionslack cli Project homepage: https://github.com/isaacadams/slack-api-client
homepagehttps://github.com/isaacadams/slack-api-client
repositoryhttps://github.com/isaacadams/slack-api-client
max_upload_size
id1488598
size52,325
Isaac Adams (isaacadams)

documentation

README

Slack CLI

This is a CLI tool for sending messages to Slack channels. It supports sending text messages, blocks, and attachments using the Slack API.

Installation

Make sure the SLACK_TOKEN environment variable is set with your Slack bot token.

export SLACK_TOKEN=xoxb-your-slack-bot-token

via cargo install

cargo install slack-cli
slack --help

via source

  1. Clone the repository.
  2. Install dependencies and compile the code using cargo build --release.
  3. cargo run -p slack-cli

Usage

General Command

slack <COMMAND> [OPTIONS]

Commands

slack send <message>

Send a message to a Slack channel.

Arguments
  • --channel (-c) - The Slack channel to send the message to. Accepts either the channel name (e.g., #general) or the channel ID.
  • --kind (-k) - The type of message to send. Options are:
    • text - A simple text message.
    • block - A message with block elements (provide a JSON object).
    • attachment - A message with attachments (provide a JSON object).
  • <message> - The content of the message. For block or attachment, provide a valid JSON object.
Example Usage

Send a text message:

slack send --channel general --kind text "Hello, Slack!"
slack send --channel=#general --kind text "Hello, Slack!"
slack send --channel "#general" --kind text "Hello, Slack!"

Send a block message:

slack send --channel general --kind block '[{"type": "section", "text": {"type": "mrkdwn", "text": "*Hello, Slack!*"}}]'

Send an attachment message:

slack send --channel general --kind attachment '[{"color":"#f2c744","blocks":[{"type":"section","text":{"type":"mrkdwn","text":"*Hello, Slack!*"}}]}]'

Environment Variables

  • SLACK_TOKEN: Required. The token for authenticating with the Slack API. Set this in your environment or use a .env file for local development.

Error Handling

Ensure that all required options are provided and that the SLACK_TOKEN environment variable is set. The CLI will display meaningful error messages if these requirements are not met.

Commit count: 17

cargo fmt