Skip to content

Instantly share code, notes, and snippets.

@Eder87rh
Created April 13, 2019 17:20
Show Gist options
  • Select an option

  • Save Eder87rh/257f49de144193d7511d4ae61556b055 to your computer and use it in GitHub Desktop.

Select an option

Save Eder87rh/257f49de144193d7511d4ae61556b055 to your computer and use it in GitHub Desktop.
5 -cropchien - createDog - index.js
exports.createDog = functions.firestore
.document('dogs/{dogId}')
.onCreate(event => {
var dog = event.data();
console.log(dog.comment);
axios.post(`https://fcm.googleapis.com/fcm/send`,{
"to" : "/topics/general",
"priority" : "high",
"notification" : {
"title" : "Nueva publicación",
"body" : dog.comment,
"click_action":"http://localhost:8081",
"icon":"http://localhost:8081/chrome/chrome-installprocess-128-128.png",
},
},{
headers: {
'Content-Type': 'application/json',
'Authorization': `key=${serverKey}`
},
}).then((response) => {
console.log(response);
console.log(response.data);
})
.catch(err => {
console.log(err.response);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment