Slack
Mercury connects to Slack as a Socket Mode bot, providing a real-time conversational interface with slash commands, streaming responses, and an organization-style access model with pairing codes and admin controls.
Prerequisites
- A Slack workspace where you can install apps.
- A Slack App with Bot Token (
xoxb-) and App-Level Token (xapp-). - Node.js 18 or later (for the
@slack/boltv4 dependency).
Mercury uses Socket Mode, which means it connects to Slack via WebSocket — no public endpoint or HTTPS certificate is needed. Your Slack app must have Socket Mode enabled and an App-Level Token with connections:write scope.
Setup
Step 1: Create a Slack App
- Go to api.slack.com/apps and click Create New App → From scratch.
- Give it a name (e.g. "Mercury") and select your workspace.
- Click Create App.
Step 2: Enable Socket Mode and Get App-Level Token
- In your app's settings, navigate to Socket Mode in the left sidebar.
- Toggle Enable Socket Mode on.
- Enter a token name (e.g. "mercury-socket") and click Generate.
- Copy the
xapp-token — you'll need this asSLACK_APP_TOKEN.
Step 3: Configure Bot Token Scopes
-
Navigate to OAuth & Permissions in the left sidebar.
-
Under Bot Token Scopes, add these scopes:
chat:write— send messageschat:write.public— send messages in channels the bot hasn't joinedchat:write.customize— customize message appearance (for streaming edits)channels:history— read channel messagesgroups:history— read private channel messagesim:history— read direct messagesim:write— send direct messagesfiles:write— upload filescommands— handle slash commandsapp_mentions:read— respond to @mentions
-
Click Install App to Workspace (or reinstall if already installed).
-
Copy the Bot User OAuth Token (
xoxb-) — this isSLACK_BOT_TOKEN.
Step 4: Enable Event Subscriptions
-
Navigate to Event Subscriptions in the left sidebar.
-
Toggle Enable Events on.
-
Under Subscribe to bot events, add:
message.channels— receive messages in public channelsmessage.groups— receive messages in private channelsmessage.im— receive direct messagesapp_mention— respond when @mentioned
-
Click Save Changes.
Step 5: Enable Interactivity
- Navigate to Interactivity & Shortcuts in the left sidebar.
- Toggle Interactivity on.
- Click Save Changes.
Step 6: Create the Slash Command
- Navigate to Slash Commands in the left sidebar.
- Click Create New Command.
- Fill in:
- Command:
/mercury - Request URL: (leave default — Socket Mode handles this)
- Short description:
Interact with Mercury Agent - Usage hint:
start | status | help
- Command:
- Click Save.
Step 7: Enable App Home Messages
- Navigate to App Home in the left sidebar.
- Check Allow users to send Slash commands and messages from the messages tab.
- Click Save.
Step 8: Invite the Bot to a Channel
In Slack, go to the channel where you want Mercury to respond and type:
/invite @Mercury
Step 9: Configure Mercury
Run mercury doctor and select Slack when prompted, or set these environment variables:
# Required
SLACK_ENABLED=true
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token
# Optional — restrict to a specific channel
SLACK_CHANNEL_ID=
# Optional — workspace/team ID
SLACK_TEAM_ID=
# Optional — enable streaming (edit-in-place) responses (default: true)
SLACK_STREAMING=true
Or add them to ~/.mercury/.env.
Step 10: Pair
- Start Mercury:
mercury up - In Slack, DM the bot or mention it in a channel with:
/mercury start - Mercury will display a pairing code. Enter it in the CLI:
mercury slack pair <code>
- You are now the Slack admin. Other users can request access, and you can approve them from the CLI.
Access Model
Mercury Slack uses an organization access model with admins and members.
| Role | Description | Can approve requests? |
|---|---|---|
| Admin | First user to pair. Can approve/reject access requests, promote/demote users. | Yes |
| Member | Approved by an admin. Can send messages and receive responses. | No |
| Pending | Sent /mercury start but not yet approved. | No |
CLI Commands
| Command | Description |
|---|---|
mercury slack list | Show approved admins, members, and pending requests |
mercury slack approve <userId> | Approve a pending request by Slack user ID |
mercury slack reject <userId> | Reject a pending request |
mercury slack remove <userId> | Remove an approved admin or member |
mercury slack promote <userId> | Promote a member to admin |
mercury slack demote <userId> | Demote an admin to member |
mercury slack reset | Clear all Slack access (start fresh) |
Features
| Feature | Description |
|---|---|
| Socket Mode | No public endpoint needed — connects via WebSocket |
| Streaming responses | Messages are edited in place as tokens arrive |
| Slash commands | /mercury for start, status, help, and more |
| Channel + DM support | Works in channels (when @mentioned) and direct messages |
| Organization access | Admin/member roles with pairing-code onboarding |
| App mentions | Respond when @mentioned in channels |
| File handling | Send and receive file attachments |
Configuration Reference
| Variable | Description | Default |
|---|---|---|
SLACK_ENABLED | Enable/disable Slack channel | false |
SLACK_BOT_TOKEN | Bot User OAuth Token (xoxb-) | — |
SLACK_APP_TOKEN | App-Level Token for Socket Mode (xapp-) | — |
SLACK_CHANNEL_ID | Restrict to a specific channel. Leave empty for all channels. | — |
SLACK_TEAM_ID | Workspace/Team ID (optional) | — |
SLACK_STREAMING | Enable real-time streaming (edit-in-place) | true |
Troubleshooting
Bot doesn't respond to messages
- Make sure
SLACK_ENABLED=trueand bothSLACK_BOT_TOKENandSLACK_APP_TOKENare set. - Verify the bot token starts with
xoxb-and the app token starts withxapp-. - Check that event subscriptions include
message.channels,message.groups,message.im, andapp_mention. - Run
mercury logsto check for connection errors.
Socket Mode connection failures
- Ensure Socket Mode is enabled in your Slack App settings.
- Verify the App-Level Token has the
connections:writescope. - If you're behind a firewall, ensure WebSocket connections to
wss://slack.comare allowed.
Bot doesn't respond in channels
- Make sure you've invited the bot to the channel:
/invite @Mercury - Check that
channels:historyandchat:write.publicscopes are enabled.
Slash commands not working
- Make sure Interactivity is enabled in your Slack App settings.
- Verify the
/mercuryslash command is configured correctly.
Streaming not working
- Ensure
SLACK_STREAMING=true(default). - Slack rate-limits message edits — Mercury handles this automatically by falling back to new messages when rate-limited.