BotNetwork

Slack Events API over HTTP: URL verification, request signing and retries

A Slack app can receive events over a WebSocket (Socket Mode) or as HTTP POST requests to a request URL you host. HTTP is required for the public Slack Marketplace and scales like any web service, but it puts three jobs on you: prove you own the URL, prove each request came from Slack, and answer fast enough that Slack does not retry.

Published 8 min read

HTTP or Socket Mode

Slack documents two ways to receive Events API payloads, slash commands and interactivity: HTTP request URLs and Socket Mode. With Socket Mode your app opens a WebSocket to Slack, so it works behind a firewall without a public endpoint. With HTTP, Slack sends a POST to a URL you control.

The Slack comparison page lists the trade-offs. HTTP is stateless and scales horizontally; Socket Mode connections are long-lived, and Slack limits them to 10 concurrent WebSocket connections per app at the time of writing. The deciding point for many teams: Slack states that HTTP is a requirement if you intend to submit your app to the Slack Marketplace, and that Socket Mode apps currently cannot be listed there. If you are still choosing, our Bolt Socket Mode vs HTTP comparison covers the hosting side.

This post covers the HTTP path end to end.

What Slack expects from your request URL

You configure the request URL in your app settings under Event Subscriptions. A few rules from the official docs shape everything else:

  • One URL per app. All subscribed events, for every workspace and event type, are delivered to the same request URL. Routing happens in your code.
  • HTTPS with a valid certificate. Slack verifies your SSL certificate when it sends the verification request, and an invalid certificate counts as a delivery failure later.
  • Case-sensitive path. Slack notes that request URLs are case-sensitive, so /slack/events and /Slack/Events are different.
  • Fast answers. Your app should respond to each event with an HTTP 2xx within three seconds.

A stable domain makes this easier to manage than a temporary tunnel URL. You can register one through Namecheap domains and point a subdomain such as slack.example.com at your server; our guide to a custom domain and HTTPS for your bot walks through DNS and certificates.

Step 1: answer the url_verification challenge

When you type the request URL into Event Subscriptions, Slack immediately sends a POST with a JSON body like this:

{
  "token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
  "challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
  "type": "url_verification"
}

Respond with HTTP 200 and the challenge value. Slack accepts it as plain text, as application/x-www-form-urlencoded with a challenge parameter, or as JSON ({"challenge": "..."}). The settings page shows a green check when it works. If your server was asleep and the first attempt timed out, the page has a Retry button.

The token field is the deprecated verification token. Slack says to rely on signing secrets instead, so do not build your security on it.

Step 2: verify the signature on every request

Signed HTTP requests from Slack (the docs list the Events API, slash commands and shortcuts, among others) carry two headers:

  • X-Slack-Request-Timestamp: Unix time in seconds.
  • X-Slack-Signature: a string such as v0=a2114d57....

Header names are case-insensitive, so read them without assuming a particular case. To check a request, follow the recipe in Slack's documentation:

  1. Read the raw request body exactly as received, before any JSON or form parsing. Re-serializing parsed JSON changes whitespace and key order and breaks the hash.
  2. Reject the request if the timestamp differs from your clock by more than five minutes. This is Slack's suggested window against replay attacks, and it means your server clock must be synced (NTP).
  3. Build the base string v0: + timestamp + : + raw body.
  4. Compute HMAC-SHA256 of that string, using your signing secret (App settings, Basic Information) as the key, and take the hex digest. Prefix it with v0=.
  5. Compare your value with the header using a constant-time function such as Python's hmac.compare_digest.

The signing secret is a plain UTF-8 string; you do not need to decode it. Treat it like a token: keep it in an environment variable or secret manager, never in the repository, as explained in securing bot tokens. If it leaks, the Regenerate button next to it in the admin panel issues a new one.

If you use Bolt for Python, JavaScript or Java, signature verification is built in once you pass the signing secret. The manual version is still worth understanding when you debug a 401 or run a plain web framework.

Step 3: acknowledge first, work later

Slack treats a delivery as failed if it does not get a 2xx within three seconds. The docs recommend responding with 200 as soon as you can, not processing events in the same request, and putting inbound events on a queue. That is the same pattern described in acknowledge before calling an LLM: the request handler only verifies, records and enqueues.

The work itself usually means calling the Web API, for example chat.postMessage, with your bot token. That happens in a worker, not while Slack is waiting.

Step 4: retries and duplicates

