Integrations and automation
HTTPSMS connects messaging activity to external systems through event-driven outputs and authenticated input endpoints. These connections let a user send SMS messages from another product, receive message and delivery events outside the dashboard, and get alerts when message or integration work fails.
Integration model
The integration layer uses a shared event stream as the link between messaging workflows and external systems. A message or device event is published once, then the configured webhook, Discord, email, or 3CX listeners act on the same event without changing the main messaging flow. The SMS message lifecycle page explains where these message events come from.
Event fan-out
The event dispatcher routes each CloudEvent to all listeners that subscribe to its type. It can place work on the push queue for later handling, and listeners run in parallel so one external destination does not define the work of another. A listener reports its own error while the dispatcher keeps the other listeners independent. The same event path also carries internal cleanup events, such as a deleted message thread, but those events only reach external systems when an integration subscribes to them.
The main event groups used by integrations are:
| Event group | External use |
|---|---|
| Message received | Send an incoming SMS to a webhook or Discord channel. |
| Message sent or delivered | Report outbound progress to a webhook. |
| Message send failed or expired | Report a terminal failure to a webhook and notify the user by email. |
| Phone availability and missed calls | Send device or call activity to subscribed webhooks. |
| Account deletion | Remove that user’s saved integration connections and contact data. |
The following diagram shows how one messaging event reaches the available connection points.
flowchart LR
A[Messaging workflow] --> B[CloudEvent]
B --> C[Event dispatcher]
C --> D[Webhook subscriptions]
C --> E[Discord channel]
C --> F[Email failure notice]
C --> G[3CX event bridge]
D --> H[User system]
E --> I[Discord server]
F --> J[User mailbox]
G --> K[3CX]
References: api/…/event_dispatcher_service.go• L22-29 api/…/event_dispatcher_service.go• L50-60 api/…/event_dispatcher_service.go• L99-142 api/…/webhook_listener.go• L33-43 api/…/message_thread_service.go• L327-355 api/…/message_listener.go• L34-47
Outbound event connections
Outbound connections consume events after HTTPSMS has accepted or processed messaging work. Each connection keeps its own user-level configuration, selects the events it understands, and sends a representation that matches the destination.
Webhook subscriptions
Webhooks are general-purpose HTTP connections for user systems. A user saves a URL, an optional signing key, event names, and optional phone-number filters; matching events are sent as JSON POST requests. The request includes the event type and can include a short-lived bearer token made from the signing key.
Webhook delivery covers inbound messages, send and delivery states, expired or failed sends, phone availability changes, and missed calls. A destination that does not respond successfully is retried once within the delivery attempt, then HTTPSMS emits a webhook-failure event for the notification path. See Webhooks for the configuration and delivery contract.
References: api/…/webhook.go• L10-19 api/…/webhook_handler.go• L43-49 api/…/webhook_service.go• L174-199 api/…/webhook_service.go• L202-248
Notification channels
Notification channels turn selected messaging events into human-readable alerts rather than general event feeds. Discord receives incoming SMS messages in a configured channel. Email reports terminal message failures or expiries and can also report failed webhook or Discord delivery.
Discord also provides an input path: its /httpsms command collects sender, recipient, message text, and optional attachments, then submits the SMS through the normal message service. Discord verifies the request signature before it accepts the interaction. See Discord and email notifications for the channel setup and notification rules.
References: api/…/discord_listener.go• L21-36 api/…/discord_handler.go• L57-67 api/…/discord_handler.go• L233-269 api/…/discord_handler.go• L288-402 api/…/email_notification_listener.go• L21-38 api/…/email_notification_service.go• L52-159
3CX event bridge
The 3CX connection maps HTTPSMS message activity into the event shape expected by a 3CX webhook. Its outbound mapping represents received, sent, delivered, and failed SMS states with message identifiers, phone numbers, times, and destination status values.
The current active 3CX listener registration removes message-event subscriptions, so the configured listener currently handles account cleanup while the service still contains the outbound message mappings. The inbound 3CX endpoint remains a separate path that accepts from, to, and text, checks the user’s entitlement, and sends the SMS through the normal message workflow. See 3CX integration for the complete boundary and its current event behavior.
References: api/…/integration_3cx_listener.go• L21-39 api/…/integration_3cx_service.go• L59-75 api/…/integration_3cx_service.go• L127-139 api/…/integration_3cx_handler.go• L39-43 api/…/integration_3cx_handler.go• L45-88
Inbound messaging workflows
Some integrations do more than consume events. They start a normal HTTPSMS send so that billing, validation, persistence, phone selection, retries, and delivery events stay consistent with messages started by the dashboard or API.
External send requests
Discord and 3CX both accept an external request and convert it into the common message-send flow. The external system supplies the sender and recipient numbers plus message content; HTTPSMS identifies the linked user, checks access, and returns the created message identifier or a destination-specific error response.
This shared path matters because an integration is not a second SMS transport. It is another entry point into the same message system. Downstream delivery events can therefore reach the user’s other configured connections as well.
References: api/…/discord_handler.go• L288-402 api/…/integration_3cx_message_request.go• L13-39 api/…/integration_3cx_handler.go• L57-88 api/…/message_service.go• L1-60
Connection ownership and cleanup
Each external connection belongs to an HTTPSMS user. Configuration is stored with that ownership, and account deletion events remove the user’s webhook, Discord, and 3CX connection records. The same event also removes related contact records so deleted accounts do not keep active integration state or contact data.
The connection records are separate from message records. Removing a connection stops future delivery to that destination without removing the SMS history that the messaging system uses for its own views and state.
Message-thread deletion follows the shared event model for internal consistency. The thread service deletes the thread, emits a message-thread.api.deleted event, and the message listener uses the owner and contact in that event to remove the related message data. This cleanup path is separate from external delivery connections.
References: api/…/webhook.go• L10-19 api/…/discord.go• L9-17 api/…/integration_3cx.go• L9-15 api/…/webhook_listener.go• L182-196 api/…/discord_listener.go• L56-69 api/…/integration_3cx_listener.go• L110-123 api/…/contact_listener.go• L14-17 api/…/contact_listener.go• L38-56 api/…/message_thread_service.go• L327-355 api/…/message_listener.go• L276-290
Change checklist
When these files or sections are changed, remember to consider these:
- Add a new message event to every integration that must expose it. Update the event payload decoding and any destination-specific mapping together.
- Keep webhook event names, phone-number filters, JSON bodies, event headers, and signing behavior aligned. External consumers depend on these values as a contract.
- Keep 3CX status names and the
message.received,message.sent, andmessage.finalizedevent mapping aligned with the 3CX payload contract. - Keep Discord slash-command option names aligned between command registration and interaction parsing. A change in one side can create an accepted command with empty message fields.
- Keep delivery-failure events connected to the email listener when a new external channel is added. Otherwise a failed destination can become silent.
- Preserve account-deletion cleanup for every user-owned connection and contact record.
- When a message-thread deletion event changes, preserve its internal cleanup subscriber and do not assume that every shared event is an external integration event.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No webhook matches the user, event type, and phone filter | HTTPSMS makes no outbound webhook request | Check the saved event names and phone-number filters. |
| A webhook endpoint times out or returns an error status | Delivery stops after the retry attempt and a webhook-failure event is emitted | Monitor the failure notification and inspect the destination response. |
| Discord sends a request with a missing or invalid signature | The interaction is rejected before it can send an SMS | Configure the Discord public key and preserve Discord request signing. |
| A Discord interaction has no linked server connection | Discord returns an error response and no SMS is sent | Keep the Discord server ID linked to the HTTPSMS user. |
| A 3CX message event is not subscribed by the active listener | The 3CX webhook receives no outbound message state for that event | Check listener registration as well as the 3CX payload mapping. |
| The user has no entitlement for an external send | The inbound integration request is rejected and no message enters the send flow | Keep billing entitlement checks before the common message-send call. |
| Account-deletion handling omits a user-owned record | Deleted-account data or an active connection remains | Register cleanup for the record with the account-deletion event. |
| A message-thread deletion event is not dispatched or consumed | The thread can be deleted while related message cleanup does not complete | Keep the deletion event dispatch and its internal subscriber aligned. |
Key files
| File | Why to read it |
|---|---|
| api/…/event_dispatcher_service.go | Defines the shared event fan-out model and async dispatch boundary. |
| api/…/message_thread_service.go | Shows how message-thread deletion emits an event for downstream cleanup. |
| api/…/message_listener.go | Shows the internal subscriber that removes message data after thread deletion. |
| api/…/webhook_listener.go | Shows which message, phone, call, and account events feed webhooks. |
| api/…/webhook_service.go | Defines webhook selection, outbound delivery, signing, retry, and failure reporting. |
| api/…/discord_listener.go | Connects received-message events to Discord delivery. |
| api/…/discord_handler.go | Shows Discord verification, slash-command input, and SMS initiation. |
| api/…/email_notification_listener.go | Shows which message and integration failures become email notifications. |
| api/…/email_notification_service.go | Defines user preference checks and duplicate-alert suppression. |
| api/…/integration_3cx_listener.go | Shows the active 3CX event subscriptions and account cleanup path. |
| api/…/integration_3cx_service.go | Defines the 3CX outbound event mapping and delivery boundary. |
| api/…/integration_3cx_handler.go | Defines the inbound 3CX SMS entry point. |
| api/…/contact_listener.go | Shows account-deletion cleanup for user-owned contact data that shares the integration event path. |