I have written the trigger below and I'm not sure what I should return in case a catch
block is called. I know that Firebase docs say that triggers should always return a Promise
...
exports.sendPushNotificationForNewMessage = functions.firestore.document("messages/{messageId}").onCreate(async (snap, context) => {
const message = snap.data()
const chatRoomId = message.chatRoomId
const senderId = message.user.id
const senderUsername = message.user.username
try {
const chatRoom = await admin.firestore().collection("chatRooms").doc(chatRoomId).get()
const receiverId = chatRoom.data().userIds.find(userId => userId != senderId)
const receiver = await admin.firestore().collection("users").doc(receiverId).get()
const deviceToken = receiver.data().deviceToken
if (deviceToken) {
const payload = {
notification: {
title: "popster",
body: `New DM from ${senderUsername}