nim-web-sdk-ng
Version:
Yunxin IM SDK next generation
1,916 lines • 86.4 kB
TypeScript
import { IMMessage } from './MsgServiceInterface';
import { V2NIMAIModelCallContent, V2NIMAIModelCallMessage, V2NIMAIModelConfigParams, V2NIMAIRAGInfo } from './V2NIMAIService';
import { V2NIMLoginClientType } from './V2NIMConst';
import { V2NIMConversationType } from './V2NIMConversationService';
import { V2NIMUpdateTeamInfoParams } from './V2NIMTeamService';
import { V2NIMTopicRefer } from './V2NIMTopicService';
import type { NIMEBaseServiceClass } from './types';
/**
* v2 消息模块
*
* 注: 使用 dist/esm 产物时,需要动态引入 V2NIMMessageService 后使用
*
* @example
* ```
* import { NIM, V2NIMMessageService } from 'nim-web-sdk-ng/dist/esm/nim'
* NIM.registerService(V2NIMMessageService, 'V2NIMMessageService')
* ```
*/
export interface V2NIMMessageService extends NIMEBaseServiceClass<V2NIMMessageListener>, V2NIMMessageExtendUtil, V2NIMMessageLogUtil {
}
export declare type V2NIMTextTranslateParams = {
/** 需要翻译的文本信息 */
text: string;
/** 输入文本对应的语言, 如果不传则默认为自动识别,如果明确源语言类型则输入源语言类型标识,支持输入:“auto”, 表示自动识别 */
sourceLanguage?: string;
/** 文本翻译的目标语言 */
targetLanguage: string;
};
export declare type V2NIMTextTranslationResult = {
/** 翻译结果文本 */
translatedText: string;
/** 输入文本对应的语言 */
sourceLanguage: string;
/** 翻译结果文本对应的语言 */
targetLanguage: string;
};
export declare class V2NIMMessageService {
/**
* 发送消息
*
* @param message 消息体, 由 V2NIMMessageCreator 的对应方法创建
* @param conversationId 会话 id
* @param params 发送消息相关配置参数
* @param progress 发送消息进度回调. 作用于需要上传的文件,图片,音视频消息
*
* @example
* ```js
* let message = nim.V2NIMMessageCreator.createTextMessage('hello world')
* const conversationId = nim.V2NIMConversationIdUtil.p2pConversationId('AI_ACCOUND_ID')
* message = await nim.V2NIMMessageService.sendMessage(message, conversationId)
* ```
*/
sendMessage(message: V2NIMMessage, conversationId: string, params?: V2NIMSendMessageParams, progress?: (percentage: number) => void): Promise<V2NIMSendMessageResult>;
/**
* 回复消息
*
* @param message 需要发送的消息体, 由 V2NIMMessageCreator 的对应方法创建
* @param replyMessage 被回复的消息
* @param params 发送消息相关配置参数
* @param progress 发送消息进度回调. 作用于需要上传的文件,图片,音视频消息
*
* @example
* ```ts
* const message = nim.V2NIMMessageCreator.createTextMessage('这是回复内容')
* const result = await nim.V2NIMMessageService.replyMessage(message, originalMessage)
* ```
*/
replyMessage(message: V2NIMMessage, replyMessage: V2NIMMessage, params?: V2NIMSendMessageParams, progress?: (percentage: number) => void): Promise<V2NIMSendMessageResult>;
/**
* 撤回消息
*
* @param message 需要撤回的消息
* @param params 撤回消息相关参数
*
* @example
* ```ts
* await nim.V2NIMMessageService.revokeMessage(message)
* ```
*/
revokeMessage(message: V2NIMMessage, params?: V2NIMMessageRevokeParams): Promise<void>;
/**
* 删除单条消息
*
* 注: 操作成功后, SDK 会抛出事件 {@link V2NIMMessageListener.onMessageDeletedNotifications | V2NIMMessageListener.onMessageDeletedNotifications}
*
* @param message 需要删除的消息
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.deleteMessage(message)
* ```
*/
deleteMessage(message: V2NIMMessage, serverExtension?: string): Promise<void>;
/**
* 批量删除消息
*
* 注: 操作成功后, SDK 会抛出事件 {@link V2NIMMessageListener.onMessageDeletedNotifications | V2NIMMessageListener.onMessageDeletedNotifications} <br/>
* - 所删除的消息必须是同一会话的消息 <br/>
* - 限制一次最多删除 50 条消息
*
* @param message 需要删除的消息
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.deleteMessages([message1, message2])
* ```
*/
deleteMessages(messages: V2NIMMessage[], serverExtension?: string): Promise<void>;
/**
* 发送消息已读回执
*
* @param message 点对点会话收到的对方最后一条消息
*
* @example
* ```ts
* await nim.V2NIMMessageService.sendP2PMessageReceipt(lastReceivedMessage)
* ```
*/
sendP2PMessageReceipt(message: V2NIMMessage): Promise<void>;
/**
* 查询点对点消息已读回执
* @param conversationId 会话 id
*
* @example
* ```ts
* const receipt = await nim.V2NIMMessageService.getP2PMessageReceipt(conversationId)
* ```
*/
getP2PMessageReceipt(conversationId: string): Promise<V2NIMP2PMessageReadReceipt>;
/**
* 查询点对点消息是否对方已读
*
* @param message 需要查询的消息
*
* @example
* ```ts
* const isRead = nim.V2NIMMessageService.isPeerRead(message)
* ```
*/
isPeerRead(message: V2NIMMessage): boolean;
/**
* 发送群消息已读回执
*
* @param messages 需要发送已读回执的消息列表. 限制一批最多 50 个且所有消息必须属于同一个会话
*
* @example
* ```ts
* await nim.V2NIMMessageService.sendTeamMessageReceipts([teamMessage1, teamMessage2])
* ```
*/
sendTeamMessageReceipts(messages: V2NIMMessage[]): Promise<void>;
/**
* 获取群消息已读回执状态
*
* @param messages 获取群消息已读回执状态. 限制一批最多 50 个且所有消息必须属于同一个会话
*
* @example
* ```ts
* const receipts = await nim.V2NIMMessageService.getTeamMessageReceipts([teamMessage])
* ```
*/
getTeamMessageReceipts(messages: V2NIMMessage[]): Promise<V2NIMTeamMessageReadReceipt[]>;
/**
* 获取群消息已读回执状态详情
*
* @param messages 需要查询已读回执状态的消息. 限制一批最多 50 个且所有消息必须属于同一个会话
*
* @example
* ```ts
* const detail = await nim.V2NIMMessageService.getTeamMessageReceiptDetail(teamMessage)
* ```
*/
getTeamMessageReceiptDetail(messages: V2NIMMessage, memberAccountIds?: string[]): Promise<V2NIMTeamMessageReadReceiptDetail>;
/**
* 取消文件类消息的附件上传
*
* 注: 若成功取消, 则算为消息发送失败处理
*
* @param message 需要取消附件上传的消息体
*
* @example
* ```ts
* await nim.V2NIMMessageService.cancelMessageAttachmentUpload(fileMessage)
* ```
*/
cancelMessageAttachmentUpload(message: V2NIMMessage): Promise<void>;
/**
* 更新消息接口
*
* @param message 需要修改的消息
* @param params 修改消息相关配置参数.
* @returns 修改后的消息
*
* @example
* ```ts
* const result = await nim.V2NIMMessageService.modifyMessage(message, { text: '修改后的内容' })
* ```
*/
modifyMessage(message: V2NIMMessage, params: V2NIMModifyMessageParams): Promise<V2NIMModifyMessageResult>;
/**
* 注册自定义消息附件解析器,解析 {@link V2NIMMessageType.V2NIM_MESSAGE_TYPE_CUSTOM | V2NIMMessageType.V2NIM_MESSAGE_TYPE_CUSTOM} 类消息的附件
*
* 注: 可以注册多个解析器, 后注册的优先级高,优先派发. 一旦某一个解析器返回了一个合法的 attachment 附件对象(即携带 raw 属性的一个对象),则不继续派发给下一个解析器.
*
* @param parser 解析器.
*
* @example
* ```ts
* const parser = (subType, attachRaw) => ({ raw: attachRaw, customField: JSON.parse(attachRaw) })
* nim.V2NIMMessageService.registerCustomAttachmentParser(parser)
* ```
*/
registerCustomAttachmentParser(parser: V2NIMMessageCustomAttachmentParser): void;
/**
* 反注册自定义消息附件解析器
*
* 注: 要传递 registerCustomAttachmentParser 所注册的, 引用页相同的那个 parser 解析器, 才能正确反注册.
*
* @param parser 解析器函数
*
* @example
* ```ts
* nim.V2NIMMessageService.unregisterCustomAttachmentParser(parser)
* ```
*/
unregisterCustomAttachmentParser(parser: V2NIMMessageCustomAttachmentParser): void;
/**
* 停止流式输出
* @param message 消息体
* @param params 停止模式等入参
*
* @example
* ```ts
* await nim.V2NIMMessageService.stopAIStreamMessage(aiMessage, { stopMode: 1 })
* ```
*/
stopAIStreamMessage(message: V2NIMMessage, params: V2NIMMessageAIStreamStopParams): Promise<void>;
/**
* 重新生成 ai 消息
*
* 注: 若是流式消息, 必须等到流式分片输出完毕, 才允许调用此 API
*
* 此外他支持两种配置
*
* 1. 更新,新消息覆盖老消息---只允许更新3天内的消息
* 2. 新消息,产生一条新消息
*
* @param message 需要重新输出的原始数字人消息
* @param params 确定重新输出的操作类型
*
* @example
* ```ts
* await nim.V2NIMMessageService.regenAIMessage(aiMessage, { regenType: 1 })
* ```
*/
regenAIMessage(message: V2NIMMessage, params: V2NIMMessageAIRegenParams): Promise<void>;
/**
* 文本翻译
*
* @param params 翻译参数
*
* @example
* ```ts
* const result = await nim.V2NIMMessageService.translateText({ text: 'hello', targetLanguage: 'zh' })
* ```
*/
translateText(params: V2NIMTextTranslateParams): Promise<V2NIMTextTranslationResult>;
/**
* 发送流式消息
*
* 用于 AI Bot 流式发送消息给人类用户
*
* 基本规则:
* - 单聊: 流式通知会实时下发给消息的发送方和接收方
* - 高级群聊: 流式通知只会下发给消息发送者。若需要下发至全员,请联系云信技术支持进行开通
* - 群定向消息: 流式通知会下发至发送占位消息时刻的成员列表
* - 消息合并: 流式消息完成或终止后,系统会自动将已接收的所有分片内容按序号合并成完整消息
*
* 接口限制:
* - 时间限制: 每次分片之间最长间隔不能超过 30 秒,否则流式消息将被终止
* - 长度限制: 所有分片 text 总长度不能超过 5000 字符,超过将立即终止流式消息
* - 终止规则: 流式消息一旦终止,该流式消息的后续请求将被拒绝
*
* 调用频率建议: 建议使用缓冲逻辑,每 200 毫秒调用一次
*
* @param message 基础消息体,当前仅支持 messageType = 0(文本消息)
* @param conversationId 会话 ID,用于指定发送目标会话,仅支持 P2P 和普通群会话
* @param streamChunkParams 流式消息相关参数
* @param ragInfoParams 大模型回复消息相关 RAG 信息(可选)
*
* @example
* ```js
* const message = nim.V2NIMMessageCreator.createTextMessage('')
* const conversationId = 'accid1|1|accid2' // P2P 会话
* // 发送第一个分片
* await nim.V2NIMMessageService.sendStreamMessage(message, conversationId, { text: '今天', index: 0, finish: 0 })
* // 发送后续分片
* await nim.V2NIMMessageService.sendStreamMessage(message, conversationId, { text: '天气', index: 1, finish: 0 })
* // 发送最后一个分片
* await nim.V2NIMMessageService.sendStreamMessage(message, conversationId, { text: '很好!', index: 2, finish: 1 })
* ```
*/
sendStreamMessage(message: V2NIMMessage, conversationId: string, param: V2NIMSendMessageParams, streamChunkParams: V2NIMMessageStreamChunkParams, ragInfoParams?: V2NIMMessageAIRagInfoParams[]): Promise<V2NIMMessage>;
/**
* 回复流式消息 (协议 30_37)
*
* 用于 AI Bot 对消息进行流式回复,支持 Thread 模式。
* 与 sendStreamMessage 类似,但额外传递 threadRoot/threadReply 相关字段。
*
* @param message 基础消息体,当前仅支持 messageType = 0(文本消息)
* @param conversationId 会话 ID,用于指定发送目标会话,仅支持 P2P 和普通群会话
* @param replyMessage 被回复的消息,用于填充 threadRoot 和 threadReply 字段
* @param param 发送消息参数,支持 messageConfig, routeConfig, pushConfig
* @param streamChunkParams 流式消息相关参数
* @param ragInfoParams 大模型回复消息相关 RAG 信息(可选)
*
* @example
* ```js
* const message = nim.V2NIMMessageCreator.createTextMessage('')
* const replyMessage = window.message // 被回复的消息
* // 回复第一个分片
* await nim.V2NIMMessageService.replyStreamMessage(message, replyMessage, {}, { text: '回复', index: 0, finish: 0 })
* // 回复最后一个分片
* await nim.V2NIMMessageService.replyStreamMessage(message, replyMessage, {}, { text: '内容', index: 1, finish: 1 })
* ```
*/
replyStreamMessage(message: V2NIMMessage, replyMessage: V2NIMMessage, param: V2NIMSendMessageParams, streamChunkParams: V2NIMMessageStreamChunkParams, ragInfoParams?: V2NIMMessageAIRagInfoParams[]): Promise<V2NIMMessage>;
}
/**
* 自定义消息附件的解析器结构
*
* 解析器必须返回一个 {@link V2NIMMessageCustomAttachment | V2NIMMessageCustomAttachment} 类型的对象. SDK 会校验这个对象一定存在属性 "raw".
*
* 注: 开发者可以定义 V2NIMMessageCustomAttachment 类型的子类型
*
* @param subType 消息的 subType, 参见 {@link V2NIMMessage.subType | V2NIMMessage.subType}. 若消息中不存在 subType, 则默认值为 0.
* @param attachRaw 消息的附件原始内容, raw 值. 开发者请小心它为空字符串的情况
* @returns {@link V2NIMMessageCustomAttachment | V2NIMMessageCustomAttachment} 类型的对象. 开发者可以定义 V2NIMMessageCustomAttachment 类型的子类型.
*
* 注: 如果返回的对象中 raw 属性一定会被入参的 attachRaw 再次覆盖, 也就是说 raw 作为原始附件内容, 不允许修改.
*/
export declare type V2NIMMessageCustomAttachmentParser = (subType: number, attachRaw: string) => V2NIMMessageCustomAttachment;
export declare type V2NIMModifyMessageResult = {
/**
* 默认为 200
*
* 注: 如果此错误码为非 200,表示修改消息失败(比如触发了云端反垃圾), 此时修改成功后的消息体返回为空
*/
errorCode: number;
/**
* 修改成功后的消息体
*/
message?: V2NIMMessage;
/**
* 云端反垃圾返回的结果
*/
antispamResult?: string;
/**
* 客户端本地反垃圾结果
*/
clientAntispamResult?: V2NIMClientAntispamResult;
};
/**
* 消息记录查询模块
*
* 注: 使用 dist/esm 产物时,需要动态引入 V2NIMMessageLogUtil 后使用
*
* @example
* ```
* import { NIM, V2NIMMessageLogUtil } from 'nim-web-sdk-ng/dist/esm/nim'
* NIM.registerService(V2NIMMessageLogUtil, 'V2NIMMessageLogUtil')
* ```
*/
export declare class V2NIMMessageLogUtil {
/**
* 查询历史消息
*
* 注: 分页接口,每次默认50条
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param option 查询消息配置选项
*
* @example
* ```ts
* const messages = await nim.V2NIMMessageService.getMessageList({ conversationId, limit: 50 })
* ```
*/
getMessageList(option: V2NIMMessageListOption): Promise<V2NIMMessage[]>;
/**
* 查询历史消息, 且提供分页锚点
*
* 注: 分页接口,每次默认50条
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param option 查询消息配置选项
*
* @example
* ```ts
* const { messages, cursor } = await nim.V2NIMMessageService.getMessageListEx({ conversationId, limit: 50 })
* ```
*/
getMessageListEx(option: V2NIMMessageListOption): Promise<V2NIMMessageListResult>;
/**
* 根据ID列表查询消息
*
* 注: 只查询本地数据库. web端不支持该接口
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param messageClientIds 消息 id 列表
*/
/**
* 根据 MessageRefer 列表查询消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param messageRefers 需要查询的消息Refer列表
*
* @example
* ```ts
* const messages = await nim.V2NIMMessageService.getMessageListByRefers([messageRefer])
* ```
*/
getMessageListByRefers(messageRefers: V2NIMMessageRefer[]): Promise<V2NIMMessage[]>;
/**
* 清空会话历史消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param option 清空消息参数
*
* @example
* ```ts
* await nim.V2NIMMessageService.clearHistoryMessage({ conversationId })
* ```
*/
clearHistoryMessage(option: V2NIMClearHistoryMessageOption): Promise<void>;
/**
* 仅清空会话漫游消息
*
* 注: 如果需要删除会话, 并且刷新页面重新初始化登录后不再看到该会话, 但后续新消息进入重新产生会话时仍能拉取历史消息,
* 可以先调用本接口清空漫游消息, 再调用会话删除接口并将 clearMessage 设置为 false.
* 这样只会删除会话和漫游消息, 不会删除云端历史消息.
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageLogUtil | V2NIMMessageLogUtil} 后使用
*
* @param conversationIds 会话 id 列表
*
* @example
* ```ts
* // 组合调用场景: 删除本地会话并清空漫游消息, 但保留云端历史消息.
* // 刷新页面重新初始化登录后, 该会话不会因漫游消息重新出现.
* // 接着因新消息弹出这个会话, 点击进入会话后, 能够拉得到历史消息记录.
* await nim.V2NIMMessageService.clearRoamingMessage([conversationId])
* await nim.V2NIMLocalConversationService.deleteConversation(conversationId, false)
* ```
*/
clearRoamingMessage(conversationIds: string[]): Promise<void>;
}
/**
* 消息扩展功能模块
*
* 注: 使用 dist/esm 产物时,需要动态引入 V2NIMMessageExtendUtil 后使用
*
* @example
* ```
* import { NIM, V2NIMMessageExtendUtil } from 'nim-web-sdk-ng/dist/esm/nim'
* NIM.registerService(V2NIMMessageExtendUtil, 'V2NIMMessageExtendUtil')
* ```
*/
export declare class V2NIMMessageExtendUtil {
/**
* pin 一条消息
*
* 注: 操作成功后, SDK 会抛出事件 {@link V2NIMMessageListener.onMessagePinNotification | V2NIMMessageListener.onMessagePinNotification}
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param message 需要被 pin 的消息体
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.pinMessage(message)
* ```
*/
pinMessage(message: V2NIMMessage, serverExtension?: string): Promise<void>;
/**
* 取消一条Pin消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param messageRefer 需要被取消 pin 的消息摘要
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.unpinMessage(messageRefer)
* ```
*/
unpinMessage(messageRefer: V2NIMMessageRefer, serverExtension?: string): Promise<void>;
/**
* 更新一条 Pin 消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param message 需要被更新 pin 的消息体
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.updatePinMessage(message, 'newExtension')
* ```
*/
updatePinMessage(message: V2NIMMessage, serverExtension?: string): Promise<void>;
/**
* 获取 pin 消息列表
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param conversationId 会话 ID
*
* @example
* ```ts
* const pinnedList = await nim.V2NIMMessageService.getPinnedMessageList(conversationId)
* ```
*/
getPinnedMessageList(conversationId: string): Promise<V2NIMMessagePin[]>;
/**
* 添加快捷评论
*
* 注: 操作成功后, SDK 会抛出事件 {@link V2NIMMessageListener.onMessageQuickCommentNotification | V2NIMMessageListener.onMessageQuickCommentNotification}
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param message 被快捷评论的消息
* @param index 快捷评论索引. 开发者可以本地构造映射关系, 例如 1 代表 笑脸; 2 代表大笑
* @param serverExtension 扩展字段, 最大8个字符
* @param pushConfig 快捷评论推送配置
*
* @example
* ```ts
* await nim.V2NIMMessageService.addQuickComment(message, 1)
* ```
*/
addQuickComment(message: V2NIMMessage, index: number, serverExtension?: string, pushConfig?: V2NIMMessageQuickCommentPushConfig): Promise<void>;
/**
* 移除快捷评论
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param messageRefer 要移除快捷评论的消息摘要
* @param index 快捷评论索引
* @param serverExtension 扩展字段
*
* @example
* ```ts
* await nim.V2NIMMessageService.removeQuickComment(messageRefer, 1)
* ```
*/
removeQuickComment(messageRefer: V2NIMMessageRefer, index: number, serverExtension?: string): Promise<void>;
/**
* 获取快捷评论列表
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param message 需要查询快捷评论的消息列表
* @returns 输出一个对象, key 为 messageClientId, value 为快捷评论列表
*
* @example
* ```ts
* const comments = await nim.V2NIMMessageService.getQuickCommentList([message])
* ```
*/
getQuickCommentList(message: V2NIMMessage[]): Promise<{
[messageClientId: string]: V2NIMMessageQuickComment[];
}>;
/**
* 添加一个收藏
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param params 添加收藏的相关参数
*
* @example
* ```ts
* const collection = await nim.V2NIMMessageService.addCollection({ collectionType: 1, collectionData: 'data' })
* ```
*/
addCollection(params: V2NIMAddCollectionParams): Promise<V2NIMCollection>;
/**
* 移除相关收藏
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param collections 需要移除的相关收藏
*
* @example
* ```ts
* const removedCount = await nim.V2NIMMessageService.removeCollections([collection])
* ```
*/
removeCollections(collections: V2NIMCollection[]): Promise<number>;
/**
* 更新收藏扩展字段
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param collection 需要更新的收藏信息
* @param serverExtension 扩展字段. 默认值为空字符串
*
* @example
* ```ts
* const updatedCollection = await nim.V2NIMMessageService.updateCollectionExtension(collection, 'newExtension')
* ```
*/
updateCollectionExtension(collection: V2NIMCollection, serverExtension?: string): Promise<V2NIMCollection>;
/**
* 按条件分页获取收藏信息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param option 查询参数
* @deprecated 该方法即将废弃,请使用 {@link V2NIMMessageExtendUtil.getCollectionListExByOption | V2NIMMessageExtendUtil.getCollectionListExByOption}
*
* @example
* ```ts
* const collections = await nim.V2NIMMessageService.getCollectionListByOption({ limit: 20 })
* ```
*/
getCollectionListByOption(option: V2NIMCollectionOption): Promise<V2NIMCollection[]>;
/**
* 按条件分页获取收藏信息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param option 查询参数
*
* @example
* ```ts
* const { collections, cursor } = await nim.V2NIMMessageService.getCollectionListExByOption({ limit: 20 })
* ```
*/
getCollectionListExByOption(option: V2NIMCollectionOption): Promise<V2NIMCollectionListResult>;
/**
* 语音转文本
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param params 参数
*
* @example
* ```ts
* const text = await nim.V2NIMMessageService.voiceToText({ voiceUrl, voiceDuration })
* ```
*/
voiceToText(params: V2NIMVoiceToTextParams): Promise<string>;
/**
* 检索云端的消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param searchParams 检索参数
*
* @example
* ```ts
* const messages = await nim.V2NIMMessageService.searchCloudMessages({ keyword: '搜索关键词' })
* ```
*/
searchCloudMessages(searchParams: V2NIMMessageSearchParams): Promise<V2NIMMessage[]>;
/**
* 检索云端的消息
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @param searchParams 检索参数
*
* @example
* ```ts
* const { messages, cursor } = await nim.V2NIMMessageService.searchCloudMessagesEx({ keyword: '搜索关键词' })
* ```
*/
searchCloudMessagesEx(searchParams: V2NIMMessageSearchExParams): Promise<V2NIMMessageSearchResult>;
/**
* 查询 thread 聊天云端消息列表
*
* 注: 使用 dist/esm 产物时,需要动态引入 {@link V2NIMMessageExtendUtil | V2NIMMessageExtendUtil} 后使用
*
* @example
* ```ts
* const result = await nim.V2NIMMessageService.getThreadMessageList({ messageRefer: threadRootMessage })
* ```
*/
getThreadMessageList(option: V2NIMThreadMessageListOption): Promise<V2NIMThreadMessageListResult>;
/**
* 设置消息过滤器. v10.9.0 开始支持
*
* 机制: 在收消息,拉取消息时, 加的一道过滤函数.
*
* 1. 过滤函数结果返回布尔值. 默认为 false 代表不过滤. 而 true 代表要过滤此消息
* 2. 收消息场景, 若过滤了该消息, 将不触发收消息的事件, 也不会触发本地会话与群通知的相关计算.
* 3. 拉取消息场景, 若过滤了该消息, 那拉取的返回结果不会包含被过滤的内容.
* 4. 由于消息过滤器对每一条消息都会生效处理, 处于性能考虑, 所以不推荐在过滤器做重型的逻辑操作.
*
* 注: 这道机制是端测行为, 会对云端会话模块产生不可预知的影响, 只建议这个机制只能与本地会话模块配合使用.
*
* @param filter 过滤器, 只允许设置一个. 若传入为 null 或者 undefined 则将移除消息过滤器
*
* @example
* ```ts
* nim.V2NIMMessageService.setMessageFilter((message) => message.messageType === 100)
* ```
*/
setMessageFilter(filter: V2NIMMessageFilter | null | void): void;
}
/**
* 消息构造类
*
* 注: 使用 dist/esm 产物时,只要引入了 {@link V2NIMMessageService | V2NIMMessageService}, 这个构造类就同样被包含了, 不需要再次注册.
*
* @example
* ```
* const message = nim.V2NIMMessageCreator.createTextMessage('hello world')
* ```
*/
export declare class V2NIMMessageCreator {
/**
* 构造文本消息
*
* @param text 文本内容. 不允许为空字符串
*
* @example
* ```
* const message = nim.V2NIMMessageCreator.createTextMessage('hello world')
* ```
*/
createTextMessage(text: string): V2NIMMessage;
/**
* 构造图片消息
*
* 注: 使用 dist/esm 产物时,需要额外引入 {@link V2NIMStorageService | V2NIMStorageService}, 才能使用上传能力
*
* @param imageObj 图片文件. 浏览器环境请传入 File 对象, 小程序及 uniapp 环境请输入临时文件路径
* @param name 文件显示名称
* @param sceneName 场景名
* @param width 图片宽度.
* @param height 图片高度.
*/
createImageMessage(imageObj: string | File, name?: string, sceneName?: string, width?: number, height?: number): V2NIMMessage;
/**
* 构造语音消息
*
* 注: 使用 dist/esm 产物时,需要额外引入 {@link V2NIMStorageService | V2NIMStorageService}, 才能使用上传能力
*
* @param audioObj 语音文件. 浏览器环境请传入 File 对象, 小程序及 uniapp 环境请输入临时文件路径
* @param name 文件显示名称
* @param sceneName 场景名
* @param duration 音频时长
*/
createAudioMessage(audioObj: string | File, name?: string, sceneName?: string, duration?: number): V2NIMMessage;
/**
* 构造视频消息
*
* 注: 使用 dist/esm 产物时,需要额外引入 {@link V2NIMStorageService | V2NIMStorageService}, 才能使用上传能力
*
* @param videoObj 视频文件. 浏览器环境请传入 File 对象, 小程序及 uniapp 环境请输入临时文件路径
* @param name 文件显示名称
* @param sceneName 场景名
* @param duration 音频时长
* @param width 视频宽度
* @param height 视频高度
*/
createVideoMessage(videoObj: string | File, name?: string, sceneName?: string, duration?: number, width?: number, height?: number): V2NIMMessage;
/**
* 构造文件消息
*
* 注: 使用 dist/esm 产物时,需要额外引入 {@link V2NIMStorageService | V2NIMStorageService}, 才能使用上传能力
*
* @param fileObj 文件. 浏览器环境请传入 File 对象, 小程序及 uniapp 环境请输入临时文件路径
* @param name 文件显示名称
* @param sceneName 场景名
*/
createFileMessage(fileObj: string | File, name?: string, sceneName?: string): V2NIMMessage;
/**
* 构造地理位置消息
*
* @param latitude 纬度
* @param longitude 经度
* @param address 详细位置信息
*/
createLocationMessage(latitude: number, longitude: number, address: string): V2NIMMessage;
/**
* 构造自定义消息消息
*
* @param text 文本
* @param rawAttachment 自定义的附件内容
*/
createCustomMessage(text: string, rawAttachment: string): V2NIMMessage;
/**
* 构造自定义消息消息. v10.5.0+ 支持
*
* @param attachment 自定义附件, 切记一定要有 raw 属性, 且是其他属性的序列化字符串. 示例 { raw: '{"test":123}', test: 123 }
* @param subType 消息的子类型, 传入的值大于等于 0
*/
createCustomMessageWithAttachment(attachment: V2NIMMessageCustomAttachment, subType?: number): V2NIMMessage;
/**
* 构造话单消息
* @param type 话单类型, 业务自定义
* @param channelId 话单频道ID
* @param status 通话状态,业务自定义状态
* @param durations 通话成员时长列表
* @param text 话单描述
*/
createCallMessage(type: number, channelId: string, status: number, durations: V2NIMMessageCallDuration[], text?: string): V2NIMMessage;
/**
* 构造转发消息,消息内容与原消息一样
*
* @param message 需要转发的消息体
*/
createForwardMessage(message: V2NIMMessage): V2NIMMessage | null;
/**
* 构造提示消息
*
* @param text 提示文本
*/
createTipsMessage(text: string): V2NIMMessage;
}
/**
* 消息附件构造类
*
* 注: 使用 dist/esm 产物时,只要引入了 {@link V2NIMMessageService | V2NIMMessageService}, 这个构造类就同样被包含了, 不需要再次注册.
*
* @example
* ```
* const messageAttachment = nim.V2NIMMessageAttachmentCreator.createCustomMessageAttachment('{"a": 123}')
* ```
*/
export declare class V2NIMMessageAttachmentCreator {
/**
* 构造地理位置消息的附件
* @param latitude 纬度.
* @param longitude 经度
* @param address 详细位置信息. 允许传入空字符串
*/
createLocationMessageAttachment(latitude: number, longitude: number, address: string): V2NIMMessageLocationAttachment;
/**
* 构造自定义消息的附件
* @param rawAttachment 需要发送的附件内容
*/
createCustomMessageAttachment(rawAttachment: string): V2NIMMessageAttachment;
}
/**
* 客户端本地反垃圾工具类
*
* 注: 使用 dist/esm 产物时,只要引入了 {@link V2NIMMessageService | V2NIMMessageService}, 这个构造类就同样被包含了, 不需要再次注册.
*
* @example
* ```
* const result = nim.V2NIMClientAntispamUtil.checkTextAntispam('hujintao', '***')
* ```
*/
export interface V2NIMClientAntispamUtil {
/**
* 对输入的文本进行本地反垃圾检查
*
* @param text 文本内容. 不允许为空字符串
*
* @example
* ```
* const result = nim.V2NIMClientAntispamUtil.checkTextAntispam('hujintao', '***')
* ```
*/
checkTextAntispam(text: string, replace?: string): V2NIMClientAntispamResult;
}
/**
* 消息更新相关参数
*
* 可更新字段:subType, text, attachment, serverExtension
*/
export declare type V2NIMModifyMessageParams = {
/**
* 消息子类型.
*/
subType?: number;
/**
* 消息内容
*/
text?: string;
/**
* 消息附属附件.
*
* 注: 仅允许定位、tip、自定义消息去更新附件信息
*/
attachment?: V2NIMMessageAttachment;
/**
* 消息服务端扩展. 请使用 JSON 序列化的字符串
*/
serverExtension?: string;
/**
* 反垃圾相关配置
*/
antispamConfig?: V2NIMMessageAntispamConfig;
/**
* 路由抄送相关配置
*/
routeConfig?: V2NIMMessageRouteConfig;
/**
* 推送相关配置
*/
pushConfig?: V2NIMMessagePushConfig;
/**
* 是否启用本地反垃圾. 默认 false
*
* - 只针对文本消息生效
* - 发送消息时候,如果为 true,则先本地反垃圾检测,检测后返回 V2NIMClientAntispamOperateType
*
* 本地反垃圾有四种结果:
* - 直接发送消息
* - 发送替换后的文本
* - 消息发送失败,返回本地错误码
* - 消息正常发送,由服务器拦截
*/
clientAntispamEnabled?: boolean;
/**
* 反垃圾命中后的替换文本
*/
clientAntispamReplace?: string;
};
export declare type V2NIMMessageAttachment = V2NIMMessageAttachmentBase | V2NIMMessageFileAttachment | V2NIMMessageImageAttachment | V2NIMMessageAudioAttachment | V2NIMMessageVideoAttachment | V2NIMMessageLocationAttachment | V2NIMMessageNotificationAttachment | V2NIMMessageCallAttachment | V2NIMMessageCustomAttachment;
export declare type V2NIMMessage = {
/**
* 客户端消息ID。可以根据该字段确定消息是否重复
*/
messageClientId: string;
/**
* 发送客户端类型
*/
fromClientType?: V2NIMLoginClientType;
/**
* 服务器消息ID
*
* - 消息发送成功后,由服务器更新
* - 发送成功之前只有客户端消息ID
*/
messageServerId: string;
/**
* 消息创建时间,由服务器返回。在发送成功之前,消息创建时间为发送者本地时间
*/
createTime: number;
/**
* 消息发送者账号
*/
senderId: string;
/**
* 消息接收者账号
*/
receiverId: string;
/**
* 消息所属会话类型
*
* 1: p2p
* 2: team
* 3: superTeam
*/
conversationType: V2NIMConversationType;
/**
* @computed
*
* 会话 ID
*/
conversationId: string;
/**
* @computed
*
* 消息发送者是否为自己
*/
isSelf: boolean;
/**
*
* 消息是否已删除
*/
isDelete?: boolean;
/**
* 附件上传状态
*/
attachmentUploadState?: V2NIMMessageAttachmentUploadState;
/**
* 消息发送状态. 未知(初始状态), 发送成功,发送失败,发送中。
*/
sendingState: V2NIMMessageSendingState;
/**
* 消息类型
*/
messageType: V2NIMMessageType;
/**
* 消息子类型
*/
subType?: number;
/**
* 消息内容
*/
text?: string;
/**
* 消息附属附件
*
* 注1: 附件的父级定义是 V2NIMMessageAttachmentBase, 其中包含了一个必定存在的 raw 属性
*
* 注2: 根据 {@link V2NIMMessage.messageType | V2NIMMessage.messageType} 的类型, 附件属性的定义类型也有区别: <br/>
* 1. 文件消息: V2NIMMessageFileAttachment
* 2. 图片消息: V2NIMMessageImageAttachment
* 3. 语音消息: V2NIMMessageAudioAttachment
* 4. 视频消息: V2NIMMessageVideoAttachment
* 5. 位置消息: V2NIMMessageLocationAttachment
* 6. 通知消息: V2NIMMessageNotificationAttachment
* 7. 话单消息: V2NIMMessageCallAttachment
*
* 可以使用 as 类型断言, 或者类型保护处理联合类型时进行类型细化, 举个例子
* @example
* ```js
* function testMessageAttachmentType(message: V2NIMMessage): void {
* if ('url' in message.attachment) {
* if ('width' in message.attachment) {
* if ('duration' in message.attachment) {
* // message.attachment 到这里就会自动推导出是 V2NIMMessageVideoAttachment 类型
* }
* }
* }
* }
* ```
*/
attachment?: V2NIMMessageAttachment;
/**
* 消息服务端扩展
*/
serverExtension?: string;
/**
* 第三方回调扩展字段
*/
callbackExtension?: string;
/**
* 消息的更新时间. 默认 0
*/
modifyTime?: number;
/**
* 该消息更新者账号
*/
modifyAccountId?: string;
/**
* 消息相关配置
*/
messageConfig?: V2NIMMessageConfig;
/**
* 推送相关配置
*/
pushConfig?: V2NIMMessagePushConfig;
/**
* 消息路由配置
*/
routeConfig?: V2NIMMessageRouteConfig;
/**
* 反垃圾相关配置
*/
antispamConfig?: V2NIMMessageAntispamConfig;
/**
* 机器人相关配置
*/
robotConfig?: V2NIMMessageRobotConfig;
/**
* Thread 消息引用
*
* 注: 仅回参时存在, 若作为发送接口的入参使用则无效
*/
threadRoot?: V2NIMMessageRefer;
/**
* 回复消息引用
*/
threadReply?: V2NIMMessageRefer;
/**
* 消息的状态相关
*
* 注: 仅回参时存在, 若作为发送接口的入参则无效
*/
messageStatus: V2NIMMessageStatus;
/**
* AI 数字人相关
*/
aiConfig?: V2NIMMessageAIConfig;
/**
* 流式输出消息相关
*/
streamConfig?: V2NIMMessageStreamConfig;
/**
* 消息来源
*/
messageSource?: V2NIMMessageSource;
/**
* Topic 引用
*
* 由协议层 `topicId(68)` 字段解析而来,格式 `${topicId}|${createTime}`,
* SDK 自动解析为结构化 `V2NIMTopicRefer` 对象挂载于此。
*
* - `topicRefer != null`:表示当前消息是 Topic 消息
* - `topicRefer == null`:表示当前消息不是 Topic 消息
*
* 如需完整 Topic 信息,通过 `V2NIMTopicService.getTopicByRefer(topicRefer)` 查询。
*
* 注:收发消息均可能携带此字段;发送时由 V2NIMTopicService 负责写入协议层 topicId(68)
*/
topicRefer?: V2NIMTopicRefer;
};
export declare type V2NIMMessageStatus = {
/**
* 消息发送错误码
*
* 注: 包括如下情况是消息发送成功了, 但是会在这处出现错误码
*
* 1,本地命中发垃圾拦截
* 2,本地发送超时
* 3,服务器AI响应消息由于反垃圾失败返回
* 4,服务器AI响应消息由于三方回调拦截返回
* 5,4两种情况服务器默认下发消息类型为tips消息,同时下发消息错误码, 由端上拦截处理上抛界面
* 6,被对方拉黑发送失败
*/
errorCode: number;
};
/**
* 发送消息时,与数字人相关的参数
*/
export declare type V2NIMMessageAIConfigParams = {
/**
* AI 数字人的账号
*/
accountId: string;
/**
* 请求大模型的内容.
*/
content?: V2NIMAIModelCallContent;
/**
* 上下文内容
*
* 注: 当前只支持文本消息
*/
messages?: V2NIMAIModelCallMessage[];
/**
* 提示词变量占位符替换. JSON 序列化的字符串
*
* 注: 如果 V2NIMAIUser 中的 modelConfig.promptKeys 存在且数组长度不为 0 ,则必填.
*/
promptVariables?: string;
/**
* 请求接口模型相关参数配置
*/
modelConfigParams?: V2NIMAIModelConfigParams;
/**
* 是否是流式响应,默认 false
*/
aiStream?: boolean;
};
/**
* 数字人流式消息状态
*/
export declare const enum V2NIMMessageAIStreamStatus {
/**
* 流式过程中(本地状态,其他为服务器状态)
*/
NIM_MESSAGE_AI_STREAM_STATUS_STREAMING = -1,
/**
* 非流式状态
*/
NIM_MESSAGE_AI_STREAM_STATUS_NONE = 0,
/**
* 占位
*/
NIM_MESSAGE_AI_STREAM_STATUS_PLACEHOLDER = 1,
/**
* 停止输出
*/
NIM_MESSAGE_AI_STREAM_STATUS_CANCEL = 2,
/**
* 停止并更新
*/
NIM_MESSAGE_AI_STREAM_STATUS_UPDATE = 3,
/**
* 输出完成
*/
NIM_MESSAGE_AI_STREAM_STATUS_COMPLETE = 4,
/**
* 服务器异常终止
*/
NIM_MESSAGE_AI_STREAM_STATUS_EXCEPTION = 5
}
/**
* 流式消息分片信息
*/
export declare type V2NIMMessageAIStreamChunk = {
/**
* 数字人流式回复分片文本
*/
content: string;
/**
* 数字人流式消息时间,即占位消息时间
*/
messageTime: number;
/**
* 数字人流式消息当前分片时间
* 注: chunkTime >= messageTime
*/
chunkTime: number;
/**
* 类型,当前仅支持0表示文本
*/
type: number;
/**
* 分片序号,从0开始
*/
index: number;
};
/**
* 消息体中的 AI 数字人相关配置
*/
export declare type V2NIMMessageAIConfig = {
/**
* AI 数字人的账号
*/
accountId: string;
/**
* 该 AI 消息的询问和应答标识
*
* 0 表示普通消息<br/>
* 1 表示是一个艾特数字人的消息<br/>
* 2 表示是数字人响应艾特的消息
*/
aiStatus?: V2NIMMessageAIStatus;
/**
* 数字人回复内容的引用资源列表
*/
aiRAGs?: V2NIMAIRAGInfo[];
/**
* @deprecated please use {@link V2NIMMessage.streamConfig | V2NIMMessage.streamConfig}
*
* 是否是流式响应,默认false
*/
aiStream: boolean;
/**
* @deprecated please use {@link V2NIMMessage.streamConfig | V2NIMMessage.streamConfig}
*
* 数字人流式消息状态
*/
aiStreamStatus: V2NIMMessageAIStreamStatus;
/**
* @deprecated please use {@link V2NIMMessage.streamConfig | V2NIMMessage.streamConfig}
*
* 数字人流式消息最近一个分片
*
* 注意:流式过程中的消息text是将接收到的分片组装好之后的结果
*/
aiStreamLastChunk?: V2NIMMessageAIStreamChunk;
};
/**
* 停止流式输出操作类型
*/
export declare const enum V2NIMMessageAIStreamStopOpType {
/**
* 停止输出保持现状
*/
V2NIM_MESSAGE_AI_STREAM_STOP_OP_DEFAULT = 0,
/**
* 停止并撤回消息
*/
V2NIM_MESSAGE_AI_STREAM_STOP_OP_REVOKE = 1,
/**
* 停止并更新消息内容
*/
V2NIM_MESSAGE_AI_STREAM_STOP_OP_UPDATE = 2
}
/**
* 流式消息更新内容
*/
export declare type V2NIMMessageAIStreamUpdateContent = {
/**
* 更新的文本内容
*/
msg: string;
/**
* 类型, 暂时只有 0, 代表文本,预留扩展能力
*/
type: number;
};
/**
* 停止数字人流式输出配置参数
*/
export declare type V2NIMMessageAIStreamStopParams = {
/**
* 停止流式消息的操作类型
*/
operationType: V2NIMMessageAIStreamStopOpType;
/**
* 更新的消息内容,仅当operationType == V2NIM_MESSAGE_AI_STREAM_STOP_OP_UPDATE有效
*/
updateContent?: string;
};
/**
* 重新输出数字人消息操作类型
*/
export declare const enum V2NIMMessageAIRegenOpType {
/**
* 更新消息不会生成新消息
*/
V2NIM_MESSAGE_AI_REGEN_OP_UPDATE = 1,
/**
* 生成一条新消息
*/
V2NIM_MESSAGE_AI_REGEN_OP_NEW = 2
}
/**
* 重新输出数字人消息配置参数
*/
export declare type V2NIMMessageAIRegenParams = {
/**
* 重新输出数字人消息操作类型
*/
operationType: V2NIMMessageAIRegenOpType;
};
export declare const enum V2NIMMessageAIStatus {
/**
* 未知. 表示普通消息, 非 AI 消息
*/
V2NIM_MESSAGE_AI_STATUS_UNKNOW = 0,
/**
* 表示是一个艾特数字人的消息
*/
V2NIM_MESSAGE_AI_STATUS_AT = 1,
/**
* 表示是数字人响应艾特的消息
*/
V2NIM_MESSAGE_AI_STATUS_RESPONSE = 2
}
/**
* 消息模块的事件定义
*
* 注: 使用 dist/esm 产物时,需要动态引入 V2NIMMessageService 后使用
*
* @example
* ```
* import { NIM, V2NIMMessageService } from 'nim-web-sdk-ng/dist/esm/nim'
* NIM.registerService(V2NIMMessageService, 'V2NIMMessageService')
* ```
*/
export interface V2NIMMessageListener {
/**
* 本端发送消息状态回调。
*
* 开发者通过监听 sendingState, 以及 attachmentUploadState 状态,可以实现消息发送状态的监听
*/
onSendMessage: [message: V2NIMMessage];
/**
* 收到新消息
*/
onReceiveMessages: [messages: V2NIMMessage[]];
/**
* 收到点对点消息的已读回执
*/
onReceiveP2PMessageReadReceipts: [readReceipts: V2NIMP2PMessageReadReceipt[]];
/**
* 收到高级群消息的已读回执
*/
onReceiveTeamMessageReadReceipts: [readReceipts: V2NIMTeamMessageReadReceipt[]];
/**
* 收到消息撤回回调
*/
onMessageRevokeNotifications: [notification: V2NIMMessageRevokeNotification[]];
/**
* 收到消息被删除通知
*/
onMessageDeletedNotifications: [notification: V2NIMMessageDeletedNotification[]];
/**
* 清空会话历史消息通知
*/
onClearHistoryNotifications: [notification: V2NIMClearHistoryNotification[]];
/**
* 收到消息 pin 状态更新
*/
onMessagePinNotification: [notification: V2NIMMessagePinNotification];
/**
* 收到消息快捷评论更新
*/
onMessageQuickCommentNotification: [notification: V2NIMMessageQuickCommentNotification];
/**
* 收到消息更新事件
*
* 1. 收到更新消息在线同步通知
* 2. 收到更新消息多端同步通知
* 3. 收到更新消息漫游通知
*/
onReceiveMessagesModified: [messages: V2NIMMessage[]];
}
export declare type V2NIMMessageServiceConfig = {
/**
* v1 兼容模式. 默认为 true
*/
compatibleWithV1?: boolean;
};
export declare type V2NIMMessageConfig = {
/**
* 是否需要消息(群消息)已读回执。默认为 false
*/
readReceiptEnabled?: boolean;
/**
* 是否需要在服务端保存历史消息。默认为 true
*/
historyEnabled?: boolean;
/**
* 是否需要漫游消息。默认为 true
*/
roamingEnabled?: boolean;
/**
* 是否需要发送方多端在线同步消息。默认为 true
*/
onlineSyncEnabled?: boolean;
/**
* 是否需要存离线消息。默认为 true
*/
offlineEnabled?: boolean;
/**
* 是否需要计算会话的最后一条消息属性。默认为 true
*/
lastMessageUpdateEnabled?: boolean;
/**
* 是否需要计算未读数。默认为 true
*/
unreadEnabled?: boolean;
};
export interface V2NIMSendMessageParams {
messageConfig?: V2NIMMessageConfig;
routeConfig?: V2NIMMessageRouteConfig;
pushConfig?: V2NIMMessagePushConfig;
antispamConfig?: V2NIMMessageAntispamConfig;
robotConfig?: V2NIMMessageRobotConfig;
/**
* 请求大模型的相关参数
*/
aiConfig?: V2NIMMessageAIConfigParams;
/**
* 群定向消息相关配置
*/
targetConfig?: V2NIMMessageTargetConfig;
/**
* 是否启用本地反垃圾. 默认 false
*
* - 只针对文本消息生效
* - 发送消息时候,如果为 true,则先本地反垃圾检测,检测后返回 V2NIMClientAntispamOperateType
*
* 本地反垃圾有四种结果:
* - 直接发送消息
* - 发送替换后的文本
* - 消息发送失败,返回本地错误码
* - 消息正常发送,由服务器拦截
*/
clientAntispamEnabled?: boolean;
/**
* 反垃圾命中后的替换文本
*/
clientAntispamReplace?: string;
}
export interface V2NIMMessageRouteConfig {
/**
* 是否需要路由消息(抄送)。默认为 true
*/
routeEnabled?: boolean;
/**
* 环境变量,用于指向不同的抄送,第三方回调等配置
*/
routeEnvironment?: string;
}
export interface V2NIMMessagePushConfig {
/**
* 是否需要推送消息。默认为 true
*/
pushEnabled?: boolean;
/**
* 是否需要推送消息发送者昵称。默认 true
*/
pushNickEnabled?: boolean;
/**
* 推送文案
*/
pushContent?: string;
/**
* 推送自定义 pushPayload
*/
pushPayload?: string;
/**
* 是否需要强制推送,忽略用户消息提醒相关设置。该设置仅在群聊时有效。默认为 false
*/
forcePush?: boolean;
/**
* 强制推送文案。该设置仅在群聊时有效
*/
forcePushContent?: string;
/**
* 强制推送目标账号列表。该设置仅在群聊时有效
*
* 注: 不存在则代表着强推给所有人. 空数组代表没有强推目标. 数组有值代表强推给指定的若干个账号
*/
forcePushAccountIds?: string[];
}
export interface V2NIMMessageAntispamConfig {
/**
* 指定消息是否需要经过安全通。默认为 true
*
* 对于已开通安全通的用户有效,默认消息都会走安全通,如果对单条消息设置 enable 为 false,则此消息不会走安全通
*/
antispamEnabled?: boolean;
/**
* 指定易盾业务id
*/
antispamBusinessId?: string;
/**
* 自定义消息中需要反垃圾的内容,仅当消息类型为自定义消息时有效
*
* 内容必须为 json 格式,格式如下:
* ```js
* {
* // 1 文本 2 图片 3 视频
* "type": 1
* // 文本内容;图片地址;视频地址
* "data": ""
* }
* ````
*/
antispamCustomMessage?: string;
/**
* 易盾反作弊,辅助检测数据,json格式
*/
antispamCheating?: string;
/**
* 易盾反垃圾,增强检测数据,json格式
*/
antispamExtension?: string;
}
export interface V2NIMMessageRobotConfig {
/**
* 机器人账号,对应控制台提前设置好的机器人
* 仅在群聊中有效,点对点聊天室中该字段会被忽略
*/
accountId?: string;
/**
* 机器人消息话题
*/
topic?: string;
/**
* 机器人具体功能,用户可以自定义输入
*/
function?: string;
/**
* 机器人自定义内容
*/
customContent?: string;
}
export interface V2NIMMessageTargetConfig {
/**
* 定向消息接收者账号列表
*/
receiverIds: string[];
/**
* true 表示接收者为 receiverIds 内的成员,false 表示除 receiverIds 的其它成员接收。超级群场景下 inclusive 必须为 true。
*/
inclusive: boolean;
/**
* 新成员是否可以查看该定向消息, 默认为 false
*/
newMemberVisible?: boolean;
}
export interface V2NIMMessageRefer {
/**
* 发送方账号 id
*/
senderId: string;
/**
* 接收方账号 id
*/
receiverId: string;
/**
* 客户端消息 id
*/
messageClientId: string;
/**
* 服务器消息 id
*/
messageServerId: string;
/**
* 创建时间
*/
createTime: number;
/**
* 会话类型
*/
conversationType: V2NIMConversationType;
/**
* @computed
* 会话 ID
*/
conversationId: string;
}
/**
* 发送消息的返回值
*/
export interface V2NIMSendMessageResult {
message: V2NIMMessage;
/**
* 第三方回调扩展字段,透传字段
*/
callbackExtension?: string;
/**
* 反垃圾返回的结果
*/
antispamResult?: string;
/**
* 客户端反垃圾结果
*/
clientAntispamResult?: V2NIMClientAntispamResult;
}
/**
* 消息检索单条会话的返回结果
*/
export interface V2NIMMessageSearchItem {
/** 会话 ID */
conversationId: string;
/** 消息列表 */
messages: V2NIMMessage[];
/** 消息数量 */
count: number;
}
/**
* 检索返回结果
*/
export interface V2NIMMessageSearchResult {
/**
* 满足检索条件的所有消息数量
*/
count: number;
/**
* 检索到的消息列表
*/
items: V2NIMMessageSearchItem[];
/**
* 下一页的 token
*/
nextPageToken?: string;
/**
* 是否还有下一页, 10.9.0 新增
*/
hasMore: boolean;
}
export declare const enum V2NIMMessageType {
/** 未知,不合法 */
V2NIM_MESSAGE_TYPE_INVALID = -1,
/** 0 文本 */
V2NIM_MESSAGE_TYPE_TEXT = 0,
/** 1 图片 */
V2NIM_MESSAGE_TYPE_IMAGE = 1,
/** 2 语音 */
V2NIM_MESSAGE_TYPE_AUDIO = 2,
/** 3 视频 */
V2NIM_MESSAGE_TYPE_VIDEO = 3,
/** 4 位置 */
V2NIM_MESSAGE_TYPE_LOCATION = 4,
/** 5 通知 */
V2NIM_MESSAGE_TYPE_NOTIFICATION = 5,
/** 6 文件 */
V2NIM_MESSAGE_TYPE_FILE = 6,
/** 7 音视频通话 */
V2NIM_MESSAGE_TYPE_AVCHAT = 7,
/** 10 提示 */
V2NIM_MESSAGE_TYPE_TIPS = 10,
/** 11 机器人 */
V2NIM_MESSAGE_TYPE_ROBOT = 11,
/** 12 话单 */
V2NIM_MESSAGE_TYPE_CALL = 12,
/** 100 自定义 */
V2NIM_MESSAGE_TYPE_CUSTOM = 100
}
export declare const enum V2NIMSearchKeywordMatchType {
/** 或匹配 */
V2NIM_SEARCH_KEYWORD_MATCH_TYPE_OR = 0,
/** 且匹配 */
V2NIM_SEARCH_KEYWORD_MATCH_TYPE_AND = 1
}
export declare const enum V2NIMSearchDirection {
/** 表示时间从新到老查询 */
V2NIM_SEARCH_DIRECTION_BACKWARD = 0,
/** 表示时间从老到新查询 */
V2NIM_SEARCH_DIRECTION_FORWARD = 1
}
export declare type V2NIMGenericFileAttachment = V2NIMMessageFileAttachment | V2NIMMessageImageAttachment | V2NIMMessageAudioAttachment | V2NIMMessageVideoAttachment;
/**
* 消息附件的父类定义
*/
export interface V2NIMMessageAttachmentBase {
/**
* 原始的附件内容。只有自定义消息类型的附件才会有
*
* 注: 一般是一个 JSON 序列化后的字符串, 但是 SDK 不会校验它.
*/
raw?: string;
}
/**
* 文件附件属性
*/
export interface V2NIMMessageFileAttachment extends V2NIMMessageAttachmentBase {
/**
* 浏览器上传时,得到 DOM 指向的 File 对象。该参数和 path 二选一
*/
file?: File;
/**
* 小程序上传时,得到的临时文件路径。该参数和 file 二选一
*/
path?: string;
/**
* 文件大小
*/
size: number;
/**
* 文件上传后的 URL 路径
*/
url: string;
/**
* 文件 md5.
*
* 注: 仅在浏览器环境支持 File 对象时有效
*/
md5?: string;
/**
* 文件扩展名
*/
ext: string;
/**
* 文件显示名称
*/
name: string;
/**
* 文件存储场景
*/
sceneName: string;
/**
* 附件上传状态
*/
uploadState: V2NIMMessageAttachmentUploadState;
}
/**
* 图片附件属性
*/
export interface V2NIMMessageImageAttachment extends V2NIMMessageFileAttachment {
/**
* 图片宽度
*/
width: number;
/**
* 图片高度
*/
height: number;
}
/**
* 语音附件属性
*/
export interface V2NIMMessageAudioAttachment extends V2NIMMessageFileAttachment {
/**
* 音频时长
*/
duration: number;
}
/**
* 视频附件属性
*/
export interface V2NIMMessageVideoAttachment extends V2NIMMessageFileAttachment {
/**
* 视频时长
*/
duration: number;
/**
* 视频宽度
*/
width: number;
/**
* 视频高度
*/
height: number;
}
/**
* 位置附件属性
*/
export interface V2NIMMessageLocationAttachment extends V2NIMMessageAttachmentBase {
/**
* 纬度
*/
latitude: number;
/**
* 经度
*/
longitude: number;
/**
* 详细位置信息
*/
address: string;
}
export interface V2NIMMessageCallAttachment extends V2NIMMessageAttachmentBase {
/**
* 话单类型, 业务自定义
*/
type: number;
/**
* 话单频道ID
*/
channelId: string;
/**
* 通话状态,业务自定义状态
*/
status: number;
/**
* 通话成员时长列表
*/
durations: V2NIMMessageCallDuration[];
/**
* 话单描述
*/
text: string;
}
export interface V2NIMMessageCustomAttachment extends V2NIMMessageAttachmentBase {
raw: string;
}
/**
* 消息通知中,群信息变更项
*/
declare type V2NIMUpdatedTeamInfo = V2NIMUpdateTeamInfoParams & {
/**
* 客户自定义扩展
*
* 注: 这个字段仅由 openApi 发请求设置. 而 SDK 只是透传这个字段.
*/
customerExtension?: string;
};
export interface V2NIMMessageNotificationAttachment extends V2NIMMessageAttachmentBase {
/**
* 通知类型
*/
type: V2NIMMessageNotificationType;
/**
* 扩展字段
*/
serverExtension?: string;
/**
* targetIds: 被操作者 id 列表
*/
targetIds?: string[];
/**
* 群成员是否被禁言
*/
chatBanned?: boolean;
/**
* 消息通知中,群信息变更项
*/
updatedTeamInfo?: V2NIMUpdatedTeamInfo;
}
export declare const enum V2NIMMessageNotificationType {
/** 未定义通知类型 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_UNDEFINED = -1,
/** 群拉人 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_INVITE = 0,
/** 群踢人 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_KICK = 1,
/** 退出群 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_LEAVE = 2,
/** 更新群信息 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_UPDATE_TINFO = 3,
/** 群解散 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_DISMISS = 4,
/** 群申请加入通过 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_APPLY_PASS = 5,
/** 移交群主 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_OWNER_TRANSFER = 6,
/** 添加管理员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_ADD_MANAGER = 7,
/** 移除管理员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_REMOVE_MANAGER = 8,
/** 接受邀请进群 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_INVITE_ACCEPT = 9,
/** 禁言群成员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_TEAM_BANNED_TEAM_MEMBER = 10,
/** 群拉人 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_INVITE = 401,
/** 群踢人 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_KICK = 402,
/** 退出群 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_LEAVE = 403,
/** 更新群信息 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_UPDATE_TINFO = 404,
/** 解散群 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_DISMISS = 405,
/** 群申请加入通过 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_APPLY_PASS = 410,
/** 移交群主 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_OWNER_TRANSFER = 406,
/** 添加管理员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_ADD_MANAGER = 407,
/** 移除管理员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_REMOVE_MANAGER = 408,
/** 接受邀请进群 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_INVITE_ACCEPT = 411,
/** 禁言群成员 */
V2NIM_MESSAGE_NOTIFICATION_TYPE_SUPER_TEAM_BANNED_TEAM_MEMBER = 409
}
export declare const enum V2NIMMessageAttachmen