This is the source of truth for the network contract. It is reverse-engineered from the official erxes-ios-sdk and the erxes React Native widget. The Android SDK must speak exactly this protocol.
All URLs derive from a single configured endpoint (base URL, e.g.
https://app.example.io). Strip a trailing / before appending.
| Purpose | Method | URL | Content-Type |
|---|---|---|---|
| GraphQL | POST | {base}/gateway/graphql |
application/json |
| Subscriptions | WS | {base}/gateway/graphql (ws/wss), graphql-ws protocol |
— |
| File upload | POST | {base}/gateway/upload-file?kind=main&maxHeight=0&maxWidth=0 |
multipart/form-data |
fileEndpointdefaults toendpoint; override only when the file server differs. Note: in the iOS SDK GraphQL actually runs onfileEndpoint(now.subdomain) — thew.host returns 405. Keep them equal unless told otherwise.- GraphQL request body:
{ "query": "<op>", "variables": { ... } }. - A GraphQL response may contain a top-level
errorsarray even with HTTP 200 — always check it.
- Multipart field name is
file; includefilenameand per-partContent-Type. - Allowed MIME types:
image/png,image/jpegonly. - Response body is the plain-text file key (not JSON). Use it as the attachment
url.
Persisted across launches (iOS UserDefaults → Android DataStore/SharedPreferences):
| Key | Meaning |
|---|---|
cachedCustomerId |
Set after a successful connect; re-identifies the customer. |
visitorId |
Generated once (Mongo-style ObjectId), reused forever. |
conversationId |
Last active conversation. |
integrationId |
The integration the identity is bound to. |
identified |
True once visitor supplied email/phone (requireAuth). |
Integration binding rule: identity is meaningless across integrations. If the
configured integrationId differs from the persisted one, clear cachedCustomerId,
visitorId, conversationId, and identified before use.
visitorId generation: Mongo ObjectId = 24 hex chars = 4-byte epoch seconds + 5-byte random + 3-byte counter. Generate one if none persisted.
Variables: integrationId (required), visitorId, cachedCustomerId, email,
phone, isUser, code, data (JSON), companyData (JSON).
Returns (top-level fields used by the client):
integrationId,customerId,visitorId,languageCodeuiOptions(JSON) —primary.DEFAULThex color,backgroundColor,textColor,wallpaper,logomessengerData(JSON) — see shape belowticketConfig— top-level, not inside messengerData:_id,name,pipelineId,channelId,selectedStatusId,parentId,formFields{ name, description, attachment, tags }where each field cfg ={ isShow, label, placeholder, order }.
messengerData shape:
supporterIds: [String], notifyCustomer: Bool, availabilityMethod: String,
isOnline: Bool, onlineHours: [{ day, from, to }], timezone: String,
messages: { greetings: { title, message }, away, thank, welcome },
links: { facebook, instagram, twitter|x, youtube, linkedin, discord, github },
knowledgeBaseTopicId: String, websiteApps: [{ _id, kind, credentials{ url, buttonText, description }, showInInbox }],
responseRate: String, requireAuth: Bool, showChat: Bool, showLauncher: Bool,
forceLogoutWhenResolve: Bool, showVideoCallRequest: Bool
After connect: persist customerId → cachedCustomerId.
widgetsSaveBrowserInfo(customerId, visitorId, browserInfo: JSON!)— may trigger auto welcome messages.widgetsMessengerSupporters(integrationId)— supporters list + online state for the launcher.
| Operation | Variables | Returns |
|---|---|---|
widgetsConversations |
integrationId!, customerId, visitorId | conversation list w/ last messages, unreadCount |
widgetsConversationDetail |
_id!, integrationId | one conversation, all messages, supporters, online |
widgetsMessengerSupporters |
integrationId! | supporters[], isOnline, availabilityMethod |
widgetsTotalUnreadCount |
integrationId!, customerId, visitorId | Int badge count |
| Operation | Notes |
|---|---|
widgetsMessengerConnect |
Handshake (above). |
widgetsSaveBrowserInfo |
Page-visit / auto messages. |
widgetsInsertMessage |
Send a chat message. Vars: integrationId!, customerId, visitorId, conversationId, message, contentType, attachments:[AttachmentInput]. Returns MessageFields. |
widgetsReadConversationMessages |
conversationId! → mark read. |
editCustomer / widgetsTicketCustomersEdit |
Update name/email/phone; returns _id to persist as cachedCustomerId. |
widgetsSaveCustomerGetNotified |
customerId/visitorId, type!, value! — email/phone opt-in. |
widgetsLeadConnect / widgetsSaveLead |
Lead/form widget. |
_id, conversationId, customerId, user{ _id, details{ avatar, fullName } }, content, createdAt, internal, fromBot, contentType, engageData{ content, kind, sentAs, fromUser{...} }, botData, messengerAppData, attachments{ url, name, size, type }
Connect to wss://{base}/gateway/graphql (derive from endpoint, not fileEndpoint:
https://→wss://, http://→ws://) with subprotocol graphql-transport-ws.
Lifecycle (confirmed against the iOS ChatViewModel): connection_init →
connection_ack → subscribe(id, payload{query,variables}) → next data frames →
error / complete. To stop, send {id, type:"complete"}. Reconnect on drop with
exponential backoff (1s → 30s cap). Dedup inbound messages by _id (the subscription
echoes your own sent messages back).
| Subscription | Variable | Payload |
|---|---|---|
conversationMessageInserted |
_id! (convId) | new message (full message fields) |
conversationBotTypingStatus |
_id! (convId) | { _id, typing } |
conversationClientMessageInserted |
userId! | echo of customer's own message (dedup) |
conversationAdminMessageInserted |
customerId! | { customerId, unreadCount } |
conversationChanged |
conversationId! | { conversationId, type } status change |
Note: the iOS
NetworkClient(Apollo) skips WS, butChatViewModelimplements the subscription directly overURLSessionWebSocketTaskwithgraphql-transport-ws— that is the authoritative framing above. The Android port mirrors it on OkHttp's WebSocket (network/RealtimeClient.kt), exposed as coldFlows.
- iOS SDK source:
Sources/MessengerSDK/Network/Operations/*.graphql - Connect parsing:
Messenger/ViewModels/AppViewModel.swift - Upload:
Network/Upload/FileUploader.swift - Session:
Session/SessionManager.swift