消息介绍
消息基本结构
| 字段 | 类型 | 描述 |
|---|---|---|
conversationType | RCIMConversationType | 会话类型 |
targetId | string | 会话 ID |
channelId | string | 所属会话的业务标识,长度限制 20 字符,仅在超级群下生效 |
messageType | RCIMMessageType | 消息的类型 |
messageId | int | 本地存储的消息的唯一值(数据库索引唯一值) |
messageUId | string | 服务器消息唯一 ID(在同一个 Appkey 下全局唯一) |
direction | RCIMMessageDirection | 消息的方向 |
receivedTime | int | 消息的接收时间(Unix 时间戳、毫秒) |
sentTime | int | 消息的发送时间(Unix 时间戳、毫秒) |
receivedStatus | RCIMReceivedStatus | 消息的接收状态 |
sentStatus | RCIMSentStatus | 消息的发送状态 |
senderUserId | string | 消息的发送者 ID |
expansion | Dictionary<string, string> | 消息扩展信息列表,该属性在消息发送时确定,发送之后不能再做修改。 扩展信息只支持单聊和群组,其它会话类型不能设置扩展信息。 默认消息扩展字典 key 长度不超过 32 ,value 长度不超过 4096 ,单次设置扩展数量最大为 20,消息的扩展总数不能超过 300 |
offLine | bool | 是否是离线消息,只在接收消息的回调方法中 有效,如果消息为离线消息,则为 YES ,其他情况均为 NO |
groupReadReceiptInfo | RCIMGroupReadReceiptInfo | 群阅读回执状态 |
userInfo | RCIMUserInfo | 消息携带的用户信息 |
mentionedInfo | RCIMMentionedInfo | 消息的 @ 信息 |
pushOptions | RCIMMessagePushOptions | 消息推送配置,仅可在发送方进行配置,接收方为空 |
extra | string | 消息的附加字段,设置后接收方收到消息后也可以拿到数据。 |
消息类型
IMLib 的消息类型(RCIMMessageType)枚举提供了预定义的文本、语音、图片等消息类型,并且支持 App 通过 RCIMMessageType.custom 实现自定义消息。
各类型消息默认会在客户端本地存储,计入未读消息数。以下类型除外:
- 撤回消息类型(
RCIMMessageType.recall):客户端本地存储,但不计入未读消息数 - 命令消息类型(
RCIMMessageType.command):客户端不进行本地存储,不计入未读消息数 - 命令通知消息类型(
RCIMMessageType.commandNotification):客户端本地存储,不计入未读消息数。 - 自定义消息类型(
RCIMMessageType.custom):由 App 自定义存储策略(RCIMCustomMessagePolicy)进行控制。
文本消息
类型:RCIMMessageType.TEXT
可访问属性:
| 属性名 | 类型 | |
|---|---|---|
text | string | 消息内容 |
构建文本消息
参数说明
| 参数名 | 类型 | |
|---|---|---|
type | RCIMConversationType | 会话类型 |
targetId | string | 会话 ID |
channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
text | string | 消息内容 |
代码示例
C #
RCIMTextMessage textMessage = engine.createTextMessage(
type,
targetId,
channelId,
text
);
语音消息
类型:RCIMMessageType.VOICE
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
local | string | 本地路径 |
remote | string | 远端路径 |
duration | int | 语音时长,单位:秒 |
构建语音消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
type | RCIMConversationType | 会话类型 |
targetId | string | 会话 ID |
channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
path | string | 语音消息的本地路径 |
duration | int | 语音消息的消息时长 |
代码示例
C #
RCIMVoiceMessage voiceMessage = engine.createVoiceMessage(
type,
targetId,
channelId,
path,
duration
);
图片消息
类型:RCIMMessageType.IMAGE
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
local | string | 本地路径 |
remote | string |