Firebase发生任何变化时,自动向所有用户发送通知 [英] Automatically send notification to all the users whenever there is any change in firebase

查看:51
本文介绍了Firebase发生任何变化时,自动向所有用户发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebase中进行更改时,如何通知所有用户?我不希望手动执行此操作.

How do I notify all users when a change is made in firebase? I do not wish to do this manually.

推荐答案

您应该使用由实时数据库触发器触发的Firebase云功能,请参阅doc 此处.查看Cloud功能的官方Firebase示例之一:

You should use a Firebase Cloud Function tiggered by a Realtime Database trigger, see doc here. Have a look at one of the official Firebase samples for Cloud Functions:

此示例演示了如何发送Firebase Cloud Messaging(FCM)实时数据库触发功能的通知.样品还具有可体验FCM通知的Web UI.

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function. The sample also features a Web UI to experience the FCM notification.

https://github.com/firebase/functions-samples/tree/master/fcm-notifications

如果您想发送电子邮件,请查看以下示例:

If you prefer to send an email, look at the following sample:

https://github.com/firebase/functions-samples/树/主/电子邮件确认

此样本显示了如何向订阅/取消订阅时事通讯的用户发送确认电子邮件".当用户在特定的实时数据库"节点下写入一些数据时,将触发该事件.因此,这与您的情况非常相似:在给定的DB节点下写入新数据时,将发送邮件.

This samples "shows how to send a confirmation emails to users who are subscribing/un-subscribing to a newsletter". It is triggered when a user write some data under as specific Real Time Database node. So it is very similar to your case: when new data is written under a given DB node, the mail is sent.

您也可以对其进行修改以使其使用Sengrid,以及其用于node.js的库 https://github.com/sendgrid/sendgrid-nodejs .它效果很好,也是Firebase推荐的解决方案.

You can also adapt it in order to use Sengrid, with their library for node.js https://github.com/sendgrid/sendgrid-nodejs. It works very well and is also a recommended solution by Firebase.

如果在将这些样本之一适合您的情况时遇到困难,请毫不犹豫地分享您的代码并寻求帮助.

In case you encounter difficulties when adapting one of these samples to your case, do not hesitate to share your code and ask for help.

这篇关于Firebase发生任何变化时,自动向所有用户发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