I'm trying to trigger a firebase cloud functions once a user creates a new firebase cloud message(FCM).
This documentation page describes exactly what to do.
Here's my code on the server side :
Side Note: subscribeToTopic can take one token or an array of tokens.
admin.messaging().subscribeToTopic(fcmToken, "/topics/news")
.then(res => {
console.log('res: ', res);
})
.catch(error =>{
console.log('error: ', error);
});
Assume fcmToken is a valid token, created from my device(client-side), i double checked it.
Now, to test if it works: I create a new notification using the notification web console provided by firebase, and after choosing title and body, i get to choose the topic like in the image.
The problem is that the cloud function is not getting triggered at all.
subscribeToTopic
does. It basically forces some client apps, identified by their tokens, to be subscribed to the given topic. It doesn't arrange for any future code to be run on your server side. - Doug Stevenson