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 / bulk-and-scheduled-messaging

Bulk and scheduled messaging

Bulk and scheduled messaging lets a user submit many outbound SMS messages and defer each send until a chosen time or an allowed phone window. The system records each message before dispatch and uses the connected Android phone as the final sender. This page extends Messaging platform and focuses on deferred delivery; see SMS message lifecycle for the wider message path and Message threads and search for message lookup and conversation views.

Submission modes

Structured bulk requests

The structured bulk API accepts one sender, a list of recipients, shared content, and optional attachment URLs. It creates one outbound message per recipient and supports up to 1,000 recipients in one request. The sender must be a phone registered to the user. The endpoint is /v1/messages/bulk-send.

The bulk request uses a shorter content limit than a single-message request. A caller can also supply a request ID for tracking. The response reports the result of accepting the messages, not the later SMS delivery result.

References: api/…/message_handler.go• L114-171 api/…/message_bulk_send_request.go• L14-71 api/…/message_handler_validator.go• L187-234 api/…/message_service.go• L461-504

File uploads

The file upload API accepts the official CSV or Excel template at /v1/bulk-messages. Each row names the sender, recipient, content, and optional send time or attachment URLs. The upload is treated as one batch, and all rows receive a shared request ID that groups their later status counts.

Validation happens before any row is queued. The file must use a supported format, contain valid phone numbers, use registered sender phones, and stay within the file, row, content, attachment, and scheduling limits. A row with no send time is eligible for the phone's normal dispatch rules. A row with a send time uses that time as an exact target.

The upload returns an accepted count rather than waiting for delivery. The dashboard can later list upload summaries and open the individual messages by their batch request ID.

References: api/…/bulk_message_handler.go• L47-143 api/…/bulk_message_handler_validator.go• L51-92 api/…/bulk_message_handler_validator.go• L95-209 api/…/bulk_message_handler_validator.go• L212-282 api/…/bulk_message.go• L5-16 api/…/gorm_message_repository.go• L172-199

Deferred-send model

Send times and phone windows

An explicit send time is an exact target for one message. RFC3339 values use their embedded offset. Time values without an offset use the user's profile time zone. Bulk upload times must be no more than 420 hours ahead. The normal single-message API allows up to 480 hours.

If a message has no exact target, the phone's optional send schedule controls the next allowed time. A send schedule is a set of non-overlapping weekly windows in an IANA time zone. The phone can use one schedule, and an empty or invalid schedule falls back to immediate eligibility. Deleting a schedule removes its link from phones, so later messages no longer use those windows.

References: api/…/bulk_message_request.go• L23-55 api/…/bulk_message_handler_validator.go• L257-264 api/…/message_send_request.go• L27-30 api/…/message_handler_validator.go• L132-184 api/…/message_send_schedule.go• L12-28 api/…/message_send_schedule.go• L30-90 api/…/message_send_schedule_handler_validator.go• L60-164 api/…/message_send_schedule_service.go• L138-164

Dispatch timing

The system combines the chosen time with the phone's message-per-minute limit. For messages without an exact target, it places each later message after the most recently scheduled notification for that phone. It then moves the message to the next valid schedule window when needed. Explicit times bypass both the phone window and rate-limit calculation.

The scheduling step creates a pending phone notification and a delayed dispatch event. When that event is due, the service sends a normal-priority push notification to the phone. The phone then asks for outstanding work and reports whether it is sending, sent, delivered, or failed.

This diagram shows how a bulk row becomes a deferred phone send and then a message result.

sequenceDiagram
    participant C as Client
    participant A as Messaging API
    participant Q as Message queue
    participant P as Phone notification queue
    participant F as Android phone
    participant R as Message record

    C->>A: Submit bulk rows
    A->>Q: Store one message per row
    Q->>P: Compute exact or window-based notification time
    P-->>A: Record scheduled state
    P->>F: Send push at due time
    F->>A: Request outstanding message
    A->>F: Return message and mark sending
    F->>A: Report send or delivery result
    A->>R: Update final message state

References: api/…/message_service.go• L461-504 api/…/message_service.go• L552-569 api/…/gorm_phone_notification_repository.go• L106-175 api/…/phone_notification_service.go• L185-300 api/…/phone_notification_listener.go• L45-143

Delivery lifecycle

Queue and dispatch states

An outbound message starts as pending after the API stores it. It becomes scheduled when the phone notification has a planned time. It becomes sending when the phone claims it. The phone's reports can move it to sent, delivered, or failed.

The message keeps both the requested send time and the actual notification schedule time. This distinction matters for bulk rows because an exact target still needs a later device event to deliver the work. Batch summaries count each message by its current status. Counts can therefore change after the upload response.

References: api/…/message.go• L24-54 api/…/message.go• L85-121 api/…/message.go• L159-224 api/…/message_service.go• L997-1034 api/…/gorm_message_repository.go• L244-278

Expiry and retry

Expiry protects a deferred send when the phone does not complete the work in time. After the push notification is sent, the phone's configured expiration duration schedules an expiry check. The allowed duration is 60 to 3,600 seconds. If the message is still pending, scheduled, or sending when the check runs, it becomes expired.

