# Events over HTTP

> Slaiky posts each event your app asked for to your server, signed. Check the signature, answer fast, and the retries cover the rest.

Source: https://slaiky.xyz/docs/events

Without Socket Mode, Slaiky sends your app what it asked for as a signed POST to a URL of yours, one per event. Your server checks the request came from Slaiky, answers `200` within 5 seconds, and does the work after.

## The request URL

On the app’s page, open **Events**, fill in **Request URL** and pick the **Events it hears**. Each event needs its permission: the page says which (**Needs** `app_mentions:read`…). In a [manifest](/docs/manifests), they are `settings.event_subscriptions.request_url` and `bot_events`.

Before the URL is saved, Slaiky checks that your server answers it. It posts a challenge, and your server sends the same string back, with a `2xx` status, within 5 seconds:

*Slaiky → your app · `url_verification`*

```json
{ "type": "url_verification", "challenge": "…" }
```

*your app → Slaiky*

```json
{ "challenge": "…" }
```

The challenge may also go back as plain text. It is signed like every other request. If it fails, the URL isn't saved. A saved URL that fails **Check again** shows **Not verified**, and nothing is sent to it until it passes. Fixed your server? **Check again** sends a new challenge.

Commands and clicks have their own URLs: each slash command its **Request URL**, and everything else the **Interactivity URL** under **Buttons and shortcuts** ([Commands, shortcuts and buttons](/docs/interactivity)). Those get no challenge, but the same signature.

With Socket Mode on, nothing goes to any of these URLs.

## Check the signature

Everything Slaiky sends your app is signed with the app’s signing secret. Find it on the app’s page, **Token and secret → Signing secret → Show secret**. **New secret** makes another one, and the old one stops working at once.

| Header | What it holds |
| --- | --- |
| `x-slaiky-request-timestamp` | When it was sent, in seconds (Unix time) |
| `x-slaiky-signature` | `v1=` and the hex HMAC-SHA256 of `v1:{timestamp}:{body}`, keyed with the signing secret |
| `x-slaiky-timestamp` | The same timestamp, for apps written before the header above |

Compute the signature over the body exactly as it arrived, byte for byte, before you parse it. Compare in constant time. Refuse a timestamp that is too old, so a copied request can’t be sent again later. Both samples do all three and answer the challenge:

*Node.js · your app → Slaiky · `verify.mjs`*

```js
// Check that a request really comes from Slaiky before you trust it. Node 22+, no packages.
import { createHmac, timingSafeEqual } from 'node:crypto';
import { createServer } from 'node:http';

const SECRET = process.env.SLAIKY_SIGNING_SECRET; // the app's signing secret (its settings page)
const MAX_AGE = 5 * 60; // seconds: refuse old requests, so a copied one can't be sent again later

export function verify(secret, timestamp, signature, rawBody) {
  if (!timestamp || !signature || Math.abs(Date.now() / 1000 - Number(timestamp)) > MAX_AGE) return false;
  const expected = `v1=${createHmac('sha256', secret).update(`v1:${timestamp}:${rawBody}`).digest('hex')}`;
  return expected.length === signature.length && timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}

if (import.meta.main) {
  createServer((req, res) => {
    let raw = '';
    req.on('data', (chunk) => (raw += chunk));
    req.on('end', () => {
      // Sign the body exactly as it arrived: parse it only after the check.
      if (!verify(SECRET, req.headers['x-slaiky-request-timestamp'], req.headers['x-slaiky-signature'], raw)) {
        res.writeHead(401).end();
        return;
      }
      const body = JSON.parse(raw);
      if (body.type === 'url_verification') {
        res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ challenge: body.challenge }));
        return;
      }
      res.writeHead(200).end(); // answer fast; do slow work after
      if (body.type === 'event_callback') console.log('event', body.event.type);
    });
  }).listen(3000, () => console.log('Listening on :3000'));
}
```

*Python · your app → Slaiky · `verify.py`*

