Messaging

Update time: 2021/09/25 13:33:18

Overview

SDK provides a complete set of messaging management services, including messaging, storing messages, uploading and downloading attachments, and managing recent contacts. It originally supports sending various types of messages, including text, audio, image, video, file, geographical data, reminder etc., and supports sending custom messages as well. For details of the messaging features, please refer to Basic messaging features in the product introduction.

NIMMessageTypeMessage type

Enumeration Value Description
kNIMMessageTypeText 0 Text message
kNIMMessageTypekNIMMessageTypeImageText 1 Image message
kNIMMessageTypeAudio 2 Audio message
kNIMMessageTypeVideo 3 Video message
kNIMMessageTypeLocation 4 Location message
kNIMMessageTypeNotification 5 System notifications (including those for joining and exiting team, etc.,
kNIMMessageTypeFile 6 File message
kNIMMessageTypeTips 10 Reminder type message, content of which should be from the kNIMMsgKeyServerExt field in the message structure and filled in according to format requirements
kNIMMessageTypeRobot 11 and AI robot messages (not yet available)
kNIMMessageTypeCustom 100 Custom message
kNIMMessageTypeUnknown 1000 Unknown type of message, it is the default value

NIMMessageFeatureMessage type

Enumeration Value Description
kNIMMessageFeatureDefault 0 Default
kNIMMessageFeatureLeaveMsg 1 Offline message
kNIMMessageFeatureRoamMsg 2 Roaming message
kNIMMessageFeatureSyncMsg 3 Default messages, which are synchronized to each terminal upon multi-terminal login
kNIMMessageFeatureCustomizedMsg 4 Passthrough message

IMMessageBasic message contents

Type Parameter Description
NIMSessionType kNIMMsgKeyToType Session type, for details please refer to NIMSessionType
string kNIMMsgKeyFromAccount sender ID, filled out by server, which the sender may ignore
string kNIMMsgKeyToAccount Receiver's id (required), which should be your own id when sending a message to yourself
NIMClientType kNIMMsgKeyFromClientType Sender client type, filled out by server, which the sender may ignore
string kNIMMsgKeyFromDeviceId Sender device ID is specified by the server, which may be ignored by sender
string kNIMMsgKeyFromNick Sender nickname, filled out by server, which the sender may ignore
int64_t kNIMMsgKeyTime Message timestamp (13-digit UNIX timestamp in milliseconds)
NIMMessageType kNIMMsgKeyType Message type, see NIMMessageType for details
string kNIMMsgKeyClientMsgid Message uuid, unique identifier, to be completed by sender
int64_t kNIMMsgKeyServerMsgid Server-side message ID, to be completed by server
string kNIMMsgKeyLocalFilePath Local absolute path of multimedia message resource, managed by SDK locally and is required when sending multimedia messages. In case of image messages, when setting up thumbnail download, this path should be the local absolute path of the thumbnails
string kNIMMsgKeyLocalTalkId Session ID, optional for sender. The receiver receives the sender ID
string kNIMMsgKeyLocalResId Session ID, optional for sender. The receiver receives the client message ID
NIMMsgLogStatus kNIMMsgKeyLocalLogStatus Local message status, see message status type for details)
NIMMsgLogSubStatus kNIMMsgKeyLocalLogSubStatus (Local message sub-status, see message sub-status type for details)
-- Message setting The following is definition description of the message setting field.
int kNIMMsgKeyResendFlag Whether to re-send a message. A value of 0 is sent for the first time. If the message is sent again, a value of 1 shall be input. It is generally used for failed re-sending.
int kNIMMsgKeyPushEnable Whether push is needed, 1: yes, 0: no
int kNIMMsgKeyPushNeedBadge (Optional) Is counting needed for push message (corner mark), 1: yes, 0: no
int kNIMMsgKeyPushNeedPrefix (Optional) Whether push messages need prefixes, set to true by default
string kNIMMsgKeyPushContent Custom push content, with a length not exceeding 200 bytes
string kNIMMsgKeyPushPayload Custom push attributes, must be unformatted json string with a length limited to 2048
int kNIMMsgKeyHistorySave (Optional) The message is once saved on the cloud? The default is 1, 1: yes, 0: no, if roaming and offline features are supported, then it must be set to 1
int kNIMMsgKeyMsgRoaming (Optional) Enable roaming for the message? The default is 1, 1: yes, 0: no
int kNIMMsgKeyMsgSync (Optional) Enable multi-terminal sync for the message? The default is 1, 1: yes, 0: no
int kNIMMsgKeyMsgRoutable (Optional) The message is copied? 0:no, 1:yes, follow app router configuration in default
int kNIMMsgKeySetMsgOffline (Optional) Save messages offline? The default is 1, 1: yes, 0: no, if roaming is supported, then it must be set to 1
int kNIMMsgKeyAntiSpamEnable Is Yidun anti-spam needed? 1: yes, 0: no
string kNIMMsgKeyAntiSpamContent (Optional) Anti-spam field customized by developer, length limit: 5000 characters, format: json string, {"type": 1: text, 2: image, 3 video, "data": "Text content or image address or video address"}
string kNIMMsgKeyServerExt Third-party extension field with a length limited to 1024
string kNIMMsgKeyLocalExt Local extension contents, local storage only, reserved field
int kNIMMsgKeyIsForcePush Force push switch for team message, with total force push set as true and force push list set as empty
string kNIMMsgKeyForcePushList_ Force push list of team messages, json array
string kNIMMsgKeyForcePushContent Text in force push team message

Note: Roaming means that the messages that have been received at one terminal will be synchronized to other terminals (the most recent 100 messages stored on the server). Multi-terminal synchronization means that when multiple device platforms log in at the same time, a message sent by one terminal will be synchronously received by other terminals. Offline means if the receiver is offline when the message is sent, it can receive the message as soon as it goes online again.

Description of message settings:

kNIMMsgKeySetMsgOffline kNIMMsgKeyHistorySave kNIMMsgKeyMsgRoaming kNIMMsgKeyMsgSync
Offline message 1 1 optional optional
Roaming message 1 1 1 optional
Multi-terminal message sync optional optional optional 1

Send Message

SDK supports common built-in messages types such as text, picture, voice, video, file, geographical data, reminder (NIMMessageType), as well as sending custom messages. At the same time, we also provide a stop sending interface, which is currently mainly used to stop sending file message that is being uploaded.

  • API prototype
void nim_talk_send_msg(const char *json_msg, const char *json_extension, nim_nos_upload_prg_cb_func prg_cb, const void *prg_user_data);
  • Parameter Description
Parameter Description
json_msg Message content, json character string. For the field definition, see IMMessage
json_extension Extension field. Reserved
nim_nos_upload_prg_cb_func Notification of upload progress callback, which informs upload progress of self-uploaded attachments such as images, audio and video files (if any)
prg_user_data Custom user data of APP. SDK only transfers the data to the callback function prg_cb and will not execute processing!

Message Setting

Sending a message also involves the following message attribute settings (Corresponding fields are contained in MessageSetting:

  • Messages can have two types of extension fields, namely server extension field kNIMMsgKeyServerExt and local extension field kNIMMsgKeyLocalExt, each with a maximum length of 1024 bytes. The server extension field will be sent to other terminals, while the local extension field is only valid locally. Both extension fields will be stored by the SDK in the database.

  • Push text field (kNIMMsgKeyPushContent, with a maximum length of 200 bytes) and custom push attribute (kNIMMsgKeyPushPayload, with a maximum length of 2048 bytes), please pay attention to the maximum length. If push text is set, the text will be displayed in the notification bar when the message is received by the recipient, if not, then SDK's default text will be used.

  • Whether push field is neededkNIMMsgKeyPushEnable, 0: not needed, 1: needed.

  • Whether message count field is needed (kNIMMsgKeyNeedBadge), 0: not needed, 1: needed.

  • Whether push nickname is needed (kNIMMsgKeyNeedPushNick), 0: not needed, 1: needed.

  • Whether to store the message in the cloud (kNIMMsgKeyHistorySave), if it is set to 0, the message cannot be obtained by calling the interface of server message history. 0: Not needed, 1: Needed.

  • Whether the message supports roaming (kNIMMsgKeyMsgRoaming). If it is set to 1, even if a certain client has received the message, other clients can still obtain it by roaming when they log in again. 0: Not needed, 1: Needed.

  • Whether the message supports multi-terminal synchronization (kNIMMsgKeyMsgSync). If it is set to 1, a message sent will be synchronized to other clients logged in at the same time. 0: Not needed, 1: Needed.

Team messages have forced push attributes (can be used to implement @ features, etc.):

  • Whether force push field (kNIMMsgKeyIsForcePush)is needed, 0: not needed, 1: needed.

  • Force push list field (kNIMMsgKeyForcePushList), should be filled in with the specified account id string array json, and left empty if forced push is enabled for all.

  • Text field (kNIMMsgKeyForcePushContent) in force push team message

Anti-spam field:

  • The ID of the anti-spam rule specified by the developer for the message (kMsgTagAntiSpamBusinessId), should be the same as that on the server side

  • Whether YiDun anti-spam is needed (kNIMMsgKeyAntiSpamEnable), 0: not needed, 1: needed.

  • (Optional) Anti-spam field customized by developer (kNIMMsgKeyAntiSpamContent), length limit: 5000 characters, format: json string, {"type": 1: text, 2: image, 3 video, "data": "Text content or image address or video address"}

  • Whether a single message uses YiDun anti-spam (kNIMMsgKeyAntiSpamUsingYiDun), 0: (YiDun activated) not passing YiDun anti-spam but general anti-spam, with all other matters still subject to original rules.

Same type of chat room message. The content is same with attachment of IM message. The packing format of attachment content is consistent.

Text Message

Create text message content, complete the necessary message setting and send the message through thenim_talk_send_msginterface.

  • Example
//Example of creating a text message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
char* content = "This is a text message." ;

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyBody] = content;
values[kNIMMsgKeyType] = kNIMMessageTypeText;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.

//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;
...

//If anti-spam is needed
values[kNIMMsgKeyAntiSpamEnable] = 1;
//Assemble anti-spam content
Json::Value jx;
jx["type"] = 1;
jx["data"] = content;//If it is a image or video, fill in the url of the attachment
values[kNIMMsgKeyAntiSpamContent] = fw.write(jx);//Get json character string from serialization

//Other settings
...

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Image Message

Create image message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface. The sent local image file will be automatically uploaded.

In addition to all fields under IMFile, the attachment the image message IMImage also includes the description of its own fields.

Type Parameter Field
int kNIMImgMsgKeyWidth Image width
int kNIMImgMsgKeyHeight Image height
  • Example
