Blog ·

Get every incoming text as a signed webhook

Point Simline at a URL and every reply, delivery report and phone status arrives as a signed POST. Payloads, signature checks in Node and Python, retries, replays and deduplication.

  • API
  • Webhooks

Polling for replies works for a script. For anything a customer is waiting on, you want Simline to tell you the moment a text arrives. Webhooks do that: you give Simline a URL, and each new text, delivery report and phone going on or offline becomes a POST to it, signed so you know it came from us.

This post sets up an endpoint, shows the real payload, verifies signatures in Node and Python, and covers what happens when your server is down.

Tested on 28 November 2026 against Simline’s API (a local build of the current code) with a simulated test phone. Both receivers below ran against it: Node 22 with only built-in modules, and Python 3.13 with Flask 3.1. Each accepted real events and rejected a forged signature with 401.

Create an endpoint

In the dashboard, open Developers → Webhooks, add your URL, and pick the events (or keep all of them) and the phones (every phone, including ones you pair later, or only some). The signing secret starts with whsec_ and is shown once.

You can do the same with an API key that has both the send and read scopes:

curl https://api.simline.dev/v1/webhooks \
  -H "Authorization: Bearer $SIMLINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/simline/hook", "events": ["message.received", "message.failed"]}'

The URL must be https:// on a public host: no IP addresses, no localhost, no internal names. A workspace can have up to 20 endpoints.

The events

Event When
message.received A new text arrived on one of your phones.
message.sent Every part of an outbound text left the phone.
message.delivered The carrier confirmed delivery of every part.
message.failed An outbound text failed; errorCode says why.
device.online / device.offline A phone came back, or became unreachable: it didn’t answer a wake-up. A phone that is just asleep (it wakes when a text arrives) sends nothing. Sent only when it changes.

There is one event per message, attempt and state, so a text that fails and then succeeds on a second attempt gives you both.

What arrives

Each request carries these headers:

POST /simline/hook
Content-Type: application/json
Simline-Event-Id: evt_cbb3ca99be3d5358e027f561a3c72896
Simline-Event-Type: message.received
Simline-Delivery-Id: whd_AuER0XoaWoMaTw3bPa7KoQ
Simline-Attempt: 1
Simline-Signature: t=1795857276,v1=5f2c…

And this body. This is the message.received event from our test, when a customer texted the shop’s second SIM:

{
  "id": "evt_cbb3ca99be3d5358e027f561a3c72896",
  "type": "message.received",
  "createdAt": "2026-11-28T09:14:36.438Z",
  "data": {
    "id": "msg_74e559d6d3b39531c3b4e054955a8461",
    "direction": "inbound",
    "status": "received",
    "finalStatus": true,
    "channel": "sms",
    "contact": "+33600000042",
    "body": "Bonjour, est-ce que la tarte aux pommes est prête ?",
    "deviceId": "dev_local",
    "simSlot": 1,
    "parts": null,
    "attempt": 1,
    "errorCode": null,
    "idempotencyKey": null,
    "apiKeyId": null,
    "userId": null,
    "agentId": null,
    "createdAt": "2026-11-28T09:14:35.414Z",
    "updatedAt": "2026-11-28T09:14:36.438Z",
    "sentAt": null,
    "deliveredAt": null,
    "readAt": null
  }
}

data is the message exactly as GET /v1/messages/{id} returns it. simSlot tells you which SIM got the text, which matters when you reply: see replying from the SIM that received the text. For device.* events, data is smaller:

{"deviceId": "dev_local", "name": "Dev phone", "status": "online", "at": "2026-11-28T09:14:39.415Z"}

Verify the signature

Simline-Signature looks like t=<unix seconds>,v1=<hex>. The hex is HMAC-SHA256 over the timestamp, a dot and the raw request body, keyed with the whole secret string, whsec_ included. To check it:

  1. Read the raw body bytes. Don’t parse and re-serialize the JSON first; a single changed space breaks the signature.
  2. Reject a timestamp more than 5 minutes from your clock, so an old request can’t be replayed at you.
  3. Compute the HMAC and compare in constant time.
  4. Accept if any v1= matches. While you rotate a secret, Simline signs with both the old and the new one for a grace period (a day by default).

Node (no dependencies)

import { createHmac, timingSafeEqual } from "node:crypto"
import { createServer } from "node:http"

const SECRET = process.env.SIMLINE_WEBHOOK_SECRET // whsec_…, shown once when you create the endpoint
const seen = new Set() // use your database in production

export function verifySimline(secret, header, rawBody, toleranceSeconds = 300) {
  const parts = header.split(",").map((p) => p.trim().split("="))
  const t = Number(parts.find(([k]) => k === "t")?.[1])
  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex")
  return parts
    .filter(([k]) => k === "v1")
    .some(([, v]) => v.length === expected.length && timingSafeEqual(Buffer.from(v), Buffer.from(expected)))
}

createServer((req, res) => {
  const chunks = []
  req.on("data", (c) => chunks.push(c))
  req.on("end", () => {
    const raw = Buffer.concat(chunks).toString("utf8")
    if (!verifySimline(SECRET, req.headers["simline-signature"] ?? "", raw)) {
      res.writeHead(401).end()
      return
    }
    const event = JSON.parse(raw)
    res.writeHead(204).end() // answer fast; do the work after

    if (seen.has(event.id)) return // a retry or replay of an event you already handled
    seen.add(event.id)
    if (event.type === "message.received") {
      console.log(`${event.data.contact} wrote: ${event.data.body}`)
    } else {
      console.log(event.type, event.id)
    }
  })
}).listen(Number(process.env.PORT ?? 8788))

With Express, use express.raw({ type: "application/json" }) on the route and pass req.body.toString("utf8") to verifySimline, so you sign-check the bytes before anything parses them.

Python (Flask)

import hashlib
import hmac
import json
import os
import time

from flask import Flask, request

app = Flask(__name__)
SECRET = os.environ["SIMLINE_WEBHOOK_SECRET"]  # whsec_…
seen: set[str] = set()  # use your database in production


def verify_simline(secret: str, header: str, raw_body: bytes, tolerance_seconds: int = 300) -> bool:
    parts = [p.strip().split("=", 1) for p in header.split(",") if "=" in p]
    t = next((v for k, v in parts if k == "t"), "")
    if not t.isdigit() or abs(time.time() - int(t)) > tolerance_seconds:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(v, expected) for k, v in parts if k == "v1")


@app.post("/hook")
def hook():
    raw = request.get_data()  # the exact bytes, before any JSON parsing
    if not verify_simline(SECRET, request.headers.get("Simline-Signature", ""), raw):
        return "", 401
    event = json.loads(raw)
    if event["id"] in seen:
        return "", 204  # already handled: a retry or a replay
    seen.add(event["id"])
    if event["type"] == "message.received":
        print(f"{event['data']['contact']} wrote: {event['data']['body']}")
    else:
        print(event["type"], event["id"])
    return "", 204

Run it with flask --app receiver run. In our test, both servers printed +33600000042 wrote: Bonjour, est-ce que la tarte aux pommes est prête ? (accents intact), and a request with a made-up v1= got 401.

Retries, replays and turning off

Simline treats your endpoint like a phone that might be asleep: it keeps the event until you take it.

  • Success is any 2xx within 10 seconds. Redirects aren’t followed.
  • Retries: attempt 1 right away, then after 30 seconds, 2 minutes, 10 minutes, 1 hour, 3 hours, 6 hours and 12 hours. That’s 8 attempts over about 22 hours. When we pointed an endpoint at a port with nothing listening, the second attempt came 31 seconds after the first.
  • Dead letters: after the 8th failure the delivery is failed, and you can replay it from the endpoint’s delivery log in the dashboard or with POST /v1/webhook-deliveries/{id}/replay. A replay sends the same event with the same id and identical bytes.
  • Auto-disable: if an endpoint has failed continuously for 3 days, Simline turns it off, marks its pending deliveries failed and emails the workspace owners. Turn it back on in the dashboard (or PATCH {"enabled": true}) once it’s fixed.
  • Test events: the Send test event button (or POST /v1/webhooks/{id}/test) sends a webhook.test event once, right away, with no retries.

Each delivery’s attempts, status codes, response snippets and timings are in the endpoint’s Delivery log.

Idempotency on your side

Delivery is at least once. A retry after a timeout, a replay you asked for, or a rare race can deliver the same event again, always with the same id. Order isn’t guaranteed either: message.delivered can, in principle, arrive before message.sent.

So:

  • Store the event id (Simline-Event-Id, or id in the body) in a table with a unique constraint, and skip events you’ve seen. Our replay test sent a handled message.received again; the receivers answered 204 and did nothing.
  • Answer first, work after. Return 2xx as soon as the signature checks out, then process. Slow handlers cause timeouts, and timeouts cause duplicates.
  • Don’t trust order, trust state. When you update a message in your database, move its status forward only (sent doesn’t replace delivered), or simply fetch GET /v1/messages/{id} and store what it says.

What webhooks don’t do

  • No texts from before pairing. The phone forwards texts that arrive after it’s connected; it can’t read the inbox.
  • No private network URLs. The live service only calls public https:// hosts and checks the address on every attempt.
  • No guaranteed order (see above).

Once replies arrive in your app, sending one back is a single call: send a text from your code. If you’d rather read and answer them without writing code, use Telegram.

FAQ

Which events can I subscribe to?
message.received, message.sent, message.delivered, message.failed, device.online and device.offline. New endpoints get all of them unless you pick some.
How long does Simline keep retrying?
Eight attempts over about 22 hours. After that the delivery is marked failed and you can replay it. An endpoint that has failed continuously for 3 days is turned off and the workspace owners get an email.
Can the same event arrive twice?
Yes. Delivery is at least once, so store each Simline-Event-Id you have handled and skip repeats.
Can I test webhooks on localhost?
Not against the live service, which only calls public https URLs. Use a tunnel to expose your local server, or send a test event once your endpoint is deployed.