Отправьте уведомление всем пользователям, у которых есть определенное местоположение, используя Firebase Cloud Functions - PullRequest
0 голосов
/ 30 октября 2019

У меня есть триггер, который срабатывает при создании предмета. Поэтому я хочу видеть, что при создании элемента все пользователи, у которых есть местоположение, сохраненное в элементе, получат уведомление

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

 exports.sendNotification = functions.firestore
.document('itens/{itenId}').onCreate((snap, context) => {

    //You get the values of the newly created doc as follows:
    const data = snap.data();
    const name = data.name;
    const location = data.location;

    const payload = {
        notification: {
            title: "Avana - Está bater",
            body: `Podes encontrar : ${name} em ${location}`,  //Here we use value
            sound: "default"
        }
    };
    const options = {
        priority: "high",
    };

    admin.messaging().sendToTopic("newItem", payload, options)
        .then(function (response) {
            console.log("Successfully sent message:", response);
        })
        .catch(function (error) {
            console.log("Error sending message:", error);
        });
    console.log("Notification sent!");
    return null;
});

1 Ответ

0 голосов
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...