```python
# Check that a request really comes from Slaiky before you trust it. Python 3, no packages.
import hashlib, hmac, json, os, time
from http.server import BaseHTTPRequestHandler, HTTPServer

SECRET = os.environ.get("SLAIKY_SIGNING_SECRET", "")  # the app's signing secret (its settings page)
MAX_AGE = 5 * 60  # seconds: refuse old requests, so a copied one can't be sent again later


def verify(secret, timestamp, signature, raw_body):
    if not timestamp or not signature or abs(time.time() - int(timestamp)) > MAX_AGE:
        return False
    digest = hmac.new(secret.encode(), f"v1:{timestamp}:{raw_body}".encode(), hashlib.sha256).hexdigest()
    return hmac.compare_digest(f"v1={digest}", signature)


class Events(BaseHTTPRequestHandler):
    def do_POST(self):
        raw = self.rfile.read(int(self.headers.get("content-length", 0))).decode()
        # Sign the body exactly as it arrived: parse it only after the check.
        if not verify(SECRET, self.headers.get("x-slaiky-request-timestamp"), self.headers.get("x-slaiky-signature"), raw):
            self.send_response(401)
            self.end_headers()
            return
        body = json.loads(raw)
        self.send_response(200)
        self.send_header("content-type", "application/json")
        self.end_headers()
        if body.get("type") == "url_verification":
            self.wfile.write(json.dumps({"challenge": body["challenge"]}).encode())
        elif body.get("type") == "event_callback":
            print("event", body["event"]["type"])


if __name__ == "__main__":
    HTTPServer(("", 3000), Events).serve_forever()
```

## Answer fast

Answer with a `2xx` status within 5 seconds. For an event, Slaiky reads only the status; the body is ignored. Put the slow work after the answer: a queue, a background task.

*Slaiky → your app · `POST /slaiky/events`*

```http
content-type: application/json
user-agent: Slaiky-Events/1.0
x-slaiky-request-timestamp: 1794312000
x-slaiky-signature: v1=…

{"type":"event_callback","eventId":"7f3c0006-5a1e-4c2b-9d6f-1a2b3c4d5e05","eventTime":1794312000,"appId":"…","workspaceId":"…","event":{"type":"app_mention","channelId":"…","channelType":"channel","threadId":null,"message":{"…":"…"}}}
```

*your app → Slaiky*

```http
HTTP/1.1 200 OK
```

A redirect counts as a failure: Slaiky doesn’t follow it. Answer at the URL itself. The body around each event is on [Events](/docs/reference/events#the-wrapper).

## Retries

A try fails when your server doesn’t answer in time, answers with a status that isn’t `2xx`, or can’t be reached. Then Slaiky tries again:

1. at once;
2. 1 minute after the first try;
3. a last time, 5 minutes after the first try.

After that the delivery is marked failed. Deliveries are stored before the first try, so a Slaiky restart loses none. Every try carries the same `eventId`: if one comes twice, it is one event, so handle it once.

A retry says why with two headers. `x-slaiky-retry-num` counts the tries before it, and `x-slaiky-retry-reason` names what went wrong with the last one:

| `x-slaiky-retry-reason` | The try before |
| --- | --- |
| `http_timeout` | had no answer within 5 seconds |
| `http_error` | was answered with a status that isn’t `2xx` |
| `connection_failed` | couldn’t reach your server |
| `too_many_redirects` | was answered with a redirect |

*your app → Slaiky*

```http
HTTP/1.1 503 Service Unavailable
```

*Slaiky → your app · `POST /slaiky/events (again, at once)`*

```http
x-slaiky-request-timestamp: 1794312001
x-slaiky-signature: v1=…
x-slaiky-retry-num: 1
x-slaiky-retry-reason: http_error

{"type":"event_callback","eventId":"7f3c0006-5a1e-4c2b-9d6f-1a2b3c4d5e05","…":"…"}
```

Only events are tried again. A command or a click is tried once, because a person is waiting for it.

## Stop the retries

If trying again can’t help, say so: answer with the header `x-slaiky-no-retry: 1`. The delivery is marked failed and not sent again.

*your app → Slaiky*

```http
HTTP/1.1 400 Bad Request
x-slaiky-no-retry: 1
```

## The delivery log

The app’s page lists the last 50 things sent to it under **Deliveries**: each one’s type, how many tries, the last error, and how it went (**Delivered**, **Failed** or **Waiting**). Commands, clicks and Socket Mode envelopes are there too. Deliveries are kept 3 days, then deleted. When a message is deleted, the deliveries about it keep only their type.

| Last error | What happened |
| --- | --- |
| `http_timeout`, `http_error`, `connection_failed`, `too_many_redirects` | As in [Retries](#retries) |
| `no_url` | There was no URL to send it to |
| `not_connected` | Socket Mode, and the app wasn’t connected. A command, click or submission fails then; an event waits for the app to connect |
| `not_acknowledged` | Socket Mode: sent, never acknowledged |
| `expired` | Socket Mode: an event waited 1 hour and the app never took it |
| `message_deleted` | The message was deleted before the delivery got through |
| `app_removed` | The app was removed |

## Private addresses are refused

Request URLs must be on the public internet. Slaiky checks the address it actually connects to, so a name that leads to `localhost`, `10.…`, `192.168.…` or another private network fails as `connection_failed`, and an events URL fails its challenge. To run an app on your own computer, use [Socket Mode](/docs/socket-mode).
