How to send Firebase Cloud Messaging from a node server?

前端 未结 3 1985
名媛妹妹
名媛妹妹 2020-11-29 01:47

Is there any way to send notifications from FCM from a node.js server?

I haven\'t found anything about it inside documentation.

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 02:16

    const admin = require('firebase-admin');
      const payload = { 
       notification: {
            title: 'this is title', body: 'this is body'
        },
       data: {
               balance: 100,
              priceplanId: 1235 
      }
    }  
    const deviceToken ='yourtoekn' | ['yourtoekn'];
    admin.messaging().sendToDevice(deviceToken, newpayload)
                    .then((_response) => console.log(_response))
                    .catch(error => console.log(error));
    

    emphasized text You can send a notification to both ios and Android devices;

提交回复
热议问题