Slack App
TL;DR
The Slack channel for @cmdop/bot uses @slack/bolt with Socket Mode to connect your CMDOP machines to Slack. Create a Slack app, enable Socket Mode, add the /cmdop slash command, then use commands like /cmdop shell, /cmdop agent, and /cmdop ls. Supports Block Kit formatting, interactive buttons, and requires no public webhooks thanks to Socket Mode.
Control your CMDOP machines from Slack using Socket Mode. Built on @slack/bolt .
How do I set up a Slack app?
- Create app at Slack API
- Enable Socket Mode and get App Token (
xapp-...) - Create Bot Token (
xoxb-...) - Add slash command
/cmdop - Install to workspace
How do I install @cmdop/bot for Slack?
# Install the @cmdop/bot package (Slack adapter is included)
npm install @cmdop/botHow do I use the Slack channel?
// Import the hub and Slack-specific channel adapter
import { IntegrationHub } from '@cmdop/bot';
import { SlackChannel } from '@cmdop/bot/slack';
// Create the hub with your CMDOP API key and default target machine
const hub = new IntegrationHub({
apiKey: process.env.CMDOP_API_KEY!,
machine: 'my-server',
});
// Add SlackChannel with both bot token (xoxb-) and app token (xapp-) for Socket Mode
hub.addChannel(new SlackChannel({
botToken: process.env.SLACK_BOT_TOKEN!,
appToken: process.env.SLACK_APP_TOKEN!,
}));
// Start the bot and begin listening for Slack commands
hub.start();What are the SlackChannel options?
| Option | Type | Required | Description |
|---|---|---|---|
botToken | string | Yes | Slack bot token (xoxb-...) |
appToken | string | Yes | Slack app-level token for Socket Mode (xapp-...) |
allowedUsers | string[] | No | Allowed Slack user IDs |
timeout | number | No | Command timeout in milliseconds (default: 30000) |
What commands can I use in Slack?
All commands use the /cmdop prefix:
| Command | Description |
|---|---|
/cmdop help | Show available commands |
/cmdop shell <cmd> | Execute shell command |
/cmdop agent <task> | Run AI agent task |
/cmdop ls [path] | List directory |
/cmdop cat <path> | Read file |
/cmdop machine <hostname> | Set target machine |
/cmdop status | Show connection status |
What features does the Slack channel support?
- Socket Mode — no public webhooks needed
- Block Kit messages for rich formatting
- Interactive buttons
- Slash command handling
- @slack/bolt adapter
What environment variables do I need?
# Slack bot token (starts with xoxb-)
export SLACK_BOT_TOKEN="xoxb-your-bot-token"
# Slack app-level token for Socket Mode (starts with xapp-)
export SLACK_APP_TOKEN="xapp-your-app-token"
# Your CMDOP API key for authenticating with the CMDOP service
export CMDOP_API_KEY="cmdop_xxx"
# Default machine hostname to target for commands
export CMDOP_MACHINE="my-server"How do I add permissions to my Slack bot?
// Import PermissionManager and PermissionLevel alongside the hub and channel
import { IntegrationHub, PermissionManager, PermissionLevel } from '@cmdop/bot';
import { SlackChannel } from '@cmdop/bot/slack';
// Create a permission manager instance
const permissions = new PermissionManager();
// Grant full admin access to a specific Slack user
permissions.addAdmin('slack:U12345678');
// Grant EXECUTE-level access to another user on a specific machine
permissions.grant({
identity: 'slack:U87654321',
machine: 'dev-server',
level: PermissionLevel.EXECUTE,
});
// Pass the permission manager to the hub
const hub = new IntegrationHub({
apiKey: process.env.CMDOP_API_KEY!,
permissions,
});
// Add the Slack channel (no allowedUsers needed — permissions handle access)
hub.addChannel(new SlackChannel({
botToken: process.env.SLACK_BOT_TOKEN!,
appToken: process.env.SLACK_APP_TOKEN!,
}));
hub.start();What does a full Slack bot example look like?
// Full production-ready Slack bot setup
import { IntegrationHub } from '@cmdop/bot';
import { SlackChannel } from '@cmdop/bot/slack';
// Create hub using environment variables for configuration
const hub = new IntegrationHub({
apiKey: process.env.CMDOP_API_KEY!,
machine: process.env.CMDOP_MACHINE,
});
// Add Slack channel with bot and app tokens from environment
hub.addChannel(new SlackChannel({
botToken: process.env.SLACK_BOT_TOKEN!,
appToken: process.env.SLACK_APP_TOKEN!,
}));
// Start the bot and log confirmation
hub.start().then(() => {
console.log('Slack bot is running');
});How do I configure the Slack app?
What scopes are required for the bot token?
chat:write— Send messagescommands— Handle slash commands
What optional scopes can I add?
app_mentions:read— Respond to @mentions
How does Socket Mode work?
Enable Socket Mode in your app settings to use xapp- tokens. This allows your bot to receive events without a public URL.
How do I set up the slash command?
- Go to “Slash Commands” in your app settings
- Create new command:
/cmdop - Description: “Control CMDOP machines”
- Usage hint:
shell <command> | agent <task> | ls [path] | cat <path>
Last updated on