Slack
Set up CodeSpar as a Slack app using Socket Mode for real-time messaging, mentions, and threaded conversations.
Slack Channel
CodeSpar integrates with Slack via a custom Slack app using Socket Mode. This means no public URL or ingress is required — the connection is outbound from your infrastructure to Slack's servers.
Prerequisites
- A Slack workspace where you have admin permissions
- CodeSpar instance running (Docker or local)
Create a Slack App
- Go to api.slack.com/apps and click Create New App
- Choose From scratch
- Name it
CodeSpar(or your preferred name) and select your workspace - Click Create App
Enable Socket Mode
Socket Mode lets the app receive events over a WebSocket instead of HTTP webhooks. This is simpler to deploy and doesn't require a public URL.
- In the app settings, go to Socket Mode in the left sidebar
- Toggle Enable Socket Mode to on
- Create an App-Level Token with the
connections:writescope - Name it
codespar-socketand click Generate - Copy the token (starts with
xapp-) — this is yourSLACK_APP_TOKEN
Configure OAuth Scopes
Go to OAuth & Permissions and add these Bot Token Scopes:
| Scope | Purpose |
|---|---|
app_mentions:read | Receive messages where the bot is @mentioned |
chat:write | Send messages and responses |
channels:read | List public channels the bot is in |
Optional scopes for enhanced functionality:
| Scope | Purpose |
|---|---|
channels:history | Read message history for context |
reactions:write | Add emoji reactions to messages |
files:write | Upload files (diffs, reports) |
Enable Event Subscriptions
- Go to Event Subscriptions and toggle to On
- Under Subscribe to bot events, add:
app_mention— triggers when someone @mentions the bot in a channelmessage.im— triggers on direct messages to the bot
Install to Workspace
- Go to Install App in the left sidebar
- Click Install to Workspace and authorize
- Copy the Bot User OAuth Token (starts with
xoxb-) — this is yourSLACK_BOT_TOKEN
Get the Signing Secret
- Go to Basic Information
- Under App Credentials, copy the Signing Secret — this is your
SLACK_SIGNING_SECRET
Environment Variables
Add these to your .env file:
How It Works
The Slack adapter uses Bolt for JavaScript (@slack/bolt) under the hood.
Channel Messages
When a user @mentions the bot in a channel, Slack fires an app_mention event:
The adapter:
- Receives the
app_mentionevent via Socket Mode - Strips the
@CodeSparmention from the text - Normalizes into a
NormalizedMessagewithchannelType: "slack" - Routes to the Project Agent linked to that channel
- Sends the response back to the same channel (in a thread if applicable)
Direct Messages
DMs use the message.im event — no @mention needed:
Threading
Slack responses are threaded by default. When a user @mentions CodeSpar in a channel, the response appears as a thread reply, keeping the channel clean. Ongoing conversation within the thread continues without needing to @mention again.
Example Conversation
Thread Support
All app_mention responses are sent as thread replies automatically. This keeps channels clean and groups related messages together.
How threading works
- When a user @mentions CodeSpar in a channel, the adapter captures the message's
ts(timestamp) value. - The response is sent with
thread_tsset to the original message'sts, creating a threaded reply. - Follow-up messages within the same thread are detected via the
thread_tsmetadata on incoming events. - Users can continue the conversation in the thread without needing to @mention the bot again.
The threadTs metadata flows through the NormalizedMessage so the agent layer does not need channel-specific logic. The Slack adapter handles thread routing transparently.
Direct messages
DMs do not use threading. Responses are sent as regular messages in the DM conversation.
File Attachments
The Slack adapter supports sending file attachments via the files.uploadV2 API. Agents can send diffs, reports, logs, and other files directly to channels or threads.
sendFile method
ChannelAttachment type
File attachments use the ChannelAttachment interface:
Required scopes
To use file attachments, ensure your Slack app has the files:write scope. See the OAuth Scopes section above.
Invite the Bot to Channels
After installation, invite the bot to any channel where you want it active:
Or go to the channel settings → Integrations → Add apps → select CodeSpar.
Troubleshooting
Bot doesn't respond to mentions
- Verify
ENABLE_SLACK=truein your environment - Check that the bot is invited to the channel
- Confirm
app_mentions:readscope is granted - Check logs for Socket Mode connection errors
"not_authed" errors
Your SLACK_BOT_TOKEN is invalid or expired. Reinstall the app to your workspace to generate a new token.
Socket Mode disconnects
Socket Mode connections can drop under high load or network instability. CodeSpar automatically reconnects, but check your logs if messages are being missed. Ensure SLACK_APP_TOKEN has the connections:write scope.
Messages appear but agent doesn't process
Verify that the channel is linked to a project. Use the CLI to check: