in coupon-on-purchase/functions/index.js [50:76]
async function sendCouponViaFCM(uid, userLanguage) {
// Fetching all the user's device tokens.
const tokens = await getDeviceTokens(uid);
if (tokens.length > 0) {
// Notification details.
let payload = {
notification: {
title: 'Thanks for your Purchase!',
body: 'Get 10% off your next purchase with "COMEBACK10".',
},
};
// Notification in French.
if (userLanguage.split('-')[0] === 'fr') {
payload = {
notification: {
title: 'Merci pour votre achat!',
body: 'Obtenez 10% de réduction sur votre prochain achat avec "COMEBACK10".',
},
};
}
// Send notifications to all tokens.
return admin.messaging().sendToDevice(tokens, payload);
}
return null;
}