A powerful and lightweight Node.js bot for automating Slack messaging operations. Built with simplicity and reliability in mind.
- 📤 Send messages to any channel
- 📝 Edit existing messages
- 🗑️ Delete messages
- ⏰ Schedule future messages
- 📥 Retrieve message history
- 🔒 Secure token handling
- ⚡ Error handling & logging
# Clone the repository
git clone https://github.com/yourusername/slack-messaging-bot.git
# Navigate to project directory
cd slack-messaging-bot
# Install dependencies
npm install
# Create .env file
echo "SLACK_BOT_TOKEN=xoxb-your-token
CHANNEL_ID=your-channel-id" > .env
# Run the bot
npm start-
Create a Slack App
- Visit api.slack.com/apps
- Click "Create New App" → "From scratch"
- Name your app and select workspace
-
Configure Permissions
- Go to "OAuth & Permissions"
- Add these scopes:
chat:write chat:write.public chat:delete chat:edit channels:history groups:history im:history mpim:history
-
Install App
- Click "Install to Workspace"
- Copy the "Bot User OAuth Token"
-
Environment Setup
- Create
.envfile in project root - Add your credentials:
SLACK_BOT_TOKEN=xoxb-your-token CHANNEL_ID=your-channel-id
- Create
const { sendMessage, editMessage, deleteMessage } = require('./slackMessaging');
// Send a message
const ts = await sendMessage("Hello, world!");
// Edit after 2 seconds
await new Promise(r => setTimeout(r, 2000));
await editMessage(ts, "Updated message!");
// Delete after 2 seconds
await new Promise(r => setTimeout(r, 2000));
await deleteMessage(ts);Sends a message to the configured channel.
const ts = await sendMessage("Hello!");Edits an existing message.
await editMessage(ts, "Updated text");Deletes a message.
await deleteMessage(ts);Schedules a message for future delivery.
await scheduleMessage("Future message", 3600); // 1 hourRetrieves recent messages.
const messages = await getMessages(10); // Last 10 messages# Install dependencies
npm install
# Run the bot
npm start
# Format code
npm run format
# Lint code
npm run lintThe bot includes comprehensive error handling:
- Input validation
- API error handling
- Custom error classes
- Detailed logging
axios- HTTP clientdotenv- Environment management
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
Anmol Mahobiya
- Slack API Documentation
- Node.js Community