How to send a notification at a random time? - node.js

I would like to find out how, using Node.js, Express, Typeorm I can send notifications at random times to users to add a post etc.
I would like to create something of the BeReal sort. Notifications should be sent according to the user's selected time zone at random times.

If you want to send automated notifications, I'd recommend using
node-cron. However, for your case, I'd propose to add a timeZone
indicative information in the database to link the user with the
timeZone(you can find it in HTTP Requests, update it after each
login).
For the actual sending of the notifications, I think you should use
some third party service like Google Firebase for mobile
notifications, and web-push for web applications.

Related

Send a push notification to opted-in users at the time which they select

After taking the user's permission to send push notifications and saving the userID in firestore, how can I use it to send notifications to them at a time of their choice daily ?
For example :
If the user selects 8:00 AM , I want to be able to send them the push notification everyday at 8 am.
I can't write the code to send the notification in the action itself.
What will I have to setup to accomplish this?
Once the user has granted you permission to send push notifications, you can use the Actions API to send the push notification.
The setup would be as follows.
Storing user preferences
1) Dialogflow agent asks the user when they want to be notified
2) User says they want to be notified at 8:00 am
3) Dialogflow detects the answer and makes a fulfillment request to your webhook (The webhook can be the inline editor in dialogflow (Functions) or another server)
4) In the handler of the intent, you have to store the UserId and the time they selected in your database (in this case, firestore)
5) Dialogflow agent gives the final answer to the user and the interaction ends
Sending the push notification
1) Identify if you have to send a notification to a user; this is the tricky part.
It is not possible to give you a definitive solution on this, because it heavily depends on the requirements of your system and the technologies that you are using/want to use.
Basically, you can use cron jobs, background infinite processes, pub/sub, cloud scheduler, or any other tool that allows you to constantly read information from your database to determine which users need to be notified. I recommend you to check this answer where is discussed an approach to tackle this problem using Firestore.
Notice that you don't necessarily need another server running, you can use the Functions used for the fulfillment.
For example. You can set up Cloud Scheduler to run each hour, and make a request to your Functions. In the request, you read from Firestore and extract the entities that need to be notified that hour.
2) Once you have the users that you want to notificate, you need to use the Actions API to send the push notification. Once again, this request can come from your fulfillment server, or another server used in the system.

Best way to efficiently send 1000 unique emails using the sendgrid/mail library for Node.JS

I have an admin panel in my Node.JS application where admins can login and send emails to groups of users. Sometimes these groups can contain up to 1,000 people. When the admin composes an email in the admin panel and hits the send button, I grab each row from the database and generate a unique link for that email body and then send it using the #sendgrid/mail npm package. I have looked at the following page and it is helpful: https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/README.md#email-use-cases
However, I don't know if it's more efficient to create a giant array of emails and dump that into one of the libraries methods, or if I should loop through and make a separate method call in each iteration and use Promise.all. I suppose I need a solution that won't make the Sendgrid rate limits angry but also not keep my http request loading for 30 seconds for the admin.
Thank you
From the UI you should get all the users that are to be emailed, into the node.js backend app.
In the backend app, assuming you get an array of the users, you use the Arrays.map() method to execute a function returns a promise that will send out the email.
You can then use Promise.all() to see what emails got send and what failed.
If there are any failures you can show that as a notification to the Admins on the UI, for only those users that failed.
Also note the SendGrid API seems to be capable of accepting 10k requests per second. Do take a look at this.

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 use trigger event in facebook messenger bot

I'm developing Facebook messenger bot. Based on the official sample
here made by Node.js, Express, ES7.
I want to use Firebase database, trigger event.
If someone updates the database, send notice to certain people. I add source code "Child Changed" to "messages.js" in messenger-api-helpers, but it doesn't work.
I can check working "Child Changed" in HTML, but in messenger, I cannot.
Where should I write the trigger events code?
You should definitely use Facebook Messenger Broadcast API for this kind of functionality. This will broadcast a notice/broadcast to users.
Caveats:
You have to apply for this permission. (pages_messaging and pages_messaging_subscriptions.Takes about 1-2 days, but
can test on Admin/Test users of the app)
Each broadcast has to be a separate broadcast. (e.g. you can't send image and a text together, each has to be its own individual broadcast).
Have some kind of un-subscription option as well. FB user might think you are spamming even if you clearly say in the messages that your bot will send updates.
Use custom labels to create targetted sends. So you can either subdivide who you will send updates to about specific issues or just label people if they unsubscribe to your broadcast or not.
Basic workflow:
Get permission to broadcast.
On event in your Database. Start process.
Create message_creative_id via POST to endpoint
Use message_creative_id to POST a broadcast_messages
On a successful send you will get back broadcast_id

Simplest way to send a notification to Evernote web application?

I'm not even sure if this is possible/options to look into.
I wrote an email-based sync where a user has a note in Evernote and when the user sends an email from Evernote to a website endpoint, I want the end point to notify the user that their request was received on Evernote.
I don't know if this is even possible. I just want to say "email received" sort of thing.
Closest thing I could think of is having an evernote with the contents updated (sync log). It's kind of like a webhook for Slack but looking for Evernote.
To clarify: The user is currently on Evernote (website) looking at their note, they send the email (from here to share the current note) I want a popup/notification of some sort to say "Email received" I don't know if there is a system for this or not. I don't think so.
Edit: In the meantime I just setup a slack webhook notification
There's no way to programmatically cause a notification to occur/appear within an Evernote client application. You could implement something that's external to Evernote using your own notification mechanism like push notification on mobile, SignalR, etc. but that would be dependent on the user's environment.

Resources