How to collapse multiple notifications into a single one using Firebase?

后端 未结 3 1782
渐次进展
渐次进展 2021-01-25 12:30

I have function in Firebase Cloud Functions which is used to send notifications to specific users within my app and has as the notificationContent the following cod

3条回答
  •  情深已故
    2021-01-25 12:43

    I had this same confusion and realized I misunderstood what collapseKey and tag are for.

    collapseKey will limit the number of notifications a client receives while they're offline, tag is what will stack notifications together in the drawer.

    So for a typical cloud function, it should look like this:

      const notification = {
        notification: {
          'title': 'Interesting title',
          'body': 'Hello, world'
        },
        'data': {
          'whatever': whatever,
        },
        'android':{
          'collapseKey': collapseKey,
          'priority': 'high',
          'notification': {
            'tag': tag,
          }
        },
        'token': fcmToken
      };
    
      admin.messaging().send(notification)
    

    Note that the "tag" parameter sits inside of the android notification, not the top-level notification.

提交回复
热议问题