I’ve tried to make a cloud function that sends a notification to multiple topics. However when I use .sendMulticast()
I receive error “Error: tokens must be a non-empty array
at Messaging.sendMulticast”.I don’t want to have any tokens since I have already specified the topics I’m sending the notification to. Here is my current cloud function:
exports.newStoreTopic = functions
.region("europe-west2")
.firestore
.document("StoreDatabase/{productName}")
.onCreate(async (snapshot, context) => {
const newStore = snapshot.data();
const store = newStore.StoreName;
const message = {
notification: {
title: "New Store!",
body: store+" has just been added",
},
topic: ["storeUpdates", newStore.StoreName],
};
return admin
.messaging()
.sendMulticast({
tokens: [],
topic: ["storeUpdates", store],
message,
})
.then(() => {
console.log("Notification sent successfully");
return null;
})
.catch((error) => {
console.error("Error sending notification:", error);
return null;
});
});