Conversation Status

To get the current ASAPPConversationStatus , implement the conversationStatusHandler callback below:

ASAPP.instance.conversationStatusHandler = { conversationStatus ->
    // handle conversationStatus.isLiveChat, conversationStatus.unreadMessages
}

If isLiveChat is true, it means the customer is currently connected to a live customer support agent or in a queue to get connected, even if the user isn’t currently on the chat screen or the application is in the background. The unreadMessages integer indicates the number of new messages the user has received since last entering Chat.

Trigger the Conversation Status Handler

You can trigger this handler in two ways.

  1. You can manually trigger it with the call:
    ASAPP.instance.fetchConversationStatus()
    
    When called, the Chat SDK will fetch the status asynchronously and callback to conversationStatusHandler once it is available.
  2. The conversationStatusHandler handler might be triggered when a push notification is received, if the application is in foreground. If your application already handles Firebase push notifications, please use ASAPP.instance.onFirebaseMessageReceived(message) so that the Chat SDK can handle incoming ASAPP push notifications. Example:
    class MyFirebaseMessagingService : FirebaseMessagingService() {
        override fun onMessageReceived(message: RemoteMessage) {
            super.onMessageReceived(message)
            val wasFromAsapp = ASAPP.instance.onFirebaseMessageReceived(message)
            // ...
        }
    }
    

The Chat SDK will only look for conversation status data in the payload and will not cache or persist any analytics about this data. If the push notification message was sent from ASAPP, the Chat SDK will return a boolean set to true and will also trigger the conversationStatusHandler callback.

Debug logs

By default, the SDK only prints error logs to the console output. To allow the SDK to log warnings and debug information, use setDebugLoggingEnabled.

You should disable debug logs for production use.

Example:

ASAPP.instance.setDebugLoggingEnabled(BuildConfig.DEBUG)

Clear the Persisted Session

To clear the ASAPP session persisted on disk, call ASAPP.instance.clearSession().

You should not use this if you allow anonymous (unidentified) users access to chat, as this will cause chat history to be lost. It is only advisable to use this function if an identified user in your application signs out.

Setting an Intent

To open chat with an initial intent, pass a map specifying the intent in a format provided by ASAPP. Please ask your Implementation Manager for more information.

Open Chat with an Initial Intent

ASAPP.instance.openChat(context, asappIntent= mapOf("Code": "EXAMPLE_INTENT"))

To set the intent while chat is open, call ASAPP.instance.setASAPPIntent() to pass in a dictionary. This should only be called if chat is already open. You can also use the ASAPP.instance.doesASAPPActivityExist boolean helper to verify whether the user is already in chat.

How to Handle Chat Events

Certain agreed-upon events may occur during chat. To react to these events, implement the ASAPPChatEventHandler interface:

ASAPP.instance.chatEventHandler = object : ASAPPChatEventHandler {
    override fun handle(name: String, data: Map<String, Any>?) {
        // Handle chat event.
    }
}

Please ask your Implementation Manager if you have questions regarding chat event names and data.

These events are related to user flows inside chat, and not to user behavior such as button clicks.