-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (21 loc) · 791 Bytes
/
index.js
File metadata and controls
26 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.firestore
.document('shoutouts/{doc_id}')
.onCreate((snap, context) => {
const newValue = snap.data();
const name = newValue.name;
const description = newValue.description;
const payload = {
notification: {
title: name + " needs your help!",
body: description,
icon: "default",
color: '#f45342'
}
};
return admin.messaging().sendToTopic("shoutouts",payload).then(result => {
console.log("Notification sent!");
});
});