We are developing a chat app for Android and iOS which uses a Firebase database for storing chat messages. We don't want keep all chat messages in Firebase database because storage gets bigger and expensive everyday. So we want to move 2 days old chat data to another database. Our purpose is to load new messages from Firebase storage and to load 2 days and older messages from another database when user wants to see older messages by scrolling up or pressing "load more" button.
Our database is like this:
Chat Room KEY
Message Id
Message
Time and Date
Reciever Id
Sender Id
I have a few questions.
Can we automatically move older messages to another database based on message created date to decrease database storage costs? What is the best method for this? Do we need to use Firebase Functions?
Do we need to implement auth for our new database so that it know if our user wants to see data? Or is is it possible to query old message data from client side without authorizing our app users. Will it have security problems?
Which database we should use? How would you solve this problem?
Thank you.
Related
I’m making an app using react with firebase, and a large part of my app involves group communication. Currently I have FCM sending notifications to people within the group whenever someone types a message into chat. Can I use onMessage to load messages in real time for all group members to see, without needing to refresh the page, or do I need to set up firebase real time database ?
Any help/advice is greatly appreciated !
I would recommend to store the messages in one of the Firebase databases. For multiple reasons. You can only send FCM messages from the backend so you need a trigger for that. Idealy when a new messages is added to the database. If all users for a group listen to messages in a group chat they would see them when you setup a realtime listener. This would work much faster and more reliable than using FCM for realtime data. FCM is idealy used to notify users when they are outside of the app or inside the app but not in the chat by using onMessage. The UI should rely only the databse data and not FCM.
I have one mobile app, and every customer have a lot of data under user account. It is possible to make one database firebase for each customer ? Xamarin app...
You can create multiple databases directly from the Firebase Console as mentioned here.
In case you need to create the databases programmatically as new users sign up or so, then you need to use Firebase Realtime Database Management API.
To create a new database, make a POST request:
https://firebasedatabase.googleapis.com/v1beta/{parent=projects/*/locations/*}/instances
Currently I'm working on a mobile app using Ionic and Angular2 with Realtime database service from firebase. I want to make a chatbot using Dialogflow to analyze the user request (i.e. I need a wheelchair) and then analyze the firebase db for any similar items stored, and if it exists, I need to show the item's name and the uid of the user who has added it into the database.
Have seen some tutorials on Dialogflow with Cloud Firestore but I'm not sure whether this works with the Realtime DB and how it would work.
Thanks in advance. 😊
To do this, you'll need to use a fulfillment webhook that will be sent the information about what the user has said, does the database search, and sends the reply using Dialogflow's response JSON format.
I'm trying to use firebase cloud messaging service for my android application and I'm trying to find the best way to manage registration ID in database server.
I was thinking to create new table with userID,registrationId (where userID is unique for each user) in my database and insert new record once the user logs in successfully and remove that record when the user logs out. but there are some situation that the registration Id will be refreshed, I can get the new registration Id to save it in the database. but how can I get the old registration Id to remove it?
Are there better way to manage the registration Id in database?
note: a device can access one account but there are might be many devices that use the same account.
Depending on the user, you might want to also have an identifier for each device they use. But for a simpler explanation, I'll go with the scenario where each user only has a single device.
If you're using Firebase Database, then the simplest way to structure the nodes would be something like this:
pushTokens/
$userId: <registration_token_here>
Simple as that. You just pair the userId that you use in your app (possibly for authentication) and place the token there. On sign out, log the user out. When the user is currently signed-in and the token refreshes, handle it in onTokenRefresh(), send the new token to the DB, and replace the older one. Deciding to keep the old one for logging purposes is your call.
Possibly helpful posts:
Firebase Cloud Messaging - Managing Registration Tokens
Managing FCM device groups
I know that Firebase has recently added support for Push Notifications and while this is a great thing, I only seem to be able to send push notifications manually via the Notifications Panel.
What I'd like to do is to send push notifications within a user scope...Let me explain that. Each User in my App has an account and then each user can join a group. Within this group the user can perform tasks and has a list of chores to do. Now when certain tasks are due for example I want to remind the user of doing it with a push notification. For 1-10 I might be able to pull this off manually, but is there a way to dynamically based on the data in the Database send out Push Notifications?
I know that certain Push Notifications can be created using the Analytics tool such as "Hey you have not visited for 3 days, please come back whatever"... but I'd like to register push notifications such as "I just created a task, this task needs to be done within 3 days. Remind me in 3 days if the task is still not done".
Is this possible with Firebase or do I need to have my own server connecting to Firebase and handling those events?
-xCoder
You need to implement FCM in your client and in a server. Let me put this straight:
First, you need that your client, or app, to register into FCM and get a FCM token that will be used to identify that device uniquely.
Then, store that token wherever you like. It can be into firebase database or other server you may like. I recommend you to store it into firebase if you are using it as a database for your users; that's my case.
Also, you need to implement a http or xmpp server in order to send FCM messages to your registered devices containing the data you are interested in. For example, you can implement a Google App Engine endpoint (can be done with Android Studio and Java) that is quite simple or a NodeJS module, depending on your preferred language.
If you are using Firebase as database you can connect from your server with the appropriate SDK and get the FCM tokens you want from your users, and then send the message to those with data. Don't forget to secure your serve.
The way you implement your server algorithm to send FCM messages depends on your app purposes.
Hope it is clear enough for you. Also you can find all the documentation with a short video that explains the general structure here: https://firebase.google.com/docs/cloud-messaging
You can use cloud functions to trigger on any create, update or delete operation in your database and in the trigger event, you can choose to send in FCM push notifications to the devices of your choice.
Here is the documentation regarding the use and structure of a cloud function: https://firebase.google.com/docs/firestore/extend-with-functions
Hope this helps!