TheDocumentation Index
Fetch the complete documentation index at: https://docs.tybritelabs.com/llms.txt
Use this file to discover all available pages before exploring further.
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 PII — order inquiries, complaints, contact details, and uploaded attachments. To prevent one customer from reading or mutating another customer’s conversation, every customer-facing messaging endpoint requires a signed customer session token (xAuthToken) issued by client.auth. The gateway enforces ownership through one of three layered gates:
| Gate | Applied To | Check |
|---|---|---|
gateByCustomerId | List / create operations | The customer_id supplied in the query or request body must match the customer_id claim on the bearer token. |
gateByThreadId | Thread-scoped reads & writes | The worker resolves thread.customer_id from the database, then asserts it equals the token’s customer_id. Applied to getThread, updateThread, getThreadMessages, sendMessage, and markThreadRead. |
gateByMessageId | Per-message edit & delete | The worker resolves the target message and asserts sender_type = 'customer' and sender_id = auth.customerId. A customer can only edit or delete messages they personally authored. |
client.auth.login(...) or client.auth.verifyOtp(...) and pass customerSession.access_token as xAuthToken on every call below.
Thread Discovery & Filtering
listThreads
Retrieve message threads with advanced server-side filtering. Pinned threads are automatically returned at the top of the result set.
Gated by
gateByCustomerId — the customerId query parameter must match the customer_id claim on xAuthToken.Computing total unread
Each thread returned bylistThreads includes unread_count_customer. Sum these client-side to display a “new messages” badge:
?unread=true as a filter.
getThread
Retrieve high-level metadata for a single thread.
Gated by
gateByThreadId — the worker resolves thread.customer_id and asserts it equals the token’s customer_id claim.updateThread 🔒
Update thread state including status, priority, or lifecycle flags.
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). Customer requests are additionally gated by gateByThreadId.markThreadRead 🔒
Marks all customer messages in the thread as read and resets the store unread count to 0.
Gated by
gateByThreadId. 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.
| Param | Type | Description |
|---|---|---|
limit | number | Max messages per page (default 50). |
cursor | string | Base64-encoded created_at for next page. |
order | string | asc (oldest first) or desc (newest first). |
Gated by
gateByThreadId — only the thread’s owning customer (or a Secret Key holder) can read its messages.sendMessage 🔒
Reply to an existing conversation.
Gated by
gateByThreadId. Returns 201 with the newly persisted message body on success.editMessage 🔒
Update the content of an existing message. Sets is_edited: true.
Gated by
gateByMessageId — the worker asserts message.sender_type = 'customer' and message.sender_id = auth.customerId. Customers cannot edit store or system messages.deleteMessage 🔒
Soft-deletes a message. The message is hidden from list responses but retained for audit trails.
Gated by
gateByMessageId — same ownership check as editMessage. Soft delete only; the row is retained for audit.createConversation 🔒
Initiate a new support ticket with an initial message.
Gated by
gateByCustomerId whenever body.customer_id is supplied — the value must match the customer_id claim on xAuthToken. Returns 201 with both the new thread and the initial message.Data Schemas
Thread Structure
| Field | Type | Description |
|---|---|---|
id | uuid | Unique thread identifier. |
subject | string | Thread title/topic. |
status | enum | active, resolved, closed, escalated, pending. |
priority | enum | low, normal, high, urgent. |
is_archived | boolean | Hidden from main list. |
is_muted | boolean | Notifications disabled. |
is_pinned | boolean | Always at top of list. |
unread_count_store | number | Messages awaiting store reply. |
Message Structure
| Field | Type | Description |
|---|---|---|
id | uuid | Unique message identifier. |
message_content | string | The text body. |
sender_type | enum | customer, store, system. |
is_edited | boolean | Whether content was changed. |
is_deleted | boolean | Whether message is soft-deleted. |
Response Codes
| Code | Meaning |
|---|---|
200 | Success on reads, updateThread patches, and markThreadRead. |
201 | Success on createConversation and sendMessage — a new resource was persisted. |
400 | Invalid request body, or a malformed UUID supplied to markThreadRead (or any thread/message ID path param). |
401 | Missing or invalid xAuthToken, or missing/invalid API key. |
403 | Customer token does not own the target thread or message (gate failure). |
404 | Thread or message not found (or filtered out by store scoping). |
429 | Rate limit exceeded. |
500 | Internal server error — safe to retry idempotent reads. |

