๐Ÿ’ฌ

How Does Slack Socket Mode Work?

Receiving Events via Outbound WebSocket Without Webhooks

Slack originally delivered events via Webhooks (Event Subscriptions), but this required a public URL. Socket Mode has the Bot server establish an outbound WebSocket connection to Slack first, and Slack pushes events through that connection. No public URL, SSL certificate, or firewall configuration needed. Internally, it uses the apps.connections.open API to receive a WebSocket URL for connection.

Architecture Diagram

Connection Phase
๐Ÿค–
My Bot Server
Behind firewall / local
โ‘  apps.connections.open wss://... URL received
โ‘ก WS connection
โ†’ outbound
๐Ÿ’ฌ
Slack
Events + Web API
Event Processing Phase
๐Ÿค–
My Bot Server
โ‘ฃ process event
โ‘ข event push (WS)
โ‘ค acknowledge (within 3s)
โ‘ฅ Web API response
๐Ÿ‘ค
User Event
Messages, slash commands, etc.
Key point: Bot opens an <strong>outbound WebSocket</strong>, so no public URL / ngrok needed
Socket Mode vs Webhook Comparison
Socket Mode
Webhook (Event API)
No public URL needed
Public URL required
Outbound WebSocket
Inbound HTTP POST
Local dev ready immediately
Tunnel (ngrok, etc.) needed
Connection must be maintained
Stateless

How It Works

1

Bot calls apps.connections.open API โ†’ receives temporary WebSocket URL

2

Bot establishes WebSocket connection to that URL (outbound)

3

Event occurs in Slack (message, slash command, interaction, etc.)

4

Slack pushes event payload to Bot via WebSocket

5

Bot processes the event and sends acknowledge response (within 3 seconds)

6

Send/update messages via Slack Web API as needed

Pros

  • No public URL needed
  • Works behind firewalls/NAT
  • Local development possible without ngrok
  • No SSL certificate needed

Cons

  • Connection maintenance required (30s ping)
  • Possible event loss on disconnect
  • Not suitable for large-scale apps (connection limits)
  • Fewer debugging tools compared to Webhooks

Use Cases

Internal Slack Bot development Running Bots behind firewalls Testing Bots in local development environment Security-critical Bots (no public URL exposure)