Guest User

Untitled

a guest
Apr 30th, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. export const sendNotification = functions.https
  2. .onRequest(async (req, res) => {
  3. try {
  4. const { token } = req.query;
  5. let tokens = 'fyTfgNZAUBA:APA91bGnx9Vp9MwRA4ohVKcNOM8d5s4a4TXdtI0KTSzcWEgZX1WoLGpofcVQFTCdSbnbqObkukzJEXF3cbmvENYD5pr2MrukjqUNy_bclDuM3rJsV5iSU1vWywL2ZVijJ3s0E9GNfRRe'
  6. var payload = {
  7. /*
  8. data = {
  9. name:'test'
  10. content:'bla bla'
  11. }
  12. */
  13. notification: {
  14. title: 'Urgent action needed!',
  15. body: 'Urgent action is needed to prevent your account from being disabled!',
  16. sound: 'default',
  17. color: '#84B2D9',
  18. icon: 'ic_notification',
  19. click_action: 'OPEN_MAIN_ACTIVITY'
  20. }
  21. };
  22.  
  23. // Set the message as high priority and have it expire after 24 hours.
  24. var options = {
  25. priority: 'high',
  26. timeToLive: 60 * 60 * 24
  27. };
  28.  
  29.  
  30. console.log('token',token)
  31. let d = await admin.messaging().sendToDevice(tokens, payload,options);
  32. return res.status(200).send({ success: d})
  33.  
  34. } catch (e) {
  35. console.info(e)
  36. return res.status(400).send({ error: 0 })
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment