npm安装时部署Firebase函数错误

时间:2020-09-23 12:59:39

标签: node.js npm

这是npm命令提升的错误日志

Here is image of error in node.js

这是我上载的index.js文件,用于创建通知

const functions = require('firebase-functions');

const admin = require('firebase-admin'); admin.initializeApp();

exports.sendNotification = functions.database.ref ('/Notifications/{user_id}/{notification_id}').onWrite((change,context)=> {

const user_id = context.params.user_id;
const notification_id = context.params.notification_id;

console.log('We have a notification to send to :',user_id);
    

if(!change.after.val()){
   
   return console.log('A notification has been deleted from the database ',notification_id);
   }

const fromUser = admin.database().ref(`/Notifications/${user_id}/${notification_id}`).once('value');

return fromUser.then(fromUserResult =>{
    
    const from_user_id = fromUserResult.val().From;
    
    console.log('you have new notification from ',from_user_id);
    
const userQuery = admin.database().ref(`users/${from_user_id}/username`).once('value');
const deviceToken = admin.database().ref(`/users/${user_id}/device_token`).once('value');  
const state_app = admin.database().ref(`/users/${user_id}/state_app`).once('value');   
//const language_app = admin.database().ref(`/users/${user_id}/language_app`).once('value');   
const notification_state = admin.database().ref(`/notifications_state/${user_id}/${from_user_id}/state`).once('value');   


        return Promise.all([userQuery,deviceToken,state_app,notification_state]).then(result =>{

            const username = result[0].val();
            const token_id = result[1].val();
            const state_app = result[2].val();
            //const language_app = result[3].val();
            const notification_state = result[3].val();

                if(state_app!="start"){

                    if(notification_state=="message"){
                
                                    const payload = {
                                            notification:{
                                                title : "New message",
                                                body  : `${username} sent you a message.`,
                                                icon  : "default",
                                                sound : "default",
                                                click_action: "com.boss8.livetalk_TARGET_NOTIFICATION_messages"

                                                },data:{
                                                    userIDvisited : from_user_id }
                                            };

                                    return admin.messaging().sendToDevice(token_id,payload).then(response => {
                                        console.log('this was the notification Feature ');

                                    });
                    }
                    if(notification_state=="video_call"){
                
                        const payload = {
                                notification:{
                                    title : "Video Call",
                                    body  : `${username} calling you.`,
                                    icon  : "default",
                                    sound : "default",
                                    click_action: "com.boss8.livetalk_TARGET_NOTIFICATION_video_call"

                                    },data:{
                                        userIDvisited : from_user_id }
                                };

                        return admin.messaging().sendToDevice(token_id,payload).then(response => {
                            console.log('this was the notification Feature video call');

                        });
                    }   
                }
                    
        });

    
    
});                   

});

0 个答案:

没有答案