Custom Message Types
In WuKongIM, all message types are custom messages. Below we use agif message as an example.
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
WkMessageContentTypeWKMessageContent and define gif message structure
Step 2: Encoding and Decoding
When encoding and decoding messages, there’s no need to consider the
type field, as the SDK handles it internallyStep 3: Register Message
WKMsg is 3, it indicates that the message is a business card message, where messageContent is the custom GifContent. At this time, you can cast messageContent to GifContent and render it on the UI.
Complete code as follows:
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.
Step 2: Encoding and Decoding
Step 3: Register Message
Complete Custom Message Example
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 thewkMsgExtra field in the message object WKMsg.
Message Read/Unread
Message read/unread is also called message receipts. Message receipt functionality can be set through settings.Send Receipt Message
WKIM.shared.messageManager.saveRemoteExtraMsg(List<WKSyncExtraMsg> list) method and save them to the SDK.
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.
Send Reply Message
Message Reactions (Likes)
When you or others react to messages (like), it will trigger cmd (command) message notifications to the application. When the app receives a sync message reaction cmd, it can call the server sync interface to update the obtained reaction data to the SDK.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.
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
Advanced Message Management Example
Next Steps
Data Source Configuration
Learn how to configure data sources for custom messages
Message Management
Return to message management functionality
Basic Features
Return to basic features
Integration Guide
Return to integration guide

