ClientSphereDocs

Hooks

The React hooks the SDK exposes, and what each field on them means.

All hooks must be used inside <SupportProvider>. SupportChatScreen is built entirely from these, so anything it does you can do yourself.

useConversation

The current conversation: history, sending, realtime replies, and the actions around it.

const {
  messages, conversationId, status, loading, error,
  send, sending, upload, attachmentUrl,
  aiStream, agentTyping, notifyTyping,
  hasMore, loadingOlder, loadOlder,
  escalate, startNew, end, refresh,
} = useConversation();
FieldMeaning
messagesOldest first. Each has id, messageText, senderType (visitor, agent, ai_assistant, system), senderName, attachments[], createdAt
conversationIdNull until the first message is sent
statusopen, closed, or null before the first message
loadingInitial history fetch in progress
errorThe last failure, as a SupportApiError where the server was involved
send(text, attachments?)Sends and resolves with the saved message. Text up to 2000 characters; may be empty when attachments are given
sendingA send is in flight
upload(file)Uploads a file and resolves with an attachment to pass to send. See Chat screen
attachmentUrl(attachment)A URL that works in <Image source={{ uri }}> and Linking.openURL
aiStream{ name, text } while the AI assistant is streaming a reply, else null. When it finishes the reply appears in messages
agentTypingAn agent is typing; clears itself after three seconds of silence
notifyTyping()Call on every keystroke; the SDK throttles it to one event per two seconds
hasMore, loadOlder(), loadingOlderPaging into older history. Stop when hasMore is false
escalate()Asks for a human. Resolves with an availability line based on the workspace's business hours, also appended as a system message
startNew()Closes the current conversation and starts a fresh one. Offer it when status is closed
end()Closes the current conversation
refresh()Re-fetches the latest page and merges it. Called for you on foreground

Messages from the visitor's own device arrive through send's result, not through the socket, so there is no duplicate to filter. Agent and system messages arrive live and are merged by id.

useConversations

Past conversations for this visitor, for a history list.

const { conversations, loading, error, refresh, loadMessages } = useConversations({ includeOpen: true });

Each item has id, status, openedAt, closedAt, closeReason, lastMessageAt, lastMessagePreview and lastMessageSender. Without includeOpen only closed conversations are returned.

loadMessages(id, { limit, offset }) fetches one conversation's history in full; the page shape is the same as useConversation uses internally.

useSupportConfig

The widget's public configuration, as set under Customer Support → Support Hub.

const { config, status, error, isHubMode, needsEmail, reload } = useSupportConfig();
FieldMeaning
configColours, welcome and placeholder text, whether AI auto-reply is on and the assistant's name, mode, hubCards, productCategories, requireEmail
statusloading, ready, or error for the whole provider
isHubModeThe workspace uses the hub landing on the web. Chat works either way; the cards are in config.hubCards if you want to render your own landing
needsEmailSee Identity and sessions
reload()Re-run the whole boot sequence, for a retry button

useSupport

The raw context, for anything the higher-level hooks do not cover.

const { client, realtime, session, identity, connected, identify, resumeCount } = useSupport();

client is the SupportClient with every public route on it, including knowledge base search, feature requests and email tickets:

const { client } = useSupport();
const { items } = await client.searchKnowledgeBase('reset password');
await client.submitFeatureRequest({ productCategory, urgency: 'medium', title, description });
await client.submitEmailTicket({ subject, message, submitterEmail });

connected is the socket state; resumeCount increments each time the app returns to the foreground and the socket was rebuilt, which is a useful dependency for anything of your own that should re-sync then.

On this page