//In case of p2p message and test account test1
//Example of creating an image message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
//Local file path
char* local_file_path = "c:\\img.png";

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeImage;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.
values[kNIMMsgKeyLocalFilePath] = local_file_path;

//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
attachment[kNIMFileMsgKeyMd5] = "0ca175b9c0f726a831d895e269332461";
attachment[kNIMFileMsgKeySize] = 409600;
attachment[kNIMMsgAttachKeyUrl]_="http://xxxxxx/img.png";//If local file is sent, the value is null.
attachment[kNIMFileMsgKeyDisplayName] = "img";
attachment[kNIMFileMsgKeyExt] = "png";

//Set image height and width
attachment[kNIMImgMsgKeyWidth] = 800;
attachment[kNIMImgMsgKeyHeight] = 600;

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Audio message

Create audio message content, complete the necessary message setting and send the message through thenim_talk_send_msginterface. The sent local audio file will be automatically uploaded.

In addition to all fields under IMFile, the attachment of the audio message IMAudio also includes the description of its own fields.

Type Parameter Field
int kNIMAudioMsgKeyDuration Audio message duration
  • Example
//In case of p2p message and test account test1
//Example of creating an audio message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
//Local file path
char* local_file_path = "c:\\audio.aac";

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeAudio;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.
values[kNIMMsgKeyLocalFilePath] = local_file_path;


//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
attachment[kNIMFileMsgKeyMd5] = "0ca175b9c0f726a831d895e269332461";
attachment[kNIMFileMsgKeySize] = 409600;
attachment[kNIMMsgAttachKeyUrl]_="http://xxxxxx/audio.aac";//If local file is sent, the value is null.
attachment[kNIMFileMsgKeyDisplayName] = "audio";
attachment[kNIMFileMsgKeyExt] = "aac";

//Set the duration
attachment[kNIMAudioMsgKeyDuration] = 8000;//ms

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Video Message

Create video message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface. The sent local video file will be automatically uploaded.

In addition to all fields under IMFile, the attachment of the video message IMVideo also includes the description of its own fields.

Type Parameter Field
int kNIMVideoMsgKeyDuration Audio message duration
int kNIMVideoMsgKeyWidth Image width
int kNIMVideoMsgKeyHeight Image height
  • Example
//In case of p2p message and test account test1
//Example of creating a video message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
//Local file path
char* local_file_path = "c:\\video.mp4";

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeVideo;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp
values[kNIMMsgKeyLocalFilePath] = local_file_path;


//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
attachment[kNIMFileMsgKeyMd5] = "0ca175b9c0f726a831d895e269332461";
attachment[kNIMFileMsgKeySize] = 409600;
attachment[kNIMMsgAttachKeyUrl]_="http://xxxxxx/video.mp4";//If local file is sent, the value is null.
attachment[kNIMFileMsgKeyDisplayName] = "video";
attachment[kNIMFileMsgKeyExt] = "mp4";

//Set the duration, length and width
attachment[kNIMVideoMsgKeyDuration] = 8000;//ms
attachment[kNIMVideoMsgKeyWidth] = 800;
attachment[kNIMVideoMsgKeyHeight] = 600;

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Geographic Location

Create location message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface.

The attachment contentNIMLocationMsgInfoof the location message contains description of

Type Parameter Field
string kNIMLocationMsgKeyTitle Location description
int kNIMLocationMsgKeyLatitude Latitude
int kNIMLocationMsgKeyLongitude Longitude
  • Example
//In case of p2p message and test account test1
// Example of creating a geographical location message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1


Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeLocation;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.


//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
//Set location name, latitude and longitude
attachment[kNIMLocationMsgKeyTitle] = "Hangzhou";
attachment[kNIMLocationMsgKeyLatitude] = 30.3;
attachment[kNIMLocationMsgKeyLongitude] = 120.2;

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

File Message

Create file message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface.

IMFileFile attachment

Type Parameter Field
string kNIMFileMsgKeyMd5 md5 of the file content
int64_t kNIMFileMsgKeySize File size, 64-bit integer
string kNIMMsgAttachKeyUrl http url of the file
string kNIMFileMsgKeyDisplayName file name
string kNIMFileMsgKeyExt File extension
  • Example
//In case of p2p message and test account test1
//Example of creating a file message
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
//Local file path
char* local_file_path = "c:\\File.doc";

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeFile;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp
values[kNIMMsgKeyLocalFilePath] = local_file_path;


//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
attachment[kNIMFileMsgKeyMd5] = "0ca175b9c0f726a831d895e269332461";
attachment[kNIMFileMsgKeySize] = 409600;
attachment[kNIMMsgAttachKeyUrl]_="http://xxxxxx/Document.doc";//If local file is sent, the value is null.
attachment[kNIMFileMsgKeyDisplayName] = "Document";
attachment[kNIMFileMsgKeyExt] = "doc";

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Tip message

Create tip message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface. If sending to server is not needed, the developer can use the insert local message to store the message in the database and update the session class table.

  • Example

//In case of p2p message and test account test1
//Example of creating a message tip
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
char* tip_content = "This is tip information";

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeTips;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.
values[kNIMMsgKeyBody] = tip_content;

//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);


Custom Message

Create custom message content, complete the necessary message setting and send the message through the nim_talk_send_msg interface. SDK will not parse the specific content of custom messages, and the corresponding work should be assumed by the developer. SDK will save custom message to message database, which will be shown in message history together with built-in message. In global settings, it is possible to configure whether to locally save custom messages, save by default.

  • Example

//In case of p2p message and test account test1
//Example of creating a message tip
Json::FastWriter fw;
//Take P2P message kNIMSessionTypeP2P for an example, with test account test1
char* content = "This is normal text content."

Json::Value values;
values[kNIMMsgKeyToAccount] = "test1";
values[kNIMMsgKeyToType] = kNIMSessionTypeP2P;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyType] = kNIMMessageTypeCustom;
values[kNIMMsgKeyLocalTalkId] = "test1";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.
values[kNIMMsgKeyBody] = content;

//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;

//Other settings
...

//Assemble attachment content
Json::Value attachment;
attachment["customFiled1"] = "Custom content 1";
attachment["customFiled2"] = 10; //Custom value

values[kNIMMsgKeyAttach] = fw.write(attachment);//Acquired attachment content

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Team Force Push Message

Send a force push message to the team to @ the specified person or everyone, see MessageSetting for details.

  • Example

//Take test team 1222222 as an example
Json::FastWriter fw;
char* content = "This is a text message." ;

Json::Value values;
values[kNIMMsgKeyToAccount] = "1222222";
values[kNIMMsgKeyToType] = kNIMSessionTypeTeam;
values[kNIMMsgKeyClientMsgid] = "Generate my unique uuid";
values[kNIMMsgKeyBody] = content;
values[kNIMMsgKeyType] = kNIMMessageTypeText;
values[kNIMMsgKeyLocalTalkId] = "1222222";
values[kNIMMsgKeyTime] = 1520500638234;//Current timestamp. If the value is 0, SDK will automatically get local timestamp.

//Configure messages as required
values[kNIMMsgKeyMsgRoaming] = 1;
values[kNIMMsgKeySetMsgOffline] = 1;
values[kNIMMsgKeyHistorySave] = 1;
...


//Other settings
...

//Configure force push message, force push test1,test2, and being a team member
values[kNIMMsgKeyIsForcePush] = 1;
values[kNIMMsgKeyForcePushContent] = "This is a force push message";

Json::Value pushlist;
pushlist.append("test1");
pushlist.append("test2");
values[kNIMMsgKeyForcePushList] = fw.write(pushlist);

//Get json of message content for nim_talk_send_msg sending
char* msg = fw.write(values);
//Send message
nim_talk_send_msg(msg,0,0,0);

Sending Result Notification

Sending is successful or failed, and the result also contains tag (if any) for client anti-spam hit.

SendMessageArcParameter description

Type Parameter Description
string kNIMSendAckKeyTalkId Session ID
string kNIMSendAckKeyMsgId Message id
NIMResCode kNIMSendAckKeyRescode Error code
int64_t kNIMSendAckKeyTimetag Message timestamp
bool kNIMSendAckKeyClientAntiSpam Is there a hit with client anti-spam, 1: Yes, 0: No
  • API prototype
void nim_talk_reg_ack_cb(const char *json_extension, nim_talk_ack_cb_func cb, const void *user_data);
  • Example
void my_nim_talk_ack_cb_func(const char *result, const void *user_data)
{
	//result is resolved into SendMessageArc
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isObject())
    {
        NIMResCode rescode = (NIMResCode)values[kNIMSendAckKeyRescode].asUInt();
        char* msg_id = values[kNIMSendAckKeyMsgId].asString();
        char* talk_id = values[kNIMSendAckKeyTalkId].asString();
        int64_t msg_timetag = values[kNIMSendAckKeyTimetag].asInt64();
        bool client_anti_spam_hit = values[kNIMSendAckKeyClientAntiSpam].asUInt();
        ...
    }
}
//Monitor event
nim_talk_reg_ack_cb(0,my_nim_talk_ack_cb_func,0);

//Cancel monitoring
nim_talk_reg_ack_cb(0,0,0);

Stop Sending Message

Stop sending message. Currently it only can be used on file messages, meaning sending can be terminated during file upload. It can't be used on a file that has already been uploaded.

  • API prototype
 void nim_talk_stop_send_msg(const char *json_msg, const char *json_extension);

  • Parameter Description
Parameter Description
json_msg Structure of the message to be stopped
json_extension Extension field. Reserved
  • Example
//The unique uuid of the message to be stopped, required
char* clientMsgId = "uuid";

Json::FastWriter fw;
Json::Value values;
values[kNIMMsgKeyClientMsgid] = client_msg_id;
values[kNIMMsgKeyType] = kNIMMessageTypeFile;
//Interrupt sending
nim_talk_stop_send_msg(fw.write(values), 0);

Receive Message

The developer needs to register the event monitoring of message reception before logging in to the SDK. Message receiving covers online, offline, synchronized, roaming messages, etc. If a multimedia message is received, the SDK will automatically download attachments in the background by default. In case of voice message, the audio file will be downloaded directly. In case of image message, only the thumbnail will be downloaded, and you can get the original image through the download interface.

Message Parsing

SDK supports parsing of built-in messages such as images, files, audio, video, geographic locations, etc. Other custom messages and attachments need to be parsed by the developer.

1. Parse content of the designated filed under message content IMMessage.

  • Example
//Example of parsing message content
void ParseIMMessage(Json::Value message)
{
	//Message content
    int session_type = (NIMSessionType)message[kNIMMsgKeyToType].asUInt();
    char* receiver_accid = message[kNIMMsgKeyToAccount].asString();
    char* sender_accid = message[kNIMMsgKeyFromAccount].asString();
    int readonly_sender_client_type = (NIMClientType)message[kNIMMsgKeyFromClientType].asUInt();
    char* readonly_sender_device_id = message[kNIMMsgKeyFromDeviceId].asString();
    char* readonly_sender_nickname = message[kNIMMsgKeyFromNick].asString();
    int64_t timetag = message[kNIMMsgKeyTime].asUInt64();

    int type = (NIMMessageType)message[kNIMMsgKeyType].asUInt();
    char* content = message[kNIMMsgKeyBody].asString();
    char* attach = message[kNIMMsgKeyAttach].asString();
    char* client_msg_id = message[kNIMMsgKeyClientMsgid].asString();
    int64_t readonly_server_id = message[kNIMMsgKeyServerMsgid].asUInt64();

    char* local_res_path = message[kNIMMsgKeyLocalFilePath].asString();
    char* local_talk_id = message[kNIMMsgKeyLocalTalkId].asString();
    char* local_res_id = message[kNIMMsgKeyLocalResId].asString();
    int status = (NIMMsgLogStatus)message[kNIMMsgKeyLocalLogStatus].asUInt();
    int sub_status = (NIMMsgLogSubStatus)message[kNIMMsgKeyLocalLogSubStatus].asUInt();

	//Message settings
    int server_history_saved = message[kNIMMsgKeyHistorySave].asInt();
    int roaming = message[kNIMMsgKeyMsgRoaming].asInt()
    int multi_sync = message[kNIMMsgKeyMsgSync].asInt();
    int push_need_badge = message[kNIMMsgKeyPushNeedBadge].asInt();
    int need_push = message[kNIMMsgKeyPushEnable].asInt();
    int push_need_prefix = message[kNIMMsgKeyPushNeedPrefix].asInt();
    int resend_flag = message[kNIMMsgKeyResendFlag].asInt();
    int routable = message[kNIMMsgKeyMsgRoutable].asInt();
    int need_offline = message[kNIMMsgKeySetMsgOffline].asInt();
    char* push_payload = message[kNIMMsgKeyPushPayload].asString();
    char* server_ext = message[kNIMMsgKeyServerExt].asString();
    char* local_ext = message[kNIMMsgKeyLocalExt].asString();
    char* push_content = message[kNIMMsgKeyPushContent].asString();
    int is_force_push = message[kNIMMsgKeyIsForcePush].asInt();
    char* force_push_content = message[kNIMMsgKeyForcePushContent].asString();
    char* force_push_list = message[kNIMMsgKeyForcePushList].asString();
    int anti_spam_enable = message[kNIMMsgKeyAntiSpamEnable].asInt();
    char* anti_spam_content = message[kNIMMsgKeyAntiSpamContent].asString();
    ...
}

2. Parse received message

Different from Parsing message content , this function parses fieldskNIMMsgKeyLocalRescode, kNIMMsgKeyLocalMsgFeatureandkNIMMsgKeyLocalReceiveMsgContent,whileParseIMMessageparses actual message content carried bykNIMMsgKeyLocalReceiveMsgContent.

  • Example
//Example of parsing received message
void ParseReceiveMessage(Json::Value received_message)
{

	NIMResCode rescode = (NIMResCode)received_message[kNIMMsgKeyLocalRescode].asUInt();
	NIMMessageFeature feature = (NIMMessageFeature)received_message[kNIMMsgKeyLocalMsgFeature].asUInt();

    Json::Value message = received_message[kNIMMsgKeyLocalReceiveMsgContent];
    //For message parsing, refer to ParseIMMessage
	ParseIMMessage(message);
    ...
}

Online Message Receiving

It is recommended to register a global callback, so that the SDK only stores onecb, registering multiple callbacks will result in overwriting, and only the last one will take effect. For parsing different types of messages, e.g. file message, image message and audio message, refer to the attachment of "Send messages". Both shall be consistent.

  • API prototype
void nim_talk_reg_receive_cb(const char *json_extension, nim_talk_receive_cb_func cb, const void *user_data);
  • Parameter Description
Parameter Description
cb Asynchronous notification callback
json_extension Extension field. Reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example

void my_nim_talk_receive_cb_func(const char *result, const char *json_extension, const void *user_data)
{
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isObject())
    {
        //Refer to ParseReceiveMessage
        ParseReceiveMessage(values);
        ...
    }
}

//Monitor event
nim_talk_reg_receive_cb(0,my_nim_talk_receive_cb_func,0);
//Cancel monitoring
nim_talk_reg_receive_cb(0,0,0);

Receive Offline, Sync, and Roaming Messages

Receive batch messages, such as offline, roaming, and synchronized bulk messages. If this batch interface is also registered while registering receive message callback, when there are incoming batch messages, this interface will be used to notify the application. For example, for offline messages received after logging in, etc., the event monitoring must be registered before logging in. The difference is callback for receiving messages online. The interface notifies the set of messages.

  • API prototype
void nim_talk_reg_receive_msgs_cb(const char *json_extension, nim_talk_receive_cb_func cb, const void *user_data);

  • Parameter Description
Parameter Description
cb Asynchronous notification callback
json_extension Extension field. Reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
void my_nim_talk_receive_cb_func(const char *result, const char *json_extension, const void *user_data)
{
	//The difference is callback for receiving messages online. The set of messages are returned here.
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isArray())
    {
        int size = value.size();
        for (int i = 0; i < size; i++)
        {
            //Refer to ParseReceiveMessage
        	ParseReceiveMessage(values);
            ...
        }
        ...
    }
}

//Monitor event
nim_talk_reg_receive_msgs_cb(0,my_nim_talk_receive_cb_func,0);

//Cancel monitoring
nim_talk_reg_receive_msgs_cb(0,0,0);

Filter Team Notifications

Register the callback for whether filtering incoming team notifications. If this callback returns true, the SDK deems the notification as processed, therefore it will not deliver it through the receive message channel, and will not save it to the local database.

  • API prototype
void nim_talk_reg_notification_filter_cb(const char *json_extension, nim_talk_team_notification_filter_func cb, const void *user_data);

  • Parameter Description
Parameter Description
cb Asynchronous notification callback
json_extension Extension field. Reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
//Assume bool filterTeamNotify = true;
bool my_nim_talk_team_notification_filter_func(const char *result, const char *json_extension, const void *user_data)
{
	//result is message content. Refer to ParseIMMessage
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isObject())
    {
        ParseIMMessage(values);
        ...
    }
	//If the notification is filtered, returns true, otherwise returns false;
    if (filterTeamNotify)
    {
        ...
        return true;
    }
    return false;
}
//Monitor event
nim_talk_reg_notification_filter_cb(0,my_nim_talk_team_notification_filter_func,0);

//Cancel monitoring
nim_talk_reg_notification_filter_cb(0,0,0);

Forward Message

The user gets a new message object via construction API, and then calls the message sending interface. The new character string of message content is returned. Developers shall actively release the memory.

  • API prototype
char *nim_talk_create_retweet_msg(const char* src_msg_json, const char* client_msg_id, enum NIMSessionType retweet_to_session_type, const char* retweet_to_session_id, const char* msg_setting, int64_t timetag);

  • Parameter Description
Parameter Description
src_msg_json Content of the received message, the same as that of IMMessage
client_msg_id New message uuid generated
retweet_to_session_id The other party's id, forwarded, user account or team id
retweet_to_session_type Session type, 0: p2p message 1: team message
msg_setting Message setting, for details, please refer to message setting description
timetag Current timestamp (in milliseconds)s
  • Example
//Assumed to be the content of the message sent or received by srcMsg
char* srcMsg;

//Configure messages as required. Refer to "Send messages".
Json::FastWriter fw;
Json::Value setting;
setting[kNIMMsgKeyMsgRoaming] = 1;
setting[kNIMMsgKeySetMsgOffline] = 1;
setting[kNIMMsgKeyHistorySave] = 1;
...

//A new message generated through srcMsg.
int64_t timeNow = 1520500638234;//Current UNIX timestamp in milliseconds
char* sessionid = "1222222";
char* clientMsgID = "uuid2";//Generate the new unique uuid;
NIMSessionType sessionType = kNIMSessionTypeTeam;
char* newMsg = nim_talk_create_retweet_msg(srcMsg,clientMsgID,sessionType,sessionid,fw.write(setting),timeNow);

//Send message
nim_talk_send_msg(newMsg,0,0,0);

free(newMsg);//Release the memory as required;

Recall Message

Sender, team owner and manager can perform recall through this interface (not applicable to chat room messages). This operation is generally time-limited (subject to global APP settings), and 508 is returned if the limit is exceeded. By registering callback notification for message recall, the developer receives notifications of message recalls on other clients. After receiving the notification, the SDK will mark the message as deleted in the message history. At the same time, the developer deletes the message displayed on the interface and can even insert a corresponding prompt if needed. For related development examples, refer to IM Demo.

RecallNotificationParameter description

Type Parameter Description
NIMSessionType kNIMRecallMsgKeyToType Session type, 0: p2p message 1: team message
string kNIMRecallMsgKeyFromAccID Message from ID
string kNIMRecallMsgKeyToAccID Message to ID
string kNIMRecallMsgKeyMsgId Unique id of the message
string kNIMRecallMsgKeyNotify Custom notification copy
int64_t kNIMRecallMsgKeyTime Timestamp of recall operation (in milliseconds)s
NIMMessageFeature kNIMRecallMsgKeyNotifyFeature Type of the recalled message, see NIMMessageFeature for details
bool kNIMRecallMsgKeyMsgExist Whether the recalled message exists locally. For example, if the other party sent and recalled a message while offline, then the other party gets an offline recall notification after going online, the tag should be false
int64_t kNIMRecallMsgKeyMsgTime Timestamp of the message to be recalled (in milliseconds) (milliseconds)
string kNIMRecallMsgKeyMsgFromNick Nickname of the sender of the message to be recalled

RecallNotificationParsing example

void ParseRecallNotification(Json::Value value)
{
	if (value.isObject())
	{
		//Parse into RecallMsgNotify
        char* from_id = value[kNIMRecallMsgKeyFromAccID].asString();
        char* to_id = value[kNIMRecallMsgKeyToAccID].asString();
        char* msg_id = value[kNIMRecallMsgKeyMsgId].asString();
        char* operator_id = value[kNIMRecallMsgKeyOpeAccID].asString();
        char* notify = value[kNIMRecallMsgKeyNotify].asString();
        NIMSessionType session_type = (NIMSessionType)value[kNIMRecallMsgKeyToType].asInt();
        int64_t notify_timetag = value[kNIMRecallMsgKeyTime].asUInt64();
        NIMMessageFeature notify_feature = (NIMMessageFeature)value[kNIMRecallMsgKeyNotifyFeature].asInt();
        bool msglog_exist = value[kNIMRecallMsgKeyMsgExist].asBool();
        int64_t msglog_timetag = value[kNIMRecallMsgKeyMsgTime].asUInt64();
        char* from_nick = value[kNIMRecallMsgKeyMsgFromNick].asString();
            ...
        ...
	}
	...
}