An expired message is retried only while its send-attempt count is below the phone's maximum. The retry creates a new phone notification and applies the normal phone schedule and rate rules again. When the attempt limit is reached, expiry is final. A phone-reported failed result is a separate terminal path and does not use this expiry retry path.

References: api/…/phone_update_request.go• L22-26 api/…/phone_handler_validator.go• L87-100 api/…/phone_notification_service.go• L128-168 api/…/message_service.go• L816-862 api/…/message_service.go• L864-955 api/…/message_listener.go• L173-250

Cancellation

Message cancellation

Deleting a message is the cancellation action for one deferred send. The API deletes the message and emits a deletion event. The phone-notification listener responds by deleting notification records for that message. The thread listener removes the message from conversation views.

Cancellation removes queued work that still exists in the notification store. It cannot recall a push already sent to the phone or undo an SMS that the phone has already sent. A delete can therefore race with dispatch near the scheduled time. Downstream status events still protect message updates by checking the current message state.

References: api/…/message_handler.go• L376-418 api/…/message_service.go• L136-181 api/…/phone_notification_listener.go• L162-176 api/…/gorm_phone_notification_repository.go• L63-78

Schedule removal

Deleting a send schedule is configuration cancellation, not message cancellation. The schedule service emits a deletion event. The phone service then clears that schedule ID from every phone that used it. Existing message notifications retain their already computed times. Future messages use immediate or other configured dispatch rules.

References: api/…/message_send_schedule_handler.go• L186-224 api/…/message_send_schedule_service.go• L138-164 api/…/phone_listener.go• L35-53 api/…/phone_service.go• L58-68

Batch tracking

Batch summaries

The batch request ID links an upload to its individual messages. The history API groups messages whose IDs begin with bulk- and reports total, pending, scheduled, sent, delivered, failed, and expired counts. The dashboard uses that ID to open message search. Engineers can therefore trace a batch without a separate batch record.

References: api/…/bulk_message_handler.go• L53-75 api/…/gorm_message_repository.go• L172-199 web/…/index.vue• L207-255 web/…/messages.ts• L68-93

Change checklist

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

  • Keep the CSV and Excel column names aligned with BulkMessage, especially the optional send-time field. Both parsers map their input into the same row model.
  • Keep bulk and single-message scheduling limits aligned with the API contract. A change in one validator can make the two submission modes accept different future ranges.
  • Keep batch request ID creation aligned with batch history grouping. A change to the prefix or grouping rule can hide uploads from the dashboard.
  • Keep exact-send behavior distinct from phone-window behavior. A change to dispatch-time calculation can alter schedule compliance and bulk rate spacing.
  • Keep message deletion paired with phone-notification deletion. Otherwise a delayed notification can send work for a message that the user removed.
  • Keep phone expiration duration and maximum attempts compatible. A positive retry limit requires a non-zero expiry duration.
  • Keep schedule deletion paired with phone schedule detachment. Deleted schedules must not remain selectable through a phone's stored schedule ID.

Important failure modes

TriggerConsequenceGuard
A bulk row has an invalid time or is too far in the futureThe whole file is rejected before rows enter the queueValidate each row's time and future limit before entitlement and dispatch
A structured bulk request has more than 1,000 recipientsThe request is rejected before message creationEnforce the recipient count limit in the bulk request validator
A sender number is not registered to the userThe bulk upload or structured request cannot be acceptedValidate every sender against the user's phones
The phone has no push token or the push send failsThe notification is marked failed and the message receives a notification failure eventSurface the phone setup error and use the message failure path
The phone does not finish before its expiration durationThe message becomes expired and may be scheduled againUse the attempt count and maximum-attempt limit to stop retries
A user deletes a message close to its due timeStored notification work is removed, but an already sent push or SMS can still completeTreat deletion as best-effort cancellation before device dispatch
A schedule is deleted while phones still reference itFuture scheduling could use a stale schedule linkEmit schedule deletion and clear the link from all affected phones

Key files

FileWhy to read it
api/…/bulk_message_handler.goDefines file upload and batch history API behavior.
api/…/bulk_message_handler_validator.goShows file parsing and the rules that must pass before queueing.
api/…/message_handler_validator.goShows the shared rules for structured bulk and single scheduled sends.
api/…/message_service.goConnects message storage, delayed dispatch, expiry checks, retries, and status changes.
api/…/gorm_phone_notification_repository.goExplains how phone windows and rate limits produce a notification time.
api/…/phone_notification_service.goShows exact scheduling, push dispatch, and notification failure handling.
api/…/message_send_schedule.goDefines the weekly window model and next-allowed-time behavior.
api/…/message_send_schedule_handler.goDefines schedule management API and deletion behavior.
api/…/phone_notification_listener.goMaps message creation, retry, notification dispatch, and deletion events to phone work.
api/…/message_listener.goMaps phone outcomes and expiry events back to message state.
api/…/gorm_message_repository.goDefines batch grouping and outstanding-message selection.
web/…/index.vueShows upload feedback, batch history, status counts, and message search navigation.