Discord and email notifications
Discord and email notifications extend SMS beyond the httpSMS web and phone clients. Discord connects a user's server to SMS send and receive actions. Email notifications turn selected delivery and integration failures into user alerts. Both paths use the event system so the source operation stays separate from the channel that reports its result. See Integrations and automation for the wider integration model.
Discord integration
The Discord integration lets a user send SMS from a Discord server and receive incoming SMS in a Discord channel. A saved connection links one httpSMS user to a Discord server and, when configured, to the channel used for incoming messages. The settings page is the user-facing place to add, edit, or remove this link.
Connection management
Connection management gives the user control of the Discord server link and prepares the Discord application for use. A create or update action registers the /httpsms command for the selected server before the connection is saved. The service accepts one integration per user through the current settings flow.
The connection records these user-facing choices:
| Choice | Purpose |
|---|---|
| Name | Identifies the connection in settings. |
| Server ID | Selects the Discord server that can use the command. |
| Incoming channel ID | Selects where received SMS messages appear. |
The authenticated integration API supports list, create, update, and delete actions under /v1/discord-integrations. Account deletion also removes the user's saved Discord connections. References: api/…/discord_handler.go• L57-67, api/…/discord_handler.go• L69-106, api/…/discord_handler.go• L109-139, api/…/discord_handler.go• L142-230, api/…/discord_listener.go• L56-69, api/…/discord.go• L9-17
Discord command flow
The Discord interaction endpoint is the entry point for sending an SMS from Discord. It first checks Discord's signed request, then resolves the server to the saved httpSMS account. The request passes through the normal message validation, entitlement, and send path, so a Discord message follows the same account rules as another SMS request.
The flow returns a Discord response with either a confirmation and message ID or a useful error. This keeps the user in Discord while httpSMS performs the SMS work. The command accepts sender, recipient, message content, and optional attachment URLs when the command is created, although the interaction handler currently builds the send request from the sender, recipient, and message fields. References: api/…/discord_handler.go• L233-285, api/…/discord_handler.go• L288-403, api/…/discord_handler.go• L405-444, api/…/discord_service.go• L139-180
Incoming SMS delivery
Incoming SMS delivery starts with the message.phone.received event. The Discord listener receives that event and asks the Discord service to find every saved connection for the user that has an incoming channel. The service then posts a formatted Discord message to each matching channel.
This event fan-out means a connection without an incoming channel remains usable for outbound commands but does not receive incoming SMS. A failed Discord post does not change the SMS event; it creates a separate discord.send.failed event for the email notification path.
The following diagram shows how one received SMS reaches Discord and how a delivery failure becomes an email candidate.
flowchart LR
A[Incoming SMS] --> B[message.phone.received event]
B --> C[Discord listener]
C --> D[Find user's connections with an incoming channel]
D --> E[Post message to each Discord channel]
E -->|success| F[SMS shown in Discord]
E -->|failure| G[discord.send.failed event]
G --> H[Email notification listener]
References: api/…/message_phone_received_event.go• L11-25 api/…/discord_listener.go• L14-54 api/…/discord_service.go• L217-280 api/…/discord_message_failed_event.go• L8-21
Discord event registration
The event dispatcher connects event names to listeners at application start. The Discord listener subscribes to received SMS events and account deletion events. Account deletion also reaches the contact cleanup listener, so removal of an account can clean up related data through separate listeners. The email notification listener subscribes to Discord delivery failures as well as the other notification events, so the Discord service only reports the failure and does not own email policy.
References: api/…/contact_listener.go• L19-24 api/…/contact_listener.go• L38-40 api/…/container.go• L1377-1388 api/…/container.go• L1441-1459 api/…/event_dispatcher_service.go• L99-151
Email notification system
The email notification system informs a user when an SMS cannot complete or when httpSMS cannot forward an event to an external integration. It is event-driven: a listener decodes an event and passes it to the email service, while the service applies user settings, duplicate suppression, email creation, and delivery.
Notification event routing
The email listener is an adapter between the event dispatcher and the email service. It does not decide whether an email should be sent. It maps each supported event to the service operation for that event.
| Event | User-facing reason |
|---|---|
message.send.failed | The phone could not send the SMS. |
message.send.expired | The SMS reached its final expired state. |
webhook.send.failed | httpSMS could not forward an event to a webhook. |
discord.send.failed | httpSMS could not post an incoming SMS to Discord. |
The shared event dispatcher can queue events for asynchronous handling and runs all subscribers for an event. A listener error is recorded by the dispatcher, while the source operation remains distinct from the notification attempt. References: api/…/email_notification_listener.go• L14-38, api/…/email_notification_listener.go• L41-107, api/…/event_dispatcher_service.go• L63-114, api/…/event_dispatcher_service.go• L116-151
Email decision flow
The email service applies the same broad decision order to each event. It first checks whether a recent email for that event and phone owner was already sent. It then loads the user and checks the matching preference. Only after those checks does it create and send the email.
sequenceDiagram
participant E as Event dispatcher
participant L as Email listener
participant S as Email service
participant C as Recent-send cache
participant U as User record
participant M as Mail service
E->>L: Notification event
L->>S: Decode and forward payload
S->>C: Check event and owner
alt Recent email exists
S-->>L: Skip notification
else No recent email
S->>U: Load user and preference
alt Preference disabled
S-->>L: Skip notification
else Preference enabled
S->>M: Build and send email
S->>C: Record recent send window
end
end
This design keeps email delivery from blocking the source feature and limits repeated alerts for the same event category and phone owner. The cache is a suppression aid rather than a record of successful SMS delivery. References: api/…/email_notification_service.go• L17-31, api/…/email_notification_service.go• L52-89, api/…/email_notification_service.go• L92-124, api/…/email_notification_service.go• L127-159, api/…/email_notification_service.go• L162-214
User notification settings
The settings page lets a user enable or disable message status emails and the combined webhook-and-Discord failure emails. The update request saves all notification switches on the user, so the settings screen sends the complete set of choices rather than changing one isolated flag.
The current email controls include these categories:
- Message status emails for failed or expired SMS messages.
- Webhook and Discord emails for failed external forwarding.
- Heartbeat emails for missing phone heartbeats.
- Newsletter emails.
Only the first two categories are handled by the notification flow described on this page. The other categories use the same user settings surface but belong to their own listeners and services. References: web/…/index.vue• L715-757, web/…/index.vue• L1255-1284, web/…/billing.ts• L256-270, api/…/user_handler.go• L144-175, api/…/user_service.go• L211-239, api/…/user.go• L73-90
Notification email content
The email factory turns an event payload into both HTML and plain-text mail. Message status emails describe the SMS and its failure or expiry. Discord failure emails identify the target channel, event, phone owner, and returned error so the user can restore Discord permissions or update the integration.
Webhook failure emails follow the same alert pattern and include the event context needed to inspect the failed forward. For the integration relationships around webhook delivery, see Webhooks. For the SMS-side event lifecycle, see SMS message lifecycle.
References: api/…/notification_email_factory.go• L8-20 api/…/hermes_notification_email_factory.go• L31-79 api/…/hermes_notification_email_factory.go• L81-140 api/…/hermes_notification_email_factory.go• L167-265
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the Discord interaction command shape aligned with the command registration and the interaction request parser.
- Keep the
message.phone.receivedanddiscord.send.failedevent payloads aligned between the source service, listeners, and email factory. - Keep Discord connection deletion tied to account deletion so a removed account cannot retain an active external connection.
- Keep the combined webhook-and-Discord preference aligned across the settings form, user update request, stored user fields, and both email service checks.
- Revisit duplicate suppression windows when adding a new failure event or changing the owner key used for notification grouping.
- Keep every account-deletion listener aligned with the account deletion event so related user data and external connections are removed together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Discord sends an unsigned or invalidly signed interaction | The request is rejected before it can send an SMS. | Verify Discord's Ed25519 signature and timestamp input at the event endpoint. |
| A Discord server has no saved httpSMS connection | The interaction cannot resolve an account and Discord returns an error response. | Save the server ID through the Discord integration settings before using /httpsms. |
| A connection has no incoming channel ID | Received SMS events do not post to that connection. | Set a valid incoming channel when configuring the connection. |
| Discord rejects an outgoing post | The SMS still exists, but the user does not see it in Discord; a discord.send.failed event starts the alert path. | Keep Discord permissions and the target channel valid, then use the failure email to repair the link. |
| An expired-message event is not final | No expiry email is sent for that intermediate attempt. | Send the notification only when the event marks the expiry as final. |
| A matching recent notification exists in the cache | The new failure is suppressed for its event category and owner. | Treat the suppression window as part of the notification contract. |
| The relevant user preference is disabled | The event is processed without sending an email. | Check the message-status or webhook/Discord setting before building mail. |
Key files
| File | Why to read it |
|---|---|
| api/…/discord_handler.go | Shows the Discord interaction boundary and the authenticated connection API. |
| api/…/discord_service.go | Explains the two Discord responsibilities: connection setup and incoming SMS forwarding. |
| api/…/discord_listener.go | Shows which events start Discord work and account cleanup. |
| api/…/contact_listener.go | Shows the separate account-deletion path that removes the user's contacts. |
| api/…/discord_message_failed_event.go | Defines the contract between Discord delivery failure and email notification. |
| api/…/email_notification_listener.go | Maps notification events to email service actions. |
| api/…/email_notification_service.go | Shows preference checks, duplicate suppression, and mail delivery policy. |
| api/…/hermes_notification_email_factory.go | Shows the user-facing purpose and content of notification emails. |
| api/…/container.go | Shows how the Discord, contact, and email listeners join the event dispatcher. |
| web/…/index.vue | Shows the user controls for Discord connections and email preferences. |