1
votes

I am a student developing an app and I have some back-end python code that utilizes the Firebase admin SDK. The app with provide an interface to an proprietary algorithm that cannot be moved into the a cloud function and so must stay within the back-end server. When a user makes a request to the algorithm, they will do so by uploading a document to Firestore with information the back-end needs to process their request.

Once a user uploads a document, an onCreate() cloud function is triggered, the goal of this function is to simply notify the back-end that there is a pending request, so that it can process it and send back to the user.

This is where I am struggling, I haven't been able to deduce a way to trigger action on the back-end from within the cloud function. I am hoping to find a way to accomplish this through Firebase without the need to implement additional libraries etc.

A way to generalize my issue would be: How would you notify an Firebase Admin SDK user through a Cloud Function?

2
You can do it same way as in any other nodejs app - for example by using http call. Please be aware that firebase free tier has restrictions for external network traffic in cloud functions. - MrAleister
Note that I am inexperienced in Node.js and have only used it as it is the required language for Cloud Functions. You imply that I should just send a http request to my back-end within the cloud function? Is there a resource I can peek that shows how I could set this up? - GermanMofo
twilio.com/blog/2017/08/http-requests-in-node-js.html - first Google result for nodejs http call - MrAleister
Okay, thank you for the potential solution, but I don't believe setting up my back-end to receive and process http requests will be my desired solution. I am looking into possibly utilizing FireBase's FCM messages. - GermanMofo

2 Answers

2
votes

FCM is used for sending messages and notifications to mobile clients. It doesn't work for sending messages to backend components.

If you want to notify some backend component, you typically use an HTTP endpoint or pubsub messaging.

0
votes

Firebase Functions SDK already uses the Firebase Admin SDK under the hood. So if you set up a Cloud Functions trigger in Node.js, you can access Admin SDK from the Function itself. For instance, taking a Cloud Storage trigger as an example:

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

exports.fn = functions.storage.object().onFinalize((object) => {
  // Call Admin SDK APIs
});

Similar integrations should be possible with Python as well: https://medium.com/@hiranya911/firebase-using-the-python-admin-sdk-on-google-cloud-functions-590f50226286