Chat SDK uses ChatKit for the message view so I would recommend that you look at their documentation before trying to add custom message types to Chat SDK. Chat SDK really just exposes the ChatKit custom message API.
Override Text Message Display
In this example, we will override the outcoming text message so that we can append "Hello World!" to every text message.
To do this, the first step is to make a new class that extends the OutcomingTextMessageViewHolder.
This is where we are registering the view holder with ChatKit. We can also specify custom layout files.
Finally, we need to tell Chat SDK to use this message handler:
Creating a Custom Message Type
Chat SDK supports completely custom message types. To do this, we need to setup a number of classes.
This is an example of a custom message type.
getTypes() - Which message types we support
hasContentFor - Is this view holder of the correct type?
onBindMessageHolders Here we register our custom types with ChatKit. We can define outcoming and incoming view holders and also define custom XML files.
The message holder exposes properties from the message to the view holders.
The view holder binds the message holder to the view. It has access to the view and can get properties from the XML layout file using itemView.findViewById().
The final step would be to send the custom message.
For another real world example you can look ad the ImageMessageHandler.
Image Message Handler
Chat SDK supports completely custom message types. To do this, we need to extend the CustomMessageHandler class. We can look at the image message handler as an example:
The onBindMessageHolder allows us to register our content type with ChatKit
The onClick method is called if the user clicks the message
The onNewMessageHolder method is called to provide a new instance of the message holder
The hasContentFor method lets the system know when this custom message type should be used
To register this with the framework, you can use the following:
Summary
This may seem complicated, if that's the case, I would recommend thoroughly reviewing the ChatKit documentation. This guide just explains how to access the ChatKit API from within Chat SDK. It doesn't go through the ChatSDK API in detail.