Brand Messenger Android SDK Conversation

Learn how to initiate a chat with an agent in the Brand Messenger Android SDK

Initiate Chat with Agent

For starting the messaging activity, using the following script:;;

If the environment is also configured with Welcome-Messages, the following can be used instead of show(context). This will also send an API request to give the user a welcome-message.


To just send the welcome-message API request without displaying the conversation screen, use the following


Intercept Message Actions

Message actions from SDK conversation screen, such as user tapping on link-buttons, can be intercepted and handled outside of the SDK via a delegate.

BrandMessengerManager.setMessageActionDelegate(new KBMMessageActionDelegate() {
    public boolean onAction(Context context, String action, Message message, Object object, Map<String, Object> replyMetadata) {
        switch (action) {
            // Example action types
            case KBMRichMessage.SUBMIT_BUTTON:
            case KBMRichMessage.QUICK_REPLY:
            case KBMRichMessage.TEMPLATE_ID + 9:
            case KBMRichMessage.WEB_LINK:
                // URL link data is found differently depending on the rich-message model type
                KBMRichMessageModel.KBMAction kbmAction = null;
                if (object instanceof KBMRichMessageModel.KBMButtonModel) {
                    kbmAction = ((KBMRichMessageModel.KBMButtonModel) object).getAction();
                } else if (object instanceof KBMRichMessageModel.KBMElementModel) {
                    kbmAction = ((KBMRichMessageModel.KBMElementModel) object).getAction();
                } else if (object instanceof KBMRichMessageModel.KBMAction) {
                    kbmAction = (KBMRichMessageModel.KBMAction) object;
                } else if (object instanceof KBMRichMessageModel.KBMPayloadModel) {
                    kbmAction = ((KBMRichMessageModel.KBMPayloadModel) object).getAction();
                String url;
                if (kbmAction != null) {
                    if (!TextUtils.isEmpty(kbmAction.getUrl())) {
                        url = kbmAction.getUrl()
                    } else if (kbmAction.getPayload() != null && !TextUtils.isEmpty(kbmAction.getPayload().getUrl())) {
                        url = kbmAction.getPayload().getUrl();

                if (object instanceof KBMRichMessageModel.KBMPayloadModel) {
                    KBMRichMessageModel.KBMPayloadModel payloadModel = (KBMRichMessageModel.KBMPayloadModel) object;
                    if (!TextUtils.isEmpty(payloadModel.getUrl())) {
                        url = payloadModel.getUrl();
                return true;
        // Return false to let SDK handle action. True if action is handled here.
        return false;
BrandMessengerManager.setMessageActionDelegate( object : KBMMessageActionDelegate {
    override fun onAction(
        context: Context?,
        action: String?,
        message: Message?,
        `object`: Any?,
        replyMetadata: MutableMap<String, Any>?
    ): Boolean {
        when (action) {
            KBMRichMessage.SUBMIT_BUTTON -> return false
            KBMRichMessage.QUICK_REPLY -> return false
            KBMRichMessage.TEMPLATE_ID -> return false
            KBMRichMessage.WEB_LINK -> {
                // handle link.
                var kbmAction: KBMRichMessageModel.KBMAction? = null
                if (kbmObject is KBMRichMessageModel.KBMButtonModel) {
                    kbmAction = kbmObject.action
                } else if (kbmObject is KBMRichMessageModel.KBMElementModel<*>) {
                    kbmAction = kbmObject.action
                } else if (kbmObject is KBMRichMessageModel.KBMAction) {
                    kbmAction = kbmObject
                } else if (kbmObject is KBMRichMessageModel.KBMPayloadModel) {
                    kbmAction = kbmObject.action
                var url: String
                if (kbmAction != null) {
                    if (!TextUtils.isEmpty(kbmAction.url)) {
                        url = kbmAction.url
                    } else if (kbmAction.payload != null && !TextUtils.isEmpty(kbmAction.payload.url)) {
                        url = kbmAction.payload.url

                if (kbmObject is KBMRichMessageModel.KBMPayloadModel) {
                    if (!TextUtils.isEmpty(kbmObject.url)) {
                        url = kbmObject.url
                return true
        return false;

Fetch new messages on every chat screen open

The SDK fetches the latest message every time the chat-screen is opened.
This functionality can be enabled/disabled. When disabled, new messages will only be fetches when a push-notification arrives or a mqtt connection message for new message is received.
Default is enabled (true).

Choosing persistent or temporary storage for the conversation

Customers can switch between using a persistent and temporary database for conversation data.
Default is temporary (false).