Web

系统通知

更新时间: 2024/03/14 19:21:11

参见 interface SystemMessageServiceInterface

API 都挂载在 friend 模块里,使用 nim.systemMessage 访问

系统通知对象

参见 type SystemMessage

其中,系统通知类型 type 有以下几种情况

team 相关

  • applyTeam
  • rejectTeamApply
  • teamInvite
  • rejectTeamInvite

friend 相关

  • friendRequest 好友添加相关的,则其 attach.type 字段有这四种可能 'addFriend', 'applyFriend', 'passFriendApply', 'rejectFriendApply'
  • deleteFriend

msg 相关

  • deleteMsgP2p 撤回 p2p 消息
  • deleteMsgTeam 撤回群消息
  • deleteMsgSuperTeam
  • deleteMsgP2pOneWay 单向删除 p2p 消息
  • deleteMsgTeamOneWay 单项删除群消息

superTeam 相关

  • applySuperTeam
  • rejectSuperTeamApply
  • superTeamInvite
  • rejectSuperTeamInvite

自定义系统通知

  • customP2p
  • customTeam
  • customSuperTeam

处理系统通知

拿好友申请举例,示例代码

jsfunction handler = function(evt) {
  // 是好友添加相关的
  if (evt.type === 'friendRequest') {
    // 是好友申请
    if (evt.attach.type === 'applyFriend') {
      // 通过好友申请
      nim.friend.passFriendApply({
        account: evt.from
      })
    }
  }
}
// 在线收到系统通知
nim.on('sysMsg', handler)
// 离线收到系统通知
nim.on('syncSysMsgs', handler)

自定义系统通知

开发者可以向其他用户或群发送自定义系统通知, 默认只发给在线用户, 如果需要发送给离线用户, 那么需要设置参数 sendToOnlineUsersOnly=false, 请参考下面的示例代码:

jsconst msgId = await nim.systemMessage.sendCustomSysMsg({
  type: 'customP2p',
  to: 'account',
  attach: JSON.stringify({
    type: 'type',
    value: 'value'
  })
});

API 参见 sendCustomSysMsg

一秒内默认最多调用该接口100次。如需上调上限,请在官网首页通过微信、在线消息或电话等方式咨询商务人员。

自定义系统通知和自定义消息的区别如下

  • 自定义消息属于消息, 需要跟其他消息一同展现给用户。
  • 自定义系统通知属于系统通知, 用于第三方通知自己, SDK 不会解析这些通知, 也不会存储,SDK 仅仅负责传递这些通知。
此文档是否对你有帮助?
有帮助
去反馈
  • 系统通知对象
  • 处理系统通知
  • 自定义系统通知