1.0.5 • Published 6 months ago
send-slack v1.0.5
Send Slack
A powerful CLI tool to send formatted Markdown messages to Slack using webhooks.
Features
- Convert Markdown to Slack blocks
- Support for complex Markdown elements (headings, lists, code blocks, etc.)
- Automatic splitting of long messages to comply with Slack's limits
- Option to send pre-formatted Slack blocks
- Add title, context, and start text to your messages
- Read input from files or directly from the command line
Installation
npm install -g send-slack
Usage
You can use this package with npx
without installing it globally:
npx send-slack [options]
Or if you've installed it globally:
send-slack [options]
Options
Option | Alias | Description | Type | Required |
---|---|---|---|---|
--webhook | -w | Slack webhook URL | string | Yes |
--markdown | -m | Markdown string or file path | string | No* |
--blocks | -b | JSON string of Slack blocks or file path | string | No* |
--title | -t | Heading for the message | string | No |
--context | -c | Context array as a JSON string | string | No |
--start-text | -s | Start text for the message | string | No |
--help | -h | Show help | boolean | No |
*Either --markdown or --blocks must be provided
Examples
Send a Markdown message
npx send-slack --webhook "https://hooks.slack.com/services/XXX/YYY/ZZZ" --markdown "# Hello World\n\nThis is a test message."
Send a message from a Markdown file
npx send-slack --webhook "https://hooks.slack.com/services/XXX/YYY/ZZZ" --markdown ./message.md
Send pre-formatted Slack blocks
npx send-slack --webhook "https://hooks.slack.com/services/XXX/YYY/ZZZ" --blocks '[{"type":"section","text":{"type":"mrkdwn","text":"Hello, World!"}}]'
Send a message with a title and context
npx send-slack --webhook "https://hooks.slack.com/services/XXX/YYY/ZZZ" --markdown "This is the main message." --title "Important Announcement" --context '["Posted by: John Doe", "Date: 2023-06-01"]'
Markdown Support
This tool supports a wide range of Markdown elements, including:
- Headings (H1 to H6)
- Bold and italic text
- Strikethrough
- Unordered and ordered lists
- Code blocks (with language highlighting)
- Blockquotes
- Horizontal rules
- Links
- Images
Slack Message Limits
This tool automatically handles Slack's message limits:
- Maximum of 50 blocks per message
- Maximum text length of 3000 characters per block
- Maximum total message length of 40,000 characters
Long messages are automatically split into multiple Slack messages while preserving formatting.
Error Handling
If an error occurs during execution, the tool will output an error message to the console and exit with a non-zero status code.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.