我正在开发一个需要通知的应用程序,并且我进行了一项研究,即Firebase函数对于实现此类功能非常有用。结果,我观看了一些youtube和论坛教程以集成此功能,但现在在部署过程中遇到了问题。因此,当我将此流动代码部署到firebase函数时,得到了意外的令牌“”我什至不知道我的代码中的错误
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{PostKey}/{notification_id}').onWrite((date,context) =>{
const user_id = context.params.PostKey;
const notification_id = context.params.notification_id;
console.log('We have a notification from : ', user_id,'this also notification_id',notification_id);
const Device_token = admin.database().ref(`/User_Data/${user_id}/Device_token`).once('value');
return Device_token = admin.then(response =>
{
const token_id = result.val();
const payload =
{
notification:
{
title:"Appointment",
body" "Appointment has been booked",
icon:"default"
};
};
return admin.messaging().sendToDevice(token_id,payload)
.then(response => {
return console.log('This was the notification feature');
});
});
});
答案 0 :(得分:1)
我在您发送的代码中看到3个语法错误:
onWrite
函数。我建议您在编写此类代码时使用JavaScript IDE。例如免费开放源代码的Visual Studio Code。