Active Message Recall

To recall messages that have been sent successfully, which relies on local history. It is required to find the message in local history according to its message id, if not the message can't be recalled.

  • API prototype
void nim_talk_recall_msg(const char *json_msg, const char *notify, const char *json_extension, nim_talk_recall_msg_func cb, const void *user_data);

  • Parameter Description
Parameter Description
json_msg For messages to be recalled, see IMMessage. Only kNIMMsgKeyClientMsgid is used.
notify Custom notification
cb Callback notification of message recall
json_extension Notification extension, reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
void my_nim_talk_recall_msg_func(int rescode, const char *result, const char *json_extension, const void *user_data)
{
	// parse result
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isArray())
    {
        int count = values.size();
        for (int i = 0; i < count; i++)
        {
            //Parse into RecallNotification. Refer to ParseRecallNotification.
            ParseRecallNotification(values[i]);
        }
        ...
    }
}
//To be assembled by yourself, currently the recall is done through msgId,
Json::FastWriter fw;
Json::Value assembleMsg;
assembleMsg[kNIMMsgKeyClientMsgid] = "uuid of recalled message"; //Only message id is used now;
nim_talk_recall_msg(fw.write(assembleMsg),"This is a recalled notification" , 0,my_nim_talk_recall_msg_func,0);

Message Recall Notification

Notify the user that the message has been recalled, this notification is available offline.

  • API prototype
void nim_talk_reg_recall_msg_cb(const char *json_extension, nim_talk_recall_msg_func cb, const void *user_data);

  • Parameter Description
Parameter Description
cb Callback of message recall notification
json_extension Notification extension, reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
//Monitor event
nim_talk_reg_recall_msg_cb(0,my_nim_talk_recall_msg_func,0);

//Cancel monitoring
nim_talk_reg_recall_msg_cb(0,0,0);

Read Receipt

CommsEase provides read receipts of point-to-point messages. Note: This feature is only valid for P2P messages.

In the session interface, the operation of calling the interface for sending the read receipt and inputting the last message means that all the previous messages have been read, and the other side will receive the receipt.

General application scenarios for sending message read receipts:

1. Entering P2P chat interface (if you repeatedly enters the interface without receiving a new message, SDK can automatically filter repeated interface calls, so that only one of them is sent to the CommsEase server).

2. When you are in the chat interface and receive a new message from the current session.

Send Read Receipt

  • API prototype
void nim_msglog_send_receipt_async(const char *json_msg, const char *json_extension, nim_msglog_status_changed_cb_func cb, const void *user_data);

  • Parameter Description
Parameter Description
json_msg Received message content, json character string. For the field definition, see IMMessage.
cb Callback notification for message status change after sending acknowledged receipt for a message. For result parsing, see "Notification for change in global message status".
json_extension Notification extension, reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
void my_nim_msglog_status_changed_cb_func(int res_code, const char *result, const char *json_extension, const void *user_data)
{
	//result: Refer to "Notification for change in global message status".
    ...
}
//Assuming msg is a message that requires sending read receipt.
nim_msglog_send_receipt_async(msg,0,my_nim_msglog_status_changed_cb_func,0);

Monitor Read Receipt Notification

Read receipt also represents a change in message status and therefore can be reflected in global message status change notification

Monitor Broadcast to All Notifications

Receive broadcast to all notifications. There are two types: individual and batch broadcast to all notifications. In general, batch notifications include offline broadcasts, synchronous broadcasts, and roaming broadcasts delivered when logging in.

BroadcastMessageDescription of broadcast notification field

Type Parameter Description
int64_t kNIMBroadcastMsgKeyID Notification message id
string kNIMBroadcastMsgKeyFromAccid Sender account, can be null
int64_t kNIMBroadcastMsgKeyTime Notification message's UNIX timestamp, in milliseconds
string kNIMBroadcastMsgKeyBody Notification content

1. Callback for receiving Individual broadcast to all notification , recommended to register it globally, so that messages can be distributed to specific sessions after accepting callbacks as a whole.

  • API prototype
 void nim_talk_reg_receive_broadcast_cb(const char *json_extension, nim_talk_receive_broadcast_cb_func cb, const void *user_data);
  • Parameter Description
Parameter Description
cb Notification callback
json_extension Extension field. Reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
void my_nim_talk_receive_broadcast_cb_func(const char *result, const char *json_extension, const void *user_data)
{
	//Process broadcast message. There is a single broadcast here.
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isObject())
    {
        int count = values.size();
        for (int i = 0; i < count; i++)
        {
        	//Parse into BroadcastMessage defined content
            char* body = values[kNIMBroadcastMsgKeyBody].asString();
            char* from_id = values[kNIMBroadcastMsgKeyFromAccid].asString();
            int64_t id = values[kNIMBroadcastMsgKeyID].asUInt64();
            int64_t time = values[kNIMBroadcastMsgKeyTime].asUInt64();
            ...
        }
        ...
    }
...
}
//Monitor event
nim_talk_reg_receive_broadcast_cb(0,nim_talk_reg_receive_broadcast_cb,0);
//Cancel monitoring
nim_talk_reg_receive_broadcast_cb(0,0,0);

