Skip to content

kfujii-6jo/simple-slack-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slack CLI Tool

A CLI tool for sending messages and DMs via Slack using User Token.

Setup

  1. Install dependencies
npm install
  1. Register CLI command globally
npm link
  1. Configure Slack User Token
cp .env.example .env
# Edit .env file and set SLACK_USER_TOKEN
  1. Create configuration files from samples
# Create recipient lists
cp recipients/users.txt.example recipients/users.txt
cp recipients/users.json.example recipients/users.json

# Create templates
cp templates/welcome.txt.example templates/welcome.txt
cp templates/announcement.txt.example templates/announcement.txt

Required Slack Scopes

  • chat:write - Send messages
  • channels:read - List channels
  • files:write - Upload files
  • groups:read - Read private channels
  • im:read, im:write - Read/write DMs
  • users:read, users:read.email - Get user information

Usage

Basic Message Sending

# Send message to a channel
slack-cli send #general "Hello, World!"

# Specify token directly
slack-cli send #general "Hello" -t xoxp-your-token

Direct Message (DM) Sending

# Specify user by email
slack-cli dm user@example.com "Hello!"

# Specify by username
slack-cli dm @username "Hello!"

# Specify by user ID
slack-cli dm U0123456789 "Hi there!"

DM with Templates

# Use template file (create from templates/welcome.txt.example)
slack-cli dm user@example.com "" --template templates/welcome.txt --vars '{"name":"John Doe","team":"Dev Team","department":"Engineering","date":"2024-01-15"}'

Bulk DM Sending

# Use text file user list
slack-cli bulk-dm recipients/users.txt "Announcement message"

# Use JSON file with template
slack-cli bulk-dm recipients/users.json "" --template templates/welcome.txt

# Adjust sending interval (default: 1000ms)
slack-cli bulk-dm recipients/users.txt "Hello" --delay-ms 2000

# Send without delay (watch for rate limits)
slack-cli bulk-dm recipients/users.txt "Hello" --no-delay

Other Commands

# List channels
slack-cli channels

# List users
slack-cli users

# Upload file
slack-cli upload #general file.pdf -c "Document attached" --title "Monthly Report"

User List File Formats

Text Format (recipients/users.txt)

# Comment lines start with #
user1@example.com
user2@example.com
@username
U0123456789

JSON Format (recipients/users.json)

[
  {
    "user": "user@example.com",
    "name": "User Name",
    "team": "Team Name",
    "any_field": "value"
  }
]

Each field in the JSON file can be used as a variable in templates.

Template Files

Template files use {{ variable }} format for variable substitution.

Example (create from templates/welcome.txt.example):

Hello {{ name }}!

Team: {{ team }}
Department: {{ department }}
Start Date: {{ date }}

Troubleshooting

  • User not found: Ensure users:read.email scope is enabled for email lookups
  • DM send failure: Verify im:write scope is enabled
  • Rate limit errors: Adjust sending interval with --delay-ms option

About

A CLI tool for sending messages and DMs via Slack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published