消息介绍
消息基本结构
| 字段 | 类型 | 描述 |
|---|---|---|
| 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 | 远端路径 |
| thumbnailBase64string | string | 图片的缩略图数据 |
| original | bool | 是否为原图 |
构建图片消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| path | string | 图片消息的本地路径 |
代码示例
C #
RCIMImageMessage message = engine.createImageMessage(
type,
targetId,
channelId,
path
);
文件消息
类型:RCIMMessageType.FILE
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| local | string | 本地路径 |
| remote | string | 远端路径 |
| name | string | 文件名 |
| fileType | string | 文件类型 |
| size | int | 文件大小,单位为 Byte |
构建文件消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| path | string | 文件消息的本地路径 |
代码示例
C #
RCIMFileMessage msg = engine.createFileMessage(
type,
targetId,
channelId,
path
);
小视频消息
类型:RCIMMessageType.SIGHT
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| local | string | 本地路径 |
| remote | string | 远端路径 |
| duration | int | 语音时长,单位:秒 |
| size | int | 视频大小 |
| name | string | 视频的名称 |
| thumbnailBase64string | string | 缩略图数据 |
构建小视频消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| path | string | 小视频消息的本地路径 |
| duration | int | 小视频消息的视频时长,请注意服务端的默认视频时长上限为 2 分钟。若需调整上限,请联系商务。 |
代码示例
C #
RCIMSightMessage sightMsg = engine.createSightMessage(
type,
targetId,
channelId,
path,
duration
);
GIF图消息
类型:RCIMMessageType.GIF
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| local | string | 本地路径 |
| remote | string | 远端路径 |
| dataSize | int | GIF 图的大小,单位字节 |
| width | int | GIF 图的宽 |
| height | int | GIF 图的高 |
构建 GIF 消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| path | string | GIF 消息的本地路径 |
代码示例
C #
RCIMGIFMessage msg = engine.createGIFMessage(
type,
targetId,
channelId,
path
);
撤回消息
撤回消息不可以主动构建发送,需要撤回消息请调用撤回消息接口
类型:RCIMMessageType.RECALL
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| local | string | 本地路径 |
| remote | string | 远端路径 |
| admin | bool | 是否是管理员操作 |
| deleted | bool | 是否删除 |
| recallTime | int | 被撤回的原始消息的发送时间(毫秒) |
| recallActionTime | int | 撤回动作的时间(毫秒) |
| originalMessage | RCIMMessage | 被撤回的原消息 |
引用消息
类型:RCIMMessageType.REFERENCE
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| text | string | 引用文本 |
| referenceMessage | RCIMMessage | 被引用的消息 |
构建引用消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| text | string | 引用的文本内容 |
| referenceMessage | RCIMMessage | 引用的消息 |
代码示例
C #
RCIMReferenceMessage referenceMsg = engine.createReferenceMessage(
type,
targetId,
channelId,
message,
text
);
位置消息
类型:RCIMMessageType.LOCATION
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| longitude | double | 经度信息 |
| latitude | double | 纬度信息 |
| poiName | string | POI 信息 |
| thumbnailPath | string | 缩略图地址 |
构建位置消息
参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| longitude | double | 经度 |
| latitude | double | 纬度 |
| poiName | string | POI 信息 |
| thumbnailPath | string | 缩略图本地路径,必须为有效路径 |
代码示例
C #
RCIMLocationMessage message = engine.createLocationMessage(
type,
targetId,
channelId,
longitude,
latitude,
poiName,
path
);
命令消息
类型:RCIMMessageType.COMMAND
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| name | string | 命令的名称 |
| data | string | 命令的扩展数据,可以为任意字符串,如存放您定义的json数据。 |
命令通知消息
类型:RCIMMessageType.COMMAND_NOTIFICATION
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| name | string | 命令的名称 |
| data | string | 命令的扩展数据,可以为任意字符串,如存放您定义的json数据。 |
自定义消息
类型:RCIMMessageType.CUSTOM
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| identifier | string | 自定义消息的标识符 |
| policy | RCIMCustomMessagePolicy | 自定义的消息存储策略 |
| fields | Dictionary<string, string> | 自定义消息的键值对 |
构建自定义消息
参数说明
| 参数名 | 类型 | |
|---|---|---|
| type | RCIMConversationType | 会话类型 |
| targetId | string | 会话 ID |
| channelId | string | 频道 ID,长度限制 20 字符,仅支持超级群使用,其他会话类型传 null 即可。 |
| policy | RCIMCustomMessagePolicy | 消息的存储策略 |
| messageIdentifier | string | 消息的标识符,需唯一 |
| fields | Dictionary<string, string> | 消息的内容键值对 |
代码示例
C #
RCIMCustomMessage msg = engine.createCustomMessage(
type,
targetId,
channelId,
policy,
messageIdentifier,
fields
);
无效类型
当接收到无法识别的消息时,会变为无效类型的消息,此消息不可主动构建发送
类型:RCIMMessageType.UNKNOWN
可访问属性:
| 属性名 | 类型 | 描述 |
|---|---|---|
| rawData | string | 消息数据 |
| objectName | string | 消息的标识 |