Guest User

Untitled

a guest
Nov 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const notification_id = event.params.notification_id;
  2.  
  3.  
  4.  
  5. console.log('Temos uma notificação para enviar para: ', receiver_id);
  6.  
  7. if(!event.data.val())
  8. {
  9. return.console.log('A notificação foi excluída do banco de dados: ', notification_id);
  10.  
  11. }
  12.  
  13.  
  14.  
  15. const deviceToken = admin.database().ref(`/usuarios/${receiver_id}/device_token`).once('value');
  16.  
  17. return deviceToken.then(result =>
  18.  
  19. {
  20.  
  21. const token_id = result.val();
  22.  
  23. const payload =
  24. {
  25. notification:
  26. {
  27. title: "Friends Request",
  28. body: "Voce tem uma requisição de um novo amigo",
  29. icon: "default"
  30. }
  31. };
  32.  
  33. return admin.messaging().sendToDevice(token_id, payload)
  34. .then(response =>
  35. {
  36. console.log('Este é o recurso de notificação.');
  37. });
  38.  
  39. });
  40.  
  41. });
Add Comment
Please, Sign In to add comment