After a failed delivery, Slack retries up to three times: nearly immediately, after one minute and after five minutes. Each retry carries two headers:

  • x-slack-retry-num: the attempt number, 1, 2 or 3.
  • x-slack-retry-reason: why, for example http_timeout (no answer within three seconds), connection_failed, ssl_error, http_error or too_many_redirects (more than two redirects).

Every event callback includes an event_id, which Slack describes as globally unique across all workspaces. Because a retry delivers the same event again, store the event_id in a shared store with a short expiry and skip events you already handled. Our post on idempotent message handling covers the store and the race conditions.

If your server is overloaded and you prefer that Slack not redeliver a particular event, include the header x-slack-no-retry: 1 in your non-200 response. Only that event is affected.

Failure limits and delayed events

Slack does not keep retrying forever. If more than 95% of delivery attempts within 60 minutes fail (bad certificate, timeouts, too many redirects or non-2xx responses), your app's event subscriptions are temporarily disabled and the app owner gets an email. Per the same page, apps receiving fewer than 1,000 events per hour are not automatically disabled. After fixing the problem, you re-enable subscriptions in app management.

By default, Slack does not attempt to deliver an event that is more than two hours late. An optional Delayed Events setting under Event Subscriptions adds hourly retries for 24 hours after the standard three. Deliveries are also capped at 30,000 events per workspace per app per 60 minutes at the time of writing; above that you receive app_rate_limited events.

A tested Python endpoint

The following FastAPI handler implements all four steps. It was tested with signed requests: the challenge is echoed, a duplicate event_id runs the handler only once, and a wrong signature or a timestamp older than five minutes returns 401.

import hashlib, hmac, json, os, time
from fastapi import BackgroundTasks, FastAPI, Request, Response

app = FastAPI()
SIGNING_SECRET = os.environ["SLACK_SIGNING_SECRET"].encode()
MAX_SKEW_SECONDS = 60 * 5
seen_event_ids = set()  # use Redis or your database in production


def valid_slack_request(body: bytes, timestamp: str, signature: str) -> bool:
    if not timestamp or not signature:
        return False
    try:
        ts = int(timestamp)
    except ValueError:
        return False
    if abs(time.time() - ts) > MAX_SKEW_SECONDS:
        return False  # too old or too far in the future: possible replay
    base = b"v0:" + timestamp.encode() + b":" + body
    expected = "v0=" + hmac.new(SIGNING_SECRET, base, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature)


def handle_event(payload: dict) -> None:
    event = payload["event"]
    print("event", payload["event_id"], event.get("type"))


@app.post("/slack/events")
async def slack_events(request: Request, tasks: BackgroundTasks):
    body = await request.body()  # raw bytes, before any JSON parsing
    if not valid_slack_request(
        body,
        request.headers.get("x-slack-request-timestamp", ""),
        request.headers.get("x-slack-signature", ""),
    ):
        return Response(status_code=401)

    payload = json.loads(body)
    if payload.get("type") == "url_verification":
        return Response(payload["challenge"], media_type="text/plain")

    if payload.get("type") == "event_callback":
        event_id = payload.get("event_id")
        if event_id and event_id not in seen_event_ids:
            seen_event_ids.add(event_id)
            tasks.add_task(handle_event, payload)  # runs after the response is sent
    return Response(status_code=200)

Two notes before production. First, seen_event_ids lives in memory, so it is lost on restart and not shared between instances; replace it with Redis or a database table keyed by event_id. Second, BackgroundTasks runs in the same process after the response; for heavy work, push the payload onto a real queue as Slack recommends.

You can check the signature logic against the worked example in Slack's documentation: with its sample signing secret, timestamp 1531420618 and body, the function above produces the same v0=a2114d57... digest the docs show. For local testing, see testing webhooks on localhost.

Where to run it

The endpoint must be reachable over HTTPS and answer within three seconds, so a server that sleeps when idle can cause timeouts on the first event. Any always-on host with a reverse proxy works. If you also want a simple site for your app's documentation and privacy policy, Namecheap hosting can serve those static pages while the bot runs elsewhere, and Namecheap keeps the domain and that site in one account.

Checklist

  • Request URL on HTTPS with a valid certificate, on a stable domain.
  • url_verification answered with the challenge value.
  • Signature checked on the raw body, with a five-minute timestamp window and constant-time comparison.
  • Signing secret stored outside the code.
  • HTTP 200 within three seconds; real work on a queue.
  • Dedupe on event_id; use x-slack-no-retry: 1 only when you mean it.
  • Alerts on non-2xx rates so you notice before subscriptions are disabled.

Sources