跳到主要内容

发送群 @ 消息

在群组中可发送群 @ 消息。

构造 @ 消息

待发送的消息内容,可以是如 RongIMLib.TextMessage 般的 IMLib 内置消息实例,也可以是通过 RongIMLib.registerMessageType() 实现的自定义消息实例。

const details = {
content: '我是一条文字信息',
mentionedInfo: {
type: 1, //1: @ 所有人 2: @ 指定用户
userIdList: ['user1'],//被 @ 的用户 Id 列表
mentionedContent: '有人@你'//携带扩展信息,例如 `有人@你`
}
}
const message = new RongIMLib.TextMessage(details)
参数类型必填说明
contentString文本内容
mentionedInfoObject@ 信息详情。
mentionedInfo.typeNumber@ 消息类型 1: @ 所有人 2: @ 指定用户
mentionedInfo.userIdListString []被 @ 的用户 Id 列表
mentionedInfo.mentionedContentString推送通知内容,例如 '有人@你'。@消息携带的 mentionedContent 优先级最高,会覆盖所有默认或自定义的 pushContent 数据。

发送 @ 消息

调用 sendMessage 在群组中发送 @ 消息,请务必设置 isMentionedtrue

const details = {
content: '我是一条文字信息',
mentionedInfo: {
type: 1,
userIdList: ['user1'],
mentionedContent: '有人@你'
}
}
const message = new RongIMLib.TextMessage(details)
//发送 @ 消息,只当 conversationType 值为 `ConversationType.GROUP` 时有效
const conversation = {
conversationType: RongIMLib.ConversationType.GROUP,
targetId: '目标ID'
}
const options = {
isMentioned: true
}
RongIMLib.sendMessage(conversation, message, options).then(res => {
if(res.code === 0){
// 发送群@消息成功
console.log(res.data)
} else {
console.log(res.code, res.msg);
}
})

sendMessage 方法具有以下参数:

  • conversation: - 消息投送目标会话,API 参考 IConversationOption

  • message:待发送的消息内容,可以是如 RongIMLib.TextMessage 般的 IMLib 内置消息实例,也可以是通过 RongIMLib.registerMessageType() 实现的自定义消息实例

  • options:定义发送行为中的一些可选项,如是否可拓展,推送等。

    参数类型必填说明
    isMentionedboolean是否为 @ 消息,只当 conversationType 值为 ConversationType.GROUP 时有效
    disableNotificationboolean当值为 true 时,服务器将不会发送 Push 信息,移动端也不会弹出本地通知提醒