Android 向Firebase中的令牌组发送消息

Android 向Firebase中的令牌组发送消息,android,node.js,firebase,firebase-cloud-messaging,google-cloud-functions,Android,Node.js,Firebase,Firebase Cloud Messaging,Google Cloud Functions,我已经创建了一个聊天应用程序,我需要在收到群消息时发送通知,我可以向一个设备发送通知,但我不知道如何处理群通知。 有什么想法吗?您需要订阅这些令牌并向该主题发送通知 订阅主题 现在您可以像这样发送到特定的组 裁判 var registrationTokens = [] db.collection('room').document({roomId}).get().then(result => { registrationTokens = result.data().usersToke

我已经创建了一个聊天应用程序,我需要在收到群消息时发送通知,我可以向一个设备发送通知,但我不知道如何处理群通知。
有什么想法吗?

您需要订阅这些令牌并向该主题发送通知

订阅主题

现在您可以像这样发送到特定的组

裁判
var registrationTokens = []
db.collection('room').document({roomId}).get().then(result => {
    registrationTokens = result.data().usersTokens // get user tokens in that chat room
})

// Subscribe the devices corresponding to the registration tokens to the
// topic.
admin.messaging().subscribeToTopic(registrationTokens, topic)
  .then(function(response) {
    // See the MessagingTopicManagementResponse reference documentation
    // for the contents of response.
    console.log('Successfully subscribed to topic:', response);
  })
  .catch(function(error) {
    console.log('Error subscribing to topic:', error);
  });
// The topic name can be optionally prefixed with "/topics/".
var topic = 'highScores';

// See documentation on defining a message payload.
var message = {
  data: {
    score: '850',
    time: '2:45'
  },
  topic: topic
};

// Send a message to devices subscribed to the provided topic.
admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });