Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. 2018-02-20T21:16:49.878Z E receiveMessage: TypeError: admin.messaging(...).send is not a function
  2. at exports.receiveMessage.functions.database.ref.onCreate (/user_code/index.js:55:27)
  3. at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)
  4. at next (native)
  5. at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
  6. at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
  7. at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
  8. at /var/tmp/worker/worker.js:695:26
  9. at process._tickDomainCallback (internal/process/next_tick.js:135:7)
  10.  
  11. const functions = require('firebase-functions');
  12.  
  13. const admin = require('firebase-admin');
  14. admin.initializeApp(functions.config().firebase);
  15.  
  16. // // Create and Deploy Your First Cloud Functions
  17. // // https://firebase.google.com/docs/functions/write-firebase-functions
  18. //
  19. // exports.helloWorld = functions.https.onRequest((request, response) => {
  20. // response.send("Hello from Firebase!");
  21. // });
  22. exports.recceiveInvitation = /* the function that works */;
  23.  
  24. exports.receiveMessage = functions.database.ref('/messages/{chatId}/{time}').onCreate((event) => {
  25. const chatId = event.params.chatId;
  26. console.log('messages', chatId);
  27. var sender = event.data.val().name;
  28. var messageContent = event.data.val().message;
  29. if(messageContent.length >= 100){
  30. messageContent = messageContent.substring(0,97)+"...";
  31. }
  32. const payload = {
  33. data: {
  34. title: `New Message from ${sender}`,
  35. body: messageContent
  36. },
  37. topic: chatId
  38. };
  39.  
  40. return admin.messaging().send(payload);
  41. });
Add Comment
Please, Sign In to add comment