部署Firebase时解析错误

时间:2018-08-07 18:27:32

标签: javascript function firebase parsing command-prompt

代码

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 a new notification from : ', from_user_id);

const userQuery = admin.database().ref('UserData/${from_user_id}/name').once('value');
return userQuery.then(userResult => {
const userName = userResult.val();

const deviceToken = admin.database().ref(`/UserData/${user_id}/TokenID`).once('value');
return deviceToken.then(result => {

const token_id = result.val();

const payload = {
notification: {
title: '${userName}',
body: "You have recieved a new Message",
icon: "default",
click_action : "com.appmaster.akash.messageplus_TARGET_NOTIFICATION"
},
data : {
from_user_id : from_user_id,
from_user_name : userName
}
};

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

Error

我不知道是什么导致了错误,因为我什至不了解命令提示符中的错误,甚至不显示错误的位置或错误的原因...有人可以帮我解决这个问题< / p>

1 个答案:

答案 0 :(得分:0)

您正在使用模板文字,但是看起来您在某些地方使用标准引号而不是反引号`。我还可以看到您正在引用user_id变量,但是它前面没有带花括号的$符号

模板文字需要看起来像这样

`string here blah blah with ${variableHere} `