Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sendFirebaseCommand (command) {
// figure out how to delay the set about of time
// i.e. wait(delay);
// Define capture command playload for FCM message
var payload = {
data: {
cmd: command
}
};
// Send a message to devices subscribed to the provided topic.
admin.messaging().sendToTopic(TOPIC, payload)
.then(function (response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log('Successfully sent message:', response);
console.log('"' + KEY_FOR_COMMAND + ': ' + command + '"' + ' to topic ' + TOPIC);
})
.catch(function (error) {
console.log('Error sending message:', error);
console.log('"' + KEY_FOR_COMMAND + ': ' + command + '"' + ' to topic ' + TOPIC);
});
}
this.unsubscribeFromTopic = function(registrationTokens, topic, callback) {
admin.messaging().unsubscribeFromTopic(registrationTokens, topic)
.then(function(response) {
// See the MessagingTopicManagementResponse reference documentation
// for the contents of response.
callback(null,response)
console.log('Successfully unsubscribed to topic:', response);
})
.catch(function(error) {
callback(error)
console.log('Error unsubscribing to topic:', error);
});
}
if(threadId === "undefined" || !threadId || threadId === null) {
throw new functions.https.HttpsError("invalid-argument", "Sender ID not valid");
}
if(body === "undefined" || !body || body === null) {
throw new functions.https.HttpsError("invalid-argument", "Sender ID not valid");
}
var status = {};
for(let uid in userIds) {
if(userIds.hasOwnProperty(uid)) {
let userName = userIds[uid];
let message = buildMessage(userName, body, action, sound, type, senderId, threadId, uid);
status[uid] = message;
admin.messaging().send(message);
}
}
// return Promise.all(promises);
// return res.send(status);
return status;
});
export const notifyChannel = (channelId, { title, body }) => {
if (!title || !body) return; // bail out
const msg = { notification: { title, body } };
admin.messaging().sendToTopic(channelId, msg)
.then(response => {
logger.info('Successfully sent message:', response);
})
.catch(error => {
logger.info('Error sending message:', error);
});
};
async sendNotification(token, username, tweetUrl) {
const message = {
data: {
title: `Here's your reminder, @${username}.👋`,
body: `You set this reminder with @RemindMe_OfThis. Tap to view the tweet.`,
url: tweetUrl,
},
token
};
return firebase.messaging().send(message)
.then((response) => {
console.log('notification.send.success:' + JSON.stringify(response));
})
.catch((error) => {
console.log('notification.send.error:' + JSON.stringify(error));
});
}
};
.then(snapshot => {
let registrationTokens = []
snapshot.forEach(token => {
if (token.val()) {
registrationTokens.push(token.key)
}
})
if (registrationTokens.length) {
return admin.messaging().sendToDevice(registrationTokens, payload)
} else {
console.log('Not tokens registered')
return null
}
})
},
Promise.all([getTokens, getAuthor]).then(([tokens, author]) => {
const payload = {
notification: {
title: `Awesome message from ${author.displayName}`,
body: message.content,
icon: author.photoURL
}
};
admin.messaging().sendToDevice(tokens, payload).catch(console.error);
});
});
icon: 'https://angularfirebase.com/images/logo.png',
actions: [
{
action: 'like',
title: '👍 Yaaay!'
},
{
action: 'dislike',
title: '☹ Boooo!'
}
]
}
},
topic: 'discounts'
};
return admin.messaging().send(payload);
}));
//# sourceMappingURL=fcm.js.map
sound: "default"
},
data: {
title: expanded,
content: snapshot.val().title,
color: '#2196F3'
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24 * 7 * 4
};
return admin.messaging().sendToTopic(category, payload, options);
});
actions: [
{
action: 'like',
title: '👍 Yaaay!'
},
{
action: 'dislike',
title: '☹ Boooo!'
}
]
}
},
topic: 'discounts'
};
return admin.messaging().send(payload);
});