0
votes

I am using FCM for notification. FCM gets triggered on creation of data from the Firebase database. I received first message. After that other consecutive messages is not received. I'm running this in a local environment. Is the problem due to the below message "Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions" or any other issue. Do I need to get into a billing plan for receiving messages. Working in test environment and that is the reason not moving to billing plan. If the issue is not related to billing plan can someone point any other problem with the code.

Firebase function log

6:22:52.133 PM
sendFollowerNotification
Function execution started
6:22:52.133 PM
sendFollowerNotification
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
6:22:52.143 PM
sendFollowerNotification
Function execution took 10 ms, finished with status: 'ok'
6:22:52.401 PM
sendFollowerNotification
1 messages were sent successfully

Node js code

exports.sendFollowerNotification = functions.database.ref('/notification/message/{gId}/{pId}')
        .onCreate(async (change, context) => {
    
          //console.log('Group id:', context.params.gId," Push ID:",context.params.pId, "Change",change);
          
          const notificationData =  change.val();
          var topic = notificationData.topic;
          var title = notificationData.title;
          var body = notificationData.body;
          var registrationTokens = notificationData.tokens;
    
          const message = {
            notification: {
              title: title,
              body: body
            },
            tokens: registrationTokens,
          };
    
          admin.messaging().sendMulticast(message)
          .then((response) => {
            // Response is a message ID string.
            console.log(response.successCount + ' messages were sent successfully');
          })
          .catch((error) => {
            console.log('Error sending message:', error);
          });
          
        });
2

2 Answers

1
votes

That message does not indicate an error. It's just a warning letting you know that outbound networking does not work if your project is not on a payment plan. FCM messaging does not fall in this category - it should work.

The problem is that your code doesn't return a promise that resolves after all asynchronous work is complete. Right now, it returns nothing, and the function terminates immediately before the message is sent. Please read and understand the documentation about this.

Minimally, you will need to return the promise chain to let Cloud Functions know when the message is sent, and it's safe to terminate.

          return admin.messaging().sendMulticast(message)
          .then((response) => {
            // Response is a message ID string.
            console.log(response.successCount + ' messages were sent successfully');
          })
          .catch((error) => {
            console.log('Error sending message:', error);
          });

Note the return keyword above.

If the message still isn't being sent, then there is some other problem here that we can't see. You might not be handling your device tokens correctly.

0
votes

I think this might answer your question: Why will I need a billing account to use Node.js 10 or later for Cloud Functions for Firebase?:

Because of updates to its underlying architecture planned for August 17, 2020, Cloud Functions for Firebase will rely on some additional paid Google services: Cloud Build, Container Registry, and Cloud Storage. These architecture updates will apply for functions deployed to the Node.js 10 runtime. Usage of these services will be billed in addition to existing pricing.

In the new architecture, Cloud Build supports the deployment of functions. You'll be billed only for the computing time required to build a function's runtime container.

On the other hand, the Service Firebase Clud Messaging itself is free:

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

Given that you are using Node in your CFs, the Platform requires to you a Billing Account.