【发布时间】:2018-04-29 21:39:04
【问题描述】:
我已使用 Firebase 函数触发的 Firebase 云消息传递 (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 函数向受众发送通知?
【问题讨论】:
标签: firebase firebase-cloud-messaging