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 fromWKMessageContent and specify the message type in the constructor.
Built-in message types in SDK can be viewed through
WKMsgContentTypeStep 2: Encoding and Decoding
We need to send the three fieldsuid, name, avatar to the recipient. The final message content passed is:
encodeMsg method of WKMessageContent to start encoding:
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 internallygetDisplayContent method:
getSearchableWord method:
Step 3: Register Message
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 fromWKMediaMessageContent instead of WKMessageContent.
WKMediaMessageContent provides url and localPath fields, so custom messages don’t need to define network address and local address fields againStep 2: Encoding and Decoding
We need to sendlongitude, latitude, address, url information to the recipient. The final message content passed is:
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 fielddecodeMsg 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 messagesStep 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 intolocal 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 thelocalExtraMap field in the message object WKMsg.
After successful update, the SDK will trigger a refresh message callback
Remote Extensions
Remote extensions are theremoteExtra 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.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
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 theWKReply 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

