Link Search Menu Expand Document

Chat Lifecycle

Table of contents

  1. Overview
  2. Lifecycle Events

Overview

Through chat progress, it can be in various states, each has it’s own meaning. The hosting app can react to chat states and control it’s flow, by listening to chat states changes.

In order to listen to chat lifecycle events, set your implemention of ChatEventListener, to the ChatController.

// on ChatController construction:
val chatController = ChatController.Builder(context)
                        .chatEventListener(listener)...build(...)

// or later in time:
chatController.chatEventListener = listener

Lifecycle Events

Name Description
Preparing
StateEvent.Preparing
Passed when chat creation is starting.
Created
StateEvent.Created
Passed when the chat was successfully created
Started
StateEvent.Started
Passed when the chat was successfully started.
On live chat: the chat was not yet accepted by an agent.
At this point the User can start posting messages on the chat, those will be received by the accepting agent.
Pending
StateEvent.Pending
Live chat only
The chat was assigned to an agent, waiting for his acceptance.
Chat unavailable will be triggered, if timeout was configured and the chat was not accepted on time.
InQueue
StateEvent.InQueue
Live chat only
The chat is in a waiting queue, waiting to be assigned to an agent. The chat position in the queue is passed was well.
Chat unavailable will be triggered, if chat end is activated by the user while in this state.
Accepted
StateEvent.Accepted
Live chat only
Passed when an agent accepts the chat.
Reconnected
StateEvent.Reconnected
Messaging chat only
Passed when the chat got reconnected after connection lost.
Unavailable
StateEvent.Unavailable
Live chat only
Passed when chat initiation was rejected due to unavailability. (no operators, out of working hours, etc.)
Ending
StateEvent.Ending
Live chat only
Passed when the chat started ending process.
Postchat form data will be available on this event.
Ended
StateEvent.Ended
Passed when the chat ends.
Idle
StateEvent.Idle
Passed when there are no more active chats in the ChatController.
ChatWindowLoaded
StateEvent.ChatWindowLoaded
will be triggered once the chat fragment was loaded and ready to display chat elements and receive injections.
ChatWindowDetached
StateEvent.ChatWindowDetached
Will be triggered once the chat window was closed and should be removed from its containing activity.

States handling code sample:
    @Override
    public void onChatStateChanged(@NotNull StateEvent stateEvent) {
        switch (stateEvent.getState()) {
            case StateEvent.Started:
                // do something
                
            case StateEvent.Unavailable:
                // do something
                
            case StateEvent.Ended:
                // do something
                
            case StateEvent.InQueue:
                // fetching the queue position from the event:
                InQueueEvent queueEvent = (InQueueEvent) stateEvent;
                int queuePosition = queueEvent.getPosition();
                
            case StateEvent.Idle:
                // no more active chats, we can remove chat fragment
                
            case StateEvent.ChatWindowLoaded:
                // do something
                
            case StateEvent.ChatWindowDetached:
                // removing chat fragment from its activity
        }
    }