CXone Mobile SDK Event Diagrams
This page provides diagrams and explanations of common events that occur during a chat interaction.
Application Becomes Active
This sequence diagram captures the flow when the mobile app becomes active, prepares chat, handles visitor and customer information, and communicates with the backend services. If any errors occur, they are appropriately handled and logged.
Initial State:
-
The SDK’s initial status is set to initial.
-
The mobile app enters the foreground.
Chat Preparation:
-
The user initiates chat preparation by calling prepare(brandId:channelId:).
-
If the chat state is not initial or offline, an IllegalChatStateError is returned.
-
Otherwise, the SDK sets the chat state to preparing and notifies the UI with onChatUpdated().
Channel Configuration:
-
The SDK requests channel configuration from the backend with getChannelConfiguration()).
-
If there’s a server error, a ServerError is returned, and the chat state is reset to initialize.
-
Otherwise, the channel configuration is received, and the SDK creates a destination ID.
-
If visitor ID or customer ID is null, they are created and stored locally.
Visitor and Customer Handling:
-
The SDK calls createOrUpdateVisitor(visitorId:customerId:deviceToken:) on the backend.
-
If there’s a server error, the chat state is reset to initialize.
-
Otherwise, the visitor and customer handling is successful.
Chat Prepared State:
-
The chat state is set to prepared.
-
The UI is notified with onChatUpdated().
-
Analytics for page views are tracked between the mobile app and backend.
Application Enters Background
This sequence diagram captures the flow when the mobile app enters the background, handles page view tracking, and communicates with the backend services. If any errors occur, they are appropriately handled. When an application enters the background, it means that it is no longer the main thing you see or interact with on your device. Imagine you’re using a messaging app, and then you press the home button or switch to another app. The messaging app is now in the background. It’s still running, but you’re not actively using it. This happens when you minimize an app, switch to a different app, or lock your phone. The app is still there, but it’s not in the foreground anymore.
Application Entering Background:
-
The UI displays a box indicating that the application is entering the background.
-
The UI notifies the SDK that the page view has ended using pageViewEnded.
-
The backend receives the pageViewEnded event.
-
If there’s a server error, it’s handled.
-
Otherwise, the event is successful.
-
Disconnecting and State Handling:
-
The UI initiates disconnection using disconnect().
-
Depending on the current state:
-
If preparing, the SDK sets the state to initial.
-
If already prepared, the SDK disconnects the socket and sets the state to prepared.
-
View Page
This sequence diagram represents the flow when a user views a page in the mobile app, including interactions with the SDK and backend services. It shows the analytics event when a user views a page, tracks visit details, and communicates with the backend services. If any errors occur, they are appropriately handled.
Application Activation Reference:
-
The diagram references the application went active event.
View Page Event:
-
The user views a page, and the UI notifies the SDK with viewPage(title:url:).
-
The chat mode is checked:
-
If not prepared, an illegalChatStateError is returned.
-
Otherwise, the visit details are checked for expiration.
-
If expired, new visit details are created (UUID and expiration).
-
If valid, the SDK adjusts the current expiration.
-
-
If the last page viewed was not sent, the SDK ends the page view.
-
The current last page viewed title, URI, and timestamp are stored.
-
If there’s a failure, like a server error, it’s handled.
-
Backend Interaction:
-
The SDK communicates with the backend services:
-
visitorVisit(date:) is called to record the visit.
-
pageView(title:uri:timestamp) is called to log the page view.
-
If there’s a server error, it’s handled.
-
Open Chat
This sequence diagram captures the flow when a user opens the chat, handles OAuth, and establishes a connection with the backend services. If any errors occur, they are appropriately handled.
Application Activation Reference:
-
The diagram references the application went active event.
Chat Opening:
-
The app user opens the chat, and the UI initiates a connection with connect().
-
The chat state is checked:
-
If connecting, the SDK establishes a WebSocket connection.
-
If initial or preparing, an IllegalChatStateError is returned.
-
If prepared, the chat mode is checked:
-
If live chat and live chat status is offline, the chat state is set to offline.
-
Otherwise, the WebSocket connection is established.
-
OAuth handling depends on whether it’s enabled or disabled.
-
-
OAuth Handling:
-
If OAuth is enabled:
-
The SDK reconnects with reconnectCustomerEventData(accessToken:).
-
If there’s a server error, it’s handled.
-
Otherwise, the CustomerReconnectedEvent is received.
-
-
If OAuth is disabled:
-
The SDK authorizes with authorizeCustomerEventData(authorizationCode:codeVerifier:).
-
If there’s a server error, it’s handled.
-
Otherwise, the CustomerAuthorizedEvent is received, and the access token and customer identity are stored.
-
Chat Connected State:
-
The chat state is set to connected.
-
The UI is notified with onChatUpdated().
-
Depending on whether the chat is single- In a single-threaded app, each contact can have only one chat thread. Any interaction they have with your organization takes place in that one chat thread. or multi-thread In a multi-threaded app, contacts can create as many threads as they want to discuss new topics. These threads can be active at the same time., the relevant chat view is displayed.
Single-Thread
This sequence diagram captures the flow when a user interacts with a single-thread In a single-threaded app, each contact can have only one chat thread. Any interaction they have with your organization takes place in that one chat thread. chat, handles thread recovery, and communicates with the backend services. If any errors occur, they are appropriately handled.
Application Activation Reference:
-
The diagram references the open chat event.
Thread Recovery:
-
The SDK loads the thread ID from local storage.
-
If any thread ID from an external platform is stored locally, the SDK recovers the messaging thread using RecoverMessagingThreadEvent(threadId:).
-
If no UUID is available, the SDK attempts recovery with RecoverMessagingThreadEvent(nil).
Thread Existence Check:
-
If the thread exists, the ThreadRecoveredEvent is received.
-
The chat and thread states are set to ready.
-
The UI is notified with onThreadUpdated().
-
-
If the thread does not exist, the ThreadRecoverFailedEvent is received.
-
The chat state is set to ready.
-
The UI is notified with onChatUpdated().
-
A note indicates that no thread recovery is needed.
-
Chat Interaction:
-
The UI displays the chat window for the user to engage with an agent.
Multi-Thread
This sequence diagram captures the flow when a user interacts with a multi-threaded In a multi-threaded app, contacts can create as many threads as they want to discuss new topics. These threads can be active at the same time. chat, handles thread retrieval, and communicates with the backend services. If any errors occur, they are appropriately handled.
Application Activation Reference:
-
The diagram references the open chat event.
Thread List Retrieval:
-
The SDK fetches the list of threads from the backend using FetchThreadListEvent.
-
If there’s a server error, it’s handled.
-
Otherwise, the thread list is fetched.
Thread Handling:
-
If threads exist:
-
The SDK sets the state of each thread to received and loads the last messages.
-
Thread metadata is loaded, and the state is set to loaded.
-
The chat state is set to ready, and the UI is notified.
-
-
If no threads exist:
-
The chat state is set to ready, and the UI is notified.
-
Create or Open Threads:
-
If creating a new thread:
-
The user initiates thread creation.
-
-
If opening an existing thread:
-
The user selects a thread.
-
The UI opens the thread using openThread(thread:).
-
The thread is recovered from the backend.
-
If there’s a server error, it’s handled.
-
Otherwise, the thread is recovered, and the state is set to ready.
-
Chat Interaction:
-
The user engages in chat with an agent.
Live Chat
This sequence diagram showcases the back-end flow of a Live Chat interaction. Live Chat is the real-time digital chat option, whereas Chat Messaging is the asynchronous messaging option, which is similar to private messages or direct messages.
Create Thread
This sequence diagram captures the flow when a user creates a new chat thread, handles thread creation, and communicates with the SDK. If any errors occur, they are appropriately handled.
User Details and Prechat:
-
If the customer name is not provided, the UI shows a user details form view.
-
If pre-chat information is available, the UI shows a pre-chat form view.
Thread Creation:
-
The user begins a conversation.
-
The UI initiates thread creation using createThread(customFields:).
-
If the chat mode is not multi-thread and the thread already exists:
-
An unsupportedChannelConfigError is returned.
-
An error alert is displayed.
-
-
Otherwise:
-
The SDK creates the thread locally with a UUID.
-
The UUID is stored locally.
-
The thread state is set to pending.
-
The UI is notified with onThreadUpdated().
-
Chat with an Agent
This sequence diagram captures the flow when an end-user interacts with an agent through chat, handles welcome messages, and communicates with the backend services. If any errors occur, they are appropriately handled.
Chat Initialization:
-
The user sends a message using sendMessage(message:).
-
If a welcome message is available:
-
The SDK sends an outbound welcome message using SendOutboundMessageEvent(welcomeMessage:).
-
If there’s a server error, it’s handled.
-
Otherwise, the MessageCreatedEvent is received, and the UI is updated.
-
-
The SDK sends the user’s message using sendMessageEvent.
-
If there’s a server error, it’s handled.
-
Otherwise, the MessageCreatedEvent is received, and the UI is updated.
-
End Contact
This sequence diagram captures the flow when a user ends a chat, handles the conversation closure, and communicates with the backend services. If any errors occur, they are appropriately handled.
Chat Ending:
-
The user presses End Conversation.
-
The UI notifies the SDK to end the conversation using endConversation().
-
The backend receives the EndConversationEvent.
-
If there’s a server error, it’s handled.
-
Otherwise, the case status is changed, and the thread state is set to closed.
-
The UI is notified with onThreadUpdated().
-
End Contact Experience View:
-
The UI displays the end contact view.
Process Large Events
One of the limitations of AWS API Gateway is that it can send only maximum of 128 KB in one message. To send larger events from the server to the client:
-
On the server, upload larger events to a publicly available S3 bucket.
-
The client can then receive only the URL to this file via WebSocket and download the actual event body through REST.