By the end of this module, you can
- Subscribe a webhook and build an endpoint that answers in time
- Verify a signature and survive duplicate, out-of-order deliveries
- Map messages to chats and answer inside the reply lane
- Use typing indicators, read receipts and tapbacks where they fit
A text is worth sending because someone may answer it. When they do, your software has to hear it, trust it, remember it and reply in a way that reads like a person. Webhooks carry the first three; iMessage’s chat features help with the fourth.
Lesson 1 of 4How replies reach you
When someone texts your line, the line’s device sees the message, iSnap records it, and iSnap sends an event to every webhook subscription that asked for it. Your server receives an HTTP POST and decides what to do: store it, hand it to your agent, alert a person.
Events cover much more than inbound texts. There are 37 event types in nine families, and three families do most of the work:
message.*(9 types):message.receivedfor inbound texts, and the life of every message you send:queued,scheduled,sent,delivered,read,failed,cancelled, andfallback_triggeredwhen a send goes out as SMS.reaction.*(3 types): tapbacks added, received and removed.line.*(12 types): a line connected, went offline, degraded, had its Apple ID flagged, neared a limit, and more. Module 5 covers what to do about each.
Subscribe
Create a subscription with your endpoint’s URL and the events you want. A family wildcard such as message.* covers every type in it, and * covers everything.
import { ISnapClient } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
// maxRetries: 0, because this operation does not honor Idempotency-Key:
// a retry after a lost response would create a second subscription.
const subscription = await client.webhooks.create(
{ url: 'https://hooks.your-domain.example/isnap', events: ['message.*'] },
{ maxRetries: 0 }
)
console.log(subscription.id)
// Store subscription.secret now as ISNAP_WEBHOOK_SECRET: no other call returns it.From the iSnap docs: Quickstart, receive its events
The response holds the signing secret, once. Store it straight away (the docs call it ISNAP_WEBHOOK_SECRET): no other call returns it. This write does not honour idempotency keys, which is why the sample turns retries off: a retry after a lost response would create a second subscription.
What arrives
Each delivery is one event as JSON. Here is a message.received, trimmed to the fields that matter here:
{
"api_version": "v1",
"event_id": "evt_Fh50GcqYY37ay4VjUxQ2rR6jN",
"event_type": "message.received",
"created_at": "2026-10-08T14:22:57.143Z",
"trace_id": "174b4a27e4e4938fa67ea87b23a18579",
"data": {
"message": {
"id": "msg_7Hq3Zd9Kp2Vx6Wn4Tb8Lc5Ym1",
"line_id": "line_8Xk2mQ4vTn7Bw9Rz3Lc6Yp1Hd",
"direction": "inbound",
"kind": "message",
"to": "+14155550124",
"from": "+14155550123",
"body": "Is the table still free at 8?",
"service": "iMessage",
"status": "delivered",
"reply_lane": false,
"created_at": "2026-10-08T14:22:57.101Z",
"delivered_at": "2026-10-08T14:22:56.000Z",
"read_at": null,
"failed_at": null,
"error_code": null,
"error_message": null,
"cancelled_at": null
},
"chat_id": "chat_6Rm1Yb5Tq9Hd3Kx7Wc2Ln8Vz4",
"contact_name": "Dana Whitfield",
"received_at": "2026-10-08T14:22:56.000Z",
"metadata": null,
"line_metadata": { "crm_account_id": "acct_4821" }
}
}From the iSnap docs: Event catalog, the envelope (trimmed)
event_idis unique to the event, and a retry of the same event carries the same id.data.messageis the message itself: who wrote, to which line, the text and the service.chat_idnames the conversation (lesson 3), andcontact_nameis there when the device knows one.line_metadatais whatever you stored on the line, such as the CRM account it belongs to, so you can route the event without a lookup.
Lesson 2 of 4What your endpoint must do
The webhook contract is short, and every rule in it is there because something breaks without it.
- Be public and secure. HTTPS on a public host with a standard certificate. No redirects: a
3xxcounts as a failure. - Verify the signature on the raw body, before you parse it.
- Answer within 10 seconds with a
2xx. Respond first, then do the work, for example from a queue. - Expect duplicates. Delivery is at least once, so deduplicate on
event_id. - Don’t rely on order. Events can arrive in a different order from the one they happened in.
- Accept event types you don’t know. New ones can be added; ignore what you don’t handle.
- Never return
410. It turns the subscription off.
Signatures
iSnap signs every delivery with the Standard Webhooks scheme, so any Standard Webhooks library works with the secret as returned. Three headers carry the signature: webhook-id (the event id), webhook-timestamp and webhook-signature. The signature is an HMAC-SHA256 of webhook-id.webhook-timestamp.raw-body, keyed with the secret base64-decoded after its whsec_ prefix. Refuse a timestamp more than 300 seconds from your clock, so an old delivery cannot be replayed at you.
With the SDK, verifyWebhook does all of it and throws WebhookSignatureError when anything is off. Note the order: read the raw body, verify, deduplicate, then process.
import { createServer, type IncomingMessage } from 'node:http'
import {
WebhookSignatureError,
isMessageEvent,
verifyWebhook,
type WebhookEventBase
} from '@isnap/sdk'
const handle = async (req: IncomingMessage): Promise<number> => {
if (req.method !== 'POST' || req.url !== '/webhooks/isnap') return 404
// Keep the body as received. Verification fails on a body that was parsed and serialized again.
const chunks: Buffer[] = []
for await (const chunk of req) chunks.push(chunk as Buffer)
const rawBody = Buffer.concat(chunks).toString('utf8')
let event: WebhookEventBase
try {
event = verifyWebhook(rawBody, req.headers, secret)
} catch (err) {
if (err instanceof WebhookSignatureError) return 400
throw err
}
// A retry or a replay carries the same event_id.
if (processed.has(event.event_id)) return 200
await processEvent(event)
// Record the event_id only after the work succeeded. When processEvent throws,
// the server responds 500, and the next attempt, if one remains, processes the event.
processed.add(event.event_id)
return 200
}From the iSnap docs: Example: handling webhooks (trimmed to the handler)
The docs’ full example adds the event handler and the server around it, and Verifying signatures has a version in Python’s standard library for servers without the SDK.
Retries, suspension and catching up
If your endpoint fails, iSnap tries again, up to 7 attempts in all: at once, then after 30 seconds, 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours. After 10 deliveries in a row fail completely, the subscription is suspended, and events that happen while it is suspended are lost.
Two tools cover the gaps. The events feed, GET /v1/webhooks/events, keeps the last 72 hours of events, and you can replay a past delivery while its record exists. Above both, the resource is the source of truth: when in doubt, read the message or the line from the API.
Lesson 3 of 4Chats, contacts and the reply lane
A chat is the conversation between one line and one contact, with an id such as chat_6Rm1Yb5Tq9Hd3Kx7Wc2Ln8Vz4. Every inbound event carries its chat_id, and the chat features in lesson 4 are called on the chat. A chat belongs to the line, not to your account: if a line moves to another account, its chats go with it.
Chats are never deleted, but the messages in them are. iSnap keeps messages for at least 72 hours, then deletes them, and attachments expire 72 hours after they are created. Copy what you need into your own system when the event arrives. Your CRM, not iSnap, is the history of the conversation.
Known and new contacts
A contact who wrote to the line in the last 30 days is known; everyone else is new. Sending to someone does not make them known: only their writing does. Lines treat the two differently (by default a line starts at most 50 conversations with new contacts a day, and can message 200 known contacts a day), which is one more reason to invite people to write first.
The reply lane
When a contact writes, your line can answer them more freely for the next 24 hours. Replies in this reply lane skip the line’s hourly and daily limits and its quiet hours. The per-minute limit and the spacing between messages still apply, and the lane has a budget: up to 8 replies per inbound message, and 150 reply-lane messages per line in 24 hours.
message.received · 9:31 PM, his time
Reply lane: sent at once, past quiet hours
message.received
That is why Inbound lines, the “text us” numbers people write to first, are so easy on a line’s limits: almost everything they send is a reply.
Lesson 4 of 4Make the conversation feel present
An agent that answers in under a second with a wall of text does not read like a person. iMessage’s chat features let your software behave like someone who is there. They are iMessage features: they are not available on SMS, and on a BYOP line they depend on the device.
Typing indicators
Every send shows typing first by default (use_typing_indicator), for a time based on the text’s length: 225 characters a minute, between 0.8 and 6 seconds. To show typing while your agent is still thinking, start it on the chat. It shows for 15 seconds, or until you clear it or send.
import { ISnapClient, UnprocessableEntityError } from '@isnap/sdk'
const client = new ISnapClient({ apiKey: process.env.ISNAP_API_KEY ?? '', maxRetries: 2 })
const chatId = 'chat_7Bw9Rz3Lc6Yp1Hd8Xk2mQ4vTn'
try {
const typing = await client.chats.typingStart(chatId, {})
console.log(`Shown until ${typing.expires_at}, if the device can show it`)
// ... write the answer, then clear the indicator if the answer is not sent.
await client.chats.typingStop(chatId)
} catch (err) {
if (err instanceof UnprocessableEntityError) {
// sms_typing_not_supported or unsupported_handle: this chat cannot show it.
console.error(err.code)
} else {
throw err
}
}From the iSnap docs: Chat features, the typing indicator
Two limits are worth knowing. iSnap never shows typing before a first message to a new contact. And it works one way: no iMessage line reports that a contact is typing.
Read receipts
Marking a chat read sends read receipts for the conversation, the way opening it on your phone would. It marks the whole conversation, not one message. Do it when your agent or a person has actually taken the message in, not the instant it arrives.
curl -sS -X POST https://api.isnap.ai/v1/chats/chat_7Bw9Rz3Lc6Yp1Hd8Xk2mQ4vTn/read \
-H "Authorization: Bearer $ISNAP_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'From the iSnap docs: Chat features, read receipts
Tapbacks and threaded replies
A tapback (love, like, dislike, laugh, emphasize or question) acknowledges a message without a new text: a like on “Booked, see you Friday” closes the loop the way a person would. Your contacts’ tapbacks reach you as reaction.received, custom emoji included. To answer one message in a busy thread, send with reply_to_message_id.
A pattern for agents
message.receivedarrives. Verify it, store it and answer2xx.- Your agent reads the conversation from your own store and drafts an answer. If that takes a while, start the typing indicator.
- When the answer is ready, mark the chat read, so the read receipt and the reply arrive together.
- Send the answer inside the reply lane, with
use_typing_indicatorleft on. - Watch
message.delivered, ormessage.failedand itserror_code, and hand the conversation to a person whenever your agent should not answer alone.
Key terms
- Webhook subscription
- Your endpoint’s URL, the events it wants, and the secret that signs them. Created with POST /v1/webhooks.
- Event
- One thing that happened, delivered as JSON: message.received, message.delivered, line.offline and 34 more types.
- event_id
- The event’s unique id. A retry or replay carries the same one: deduplicate on it.
- Signing secret
- The whsec_ value returned once when you subscribe. It verifies that a delivery came from iSnap.
- Standard Webhooks
- The open signing scheme iSnap uses: HMAC-SHA256 over the id, the timestamp and the raw body.
- Chat
- The conversation between one line and one contact. It belongs to the line and is never deleted.
- Known contact
- Someone who wrote to the line in the last 30 days. Everyone else is a new contact.
- Reply lane
- For 24 hours after a contact writes, replies to them skip hourly and daily limits and quiet hours, within a budget.
- Tapback
- An iMessage reaction: love, like, dislike, laugh, emphasize or question.
- Events feed
- GET /v1/webhooks/events: the last 72 hours of events, to catch up after an outage.
Check yourself
Answer each question in your head first, then open it to compare.
Your endpoint receives the same message.received event twice. Is something broken?
No. Delivery is at least once, so duplicates are normal. Both carry the same event_id: record ids once the work succeeds, and answer 200 to a repeat without doing the work again.
Your handler parses the JSON, serialises it again and verifies that. Every signature fails. Why?
The signature covers the raw body, byte for byte. Parsing and serialising again changes spacing and key order. Verify the body exactly as received, then parse it.
A lead texted at 9:30 PM their time. Your agent’s answer is ready a minute later. Does it go now?
Yes. A reply within 24 hours of the contact’s message rides the reply lane, which skips quiet hours and the hourly and daily limits. The per-minute limit and spacing still apply, so it may wait a few seconds, not until morning.
Back to the course, or go deeper in the iSnap API docs.