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 / contacts-and-conversation-recipients

Contacts and conversation recipients

Contacts are user-owned records that add names and optional details to phone numbers used in messaging. The contact service validates and stores these records, while message threads use the recipient phone number to resolve a contact at read time for the dashboard. See Messaging platform for the wider message system and Message threads and search for thread history and search.

Contact records

Contact data

A contact is a saved person or organization for one user. It has a name and at least one phone number. It can also have email addresses and free-form string properties for extra user data. The record has its own ID and timestamps, and its phone numbers remain the values used to match message recipients. api/…/contact.go• L16-17, api/…/contact.go• L66-80

The contact record is separate from a message thread. A thread stores the recipient phone number as its conversation key. Contact details are looked up when the thread is read, so changing a name changes the dashboard label without changing message history. api/…/message_thread.go• L9-27, api/…/message_thread_service.go• L281-305

References: api/…/contact.go• L16-17 api/…/contact.go• L66-80 api/…/message_thread.go• L9-27 api/…/message_thread_service.go• L281-305

Ownership and storage

Every contact belongs to an authenticated user. Contact reads, writes, searches, and deletes use both the user identity and the contact ID or phone number, which keeps one user from reading or changing another user’s records. api/…/contact_handler.go• L73-103, api/…/gorm_contact_repository.go• L63-80

The service can use either supported contact repository to persist the same contact model. It stores contacts in batches and invalidates phone-based lookup data after create, update, or delete operations. Account deletion also removes all contacts for that user. api/…/contact_service.go• L119-220, api/…/contact_repository.go• L10-36

The service keeps lookup results separate for each user and phone number. It also handles overlapping reads and contact changes so an older in-flight lookup does not repopulate a cache generation that a newer update has invalidated. api/…/contact_service_test.go• L310-353, api/…/contact_service_test.go• L396-425

References: api/…/contact_handler.go• L73-103 api/…/gorm_contact_repository.go• L63-80 api/…/contact_service.go• L119-220 api/…/contact_repository.go• L10-36 api/…/contact_service_test.go• L310-353 api/…/contact_service_test.go• L396-425

Contact creation and validation

JSON creation

The contact API accepts one or many contact items through POST /v1/contacts. A request can be a JSON array or an object with a contacts array. The handler sanitizes the values, validates the whole batch, checks the user’s contact entitlement, and then stores the new records. api/…/contact_handler.go• L106-154, api/…/contact_store.go• L21-46

The service creates a new ID and timestamps for each record. A successful response returns all created contacts. The create path does not merge records that share a phone number, so callers should treat each submitted item as a distinct contact. api/…/contact_store.go• L57-78, api/…/contact_responses.go• L11-15

References: api/…/contact_store.go• L57-78 api/…/contact_responses.go• L11-15

CSV import

The contact API also accepts a CSV file through POST /v1/contacts/upload. The file uses the columns Name, Emails, and PhoneNumbers; semicolons or commas separate multiple values inside a cell. The dashboard provides the same template for download and uses the upload path for bulk contact entry. api/…/contact_handler.go• L156-206, api/…/contact_handler_validator.go• L243-349, web/…/httpsms-contacts.csv• L1-4

The upload is checked before any records are stored. The file must be a CSV of no more than 500 KB, and one request or file can contain no more than 1,000 contacts. Row errors are returned with their row number so the dashboard can show which input needs correction. The validator accepts common CSV upload MIME values and empty MIME metadata when the file name is valid, but it rejects unrelated MIME values and non-CSV file names. api/…/contact_handler_validator.go• L56-74, api/…/contact_handler_validator.go• L116-167, api/…/contact_handler_validator.go• L208-240, api/…/contact_handler_validator_test.go• L228-305

References: api/…/contact_handler.go• L156-206 api/…/contact_handler_validator.go• L116-167 api/…/contact_handler_validator.go• L208-349 api/…/contact_handler_validator_test.go• L208-373 web/…/httpsms-contacts.csv• L1-4

Input rules

Validation requires a non-empty name and at least one phone number. Phone numbers must be valid E.164 numbers. Email values are optional, but every supplied value must be a valid email address. Empty phone and email elements are rejected. api/…/contact_handler_validator.go• L170-206, api/…/contact_handler_validator_test.go• L71-143

Sanitization runs before validation and storage. It trims names, lowercases and de-duplicates email values, normalizes and de-duplicates phone values, and represents missing properties as an empty map. The JSON and CSV paths use the same normalization rules, so a CSV value without a leading + can be accepted and stored in the same form as a JSON value. api/…/contact_store.go• L49-55, api/…/contact_store.go• L81-96, api/…/contact_update.go• L20-33, api/…/contact_handler_validator_test.go• L375-392

The creation path also checks the user’s contact entitlement against the number of contacts already stored plus the new batch. A denied check returns a payment-required response instead of creating only part of the batch. api/…/contact_handler.go• L137-150, api/…/contact_handler.go• L313-321

References: api/…/contact_handler.go• L106-206 api/…/contact_store.go• L21-46 api/…/contact_store.go• L49-96 api/…/contact_handler_validator.go• L56-74 api/…/contact_handler_validator.go• L116-206 api/…/contact_handler_validator_test.go• L31-206 api/…/contact_handler_validator_test.go• L375-392 api/…/contact_handler.go• L313-321 web/…/httpsms-contacts.csv• L1-4

Contact updates and lifecycle

Contact updates

PUT /v1/contacts/:contactID replaces the editable contact details after the API validates the ID and request. The update includes the name, complete phone-number list, complete email list, and properties. It also advances the update time. api/…/contact_handler.go• L209-265, api/…/contact_update.go• L11-43

Before saving, the service keeps the old phone numbers as well as the new ones for lookup invalidation. This matters when a phone number is removed because a cached thread lookup must not keep returning the old contact match. Invalidation runs only after the repository write succeeds, so a failed update does not discard a still-valid cached result. api/…/contact_service.go• L176-189, api/…/contact_service_test.go• L369-394, api/…/contact_service_test.go• L549-570

References: api/…/contact_handler.go• L209-265 api/…/contact_update.go• L11-43 api/…/contact_service.go• L176-189 api/…/contact_service_test.go• L369-394 api/…/contact_service_test.go• L549-570

Contact deletion

DELETE /v1/contacts/:contactID removes one contact after confirming that the contact belongs to the authenticated user. Deletion does not remove message records or message threads because those records use phone numbers as their own conversation data. It does clear contact lookup state, so later thread reads can fall back to the phone number. api/…/contact_handler.go• L267-310, api/…/contact_service.go• L192-220

Account-wide contact deletion is user-scoped and does not evict another user’s cached contact matches. api/…/contact_service_test.go• L427-453

References: api/…/contact_handler.go• L267-310 api/…/contact_service.go• L192-220 api/…/contact_service_test.go• L427-453

Contact listing

API listing

GET /v1/contacts returns a page of contacts for the authenticated user and a total count for the full filtered set. The list supports text search across names, emails, and phone numbers. It supports sorting by name or update time plus skip and limit paging. api/…/contact_handler.go• L55-103, api/…/contact_index.go• L9-43, api/…/contact_responses.go• L17-24

The list and count use the same user scope and search filter. The default page starts at zero with a limit of 20, while valid API limits range from 1 to 100. When no sort is given, recently updated contacts appear first. api/…/contact_index.go• L19-32, api/…/contact_handler_validator.go• L89-113, api/…/gorm_contact_repository.go• L83-144, api/…/contact_handler_validator_test.go• L176-206

References: api/…/contact_handler.go• L55-103 api/…/contact_index.go• L9-43 api/…/contact_handler_validator.go• L89-113 api/…/contact_handler_validator_test.go• L176-206 api/…/gorm_contact_repository.go• L83-144 api/…/contact_responses.go• L17-24

Dashboard contact view

The dashboard’s Contacts page turns the API list into a server-paged table. It shows names, all phone numbers, all emails, and created and updated times. Users can search by name, phone number, or email, add or edit a contact, delete a contact, or import a CSV file. web/…/index.vue• L32-46, web/…/index.vue• L225-293, web/…/index.vue• L295-418

The page keeps the current page and sort choice when it refreshes after a change. Search waits briefly after typing and returns to the first page. The contacts store also ignores older in-flight responses, which prevents a slow request from restoring stale rows after a newer change. web/…/contacts.ts• L38-115, web/…/contacts.ts• L117-249

References: web/…/index.vue• L32-46 web/…/index.vue• L225-418 web/…/contacts.ts• L38-249

Conversation recipient association

Phone-based contact matching

When the thread API requests contact details, the message thread service collects the thread recipient phone numbers and asks the contact service for matching contacts. The lookup is scoped to the user and returns only contacts whose phone-number list contains a requested number. A contact can match more than one thread recipient when it has multiple phone numbers. api/…/message_thread_service.go• L272-307, api/…/contact_service.go• L223-282, api/…/gorm_contact_repository.go• L147-160

The contact service caches each user-and-phone lookup for a short period. Contact mutations advance the user’s lookup generation and invalidate old phone entries, which keeps name changes and removed numbers from remaining in normal reads. A lookup result fetched before a contact update cannot replace the newer generation after the update. A contact lookup failure does not prevent the thread list from loading; the thread can remain without resolved contact details. api/…/contact_service.go• L17-20, api/…/contact_service.go• L223-291, api/…/message_thread_service.go• L291-307, api/…/contact_service_test.go• L396-425

If more than one contact matches the same user and phone number, the most recently updated contact wins. This gives the dashboard one stable contact label for a phone-keyed recipient. api/…/contact_service_test.go• L355-367

References: api/…/message_thread_service.go• L272-307 api/…/contact_service.go• L223-291 api/…/gorm_contact_repository.go• L147-160 api/…/contact_service_test.go• L288-367 api/…/contact_service_test.go• L396-425

Thread API enrichment

GET /v1/message-threads has a contacts query option. When it is true, each matching thread may include contact_details; this field is resolved at read time and is not stored in the thread. The dashboard sets this option so its inbox can show contact names. api/…/message_thread_handler.go• L49-65, api/…/message_thread_index_request.go• L13-67, api/…/message_thread.go• L24-27, web/…/threads.ts• L46-68

The thread still keeps the raw recipient phone number as its stable message target. If no contact matches, the dashboard formats that number and uses it as the title. If a contact name matches, the dashboard uses the name and can show the formatted number as supporting detail. web/…/MessageThread.vue• L32-45, web/…/index.vue• L111-117, web/…/index.vue• L286-326

The dashboard uses the resolved contact for more than display. From a thread, the user can edit the matched contact or add a new contact when the recipient is only a phone number. The message composer continues to send to the thread’s phone value, so contact presentation does not change message routing. web/…/index.vue• L225-243, web/…/index.vue• L309-326, web/…/index.vue• L600-616

This diagram shows how a stored contact becomes optional display data for a phone-keyed conversation.

flowchart LR
    Contact[User contact] --> Store[Contact storage]
    Message[Message activity] --> Thread[Thread keyed by owner and recipient phone]
    Thread --> Request[Thread list with contacts enabled]
    Store --> Lookup[User and phone lookup]
    Request --> Lookup
    Lookup --> Enriched[Thread with contact details]
    Enriched --> Dashboard[Name or formatted phone in dashboard]
    Thread --> Dashboard

For the thread lifecycle and the detailed message history behind this association, read Message threads and search. For the message events that create and update those threads, read SMS message lifecycle. For recipient lists used in large sends, read Bulk and scheduled messaging. api/…/message_thread_service.go• L87-140, api/…/message_thread_service.go• L281-307, web/…/threads.ts• L53-85

References: api/…/message_thread_handler.go• L49-65 api/…/message_thread_index_request.go• L13-67 api/…/message_thread.go• L24-27 web/…/threads.ts• L46-85 web/…/MessageThread.vue• L32-45 web/…/index.vue• L111-117 web/…/index.vue• L225-243 web/…/index.vue• L286-326 web/…/index.vue• L600-616

Change checklist

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

  • Keep contact phone normalization identical for JSON input, CSV input, updates, storage, and phone-based thread lookup. A mismatch can make a saved name disappear from a conversation.
  • Keep the contact API page limit, search fields, sort fields, and total-count meaning aligned with the dashboard table and its page state.
  • When contact fields change, update the shared API types, form payload, validation, stored entity, and both repository mappings together.
  • When a contact phone number changes or a contact is deleted, preserve invalidation for both old and new numbers and prevent older lookups from restoring stale results.
  • Keep the thread contacts option, contact_details response shape, phone lookup map, and dashboard fallback title aligned.
  • If thread enrichment behavior changes, preserve the raw owner and recipient phone values used by message history and message sending.

Important failure modes

TriggerConsequenceGuard
A contact phone is stored in a different form from the thread recipient phone.The thread has no contact name and shows the formatted number instead.Apply the shared phone normalization before validation and use the normalized value for storage and lookup. api/…/contact_store.go• L81-96, api/…/contact_service.go• L223-282
A contact update removes a phone without invalidating the old value.A later thread read can show the deleted contact name from stale lookup data.Invalidate both the previous and current phone lists after a successful update. api/…/contact_service.go• L176-189
A contact write fails but its lookup cache is cleared anyway.A still-valid contact lookup is lost and the next thread read must fetch it again.Invalidate only after the repository update or delete succeeds. api/…/contact_service_test.go• L549-589
A completed contact update is followed by an older in-flight lookup result.The dashboard can briefly show the old contact name after the update.Use a new lookup generation and reject stale results from older generations. api/…/contact_service_test.go• L396-425
Two contacts match the same user and phone number.The dashboard can show an unstable or unexpected recipient name.Select the most recently updated matching contact. api/…/contact_service_test.go• L355-367
Contact enrichment fails while threads are listed.The inbox still loads but falls back to phone numbers for affected threads.Treat contact details as optional read-time data and keep the thread’s raw recipient phone. api/…/message_thread_service.go• L291-307, api/…/message_thread.go• L24-27
The dashboard page sends a limit above the contact API maximum.Contact loading fails validation and the table cannot show that page.Keep table page-size options within the API range of 1 to 100. api/…/contact_handler_validator.go• L89-105, web/…/index.vue• L41-46
A CSV file has an invalid name or unrelated MIME type.The import is rejected before contact rows are stored.Use a .csv file and an accepted CSV MIME value. api/…/contact_handler_validator_test.go• L228-305
A CSV row has no name, no phone, or an invalid phone or email.The full import is rejected with row-specific validation errors.Use the official columns and correct the reported row before retrying. api/…/contact_handler_validator.go• L148-167, api/…/contact_handler_validator.go• L170-206
A thread update replaces a contact-enriched row with a response that has no contact_details.The contact name can disappear from the inbox after marking the thread read.Preserve the existing resolved contact when the thread phone is unchanged. web/…/threads.ts• L27-43

Key files

FileWhy to read it
api/…/contact.goDefines the user-owned contact data and its stored fields.
api/…/contact_store.goShows create input forms, normalization, and conversion to stored records.
api/…/contact_update.goShows the full replacement update contract.
api/…/contact_handler_validator.goDefines contact rules and CSV import limits.
api/…/contact_handler_validator_test.goShows the accepted CSV formats and validation guarantees.
api/…/contact_handler.goDefines the create, import, list, update, and delete API boundary.
api/…/contact_service.goConnects contact persistence with phone lookup and cache invalidation.
api/…/contact_service_test.goShows user isolation, cache freshness, tie-breaking, and write-failure behavior.
api/…/gorm_contact_repository.goShows user-scoped contact search, paging, counting, and phone matching.
api/…/message_thread.goShows the phone-keyed thread and its non-persisted contact enrichment.
api/…/message_thread_service.goShows how thread recipients resolve to contact details for reads.
api/…/message_thread_handler.goDefines the thread-list option that enables contact details.
web/…/contacts.tsShows dashboard contact loading and mutation state.
web/…/index.vueShows the contact table, search, paging, edit, delete, and import flows.
web/…/threads.tsShows how the dashboard requests and retains enriched thread rows.
web/…/MessageThread.vueShows the inbox title and avatar fallback from contact data.
web/…/index.vueShows contact names in conversation detail and add or edit actions.