Untitled

 avatar
unknown
plain_text
2 years ago
866 B
3
Indexable
exports.sendNotificationOnNewDocument = functions.firestore
    .document('teste/{documentId}')
    .onCreate(async (snapshot, context) => {
        const fcmToken = 'd8HCFFUlBUzzmz2wHAv5-l:APA91bHmobU32JoQan_ubl50-CiqxEHdJlxDphK89aPR1rWdInLF73SRhMHkL9VFviaxOrQQQdNhMShVsHGgdKubYHBqoXpHwa0PIOzUJ3PDlVWnvUxbaWxamPBXS8HyBC_nGQqlsKWp'; // Replace with the actual FCM token

        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;
    });
Editor is loading...