Does we start writing cloud functions for firebase locally? - android

I'm going to use cloud functions for firebase to recursively delete documents and collections in Firestore that is triggered by HTTP request (I'm using HTTP Callable function specifically). I have found some useful information from the following links:
https://firebase.google.com/docs/functions/callable
https://firebase.google.com/docs/firestore/solutions/delete-collections
But I'm not sure about one thing: It looks like from the tutorial, the functions are written locally and then deployed to cloud server. So where do I keep all the functions and their dependencies? If I keep the local written function within my android project, then each time when I update the function locally I will have to publish a new version of the app, which is too much work. Is it ok to start the local written function in another folder other than the android project? Also, if I want to start writing the function directly at cloud functions at GCP (so that I can update the function in cloud server), where can I get the dependencies files such as package.json, package-lock.json and .eslintrc.json etc.? I didn't find useful tutorial to that. Can someone help me? Thanks!

To answer your questions, first you can keep your functions and dependencies anywhere as long as you have access and logged your account to the CLI with the right project configured in it. Each time you update your function locally then yes, you have to redeploy it.
If you want, you can consider setting up CI/CD with your Firebase Functions so you can automate deployments whenever you hit commit on master and staging branch of your repo.
Second, you can start the local written function anywhere, as long as it contains the right dependencies for your app. As Doug mentioned, it doesn't matter how your files are organized.
And third, the dependencies files such as package.json, package-lock.json, and .eslintrc.json is something that you need to provide on your own. I suggest that you read through their docs and see what works best for you.

If I keep the local written function within my android project, then each time when I update the function locally I will have to publish a new version of the app, which is too much work.
That's not true. It doesn't really matter where you project files are organized. You can still deploy the function whenever you want. It's completely separate from your app code.
Is it ok to start the local written function in another folder other than the android project?
If that's your preference, then do it. As I mentioned, it doesn't matter how your files are organized.
Also, if I want to start writing the function directly at cloud functions at GCP (so that I can update the function in cloud server), where can I get the dependencies files such as package.json, package-lock.json and .eslintrc.json etc.?
If you're having problems working with functions in the console, you should ask a separate question about that and indicate where you are stuck in that process.

Related

Firebase Realtime Database connection killed: Different Region

I am trying to build a simple login user authentication Android application that uses Firebases Realtime Database but I am getting the error:
[Firebase Database connection was forcefully killed by the server. Will not attempt to reconnect. Reason: The database lives in a different region. Please change your database URL to https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app]
I am currently using the Singapore(asia-southeast1) server since I live in the Philippines. Is this wrong? or Should I be using the US one? How do I change my Database URL?
It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created. In such cases the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.
There are two possible solutions:
Download an updated google-services.json from the Firebase console, and add that to your Android app.
Specify the database URL in your code instead, like this: FirebaseDatabase.getInstance("https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app")...
Both have the same result, so pick whichever one seems easiest to you.
It cat still not work after the accepted answer (as in my case). If so, try:
Clean Project
Rebuild Project
Invalidate Caches & Restarte
and run it again.
If you are a New Flutter User who followed the new firebase doc, run this command in the terminal. It will automatically update the firebase_options.dart file.
flutterfire configure
I faced the same problem and that's because when you set up the app, the google-service.json doesn't contain the firebase_url.
These problems faced you when configuring your set up manually, You can fix all that problems by using flutterfire, it will help you a lot and set up your app in a few steps.
see docs firebase
It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created. In such cases, the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.
You can fix it either way.
After configuring the database service setup you have to download the new "GoogleService-Info.plist" file and replace the previous one.
or
You can manually set the key in your "GoogleService-Info.plist" file
<key>DATABASE_URL</key>
<string>https://<app-instance-default-rtdb>.asia-southeast1.firebasedatabase.app</string> '

How to stub Firebase for UI test Android?

Problem: I want to know which data go to Firebase Firestore and Firebase Authentication.
In my project, I'm using pure Firebase without RxJava or something else.
Here is my project on GitHub: https://github.com/Artemius-dev/Projemanag_Trello_Clone
I have found only one solution so far.
Firstly you need to make sure that you have good architecture in your app. Then make sure that you can add DI to your project if you haven't done it already
Secondly, make separate DI (Dagger or Hilt) for AndroidTest
(preferably not necessary add some common Interface for example: to add Notes or Users to your app so you can implement the same Interface in your AndroidTests and inject it to your main app with new methods which will be only executed in your tests so you won't add anything in your production code)
Thirdly use Firebase Emulator Suite to work with not production data and database
P.S (As I have seen so far the Firebase Emulator Suite is the best solution to test Firebase)

my firebase function is being deleted when i try to upload new one

I want to create a function for a push notification but when I try to upload new function then the previous function which is for different purpose is being deleted . I don't know why currently I have 3 functions. This is the screenshot of my node js
This is the way deployments with the Firebase CLI work by default. Every time you deploy, all the functions you deploy completely replace any other functions you previously deployed.
If you want to deploy only certain functions without replacing everything, you need to specify that on the command line as described in the documentation:
When deploying functions, you can target specific ones:
firebase deploy --only functions:function1
firebase deploy --only functions:function1,functions:function2
Most likely you renamed the previous function in the index file.
That would show up as a "delete" prompt when deploying.
If that is not the case, please include the index.js / index.ts file.

Dialogflow minimal viable product

I am trying to create the bare minimum of a chatbot with dialogflow in an Android app. Initially I do not need the bot to hook into things or have context and entities. I just want it to match questions with answers as good as it can.
I do not come from the web world so this https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation confuses me. The final part of the tutorial is not finished and it leaves me hanging a bit.
As an Android dev I want the app to:
call a rest api with the user text
or possibly:
invoke an SDK and have a local pretrained agent and not involve the internet an all
You can download the Agent but that is just some json files. I found an Dialogflow.SDK but it seems to be related to speech. In the dialog flow console you can 'copy curl':
curl 'https://api.dialogflow.com/v1/query?v=20170712&query=Hi&lang=en&sessionId=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx' -H 'Authorization:Bearer xxxxxxxxxxxxxxxxxxxxxxxxx'
I want to access the agent like that from multiple instances of an app.
Do you always need a 'fulfillment'?
The guide mentions creating folders on your local machine(in conjunction with fulfillment) are these only used to do a 'deploy' from your local machine to configure the web hook in the cloud? Or are they also used to deploy the entire Agent to the cloud project? (which i can't seem to find any instructions for, unless it's the same as for webhooks?)
gcloud beta functions deploy weatherWebhook --stage-bucket [BUCKET_NAME] --trigger-http
I have read questions with both tags DialogFlow and Android but most of them seem to involve Google Android Assistent which I have no interest in.
You do not need fulfillment. This is primarily for Dialogflow to take advanced actions or to use more complicated logic to handle the response.
You also cannot run Dialogflow processing on your device - all operations take place in the cloud. So you don't need to download the zip file unless you want to make a backup copy of your agent.
The REST interface you're looking for is the one you found. It handles more than speech - the /query endpoint can take a query parameter which contains "Natural language text to be processed."

Firebase Realtime Database - deleting a child node after specific time. Are there cloud functions for it?

I'm writing an android app with objects that I want to expire after a certain time automatically. Even when the user closes out of the app and services.
Oh yeah, I've written code in background services to trigger and organize deleted objects and move them into other nodes, but I'd like to find out if this is possible strictly on the back end.
Any insight would be very helpful!
Thanks
-T
I don't think there is any special function for what you want.
You have to trigger it manually java.time utility of android/java might be useful for this. write a method which check the time of system and and when the desire time match with your function timing trigger the postRef.remove for firebase.
maybe this helps
if(java.time.LocalDateTime==urTimeForDelete){postRef.remove();}
As every Firebase project is backed with a Google cloud project you use App engine Cron service to get you job done.

Categories

Resources