I am generating an application in ionic with cloud firestore, I need to send a notification to the devices when I add a document to the news collection, I have been able to recover the Token from my emulator, and I have succeeded in sending a notification to the devices from Cloud Messaging, but I could not receive the notification from cloud functions, I'm new in this hopefully someone knows if I have omitted something
const functions = require('firebase-functions');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.newPopularPost = functions
.firestore
.document('noticias/{docID}')
.onCreate((snapshot, context) => {
var message = "There's a new popular post for you: " + snapshot.data().title;
var payload = {
notification: {
title: 'New Popular Post!',
body: message
},
topic: 'popularPosts'
};
return admin.messaging()
.send(payload, true) // Send the push in dry-run mode
.then(response => {
console.log('push success: ' + response);
return null;
});
});
I am using this code as proof