简体   繁体   中英

Is there a way to send email digest to a user when they have unread messages/notifications using firebase cloud functions?

I am trying to send emails to users who have unread messages/notifications, but I am struggling to find a way to do it. I was thinking of a system that keeps track of messages/notifications and if they are unread for an hour, then it would send email to the user that will inform them of the messages.

What I found : With cloud scheduler, I will be able to send emails every hour to users that have unread notifications. However, if the user got a notification a minute ago, they will still get an email and that will be annoying for them.

Sending email notification with every message/notifications, with firestore onUpdate will be even more annoying.

Does anyone know if there is a way to do this by tracking notifications/messages as I described on the top? Is there any other way of doing this, that I missed?

Why don't you try

  1. Set the cloud function to run every 1-5 minutes.
  2. Filter the notification from 1 hour and before which are not read. Something like: .where("Read","==",false").where("Date Reminded","<=", currentTime - 60 * 60 * 1000) . Note that we used date reminded here which is set to the same as date created upon creation and updated every time the email is sent to avoid sending emails every minute.
  3. Send emails to these users after linking the notifications to each user.

An obvious alternative of course is to deploy a server that watches the cloud firestore and send emails using the node-schedule module.

You can use Cloud Tasks to kick off a task for each unread notification, to invoke a function that sends the email for that notification on some delay. You would need to write a fair amount of code to create and configure the task , and the function (perhaps a Cloud Function) to receive the delayed message.

If you want to send emails with batch notifications, you will obviously have to implement some additional logic to make sure that each task sends a rollup rather than an individual message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM