Skip to main content
The MessagingService class (accessed via client.messaging) handles real-time customer ↔ store communication. It manages threaded conversations, message delivery, read state, and full thread lifecycle management.

Security Model

Messaging threads carry sensitive customer information — order inquiries, complaints, contact details, and uploaded attachments. To prevent one customer from reading or changing another customer’s conversation, every customer-facing messaging endpoint requires a signed customer session token (xAuthToken) issued by client.authentication. Ownership is enforced on every call: The publishable key is read from the Authorization header on every messaging route. The WebSocket handshake is the one request that also reads it from an api_key query parameter, because a browser WebSocket cannot set headers; a secret key in the query string is refused with 400 invalid_request. Obtain a customer session via client.authentication.login(...) or client.authentication.verifyOtp(...) and pass customerSession.access_token as xAuthToken on every call below. If you authenticate shoppers with your own identity provider rather than through Galactic Core, send xExternalAuth (a signed identity assertion) or xIdpToken (your provider’s own token, which Galactic Core forwards to the store’s configured verifier) in place of xAuthToken. The examples below use xAuthToken, but every one of these endpoints accepts any of the three — send exactly one.
Each Thread object returned by listThreads and getThread includes an unread_count_customer field. Sum these client-side to compute a customer’s total unread count — no separate endpoint is needed.

Messaging on a marketplace

A marketplace shopper writes to one seller at a time. With a marketplace operator or marketplace key, createConversation names the seller in storeId (an active seller of that marketplace, otherwise 404), and listThreads returns the signed-in shopper’s conversations across every seller of the marketplace, newest activity first. Passing storeId to listThreads narrows the inbox to one seller. Each thread carries store_id and store_name.
  • Shopper identity. A signed-in shopper sends a marketplace shopper session (xAuthToken) or an assertion signed with the marketplace’s secret (xExternalAuth). A guest sends customer_email; the seller’s replies reach the guest by email with a link that opens viewGuestThread and replyToGuestThread.
  • Thread types. general contacts the shop, product_inquiry needs a product_id of that seller, and order_inquiry needs the order_id of an order the signed-in shopper placed in this marketplace (a guest receives 401, another shopper’s order 404). An order conversation carries order_help, the endpoints for returns, return eligibility and disputes; a conversation never opens a return or a dispute.
  • Contact details. Neither side receives the other’s email address or phone number. customer_name is the name the seller sees and cannot contain an email address or phone number. Reply notices go to the address the shopper’s credential carries. The store’s internal notes are never returned.
  • Marketplace visibility. The marketplace can read a conversation and join it. Each marketplace thread carries a marketplace object (name, operator_can_read, operator_joined, restricted, notice) so a storefront can disclose this beside the conversation. A message from the marketplace has sender_type: system and the marketplace’s name as sender_name. While restricted is true the shopper’s replies are refused with 403.
  • Limits. New conversations are limited to 30 an hour per address (10 at one seller), 10 an hour per signed-in shopper or guest email, and 3 at one seller per shopper. A server calling with a secret key forwards the shopper’s address in xForwardedShopperIp so each shopper has a separate budget.

reportThread

Reports a conversation to the marketplace for spam, abuse, a scam or a request to deal off the marketplace (reason is spam, abuse, scam, off_platform or other, with an optional note and message_id). The thread must be the signed-in shopper’s own (404 otherwise). Repeating an open report on the same conversation and message returns the existing report with already_reported: true. The limit is 20 reports an hour per address and per shopper.
Response

reportGuestThread

Reports a marketplace guest conversation from the token in the reply email, under the token rules of viewGuestThread. Every token failure answers the same 404. The limit is 20 reports an hour per address and 12 per token.

Thread Discovery & Filtering

listThreads

Retrieve message threads with advanced server-side filtering. Pinned threads are automatically returned at the top of the result set.
Response
The customerId query parameter must match the customer_id on xAuthToken, otherwise the request is rejected.

Computing total unread

Each thread returned by listThreads includes unread_count_customer. Sum these client-side to display a “new messages” badge:
To fetch only threads with unread messages for the shopper (unread_count_customer greater than 0), pass ?unread=true as a filter.

Read receipts

Each thread records when each side last read it. A storefront shows a message the shopper sent as read once store_last_read_at is later than the message’s created_at, and a store message as read once customer_last_read_at is later than its created_at. Both fields are null until that side has read the thread.

getThread

Retrieve high-level metadata for a single thread.
Response
The thread must belong to the customer on your session token, otherwise the request is rejected.

updateThread 🔒

Archives, mutes or pins the customer’s own thread, or closes it. A customer cannot change a thread’s priority or set any other status (403); a value outside the allowed list is 400.
Requires a Secret Key (for merchant lifecycle changes) or a customer xAuthToken belonging to the thread owner (for customer-driven actions like muting or archiving their own conversation). A customer request must own the thread, otherwise it is rejected.

markThreadRead 🔒

Marks all customer messages in the thread as read and resets the store unread count to 0.
The caller must own the thread. The id must be a valid UUID — malformed values return 400.

Message Operations

getThreadMessages

Fetch paginated history for a thread. Deleted messages are automatically excluded.
Response
Only the thread’s owning customer (or a Secret Key holder) can read its messages.

sendMessage 🔒

Reply to an existing conversation.
The caller must own the thread. Returns 201 with the newly persisted message body on success.

editMessage 🔒

Update the content of one of the customer’s own messages. Sets is_edited: true and records edited_at. Works with a publishable key plus the customer’s xAuthToken (a customer-self write, same browser-origin pattern as cart/wishlist) — the session token proves ownership of the message.
Response
You can only edit or delete messages the customer personally authored. Store and system messages cannot be modified.

deleteMessage 🔒

Soft-deletes one of the customer’s own messages. The message is hidden from list responses but retained for audit trails. Works with a publishable key plus the customer’s xAuthToken (the session token proves ownership). Returns success, the message_id, and the deleted_at timestamp.
Same ownership check as editMessage — you can only delete a message you authored. Soft delete only; the row is retained for audit.

createConversation 🔒

Initiate a new support ticket with an initial message. A customer cannot set a priority; threads start at normal.
Response
Whenever body.customer_id is supplied, it must match the customer_id on xAuthToken. Returns 201 with both the new thread and the initial message.
thread_type may be dispute for a conversation about a dispute over an order or product; a shopper may open one. source_thread_id opens the conversation from an earlier thread of the same shopper, for example a dispute about a product the shopper had already written to the store about, so the store sees the history in one place. It must be a thread of this shopper in the same store and environment, otherwise the call returns 400. When order_id or product_id is omitted, the earlier thread’s value is used. The new thread returns source_thread_id, which is null when it was not opened from another. thread_type is inferred when it is not supplied: order_inquiry when order_id is present, product_inquiry when product_id is present, and general otherwise. The response echoes the resolved thread_type along with order_id and product_id, so a storefront can confirm the classification its own request produced without a follow-up read.

Data Schemas

viewGuestThread

Returns a guest’s conversation for the link token in the store’s reply email, oldest message first. The token opens one conversation of the key’s store and environment. Contact details are never returned.
Response

replyToGuestThread

Adds the guest’s reply to the conversation the link token opens. An expired, revoked or unknown token returns 404.

Thread Structure

Message Structure


Performance Tip: When building a chat UI, use getThreadMessages with order: 'desc' to load the most recent activity first, then use the next_cursor to load history as the user scrolls up.

Realtime messaging

A thread’s new messages arrive as they are sent over a WebSocket, rather than on the interval a getThreadMessages poll would impose. The subscribeToThread helper is exported from the SDK package root and uses the runtime’s built-in WebSocket, so it runs on browsers, Deno, Bun, and Node 22+ with no additional dependency.

subscribeToThread

Opens a WebSocket to the thread and calls onMessage for every new message — including the store’s replies — as it arrives. Pass your publishable key plus one customer credential (the signed-in customer’s session token, or a bring-your-own-auth assertion). It returns an unsubscribe function.
The value subscribeToThread returns is a callable unsubscribe function (call it to disconnect) that also carries two senders for publishing your own state:
markRead() both sends the instant “seen” cue over the socket and persists your read position via POST /v1/messaging/threads/{id}/read, so the receipt survives a reconnect. The connection is authorized server-side: the customer credential is validated and confirmed to be the thread’s participant before the socket is accepted, so a customer only ever receives their own thread’s messages. The same call works for both Galactic-Core-authenticated customers (pass authToken) and bring-your-own-auth customers (pass externalAuth).
This is a WebSocket, not a request that counts toward your monthly request quota.

Raw WebSocket protocol (without the SDK)

If you’re not using the TypeScript SDK — a mobile app, another language, or your own client — connect to the WebSocket directly and speak the frame protocol below. Everything the subscribeToThread helper does (messages, presence, typing, read receipts) is available on the raw socket. Connect (browsers/WS handshakes can’t set headers, so credentials go in the query string):
The server validates the credential + participant membership before accepting the socket, then keeps it open. All frames are JSON strings, except the heartbeat (a bare ping/pong). Server → client frames (things you receive): Client → server frames (things you send): pid is the participant id (the shopper’s customer id, or store for the merchant); role is customer or store. Presence is per-conversation — it reflects who’s connected to this thread, not global online state. Build a “seller is online” dot from presence.join/leave, a typing bubble from presence.typing, and read ticks from presence.read.

Response Codes