Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
682 B
1
Indexable
Never
exports.sendNotificationOnNewDocument = functions.firestore
    .document('teste/{documentId}')
    .onCreate(async (snapshot, context) => {
        const fcmToken = '...token aqui...';

        if (fcmToken) {
            const payload = {
                data: {
                    title: 'New Document Added',
                    body: 'A new document was added to the "teste" collection.'
                }
            };

            await admin.messaging().send({ token: fcmToken, data: payload.data });
            console.log('Notification sent successfully');
        } else {
            console.error('FCM token is not provided');
        }

        return null;
    });