简体   繁体   English

使用Firebase云消息发送通知

[英]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.

相关问题 Firebase Cloud Messaging,用于将通知发送到所有无法使用的已注册设备 - Firebase Cloud Messaging for sending notification to all the registered devices not working 向Firebase云消息传递通知添加操作 - Adding actions to firebase cloud messaging notification Firebase 云消息前台通知在 Vue 中不起作用 - Firebase Cloud Messaging foreground notification not working in Vue 单击通知后如何访问通知数据(firebase 云消息传递) - How to access notification data after clicking on notification (firebase cloud messaging) 使用Firebase云功能发送通知有困难吗? - Difficulties sending a notification with Firebase cloud function? Firebase 云消息传递:通知图标背景仅在第二次尝试时有效 - Firebase Cloud Messaging: Notification Icon Background is only working on second attempt 如何从 javascript 发送 firebase 云消息通知? - How can I send a firebase cloud messaging notification from javascript? 向所有Firebase云消息传递令牌(Web)发送通知 - Send Notification To All Firebase Cloud Messaging Tokens (Web) 自定义在后台处理程序中运行的Firebase云消息传递的通知 - Customize notification from firebase cloud messaging running in background handler 如何通过 NodeJs 使用 Azure、firebase 云消息推送 android 通知 - How to push android notification using Azure, firebase cloud messaging by NodeJs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM