[英]sending notification with firebase cloud messaging
I'm trying to send notification to users with firebase cloud messaging when they are being sent friend request in my app using the below function which i deployed to my firebase functions 当我使用我部署到我的Firebase函数的以下功能在我的应用中向其发送好友请求时,我正在尝试通过Firebase云消息传递向用户发送通知
'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/Notifications/{user_id}/{notifications_id}').onWrite(event => { const user_id = event.params.user_id; const notifications = event.params.notifications; console.log('This User Id is :', user_id); });
but when it trys to send the notification, i get the following error in my functions logs 但是当它尝试发送通知时,我的函数日志中出现以下错误
sendNotification TypeError: Cannot read property 'user_id' of undefined at exports.sendNotification.functions.database.ref.onWrite.event (/user_code/index.js:8:30) at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) at /var/tmp/worker/worker.js:758:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
you have to add context and get the parameter from there. 您必须添加上下文并从那里获取参数。 Try:
尝试:
..'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database
.ref('/Notifications/{user_id}/{notifications_id}')
.onWrite((event, context) => {
const user_id = context.params.user_id;
const notifications = context.params.notifications;
console.log('This User Id is :', user_id);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.