Firebase Messaging Push Notifications - node.js

hi guys I'm trying to add push notifications to my flutter app. I want them to be sent to specific users an hour before an event happens the time of the event will be stored in firebase by the user. I have been doing my research and I think need to write these conditions in a node.js file? I also want to send another notification if an entry is added which is pretty straight forward. However I only would want to send it to the users in the same area as the user who added the entry. In my flutter app I use geohashes and haversine to query firebase for the user in the same area would I need to do the same in the node.js file. I am having trouble finding some good examples if this correct please direct me to some better resources if not please help me better understand what I should be doing. Thank you

Your question's scope is wide but I will try to give you some kind of guideline for you to begin with.
First to set up an environment for firebase functions follow this, then there are different triggers for firebase functions like database write calls a function to be executed when new data is written to the database.
In your case when you add an event inside your trigger write some code to get the users near that area and send notifications, and to send the notifications you will need to get the token of every user when they login to your app and save it somewhere else.
For firebase functions, you need to know basic Javascript/TypeScript and for that, this video series of Doug Stevenson is very helpful. I recommend finishing the tutorial first.

Related

How to listen for Database-changes using an RestAPI from Google/Microsoft/Notion?

I am trying to integrate Google Calendar and Microsoft Todo into my Notion Workspace using NodeJS. It is quite easy to make Requests in order to create, read, update and delete data but I was wondering how I could listen for changes in the database. For instance if someone creates an event in Google Calendar, how can I directly respond to this change in Google's database by creating a new event in the Notion Database? I thought of making as many requests per minute as possible in order to notice changes as early as possible, but I do not think that is quite resource friendly.
Eventually I was also wondering if it is even possible to make a RestAPI-Server that sends out some kind of Notifications.
I hope my question is understandable.
Thank you and stay save!
They keyword you're looking for is "webhook", I don't know if Google Calendar and Microsoft Todo support webhook or not but Notion currently doesn't, learn more at https://www.reddit.com/r/Notion/comments/nd76ec/notion_api_webhooks/

How to build a notification system for followed posts

MERN stack
In my app, you can follow users and when those users make a post, you should get a notification.
Currently, my User model has an array that lists all the users they're following as well as users who are following them:
users_you_follow: [ <object_ids>... ],
users_who_follow_you: [ <object_ids>... ]
My current idea looks something like this:
When a user makes a post in the frontend, we pass in the array of users_who_follow_you as well as the post details into the backend.
Then, using mongoose, parse the users_who_follow_you and find the users with the same ID's.
Finally, within that User model, I would store the post details along with some other metadata.
Then in the frontend, I would have a setInterval call to check if there are any new notifications.
This method although might work seems very server intense with all the API calls to check notifications. Is there a better way around this?
I currently don't know how to start on this process. From my research, some people said to use websockets while others say web workers.
What would be the best way to achieve something like this?
A very similar system to compare it to would be StackOverflows inbox thing. If a user comments on your post, the header/navbar shows a notification without having you to refresh your screen.
Thank you.

How to get instant changes in background from private api in mobile app?

I am planning to create a mobile application for android and ios users, i think i will take a try with xamarin since i will be alone on this project and i don't have a lots of time.
I want that the mobile app for both platform get datas from the api, then if there is new datas available we notify the user by a notification.
How the mobile will work in that kind of project? I mean should i make a background service then check every x seconds/minutes by http request? In that case which time interval? Should i use websockets instead for this case?
The app might be used by many people, so i would to know the scenario in this kind of project: Getting very fast changes, without overload the server due to too many connects or whatever else.
I'm confused about this and i need some lights around, any mobile application/server experiences related would be apprecied!
EDIT:
As suggered by an user, here additional infos:
The api is homemade, restful using JWT made in NodeJS.
Each users on their device should get messages from server asap, even when the app is in background/closed.
Maybe in the future a way to send messages between users themselves.
You have to implement push notification.
It is quite easy to implement this in xamarin. just send the push notification to the device and on the notification received call back send the API request to retrieve the updated data.
Here is the document for sending push notification from custom API.
https://learn.microsoft.com/en-us/appcenter/push/pushapi
I'm not a mobile developer, so take this with a grain of salt.
The answer to this really depends on what you're doing, which informs how often to check the API. If it's a messaging app, for example, you could have it check every couple minutes to see if there are undelivered messages, then check more frequently for the next X minutes (to facilitate a conversation in real time).
If it's a GPS navigation app to be used while driving, you'd need much more frequent requests.
As for the API, that also depends on what type of API and the number of requests you can make to it. Is it a commercial API that you get x number of calls per hour on? Is it an API that you built? Etc.
Basically, you need to give more information in order to get more specific answers.

How to retrieve and update data from database using Dialogflow chat bot

I am very new to api.ai(Dialogflow). In my scenario i have to create a chat bot who should be able to update customer information in the real time database by taking the input from customer.
I am not sure how to do this. By some research i understood either by writing code in firebase function it is possible or by writing webhook and deploying to server.
But i am not understanding how to write the code. Any one can give any suggestions or any reference so that i can start coding.
I tried to write by seeing the weather webhook but did not understand this.
Any help is appreciated.
Thanks

Control your device with custom commands using Actions in Google

just getting started with Assistant features in RPi and I am able to successfully implement upto this point and wondering few thing.
Scenario:
user: hey google "please turn on my living room Lights"
List item my code in horword.py : has a function to perform same action based on ON_RECOGNIZING_SPEACH_FINISHED
RPi/google home: I am not sure how respond to that
I was able to capture the request query asked by user using ON_RECOGNIZING_SPEACH_FINISHED = Args.text(str) and use it in my logic to perform the task. However, at the same time, "ok google" is responding with this answer.
to mitigate this problem, I created an google-actions, now it understands my query and respond with intention from api.ai. However, didn't acts on turn lights ON. So, wondering how can I read response from google home/api.ai in text and change code to act on it locally.
appreciate it.
You will not get response as text.
For getting response to client app use webhook in API.AI and send message using fcm to client app.
Read the fcm message in client app and do the corresponding actions.
finally was able to figure out multiple ways. answered this in other stack question. find more details in this post.
Multiple ways to handle this since google doesn't gives voices transcript and we let google say our transcript which is kind off solution for now.

Resources