Skip to main content
Advanced features provide developers with the ability to extend WuKongIM Android SDK, including custom message types, message extensions, message receipts, message editing and message replies and other enterprise-level features.
In WuKongIM, all message types are custom messages

Custom Messages

Custom Regular Messages

Below we use a business card message as an example to show how to create custom message types.

Step 1: Define Message

Define a message object that inherits from WKMessageContent and specify the message type in the constructor.
Built-in message types in SDK can be viewed through WKMsgContentType
Note: Custom message objects must provide a parameterless constructor

Step 2: Encoding and Decoding

We need to send the three fields uid, name, avatar to the recipient. The final message content passed is:
Override the encodeMsg method of WKMessageContent to start encoding:
Override the decodeMsg method of WKMessageContent to start decoding:
When encoding and decoding messages, there’s no need to consider the type field, as the SDK handles it internally
If you want to control the content displayed when this custom message is retrieved, you can override the getDisplayContent method:
If you want this type of message to be searchable in global search, you can override the getSearchableWord method:

Step 3: Register Message

Through these three steps, the custom regular message is complete. When receiving a message, if the type in WKMsg is 3, it indicates that the message is a business card message, where baseContentMsgModel is the custom WKCardContent. At this time, you can cast baseContentMsgModel to WKCardContent and render it on the UI.
Complete code reference: Business Card Message

Complete Business Card Message Implementation Example

Custom Attachment Messages

Sometimes we need to send messages with attachments when sending messages. WuKongIM also provides custom attachment messages, which are not much different from regular messages. Below we use location messages as an example.

Step 1: Define Message

Note that custom attachment messages need to inherit from WKMediaMessageContent instead of WKMessageContent.
WKMediaMessageContent provides url and localPath fields, so custom messages don’t need to define network address and local address fields again

Step 2: Encoding and Decoding

We need to send longitude, latitude, address, url information to the recipient. The final message content passed is:
Override the encodeMsg method of WKMessageContent to start encoding:
When encoding messages, you can write localPath local fields. After the SDK saves the message, the message sent to the recipient does not include this field
Override the decodeMsg method of WKMessageContent to start decoding:
When decoding messages, if decoding local fields, you need to check if the field exists, because received messages don’t have local fields. For example, localPath is not available when receiving messages

Step 3: Register Message

Message Extensions

As business develops, applications have increasingly more features in chat. To meet most requirements, WuKongIM has added message extension functionality. Message extensions are divided into local extensions and remote extensions. Local extensions are only for local app use and will be lost after uninstalling the app. Remote extensions are saved on the server and data will be restored after uninstalling and reinstalling.

Local Extensions

Local extensions are the localExtraMap field in the message object WKMsg.
After successful update, the SDK will trigger a refresh message callback

Remote Extensions

Remote extensions are the remoteExtra field in the message object WKMsg.
After successful update, the SDK will trigger a refresh message callback

Message Read/Unread

Message read/unread is also called message receipts. Message receipt functionality can be set through settings.
When a logged-in user views messages sent by others, if the sender has enabled message receipts, the viewed messages need to be uploaded to the server to mark them as read. When the sender or yourself uploads read messages, the server will send a sync message extension cmd (command) message syncMessageExtra. At this time, you need to sync the latest message extensions and save them to the SDK.

Message Editing

When we send a message to someone and find that the content is wrong, we don’t need to recall and resend it. We just need to edit the message.

Set Edit Content

After changing the SDK message edit content, you need to upload the edited content to the server, which requires listening for upload message extensions.

Listen for Upload Message Extensions

Message Reply

In chat, if there are too many messages, sending message replies will make the messages very messy and hard to follow. At this time, you need to make specific replies to certain messages, which is message reply. When sending a message, you just need to assign the WKReply object in the message content WKMessageContent to achieve the message reply effect.

WKReply Object Core Fields

Message Reactions (Likes)

Save Message Reactions

The same user can only make one reaction to the same message. Repeated reactions with different emojis to the same message will be treated as modifying the reaction, while repeated reactions with the same emoji will be treated as deleting the reaction. After the SDK updates message reactions, it will trigger a message refresh event. The app needs to listen for this event and refresh the UI.

Get Message Reactions

Next Steps

Data Source Configuration

Return to data source configuration

Message Management

Return to message management functionality

Basic Features

Return to basic features

Channel Management

Return to channel management