使用功能在(分析)受众中发送Firebase中的推送通知



我已经使用Firebase函数触发的Firebase Cloud Messaging(FCM(成功发送通知:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const fs = require('fs');
admin.initializeApp();

exports.testNotif = functions.https.onRequest((request, response) => {
    const mySecretNumber = getRandomInt(147)
    var payload = {
      notification: {
        title: `You got a new Message`,
        body: `My highest break ${mySecretNumber}`,
        badge: mySecretNumber.toString(),
        sound: `notif1.aiff`,
      }
    };
 const ackString = `All done ${mySecretNumber}`;
 console.log(ackString)
 response.send(ackString);
 //send to all topic
 admin.messaging().sendToTopic(`all`, payload)
});

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

您可以看到,我将通知发送给一个称为"全部"的主题。

在Firebase控制台中,您可以向观众发送通知您可以创建的。就我而言,我根据分析模块的用户属性创建了不同的受众。

是否也可以通过Firebase函数发送通知给受众?

没有分析API可以检索属于特定分析受众的用户。也没有FCM API向此类受众发送通知。

如果您想向观众发送通知,则必须创建自己定义这些受众的方式。最直接的方法是将Firebase的Google Analytics(分析(连接到BigQuery,然后在您收到的分析事件中定义受众。

另请参阅:如何通过http

向受众发送壁炉通知

最新更新