Firebase功能-在某些情况下迭代条目并发送通知 [英] Firebase functions - iterate entries and send notification for certain conditions

查看:45
本文介绍了Firebase功能-在某些情况下迭代条目并发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Firebase功能工具来迭代某个键的所有条目并为相关用户发送通知?我们的数据库如下所示:

Is there a way to use the Firebase functions tool to iterate all the entries of a certain key and send notifications for the relevant users? Our database looks as follows:

"Jobs" : {
    "066802368bd24eab86281df1927df508" : {
      "dates" : [ {
        "date" : 12,
        "day" : 0,
        "hours" : 17,
        "minutes" : 38,
        "month" : 4,
        "seconds" : 54,
        "time" : 61484283534357,
        "timezoneOffset" : -120,
        "year" : 2018
      } ],
      "duration" : "60",
      "jobBidds" : [ {
        "bid" : 552,
        "date" : {
          "date" : 12,
          "day" : 0,
          "hours" : 17,
          "minutes" : 38,
          "month" : 4,
          "seconds" : 54,
          "time" : 61484283534357,
          "timezoneOffset" : -120,
          "year" : 2018
        },
        "myJobId" : "066802368bd24eab86281df1927df508",
        "myPersonId" : "gAUhdaihH1VFUReTKTjjJtVQV112",
        "personId" : "gAUhdaihH1VFUReTKTjjJtVQV112"
      }, {
        "bid" : 56,
        "date" : {
          "date" : 12,
          "day" : 0,
          "hours" : 17,
          "minutes" : 38,
          "month" : 4,
          "seconds" : 54,
          "time" : 61484283534357,
          "timezoneOffset" : -120,
          "year" : 2018
        },
        "myJobId" : "066802368bd24eab86281df1927df508",
        "myPersonId" : "gAUhdaihH1VFUReTKTjjJtVQV112",
        "personId" : "gAUhdaihH1VFUReTKTjjJtVQV112"
      } ],
      "jobCategory" : "סטטיסטיקה",
      "jobImageURL" : "default",
      "jobLatLang" : {
        "latitude" : 32.106922499999996,
        "longitude" : 34.80368359375002
      },
      "jobType" : "PRIVATELESSONS",
      "myDetails" : "",
      "personUid" : "gAUhdaihH1VFUReTKTjjJtVQV112",
      "phoneNumber" : "865"
    },
    "4fdeb7dbfc5c423591df0144d9316f63" : {         etc

每个工作"都有与之相关的日期.
我们希望服务器以某种方式遍历所有作业,如果日期(特定作业)过去了,则服务器将向"myPersonId"发送通知,以通知他.
是否可以为功能设置时间戳(即告诉Firebase每10分钟运行一次功能X)?有没有办法设置发送给用户的通知以在android(用户端)中打开特定活动?

where each 'job' has a date related to it.
We want the server to somehow iterate through all the jobs, and if the date(for a specific job) has passed, the server will send a notification to the "myPersonId" notifying him.
Is it possible to set timestamps for a function(i.e tell firebase to run function X every 10 minutes)? Is there a way to set the notification sent to the user to open a specific activity in android(user-side)?

推荐答案

此后,您会找到指向满足您需求的教程或代码示例的链接:

You will find hereafter links to tutorials or code examples covering your needs :

1/要定期调用Cloud Function,您必须通过cron-job通过http触发它.

1/To call a Cloud Function regularly, you have to trigger it via http through a cron-job.

https://firebase.google.com/docs/functions/http-events).

https://www.youtube.com/watch?v=CbE2PzvAMxA

2/用于发送通知:

https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens

https://github.com/firebase/functions-samples/blob/master/developer-motivator/functions/index.js

https://android.jlelse.eu/serverless-notifications-with-cloud-functions-for-firebase-685d7c327cd4

PS:一个额外的建议:如果可能的话,您最好将日期存储为一个String.最好的选择是将日期转换为格林尼治标准时间1970年1月1日00:00:00以来的毫秒数

PS: an extra advice : you should better store your dates as one String if possible. The best option being to convert your date to the number of milliseconds since January 1, 1970, 00:00:00 GMT

这篇关于Firebase功能-在某些情况下迭代条目并发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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