SMSNET
Guide · Pillar

How to Receive SMS and Handle Replies with Webhooks

To receive SMS replies, poll GET /api/v1/messages with a cursor, or register a webhook and let SMSNET POST each reply as it arrives. Polling needs no public URL and suits scripts; a webhook delivers in about a second, signs every event, and retries 6 times over 9 hours when you are down. Prototype with polling, ship with a webhook.

Should I poll or use a webhook?

FeaturePollingWebhook
How it worksGET /api/v1/messages?direction=inbound, passing back next_cursor as sinceSMSNET POSTs a message.received event to your URL
Needs a public URLNoYes, HTTPS
LatencyWhatever your poll interval is, usually secondsAbout a second
Best forScripts, prototypes, and as a backup readerProduction servers, instant answers, automation

Polling starts without since to get the latest page, then keeps the cursor:

curl "https://smsnet.net/api/v1/messages?direction=inbound&limit=100" \
  -H "X-API-Key: $SMSNET_API_KEY"
curl "https://smsnet.net/api/v1/messages?direction=inbound&limit=100&since=<next_cursor>" \
  -H "X-API-Key: $SMSNET_API_KEY"

Every message carries from_number, body and conversation_id. The same feed reports delivery of your outbound texts through message.status events, so one reader covers both directions. A Python polling loop is shown in Send an SMS from a Python Script.

Polling calls the feed on a timer with a cursor; a webhook receives each event signed, with dedupe and retries.

Polling vs webhook: two paths that read the same replies Side by side comparison. On the left, polling: your code calls GET messages with a since cursor on a timer and needs no public URL. On the right, webhook: SMSNET posts each event to your URL with an HMAC signature, delivery dedupe, and 6 retries. Both paths converge on the same message states. Polling vs webhook: pick by setup, both read the same feed Prototype with polling, ship with a webhook, keep polling as backup. Poll: you ask on a timer GET /messages?direction=inbound since cursor: next_cursor back each call No public URL needed, fits scripts Latency equals your poll interval Miss nothing: cursor dedupes repeats Webhook: SMSNET calls you POST message.received to your URL HMAC signature verified first Delivery id dedupes every retry 6 retries over about 9 hours About a second, needs HTTPS Both observe the same states pending, ready, sent, delivered, failed, expired
Diagram comparing polling and webhooks: polling calls GET messages with a since cursor on a timer and needs no public URL, while a webhook receives a signed POST with delivery dedupe and six retries, and both observe the same message states.

How do I register a webhook?

Register your HTTPS endpoint once with PUT /api/v1/webhooks and keep the secret from the response for signature checks:

curl -X PUT https://smsnet.net/api/v1/webhooks \
  -H "X-API-Key: $SMSNET_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/sms"}'

SMSNET then POSTs two event types to that URL: message.received for every inbound reply and message.status when an outbound message reaches sent, delivered or failed. Before any real traffic exists, replay a sample event any time with:

curl -X POST https://smsnet.net/api/v1/webhooks/test \
  -H "X-API-Key: $SMSNET_API_KEY"

How do I verify the signature?

Every delivery carries three headers: X-SMSNET-Timestamp, X-SMSNET-Signature (the literal v1= plus hex HMAC-SHA256 over the timestamp, a dot, and the raw request body), and X-SMSNET-Delivery (a stable id for dedupe). Reject anything older than 5 minutes, compare in constant time, and verify against the raw body before any parser touches it. In Node:

import crypto from "node:crypto";

function verifySmsnetWebhook(secret, timestamp, rawBody, signature) {
  if (Math.abs(Date.now() / 1000 - Number(timestamp || 0)) > 300) return false;
  const expected = "v1=" + crypto.createHmac("sha256", secret)
    .update(timestamp + "." + rawBody, "utf8").digest("hex");
  if (expected.length !== (signature || "").length) return false;
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature));
}

The same check in Python behind Flask:

