类型: class
IM 类,所有 API 交互都通过该类的实例来操作,实例化支持的参数参见 IMOption。
API
初始化 SDK。
初始化时会完成与服务端的消息游标同步和历史信息同步。
类型
(params?: { convLimit?: number; msgLimit?: number; convTotal?: number;}) => Promise<InitResult>
ts注意
可设置 disableInitPull 关闭历史信息同步。
参数
params
类型: { convLimit?: number; msgLimit?: number; convTotal?: number; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| convLimit | number | 每次调用初始化拉取接口时,会话数量限制。 |
| msgLimit | number | 每次调用初始化拉取接口时,每个对话返回的消息数量限制。 |
| convTotal | number | 初始化拉取的会话总数量限制。该值非 0 时,当本地会话数量大于等于该值时停止拉取。 |
返回值
类型: Promise<InitResult>
初始化结果。
拉取用户混链消息。
通常无需业务调用,SDK 内部会轮询。
类型
(params?: { cursor?: Long | string | number | Date; limit?: number; inboxType?: number;}) => Promise<void>
ts参数
params
类型: { cursor?: Long | string | number | Date; limit?: number; inboxType?: number; }
值: ' {}'
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| cursor | string | number | Long | Date | 拉取消息位置游标。 |
| limit | number | 单次拉取消息数量。 |
| inboxType | number | 信箱类型。 |
创建自定义消息。
类型
(params: { conversation: Conversation; content: string; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; content: string; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 当前发送消息的会话。 |
| content | string | 消息体。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
创建文本消息。
类型
(params: { conversation: Conversation; content: string; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; content: string; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 当前发送消息的会话。 |
| content | string | 消息体。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
发送消息。
类型
(params: { message: Message;}) => Promise<SendMessageResult>
ts参数
params
类型: { message: Message; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 要发送的消息,由 createXxxMessage 接口创建。 |
返回值
发送消息结果。
删除消息。
类型
(params: { message: Message; localOnly?: boolean;}) => Promise<void>
ts参数
params
类型: { message: Message; localOnly?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 待删除的消息。 |
| localOnly | boolean | 是否仅删除本地,不同步到服务端。 |
删除消息。
类型
(params: { message: Message;}) => Promise<void>
ts参数
params
类型: { message: Message; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 待撤回的消息。 |
获取消息的实时信息。
类型
(params: { conversation: Conversation; serverMessageId: string;}) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; serverMessageId: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| serverMessageId | string | 消息的 serverid。 |
获取引用消息链。
若消息 B 引用了消息 A,消息 C 引用了消息 B,那么 A -> B -> C 就是一条引用消息链。通过 A、B、C 任意一条消息都可以获取这条消息链。
类型
(params: { message: Message;}) => Promise<Message[]>
ts参数
params
类型: { message: Message; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 消息体。 |
返回值
类型: Promise<Message[]>
引用消息链。
设置消息属性。
常见使用场景:给某条消息点赞、加急等。
类型
(params: { message: Message; modifyContent: Array<{ key: string; operation?: im_proto.OPERATION_TYPE; value?: string; idempotentId?: string; }>;}) => Promise<ModifyMessagePropertyResult>
ts注意
消息加急本质上是修改消息属性,在中台侧仅为一个状态变更。加急之后的附加操作(如全局提醒、短信电话提醒等)需要业务方自行处理。
参数
params
类型: { message: Message; modifyContent: Array<{ key: string; operation?: im_proto.OPERATION_TYPE; value?: string; idempotentId?: string;}>; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 消息体。 |
| modifyContent | { key: string; operation?: im_proto.OPERATION_TYPE; value?: string; idempotentId?: string; }[] | 消息属性。 |
| modifyContent.key | string | 表情回应消息,例如 OK/点赞/done 等。 |
| modifyContent.operation | im_proto.OPERATION_TYPE | 操作类型。 |
| modifyContent.value | string | 对应 content。也可以什么都不存,只代表有这个 key。 |
| modifyContent.idempotentId | string | 幂等 ID。通常为 user ID,防止对单个点赞动作重复操作。 |
返回值
类型: Promise<ModifyMessagePropertyResult>
设置消息属性结果。
获取指定单个本地会话。
类型
(params: { conversationId: string;}) => Conversation
ts参数
params
类型: { conversationId: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversationId | string | 会话 ID。 |
请求服务端更新本地会话后,获取指定单个会话。
类型
(params: { conversationId: string; shortId: string; type: im_proto.ConversationType;}) => Promise<Conversation>
ts参数
params
类型: { conversationId: string; shortId: string; type: im_proto.ConversationType; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversationId | string | 会话 ID。 |
| shortId | string | shortId。 |
| type | im_proto.ConversationType | 会话类型。 |
获取本地会话列表。
类型
(params?: { filter?: (c: Conversation) => boolean; }) => Conversation[]
ts参数
params
类型: { filter?: (c: Conversation) => boolean; }
值: ' {}'
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| filter | (c: Conversation) => boolean | 过滤条件,默认过滤陌生人会话和空会话。 |
请求服务端更新本地会话后,获取会话列表。
类型
(params?: { filter?: (c: Conversation) => boolean; }) => Promise<Conversation[]>
ts参数
params
类型: { filter?: (c: Conversation) => boolean; }
值: ' {}'
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| filter | (c: Conversation) => boolean | 过滤条件,默认过滤陌生人会话和空会话。 |
请求服务器获取会话内的消息列表。
类型
(params: { conversation: Conversation; cursor?: string | Long | Message; direction?: number; limit?: number; limitIndex?: Long;}) => Promise<{ messages: Message[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { conversation: Conversation; cursor?: string | Long | Message; direction?: number; limit?: number; limitIndex?: Long; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| cursor | string | Long | Message | 拉取消息位置游标。 |
| direction | number | 拉取消息方向。 |
| limit | number | 拉取消息数量。 |
| limitIndex | Long | 保留参数,无意义。 |
请求服务器获取用户的会话列表。
类型
(params: { type: im_proto.ConversationType; inboxType?: number; cursor?: Long | string; limit?: number; sortType?: im_proto.SortType; includeRole?: number; excludeRole?: number; withCold?: boolean;}) => Promise<{ conversation: Conversation[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { type: im_proto.ConversationType; inboxType?: number; cursor?: Long | string; limit?: number; sortType?: im_proto.SortType; includeRole?: number; excludeRole?: number; withCold?: boolean; }
创建群聊。
类型
(params: { participants: string[] | string; bizExt?: { [k: string]: string; }; inboxType?: number; type?: im_proto.ConversationType; persistent?: boolean; idempotentId?: string; name?: string; avatarUrl?: string; desc?: string; }) => Promise<CreateConversationResult>
ts参数
params
类型: { participants: string[] | string; bizExt?: { [k: string]: string; }; inboxType?: number; type?: im_proto.ConversationType; persistent?: boolean; idempotentId?: string; name?: string; avatarUrl?: string; desc?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| participants | string | string[] | 会话内的用户 ID。 |
| bizExt | { [k: string]: string; } | 业务拓展信息。 |
| inboxType | number | 信箱类型。 |
| type | im_proto.ConversationType | 会话类型。 |
| persistent | boolean | 持久化幂等,默认为 true,不建议修改。 |
| idempotentId | string | 幂等 ID。由业务方自己生成,以同样的幂等 ID 创建群聊会话时,会返回之前已经创建好的群聊会话。 |
| name | string | 群名称。 |
| avatarUrl | string | 群头像的 url 链接。 |
| desc | string | 群描述。 |
返回值
类型: Promise<CreateConversationResult>
创建结果。
离开群组。
类型
(params: { conversation: Conversation;}) => Promise<void>
ts参数
params
类型: { conversation: Conversation; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
删除会话。
类型
(params: { conversation: Conversation; localOnly?: boolean;}) => Promise<void>
ts参数
params
类型: { conversation: Conversation; localOnly?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 待删除的会话。 |
| localOnly | boolean | 是否仅在本地删除,不同步到服务端。 默认值为 false,即本地和服务端均删除。 |
解散群聊。
类型
(params: { conversation: Conversation;}) => Promise<void>
ts参数
params
类型: { conversation: Conversation; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
设置会话附加信息,如置顶、免打扰、收藏等。
类型
(params: { conversation: Conversation; stickOnTop?: boolean; mute?: boolean; favorite?: boolean; pushStatus?: PushStatus;}) => Promise<SetConversationSettingInfoResult>
ts参数
params
类型: { conversation: Conversation; stickOnTop?: boolean; mute?: boolean; favorite?: boolean; pushStatus?: PushStatus; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| stickOnTop | boolean | 是否置顶。 |
| mute | boolean | 是否免打扰。 |
| favorite | boolean | 是否收藏。 |
| pushStatus | PushStatus | 消息推送模式。 |
返回值
类型: Promise<SetConversationSettingInfoResult>
设置结果。
配置会话低打扰模式。
类型
(params: { conversation: Conversation; config: ConversationSettingWeakMuteInfo;}) => Promise<{ success: boolean; payload: Conversation; checkCode: Long; checkMsg: string; statusCode: number; statusMsg: string; }>
ts参数
params
类型: { conversation: Conversation; config: ConversationSettingWeakMuteInfo; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| config | ConversationSettingWeakMuteInfo | 会话低打扰模式配置。 |
更新 Setting ext 拓展信息。
类型
(params: { conversation: Conversation; ext?: { [k: string]: string; }; }) => Promise<{ success: boolean; payload: Conversation; checkCode: Long; checkMsg: string; statusCode: number; statusMsg: string; }>
ts参数
params
类型: { conversation: Conversation; ext?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| ext | { [k: string]: string; } | 拓展信息。 |
设置群聊信息。
类型
(params: { conversation: Conversation; name?: string; desc?: string; icon?: string; notice?: string; isNameSet?: boolean; isDescSet?: boolean; isIconSet?: boolean; isNoticeSet?: boolean;}) => Promise<SetConversationSettingInfoResult>
ts参数
params
类型: { conversation: Conversation; name?: string; desc?: string; icon?: string; notice?: string; isNameSet?: boolean; isDescSet?: boolean; isIconSet?: boolean; isNoticeSet?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| name | string | 群名称。 |
| desc | string | 群描述。 |
| icon | string | 群头像的 url 链接。 |
| notice | string | 群公告。 |
| isNameSet | boolean | 是否设置群名称。 |
| isDescSet | boolean | 是否设置群描述。 |
| isIconSet | boolean | 是否设置群头像。 |
| isNoticeSet | boolean | 是否设置群公告。 |
返回值
类型: Promise<SetConversationSettingInfoResult>
群聊信息设置结果。
更新 Core ext 拓展信息。
类型
(params: { conversation: Conversation; ext?: { [k: string]: string; }; }) => Promise<{ success: boolean; payload: Conversation; checkCode: Long; checkMsg: string; statusCode: number; statusMsg: string; }>
ts参数
params
类型: { conversation: Conversation; ext?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| ext | { [k: string]: string; } | 拓展信息。 |
获取顶置会话。
类型
(params?: { cursor?: string | Long; limit?: number; inboxType?: number;}) => Promise<{ conversation: Conversation[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { cursor?: string | Long; limit?: number; inboxType?: number; }
值: ' {}'
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| cursor | string | Long | 拉取消息位置游标,默认值为 0。 |
| limit | number | 拉取消息数量。 |
| inboxType | number | 信箱类型。 |
获取收藏会话。
类型
(params?: { cursor?: string | Long; limit?: number; inboxType?: number;}) => Promise<{ conversation: Conversation[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { cursor?: string | Long; limit?: number; inboxType?: number; }
值: ' {}'
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| cursor | string | Long | 拉取消息位置游标,默认值为 0。 |
| limit | number | 拉取消息数量。 |
| inboxType | number | 信箱类型。 |
标记会话已读。
类型
(params: { conversation: Conversation; readIndex?: string | Long | Message; convUnreadCount?: number; totalUnreadCount?: number;}) => Promise<void>
ts参数
params
类型: { conversation: Conversation; readIndex?: string | Long | Message; convUnreadCount?: number; totalUnreadCount?: number; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| readIndex | string | Long | Message | 消息的 indexInConversation。默认为会话的 lastMessageIndex(最后一条消息的 index)。 |
| convUnreadCount | number | 会话中未读消息数。 |
| totalUnreadCount | number | 总未读消息数。 |
添加群成员。
类型
(params: { conversation: Conversation; participant: Participant | Participant[] | string[] | string; bizExt?: { [k: string]: string; }; isDropReconnect?: boolean; }) => Promise<AddParticipantResult>
ts参数
params
类型: { conversation: Conversation; participant: Participant | Participant[] | string[] | string; bizExt?: { [k: string]: string; }; isDropReconnect?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| participant | string | string[] | Participant | Participant[] | 待添加的群成员 ID 列表。 |
| bizExt | { [k: string]: string; } | 业务拓展信息。 |
| isDropReconnect | boolean | 是否是掉线重连。若用户因网络波动等原因掉线,SDK 会在网络恢复后自动重连。 |
返回值
类型: Promise<AddParticipantResult>
添加成员结果。
移除群成员/离开直播群/移除直播群成员,v1.1.0 新增直播群功能。
类型
(params: { conversation: Conversation; participant: Participant | Participant[] | string | string[]; bizExt?: { [k: string]: string; }; }) => Promise<RemoveParticipantResult>
ts参数
params
类型: { conversation: Conversation; participant: Participant | Participant[] | string | string[]; bizExt?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| participant | string | string[] | Participant | Participant[] | 待移除的群成员 ID 列表。 |
| bizExt | { [k: string]: string; } | 业务拓展信息。 |
返回值
类型: Promise<RemoveParticipantResult>
移除成员结果。
更新群成员信息。
类型
(params: { conversation: Conversation; userId: string; role?: number; alias?: string; bizExt?: { [k: string]: string; }; }) => Promise<UpdateParticipantResult>
ts参数
params
类型: { conversation: Conversation; userId: string; role?: number; alias?: string; bizExt?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| userId | string | 成员的用户 ID。 |
| role | number | 成员角色。 0 为普通成员,1 为群主。 |
| alias | string | 成员群昵称。 |
| bizExt | { [k: string]: string; } | 业务拓展信息。 |
返回值
类型: Promise<UpdateParticipantResult>
更新结果。
获取 SDK 本地维护的群成员列表。
类型
(params: { conversation: Conversation;}) => Participant[]ts
参数
params
类型: { conversation: Conversation; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
获取群成员列表。
此方法会在 SDK 内部循环调用分页接口,直至没有更多数据,然后把所有群成员数据一次返回。当群成员较多时,此方法耗时较久。
类型
(params: { conversation: Conversation; limit?: number; cursor?: Long;}) => Promise<{ participants: Participant[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { conversation: Conversation; limit?: number; cursor?: Long; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| limit | number | 单页拉取消息数量。 |
| cursor | Long | 下一页拉取消息位置游标。 |
设置群禁言(会话维度)。
类型
(params: { conversation: Conversation; block: boolean; normalOnly?: boolean;}) => Promise<Conversation>
ts参数
params
类型: { conversation: Conversation; block: boolean; normalOnly?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| block | boolean | 是否禁言。 |
| normalOnly | boolean | 是否只禁言普通群成员。 |
设置群禁言(成员维度)。
类型
(params: { conversation: Conversation; block: boolean; blockDuration: { [k: string]: string | number | Long; }; bizExt?: { [k: string]: string; }; }) => Promise<Conversation>
ts参数
params
类型: { conversation: Conversation; block: boolean; blockDuration: { [k: string]: string | number | Long; }; bizExt?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| block | boolean | 是否禁言。 |
| blockDuration | { [k: string]: string | number | Long; } | 禁言用户和时间。key 是用户 ID;value 是禁言时间,单位为秒。{111: 1000} 表示把用户 111 禁言 1000 秒。 |
| bizExt | { [k: string]: string; } | 业务拓展信息。 |
手动卸载 SDK。
类型
() => void
ts类型: class
直播群插件,在 IM 实例化时传入后,IM 实例增加直播群相关的方法。v1.1.0 新增。
API
| 名称 | 描述 |
|---|---|
| setParticipantBlockTime() | 拉黑直播群成员。 |
| getMuteParticipantsOnline() | 获取直播群禁言成员列表。 |
| getBlockParticipantsOnline() | 获取直播群被拉黑成员列表。 |
| getLiveConversationListOnline() | 获取直播群列表。 |
| getLiveParticipantsOnline() | 获取直播群在线成员列表。 |
参数
ctx
类型: RuntimeContext
拉黑直播群成员。
类型
(params: { conversation: Conversation; block: boolean; blockDuration: { [k: string]: string | number | Long; }; bizExt?: { [k: string]: string; }; }) => Promise<im_proto.IBlockMembersResponseBody>
ts参数
params
类型: { conversation: Conversation; block: boolean; blockDuration: { [k: string]: string | number | Long; }; bizExt?: { [k: string]: string; }; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| block | boolean | 是否拉黑。 |
| blockDuration | { [k: string]: string | number | Long; } | 用户ID/拉黑时长。 |
| bizExt | { [k: string]: string; } |
返回值
拉黑的消息。
获取直播群禁言成员列表。
类型
(params: { conversation: Conversation; limit?: number; cursor?: Long;}) => Promise<{ participants: Participant[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { conversation: Conversation; limit?: number; cursor?: Long; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 直播群信息。 |
| limit | number | 每页多少条,默认20条。 |
| cursor | Long | 游标。 |
返回值
成员列表信息。
获取直播群被拉黑成员列表。
类型
(params: { conversation: Conversation; limit?: number; cursor?: Long;}) => Promise<{ participants: Participant[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { conversation: Conversation; limit?: number; cursor?: Long; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 直播群信息。 |
| limit | number | 每页多少条,默认20条。 |
| cursor | Long | 游标。 |
返回值
成员列表信息。
获取直播群列表。
类型
(params: { cursor?: Long; policy?: number; limit?: number;}) => Promise<{ conversation: Conversation[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { cursor?: Long; policy?: number; limit?: number; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| cursor | Long | 游标。 |
| policy | number | 过滤条件 1: 所有的群 3: 自己是群主的群。默认返回所有群。 |
| limit | number | 每页多少条,默认20条。 |
返回值
直播群列表信息。
获取直播群在线成员列表。
类型
(params: { conversation: Conversation; limit?: number; cursor?: Long;}) => Promise<{ participants: Participant[]; hasMore: boolean; cursor: Long; }>
ts参数
params
类型: { conversation: Conversation; limit?: number; cursor?: Long; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 直播群信息。 |
| limit | number | 每页多少条,默认20条。 |
| cursor | Long | 游标。 |
返回值
在线成员列表信息。
类型: class
多媒体消息插件,在 IM 实例化时传入后,IM 实例增加发送媒体消息的方法。
API
| 名称 | 描述 |
|---|---|
| createImageMessage() | 创建图片消息。 |
| createAudioMessage() | 创建音频消息。 |
| createVideoMessage() | 创建视频消息。 |
| createFileMessage() | 创建文件消息。 |
| refreshFileUrl() | 根据消息内容刷新文件 URL。 |
| validateFileUrl() | 校验文件 url 是否在有效期 |
| getImageResizeUrls() | 获取图片 URL(缩放、转码)。 |
参数
ctx
类型: RuntimeContext
创建图片消息。
类型
(params: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| fileInfo | FileInfo | 文件信息。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
返回值
创建的消息。
创建音频消息。
类型
(params: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| fileInfo | FileInfo | 文件信息。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
返回值
创建的消息。
创建视频消息。
类型
(params: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| fileInfo | FileInfo | 文件信息。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
返回值
创建的消息。
创建文件消息。
类型
(params: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }) => Promise<Message>
ts参数
params
类型: { conversation: Conversation; fileInfo: FileInfo; clientId?: string; ext?: { [k: string]: string; }; mentionedUsers?: string[]; insert?: boolean; referenceMessage?: Message; referenceHint?: string; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| conversation | Conversation | 会话信息。 |
| fileInfo | FileInfo | 文件信息。 |
| clientId | string | 客户端 ID。 |
| ext | { [k: string]: string; } | 消息拓展属性。 |
| mentionedUsers | string[] | 需要 @ 的用户列表。 |
| insert | boolean | 消息创建后是否 process 处理(新消息处理流程)。 |
| referenceMessage | Message | 引用的消息。 |
| referenceHint | string | 业务透传的引用信息,传入自定义引用线索。 |
返回值
创建的消息。
根据消息内容刷新文件 URL。
类型
(params: { message: Message; ignoreCache?: boolean;}) => Promise<Message>
ts参数
params
类型: { message: Message; ignoreCache?: boolean; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 消息内容。 |
| ignoreCache | boolean | 是否忽略缓存。 |
校验文件 url 是否在有效期
类型
(params: { message: Message; delta?: number;}) => boolean
ts参数
params
类型: { message: Message; delta?: number; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| message | Message | 消息内容 |
| delta | number | 有效期偏移量,单位秒,默认提前30s认定过期 |
返回值
类型: boolean
获取图片 URL(缩放、转码)。
类型
(params: { uri: string; format?: string; width: number; height: number;}) => Promise<string[]>
ts参数
params
类型: { uri: string; format?: string; width: number; height: number; }
成员
| 名称 | 类型 | 描述 |
|---|---|---|
| uri | string | 图片 URI。 |
| format | string | 图片格式,目前支持 jpeg, png, webp, gif。 |
| width | number | 图片宽度。 |
| height | number | 图片高度。 |
返回值
类型: Promise<string[]>
类型: class
API
| 名称 | 描述 |
|---|---|
| subscribe() | 创建一个事件订阅 |
| unsubscribe() | 取消一个事件订阅 |
创建一个事件订阅
类型
<T extends keyof IMEventTypeMap>(event: T, func: EventHandler<IMEventTypeMap[T]>) => Subscription<IMEventTypeMap[T]>
ts参数
event
类型: T
事件类型,参看 IMEvent。
func
类型: EventHandler<IMEventTypeMap[T]>
事件回调函数,入参参看 IMEventTypeMap。
返回值
类型: Subscription<IMEventTypeMap[T]>
回调函数 Index
取消一个事件订阅
类型
(event: IMEvent, handler: Subscription<any>) => void
ts参数
event
类型: IMEvent
事件类型
handler
类型: Subscription<any>
回调函数 Index