gpt4 book ai didi

javascript - 引用错误 : noticication_id is not defined in firebase notification

转载 作者:行者123 更新时间:2023-11-30 19:01:47 26 4
gpt4 key购买 nike

我没有在 Android 设备上收到通知。此错误出现在函数日志中。

ReferenceError: noticication_id is not defined at exports.sendNotification.functions.database.ref.onWrite (/srv/index.js:28:84) at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:131:23) at /worker/worker.js:825:24 at at process._tickDomainCallback (internal/process/next_tick.js:229:7)


我在 Index.js 文件中的代码:

'use strict'

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


exports.sendNotification = functions.database.ref('/notifications/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
const receiver_user_id = context.params.receiver_user_id;
const notification_id = context.params.notification_id;


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


if (!data.after.val())
{
console.log('A notification has been deleted :' , notification_id);
return null;
}

const sender_user_id = admin.database().ref(`/notifications/${receiver_user_id}/${noticication_id}`).once('value');

return sender_user_id.then(fromUserResult =>
{
const from_sender_user_id = fromUserResult.val().from;

console.log('you have a notification :',sender_user_id);

const userQuery = admin.database().ref(`/users/${receiver_user_id}/device_token`).once('value');

return userQuery.then(userResult =>
{
const senderUserName = userResult.val();

});


const DeviceToken = admin.database().ref(`/users/${receiver_user_id}/device_token`).once('value');

return DeviceToken.then(result =>
{
const token_id = result.val();

const payload =
{
notification:
{
from_sender_user_id : from_sender_user_id,
title: "New Chat Request",
body: `you have a new Chat Request from${senderUserName}`,
icon: "default"
}
};

return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
});
});

最佳答案

改变这个:

const sender_user_id = admin.database().ref(`/notifications/${receiver_user_id}/${noticication_id}`).once('value');

进入这个:

const sender_user_id = admin.database().ref(`/notifications/${receiver_user_id}/${notification_id}`).once('value');

你在变量中有错别字,在 ref() 中,它应该是 notification_id 而不是 noticication_id

关于javascript - 引用错误 : noticication_id is not defined in firebase notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59443651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com