1

Previously I send the push notification using FCM token of the devices for particular user using admin.messaging().sendToDevice(tokens, payload). Now I'm trying to send the push notification to all the users. But it's not working. Here is my implementation. Is this correct? If wrong how to achieve my task?

    const payload = {
                    notification: {
                      title: 'Hey! ',
                      body: `Check Choice of the day.`,
                      sound: 'default',
                      icon: '',
                      type: 'Editorial',
                      badge : '1'
                    }
                  };

    return admin.messaging().sendToTopic("News",payload)
        .then(function(response){
             console.log('Notification sent successfully:',response);
        }) 
        .catch(function(error){
             console.log('Notification sent failed:',error);
        }); 
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
isuru
  • 3,385
  • 4
  • 27
  • 62
  • 1
    This code sends a notification to the `News` topic. App instance can only receive this, if they are subscribed to the `News` topic. – Frank van Puffelen Mar 19 '19 at 13:15
  • @FrankvanPuffelen Can't we send the notifications without using topic for all users? – isuru Mar 21 '19 at 00:42
  • 1
    There is no built-in way to send to all users. See https://stackoverflow.com/questions/38237559/how-do-you-send-a-firebase-notification-to-all-devices-via-curl, https://stackoverflow.com/questions/39772167/firebase-cloud-messaging-send-message-to-all-users, https://stackoverflow.com/questions/49013491/firebase-cloud-messaging-how-to-send-data-message-to-all-users – Frank van Puffelen Mar 21 '19 at 00:46

0 Answers0