import hmac, hashlib, os, time
from flask import Flask, request, abort

app = Flask(__name__)
SECRET = os.environ["SMSNET_WEBHOOK_SECRET"]
seen = set()

@app.post("/sms")
def sms_webhook():
    ts = request.headers.get("X-SMSNET-Timestamp", "")
    sig = request.headers.get("X-SMSNET-Signature", "")
    if abs(time.time() - int(ts or 0)) > 300:
        abort(400)  # older than the 5 minute tolerance, or missing
    expected = "v1=" + hmac.new(SECRET.encode(), f"{ts}.".encode() + request.get_data(), hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, sig):
        abort(400)
    delivery = request.headers.get("X-SMSNET-Delivery", "")
    if delivery in seen:
        return "", 200  # a retry of an event already handled
    seen.add(delivery)
    event = request.get_json()
    if event["event"] == "message.received":
        print("reply from", event["data"]["from"], ":", event["data"]["body"])
    elif event["event"] == "message.status":
        print(event["data"]["message_id"], "is now", event["data"]["status"])
    return "", 200

What if my endpoint is down?

SMSNET retries the delivery 6 times over about 9 hours with the same X-SMSNET-Delivery id, then stops. Two habits make this painless: return 200 fast and process each event asynchronously so a slow handler never looks like downtime, and keep polling GET /api/v1/messages as a backup reader so nothing is ever truly lost.

How do I keep replies in one thread?

Every inbound and outbound message with one contact shares a conversation_id. Store it alongside your user record when the first message arrives, answer with POST /api/v1/messages/send to the same number, and the exchange stays in one thread on both sides. That id is also the key for automation: SMS Automation routes each inbound event to the right workflow by conversation.

Replies never count against your plan, and everything here runs on the free plan: 300 outbound messages a month and 20 a day. The full endpoint list lives in What Is an SMS API and How to Use One, and agents can poll and reply through the MCP server. Grab a key in the app and send yourself the test event first.

FAQ

How do I receive SMS replies with the API?

Either poll GET https://smsnet.net/api/v1/messages with direction inbound and pass back next_cursor as since on each call, or register a webhook once and receive a signed message.received event for every reply. Polling needs no public URL; a webhook delivers in about a second.

How do I register a webhook endpoint?

Send PUT to https://smsnet.net/api/v1/webhooks with JSON holding your HTTPS url, using your SMSNET API key, and keep the secret from the response for signature checks. Then send POST to /api/v1/webhooks/test to replay a sample event before real traffic arrives.

How do I verify a webhook signature?

Take the X-SMSNET-Timestamp header, a dot, and the raw request body, compute HMAC-SHA256 with your webhook secret, and compare it with the X-SMSNET-Signature header, which starts with v1=. Reject anything older than five minutes and compare with a constant time function.

What happens if my server is down when a reply arrives?

SMSNET retries the delivery nine times over about three days with the same X-SMSNET-Delivery id, then stops. Return 200 fast and process each event asynchronously so a slow handler never looks like downtime.

How do I avoid handling the same reply twice?

Deduplicate on the X-SMSNET-Delivery header, which is stable across retries of the same event. Store each id you have processed and skip repeats; polling with next_cursor gives the same guarantee in the other direction.

How do I keep a conversation in one thread?

Group messages by conversation_id, which is shared by every inbound and outbound message with one contact. Answer with POST /api/v1/messages/send to the same number and the reply lands in the same thread on both sides.

This pillar builds on What Is an SMS API and How to Use One. Next steps: SMS Automation: Trigger Texts from Any Workflow, Send an SMS from a Python Script, and What Is an MCP Server for SMS?.

Send your first message today

Free plan, no card: 400 messages a month from your own number, with the API, webhooks and MCP included.

Get the app See pricing

Get it on Google Play

Written by , who builds SMSNET. Product facts on this page are checked against the live pricing page and the running API on the date shown above.