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

Custom Messages

Custom Regular Messages

Below we use business card messages as an example.

Step 1: Define Message

Define a message object that inherits from WKMessageContent and specify the message type in the constructor.

Step 2: Encoding and Decoding

We need to send uid, name, avatar three field information to the recipient. The final message content passed is:
Override the encodeJson and decodeJson methods of WKMessageContent to start encoding and decoding:
When encoding and decoding messages, there’s no need to consider the type field, as the SDK handles it internally

Step 3: Register Message

Complete Business Card Message Implementation

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 encodeJson and decodeJson methods of WKMessageContent to start encoding and decoding:

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 business 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 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 Structure Description

Message Reactions (Likes)

Save

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. Listen for message reaction refresh:

Get

WKMsgReaction Data Structure Description

Complete Advanced Features Manager

Next Steps

Data Source Configuration

Return to data source configuration

Message Management

Return to message handling functionality

Channel Management

Return to channel management functionality

Basic Features

Return to basic features

Summary

HarmonyOS SDK has now completed all core functionality documentation: Integration Guide - Complete installation and configuration guidance
Basic Features - Connection management and basic APIs
Message Management - Message sending/receiving and history messages
Channel Management - Channel information and member management
Conversation Management - Conversation lists and unread messages
Data Source Configuration - File upload and data synchronization
Advanced Features - Custom messages and extension features
HarmonyOS SDK documentation is now fully complete, providing developers with comprehensive technical guidance from beginner to advanced levels! 🎉