小编Kat*_*tie的帖子

您如何停止使用App Engine Flex实例?

我正在使用Google Cloud的免费试用版,而我几乎已经获得免费赠送的一半.我不知道我做错了什么,或者它的成本是否超出我的预期,所以我看着定价并意识到我不了解其中的大部分内容.我只是在学习和玩乐,所以我实际上并不想花钱(或者至少没有那么多),所以任何事情都可以帮助制作去年的免费学分:)

https://firebase.google.com/pricing/

我对我的功能所做的是从Firebase数据库获取有关通知的信息,然后使用Firebase Messaging发送通知.这是代码,如果有帮助的话.

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotifications = functions.database.ref('/Notifications/{pushID}/title')
  .onWrite(event => {

    if (!event.data.exists())
      return;

    event.data.ref.parent.once('value').then(function(dataSnapshot){

      // Grab the eventName and the message
      const title = dataSnapshot.child('title').val();
      const message = dataSnapshot.child('message').val();
      const recipients = dataSnapshot.child('recipients').val();
      const tag = dataSnapshot.child('tag').val();

      const payload = {
        notification:{
          title: title,
          body: message,
          tag: tag,
          color: "#51E0F5",
          sound: 'default'
        },
      };

      const options = {
        priority: 'high',
        collapseKey: 'chat',
        timeToLive: 3600    // 6 days
      }; …
Run Code Online (Sandbox Code Playgroud)

google-app-engine billing google-cloud-messaging firebase-realtime-database google-cloud-functions

3
推荐指数
2
解决办法
989
查看次数