Introducing a new way to review your PRs.

Read the announcement

capcom6 / android-sms-gateway

The SMS Gateway for Android™ app enables sending and receiving SMS messages through an API that can be accessed directly on the device or via a cloud server when direct device access is not possible.

View on GitHub

20 documents · Updated Nov 20, 2026

docs / webhook-event-payloads

Webhook event payloads

Webhook events are JSON notifications that report message activity or application state to an external consumer. Each request has a common envelope with event identity and a typed payload, while the payload shape depends on the event family. See Webhook delivery for registration, queuing, retry, and transport behavior.

Event taxonomy

The event taxonomy separates inbound message events from outbound SMS state events, device health signals, and application lifecycle signals. Batch variants exist only for inbound SMS, data SMS, and MMS flows.

Event familyEventsPayload purpose
Inbound SMSsms:receivedText SMS content and receipt details
Inbound data SMSsms:data-receivedBase64-encoded binary SMS data and receipt details
Outbound SMSsms:sent, sms:delivered, sms:failed, sms:cancelledState changes for a sent message
Inbound MMSmms:received, mms:downloadedMMS notice before download or full content after download
Batch deliverysms:batch:received, sms:batch:data-received, mms:batch:received, mms:batch:downloadedA list of payloads from the matching inbound event
Device and application statesystem:ping, app:startedHealth status or active SIM information

An event consumer should use the event value to select the payload schema. A batch event is not a different message model. It wraps several payloads from one supported inbound event in a messages list.

References: app/…/WebHookEvent.kt• L5-55 app/…/swagger.json• L1384-1449

Webhook envelope

The webhook envelope identifies the delivery and its source device. The payload field carries the event-specific object, so consumers can route by event before reading message or application fields.

FieldMeaning
idUnique identifier for this webhook event delivery
webhookIdIdentifier of the registered webhook that receives the event
eventEvent name from the webhook taxonomy
deviceIdIdentifier of the device that emitted the event
payloadEvent-specific payload object

The application creates one envelope for each registered webhook that matches the event. The same source event can therefore produce separate deliveries with different webhookId values.

References: app/…/WebHookEventDTO.kt• L3-9 app/…/WebHooksService.kt• L126-167

Message payloads

Message payloads share identifiers and phone context so an external system can join receipt and delivery events to one message. messageId identifies the message, sender identifies its source, recipient identifies its destination when known, and simNumber identifies the one-based SIM slot when the device can determine it.

phoneNumber is retained as a compatibility field. New consumers should use sender for received events and recipient for sent events. Phone context can be absent when the device cannot determine its SIM number or phone number.

Shared fieldMeaning
messageIdMessage identifier used across related message events
senderSender phone number; for outbound events this can be the device number
recipientRecipient phone number; for inbound events this can be the device number
simNumberOne-based SIM slot number, or null when unknown
phoneNumberOlder sender-or-recipient field kept for compatibility

Event-specific fields extend this shared model:

EventAdditional fields
sms:receivedmessage, receivedAt
sms:data-receiveddata, receivedAt
sms:sentpartsCount, sentAt
sms:delivereddeliveredAt
sms:failedfailedAt, reason
sms:cancelledcancelledAt

Time fields represent the event time and are serialized as date-time values. Data SMS content is Base64 encoded. A failed SMS includes a reason chosen from the message state error or an Unknown fallback.

The system:ping payload reports the current health value in a health field. It is a health signal rather than a message payload.

References: app/…/MessageEventPayload.kt• L3-11 app/…/SmsEventPayload.kt• L5-65 app/…/EventsReceiver.kt• L32-91 app/…/swagger.json• L1451-1497

MMS payloads

MMS delivery has two stages because the first notification can arrive before the message content is available. mms:received reports the incoming MMS and its download metadata. mms:downloaded reports the full message body and the attachment data available after download.

EventAdditional fieldsMeaning
mms:receivedtransactionId, subject, size, contentClass, receivedAtEarly MMS notice and content metadata
mms:downloadedbody, subject, attachments, receivedAtDownloaded message content

Each item in attachments contains partId, contentType, name, size, and data. data is Base64 encoded and can be null when content is not available. body and subject can also be null.

The two events use the shared message fields. Consumers that need message content should wait for mms:downloaded; consumers that only need arrival notice can act on mms:received.

The Inbound SMS and MMS capture page explains how these inbound events enter the system. The Outbound message delivery page explains the message states that produce outbound SMS events.

References: app/…/MmsReceivedPayload.kt• L5-15 app/…/MmsDownloadedPayload.kt• L5-21 app/…/ReceiverService.kt• L174-203 app/…/swagger.json• L4-112

Batch payloads

Batch payloads reduce the number of webhook requests when several inbound messages are processed together. The payload is an object with a messages list, and every list item uses the single-message model for the related event.

The supported mappings are:

Batch eventItem payload
sms:batch:receivedsms:received payload
sms:batch:data-receivedsms:data-received payload
mms:batch:receivedmms:received payload
mms:batch:downloadedmms:downloaded payload

The application groups messages by event type before it builds batches. It then splits each group into bounded chunks. This keeps unlike message types out of one batch and preserves the item shape that consumers already use for individual events.

References: app/…/BatchEventPayload.kt• L3-5 app/…/SmsBatchReceivedPayload.kt• L3-5 app/…/SmsDataBatchReceivedPayload.kt• L3-5 app/…/MmsBatchReceivedPayload.kt• L3-5 app/…/MmsBatchDownloadedPayload.kt• L3-5 app/…/ReceiverService.kt• L207-247

Application-started payload

The app:started event tells external consumers that the application has started and reports the active SIM cards at that point. Its payload contains a simCards list rather than message fields.

Each SIM entry describes the physical slot and the available subscription data:

FieldMeaning
slotIndexZero-based physical slot index
simNumberOne-based SIM slot number
phoneNumberPhone number associated with the SIM, when available
carrierNameCarrier name, when available
iccidSIM identifier, when available

The event is emitted after the application starts its main services. It gives an external consumer a current device and SIM view without requiring a separate message event.

References: app/…/AppStartedPayload.kt• L3-7 app/…/SimCard.kt• L3-18 app/…/OrchestratorService.kt• L35-66 app/…/swagger.json• L1226-1249

Event-to-payload flow

Inbound capture and message state changes produce typed payloads before the webhook service adds the common envelope. The resulting event is then matched to registered consumers and enters the delivery flow described in Webhook delivery.

flowchart LR
    A[Inbound SMS or MMS] --> B[Message payload]
    C[Outbound message state] --> B
    D[Application start or ping] --> E[System payload]
    B --> F[Event name]
    E --> F
    F --> G[Common webhook envelope]
    G --> H[Matching registered webhook]
    H --> I[External consumer]

The inbound path saves the message before it emits its payload. Duplicate inbound messages do not create another event. Outbound state events are emitted per destination, so one multi-recipient message can yield separate recipient-specific deliveries.

References: app/…/ReceiverService.kt• L100-186 app/…/EventsReceiver.kt• L17-93 app/…/OrchestratorService.kt• L61-66 app/…/WebHooksService.kt• L126-170

Change checklist

When these files or sections are changed, remember to consider these:

  • Update the event taxonomy and the API schema together when an event name is added, removed, or renamed.
  • Keep each batch event mapped to the same item payload as its individual event. A mismatch breaks consumers that share item parsing logic.
  • Preserve the shared message-field meaning across inbound and outbound events. In particular, check sender, recipient, and the compatibility phoneNumber field.
  • Update both MMS stages when message identifiers or attachment fields change. Consumers may use mms:received as the key for later mms:downloaded content.
  • Keep app:started SIM field names aligned with the SIM model used by the device and API schema.
  • Treat date-time and Base64 fields as external data contracts. A format change affects every event consumer.

Important failure modes

TriggerConsequenceGuard
Consumer parses only the single-message schema for a batch eventThe top-level messages list is not processedBranch on the event value before decoding payload
Consumer treats mms:received as full MMS contentThe consumer acts before body or attachment data is availableUse mms:downloaded for content-dependent work
SIM or phone data is unavailablesimNumber, recipient, or SIM-card fields can be nullHandle missing device subscription data without rejecting the event
Data SMS or attachment content is decoded as plain textBinary content is corruptedBase64-decode data fields before use
One outbound message has multiple recipientsState events arrive as separate recipient-specific deliveriesCorrelate by messageId and recipient
An inbound message is detected as a duplicateNo new payload is emitted for that messageUse the message identifier and event history as an idempotency key

Key files

FileWhy to read it
app/…/WebHookEvent.ktDefines the event names and supported batch relationships
app/…/WebHookEventDTO.ktDefines the common webhook envelope
app/…/MessageEventPayload.ktDefines fields shared by message events
app/…/SmsEventPayload.ktDefines SMS receipt and outbound state payloads
app/…/MmsReceivedPayload.ktDefines the pre-download MMS notice
app/…/MmsDownloadedPayload.ktDefines downloaded MMS content and attachment data
app/…/ReceiverService.ktConnects inbound SMS/MMS records to individual and batch webhook payloads
app/…/EventsReceiver.ktConnects outbound message states and system pings to webhook events
app/…/OrchestratorService.ktEmits the application-started event
app/…/swagger.jsonPublishes the external event and payload schema