How to use Firebase trigger to send push notification with an atomic update
0
I'm going to send notifications to devices in a trigger. The trigger is triggered when an object under "/chats/{chatId}" was created. The chat object has a structure like: { members: { 0: "userId1", 1: "userId2" }, ... } The logic behind my code is to read userToken (proprierty of each user) forEach members; send notification (payload) to every token. The code below works. exports.onChatCreate = functions.database .ref("/chats/{chatId}") .onCreate((chatSnap, context) => { // const members = chatSnap.val().members; // works?! let database = admin.database(); let messaging = admin.messaging(); const chatId = context.params.chatId; let tokens = ; let notifications = ; const payload = { notificatio...