Created
December 28, 2021 01:41
-
-
Save ologunB/380fd1190995b8f45156336fe37f3c14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.sendToAllUsers = functions.https.onCall(async (snap, context)=>{ | |
const payload = { | |
notification:{ | |
title : 'New Trivia' , | |
body : 'A new Trivia is availble on the app, check now', | |
badge : '1', | |
sound : 'default' | |
}, | |
data: { | |
type: 'new-trivia', | |
click_action: "FLUTTER_NOTIFICATION_CLICK", | |
status: "done", | |
} | |
} | |
return admin.firestore().collection('Tokens').get().then(tokensSnap=> { | |
if (tokensSnap != null) { | |
const results = []; | |
tokensSnap.forEach(doc => { | |
results.push(doc.data().token); | |
}); | |
console.log('sent to '+ results.length + ' users'); | |
return admin.messaging().sendToDevice(results,payload); | |
} else { | |
return console.log("=========there was an errror =================="); | |
} | |
}).catch((error) => { | |
return console.log(`Error ${error}`); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment