I am writing a firebase function using TypeScript to send push notifications to multiple users. But when I run firebase deploy --only functions
command, TSLint gives an error "Promises must be handled appropriately".
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
export const broadcastJob = functions.https.onRequest((request, response) => {
const db = admin.firestore();
db.collection('profiles').get().then(snapshot => {
snapshot.forEach(doc => {
const deviceToken = doc.data()['deviceToken'];
admin.messaging().sendToDevice(deviceToken, { //<-- Error on this line
notification: {
title: 'Notification',
body: 'You have a new notification'
}
});
});
response.send(`Broadcasted to ${snapshot.docs.length} users.`);
}).catch(reason => {
response.send(reason);
})
});