Я успешно отправляю уведомления с помощью Firebase Cloud Messaging (FCM), запускаемые функцией Firebase:
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 для аудитории?