2. Batch broadcast to all notifications

Callback for receiving batch broadcast messages. If this batch interface is also registered while registering receive message callback, when there are incoming batch messages, including offline messages received after logging in, this interface will be used to notify the application.

  • API prototype
nim_talk_reg_receive_broadcast_msgs_cb(const char *json_extension, nim_talk_receive_broadcast_cb_func cb, const void *user_data);

  • Parameter Description
Parameter Description
cb Callback of batch messages
json_extension Extension field. Reserved
user_data Custom user data of APP. SDK only transfers the data to the callback function and will not execute processing.
  • Example
void my_nim_talk_receive_broadcasts_cb_func(const char *result, const char *json_extension, const void *user_data)
{
	//Process broadcast messages. This is a set of multiple broadcasts here.
    Json::Value values;
    Json::Reader reader;
    if (reader.parse(result, values) && values.isArray())
    {
        int count = values.size();
        for (int i = 0; i < count; i++)
        {
        	Json::Value value = values[i];
            //Parse into BroadcastMessage defined content
            char* body = value[kNIMBroadcastMsgKeyBody].asString();
            char* from_id = value[kNIMBroadcastMsgKeyFromAccid].asString();
            int64_t id = value[kNIMBroadcastMsgKeyID].asUInt64();
            int64_t time = value[kNIMBroadcastMsgKeyTime].asUInt64();
			...
        }
        ...
    }
}
//Monitor event
nim_talk_reg_receive_broadcast_msgs_cb(0,my_nim_talk_receive_broadcasts_cb_func,0)
//Cancel monitoring
nim_talk_reg_receive_broadcast_msgs_cb(0,0,0)

Get Local Path from Message Attachment

Get local paths of message attachments (image, voice, video, etc.). If pre-loaded only thumbnails without downloading the original images, files in the path obtained here may not exist, and the developer needs download them by callingnim_nos_download_media. If thumbnail is preloaded according to global setting and the original image is needed, then before passing in the message content, the fieldkNIMMsgKeyLocalFilePathshould be set to blank or a custom save path.

  • API prototype
char *nim_talk_get_attachment_path_from_msg(const char *json_msg);
  • Parameter Description
Parameter Description
msg For message content to be acquired, see IMMessage.
  • Example
//Assuming msg is a message to be obtained
char* filePath = nim_talk_get_attachment_path_from_msg(msg);

//Download original image
Json::FastWriter fw;
Json::Reader reader;
Json::Value message;
if (reader.parse(msg, message))
{
    message[kNIMMsgKeyLocalFilePath] = "";//It is null, or set to custom save path;
}
nim_nos_download_media(fw.write(message),0,0,0,0);

free(filePath);//Developers shall release the memory.

Get Image Thumbnail

In default, after receiving an image message, CommsEase PC SDK will pre-load the original image and put it into the local cache. If you want to control the quality of downloaded images, you can do so by configuringkNIMPreloadImageQuality(for quality control) andkNIMPreloadImageResize(for size control) when initializing the SDK. The IM Demo's development example downloads original images by default. Therefore, in case of development using source codes of IM Demo, you need to download the original images for image preview or other links that need to use original images.

In scenes including but not limited to the following, developers can download thumbnails by themselves:

  • There are special requirements on image size
  • Received picture messages in chat room

Currently SDK provides two schemes for obtaining thumbnails:

  • To update image quality

    After receiving the image message, the user can obtain the download address of the image by parsing the content of attachmentkNIMMsgKeyAttach(kNIMChatRoomMsgKeyAttachif chat room message), and then obtain the image of specified quality based on parameters for splicing download interface: Download address is http(s)://?imageView&quality=N; http(s)://xxx; where N is image quality, with a range of 0 to 100.

  • The image is intra-shrunk by length and width (in proportion to the original size, with the obtained image having "one side of the requested length, and the other of less than or equal to the requested length")

    After receiving an image message, users can obtain the download address of the image by parsing the content of attachment kNIMMsgKeyAttach (kNIMChatRoomMsgKeyAttach if chat room message), and then obtain the thumbnail based on parameters for splicing download interface: http(s)://xxx?imageView&thumbnail=XxY; http(s)://xxx is the image download address; where X is the width, Y is the height, and the middle symbol is the lowercase x. The value of width and height vary within the range of 0-4096.

    Variations of several parameters: 1. XxY: general (intra) shrink 2. Xx0: fixed width and adaptive height (intra shrink) 3. 0xY: fixed height and adaptive width (intra shrink)

Currently in IM Demo project, images displayed in messages are all compressed, for details refer to bubble_image.cpp

Was this page helpful?
Yes
No
  • Overview
  • Send Message
  • Message Setting
  • Text Message
  • Image Message
  • Audio message
  • Video Message
  • Geographic Location
  • File Message
  • Tip message
  • Custom Message
  • Team Force Push Message
  • Sending Result Notification
  • Stop Sending Message
  • Receive Message
  • Message Parsing
  • Online Message Receiving
  • Receive Offline, Sync, and Roaming Messages
  • Filter Team Notifications
  • Forward Message
  • Recall Message
  • Active Message Recall
  • Message Recall Notification
  • Read Receipt
  • Send Read Receipt
  • Monitor Read Receipt Notification
  • Monitor Broadcast to All Notifications
  • Get Local Path from Message Attachment
  • Get Image Thumbnail