Firebase云消息传递每个then()应该返回一个值或抛出Promise / Always-Return

时间:2018-09-14 19:11:42

标签: javascript android firebase firebase-cloud-messaging google-cloud-functions

我正在为我的Android应用程序编写Firebase的云函数。我无法解决此错误。我是一个完整的新手。

  

29:73错误每个then()应该返回一个值或抛出promise / always-return

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/comment')
 .onWrite((change, context) => {

     // get user ids
     const reciever_id = context.params.reciever_id;
     const sender_id = context.params.sender_id;
     const comment = context.params.comment;
     const object_id = context.params.object_id;
     const objecttype = context.params.objecttype;

     //get the token of reciever 
     return admin.database().ref("/users/" + reciever_id).once('value').then(snap => {
         const token = snap.child("token").val();
         // Create a payload
         var payload = {
             data: {
                 data_type: "direct_message",
                 title: "Comment from" + sender_id,
                 comment: comment,
                 object_id: object_id,
                 objecttype: objecttype,
             }
         };

         // Sent To device with token Id : THIS IS LINE 29
         return admin.messaging().sendToDevice(token, payload).then(response => {
             console.log("Successfully sent message:", response);})
            .catch(error => {console.log("Error:", error); });

});  // token

}); // onWrite

0 个答案:

没有答案