Introducing a new way to review your PRs.

Read the announcement

ndolestudio / httpsms

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API with end to end encryption supported.

View on GitHub

22 documents · Updated Nov 18, 2026

docs / webhooks

Webhooks

Webhooks let an account send selected HTTPSMS events to an external HTTP endpoint. An account stores each destination with its event and phone filters, and the event system can send a signed JSON request when a matching message or phone event occurs. This page is a child of Integrations and automation; see SMS message lifecycle for the source message events, Discord and email notifications for related alert paths, and 3CX integration for a separate external message integration.

Webhook configuration

Webhook configuration defines which account events reach which external system. The account can create, list, update, and delete configurations through the authenticated webhook API; each configuration has a URL, a set of phone numbers, a set of event names, and an optional signing key. api/…/webhook_handler.go• L43-49 api/…/webhook.go• L10-20

The service accepts only known event names and requires each selected phone number to belong to the account. It removes duplicate event names during input cleanup. An account can have up to ten webhook configurations unless it uses the enterprise plan. api/…/validator.go• L135-163 api/…/webhook_handler_validator.go• L64-103 api/…/webhook_handler.go• L150-172

Configuration filters

The event filter and phone filter work together. A webhook receives an event only when both the event name and the phone number appear in that webhook's saved lists. The supported user-selectable events are:

Event groupEvent names
Message activitymessage.phone.received, message.phone.sent, message.phone.delivered
Message failure or expirymessage.send.failed, message.send.expired
Phone availabilityphone.heartbeat.online, phone.heartbeat.offline
Call activitymessage.call.missed

Account deletion is handled as an internal cleanup event. It is not a selectable delivery event. api/…/validator.go• L135-163 api/…/webhook_listener.go• L33-43

References: api/…/validator.go• L135-163 api/…/webhook_listener.go• L33-43 api/…/gorm_webhook_repository.go• L76-89

Webhook management API

The management API keeps webhook changes inside the authenticated account boundary. Its main contract is:

OperationEndpointResult
ListGET /v1/webhooksReturns the account's saved webhooks with paging and URL search.
CreatePOST /v1/webhooksSaves a new webhook and returns its state.
UpdatePUT /v1/webhooks/{webhookID}Replaces the destination, signing key, event list, and phone list.
DeleteDELETE /v1/webhooks/{webhookID}Removes one webhook from the account.

The dashboard uses the same API for webhook management. api/…/webhook_handler.go• L43-49 web/…/billing.ts• L88-124

References: api/…/webhook_handler.go• L43-49 api/…/webhook_handler.go• L67-89 api/…/webhook_handler.go• L105-121 api/…/webhook_handler.go• L138-172 api/…/webhook_handler.go• L190-213 api/…/webhook_handler_validator.go• L64-149

Event dispatch

The event dispatcher is the shared path from a product event to its listeners. It validates each CloudEvent, places asynchronous work on the event queue, and invokes all listeners registered for that event type. The webhook listener is one such listener and passes matching message or phone events to the webhook service. api/…/event_dispatcher_service.go• L50-60 api/…/event_dispatcher_service.go• L99-142 api/…/container.go• L1543-1554

The dispatch path separates event creation from external delivery. This means the event producer does not need to know the configured destinations, while one event can reach several matching webhooks. The dispatcher runs listeners in parallel, and the webhook service starts one delivery path per matching webhook. api/…/webhook_listener.go• L14-43 api/…/webhook_service.go• L174-199

The following flow shows how a product event becomes one or more outbound requests.

flowchart LR
    A[Product event] --> B[Event dispatcher]
    B --> C[Webhook listener]
    C --> D[Load matching account webhooks]
    D --> E[Build request for each match]
    E --> F[Send to external endpoint]
    F --> G{Success?}
    G -- Yes --> H[Record delivery in logs and telemetry]
    G -- No --> I[Retry once]
    I --> J[Emit webhook.send.failed]

References: api/…/event_dispatcher_service.go• L63-105 api/…/event_dispatcher_service.go• L116-152 api/…/webhook_listener.go• L33-195 api/…/webhook_service.go• L174-199

Outbound delivery

Each delivery is an HTTP POST with a JSON body. The body normally contains the original CloudEvent, and the request identifies the event type in X-Event-Type. A Discord webhook URL receives a Discord-shaped message for incoming-message events so that the same integration can display those messages in Discord. api/…/webhook_service.go• L252-325

When a signing key is configured, HTTPSMS adds a short-lived JWT in the Authorization: Bearer header. The token binds the request to the destination URL and account, and the receiver can validate it with the shared signing key. api/…/webhook_service.go• L261-277 api/…/webhook_service.go• L328-337

Delivery attempts

The service treats a response below HTTP 400 as successful. Network errors, request creation errors, timeouts, and responses at or above HTTP 400 cause a second attempt. Each attempt has a five-second request limit. Delivery runs for the matching webhooks in parallel, but the event listener waits for those paths to finish before it returns. api/…/webhook_service.go• L189-249

The delivery path does not persist a per-attempt record or a success state on the webhook. Logs and telemetry show successful sends and errors. A final failure becomes a new event for the rest of the event system to handle. api/…/webhook_service.go• L202-249 api/…/webhook_service.go• L340-382

References: api/…/webhook_service.go• L202-277 api/…/webhook_service.go• L280-337 tests/helpers_test.go• L255-285

Failure handling

After the final failed attempt, the service emits webhook.send.failed. That event carries the webhook, source event, account, owner phone, error text, and any HTTP response status. A network failure has no response status; an HTTP failure includes the response status and uses the response body as the error detail when one is available. api/…/webhook_event_failed_event.go• L8-21 api/…/webhook_service.go• L340-382

The failure event is separate from the original delivery. It can notify the account without sending the failure event back to the same user webhook, because webhook.send.failed is not in the selectable webhook event list. The email notification path checks the account preference and suppresses repeated webhook failure emails for the same owner for one hour. See Discord and email notifications for the wider notification system. api/…/validator.go• L145-158 api/…/email_notification_service.go• L127-159

References: api/…/webhook_service.go• L218-248 api/…/webhook_service.go• L340-382 api/…/webhook_event_failed_event.go• L8-21 api/…/email_notification_service.go• L127-159

Webhook state persistence

Webhook state is account-owned persistent data. Each record stores its identity, account owner, URL, signing key, phone filters, event filters, and creation or update times. The repository supports save, account-scoped lookup, event-and-phone matching, single deletion, listing, and deletion of all records for an account. api/…/webhook.go• L10-20 api/…/webhook_repository.go• L11-29

Account scoping applies to reads and writes. Updating or deleting a webhook first resolves it by both account ID and webhook ID, so a user cannot manage another account's configuration through the webhook ID alone. When an account deletion event is processed, the webhook listener removes all webhook records for that account. The same account event also drives cleanup in other account-owned stores through their own listeners. api/…/webhook_service.go• L58-69 api/…/webhook_service.go• L87-103 api/…/webhook_service.go• L151-171 api/…/gorm_webhook_repository.go• L35-43 api/…/webhook_listener.go• L182-195 api/…/contact_listener.go• L19-56

The saved configuration is the source of truth at dispatch time. A change to its URL, signing key, event list, or phone list changes future matching and delivery behavior. Past outbound attempts are not part of this state. api/…/gorm_webhook_repository.go• L46-89

References: api/…/webhook.go• L10-20 api/…/webhook_repository.go• L11-29 api/…/gorm_webhook_repository.go• L35-121 api/…/webhook_listener.go• L182-195 api/…/contact_listener.go• L19-56

Change checklist

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

  • Keep the selectable event allowlist aligned with the webhook listener routes. A name accepted by configuration but not subscribed by the listener silently produces no delivery.
  • Keep the event payload fields aligned with WebhookSendFailedPayload and its email listener. Failure alerts depend on the original event ID, event type, status, and error detail.
  • Keep the phone ownership check aligned with the event payload field used as the delivery owner. A mismatch can make a saved filter valid but unable to match real events.
  • Keep the JWT receiver contract aligned with the signing-key behavior. Changes to the header, issuer, audience, or expiry affect every signed integration.
  • Keep account deletion cleanup aligned with all listeners of the account lifecycle event. Webhook state and other account-owned state must not outlive the account.

Important failure modes

TriggerConsequenceGuard
The event name is missing from the supported-event allowlistThe configuration request is rejected, or a newly introduced event has no webhook routeUpdate the allowlist and listener registration together.
The configured phone number is not owned by the accountThe webhook cannot be created or updatedValidate phone ownership before saving the configuration.
The endpoint returns HTTP 400 or higher, or does not answer within the attempt limitHTTPSMS retries once, then emits webhook.send.failedInspect the failure event and the endpoint response or timeout detail.
The receiver uses a signing key but does not validate the Bearer JWT with the current keyThe receiver may reject otherwise valid requestsShare the current key and validate the token claims against the destination.
Account deletion cleanup does not run for all registered listenersThe account's webhook records or other account-owned records remain persistedProcess user.account.deleted through each required cleanup listener.

Key files

FileWhy to read it
api/…/webhook_service.goMain policy for matching, request creation, signing, retries, and failure events.
api/…/webhook_listener.goMaps product event types to webhook delivery and account cleanup.
api/…/event_dispatcher_service.goShows the shared event validation, queue, listener, and parallel dispatch model.
api/…/webhook_handler.goDefines the authenticated webhook management API.
api/…/validator.goDefines the allowed user-selectable webhook events.
api/…/webhook.goDefines the persistent webhook integration state.
api/…/gorm_webhook_repository.goShows account-scoped storage and event-plus-phone matching.
api/…/webhook_event_failed_event.goDefines the failure event contract used by alerting.
api/…/contact_listener.goShows another account-deletion cleanup listener that shares the webhook lifecycle event.
web/…/billing.tsShows how the dashboard calls the webhook management API.