【问题标题】:FCM Send a batch of messages (device groups)FCM 发送一批消息(设备组)
【发布时间】:2021-01-26 07:36:26
【问题描述】:

我必须为每组设备发送不同的消息。为了不逐条发送消息,我想使用批处理选项。团体可以吗? (send batch messages doc)

例子:

const messages = [];

messages.push({
  notification: { title: 'notf. Group 01', body: '...'},  // Message for group 01
  token: notification_key,  // Group key 01
});

messages.push({
  notification: { title: 'notf. Group 02', body: '...'},  // Message for group 02
  token: notification_key,   // Group key 02
});

.
.
.

admin.messaging().sendAll(messages)
  .then((response) => {
    console.log(response.successCount + ' messages were sent successfully');
  });

【问题讨论】:

    标签: javascript node.js firebase google-app-engine firebase-cloud-messaging


    【解决方案1】:

    根据documentation,设备群组消息通过旧版 XMPP 或 HTTP 协议或基于旧版协议的适用于 Node.js 的 Firebase Admin SDK 得到支持。

    据我了解,为了 send a batch of messages 必须指定注册令牌、主题或指定目标主题的条件,然后通过将其作为参数传递给 sendAll() 方法来发送整个 messages[] 数组.请注意,message type aliases 中不包含通知键。

    为了向device group 发送消息,通知键作为参数传递给sendToDeviceGroup() 方法。再看sendAll()方法,它是用来批量发送消息的,它没有一个参数来接受通知键作为输入。

    希望以上内容对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多