How to push something to user in a rest API? - api

We already have a system in place that uses Restful APIs in order to send let's say SMS. All of our clients are using our server to send their requests to Rest API so we drop connections except our server IP to handle authentication.
Now policy has been changed. We want to expose our APIs to the outside world. We now want to be able to push to user under specific circumstances. Let's say that I want to send a delivery report to the user when SMS has been delivered. Or when something has been scheduled for a specific time, when that time arrives user get notified.
How to handle these notifs? Has anyone used the same or similar approach?

Assuming you can reach your clients back via HTTP. The model to do this is to use callbacks. When someone posts a scheduled job on your server, they should also post a callback URI where your server can notify when the job is complete.
Sample below:
https://schedulingSevrer.com/runSchedule?callback=http://clientserver.com/reportStatusHere
So when the job is done your callback will be like
http://clientserver.com/reportStatusHere?jobId=12345&status=complete
Or if your clients are mobile apps on Andorid you can use the Google Push notifications.

Related

Strategy for notification checking

Is there a recommended strategy for checking of notifications within my AngularJS app?
By 'notification' I'm talking about message alerts that are to be displayed to a user when they're logged into the application.
My plan is to notify the user of unread notifications in the app's NavBar as shown below:
My app communicates with my restFul API (written using Node.js, express, MongoDB), so I anticipate that new notification will be written to a MongoDB collection with details the user the notification is intended for.
What I'm unsure about is how the AngularJS application will check for notifications once a user is logged on. I could call my API for unread notifications every time the user navigates from one path to another but that seems simplistic and it wouldn't work if a new notification occurs whilst a user is viewing a page.
Another way would be some sort of timer system that checked, say, every 30 seconds. But this would results in unnecessary polling of my API when there aren't any new notification for a user.
So, wondering if there is a recommended strategy. Thanks for your help.
Polling is a solution but it is very inefficient. The solution to your problem are websockets. Websockets is a technology that provides a full-duplex bidirectional communication between your clients and your server. So you can send messages from your server to your connected clients. Your server maintains an array of connected clients and you just have to know which ID you need to send a message to it.
For your stack, the best solution I have came to is Socket.io http://socket.io
It also have cool features. For example, you can "observe" models, so if a model change in your database, for example an update to a user profile is made, you can trigger an event and automagically send a message to your client. This client get and handles the notification and do something, like put a badge on your alerts icon.
Hope this is useful for you.

Twilio How to collect incoming SMS messages using .net efficiently

I created an application in VB.net that ties into a scheduling software. It keeps our employees up to date by sending them SMS updates. Employees can reply back to us. Sending messages works great. The application uses the Rest API to connect to Twilio. I can also get a list of incoming messages but I can't seem to get it in a way that works well for me.
Currently my application checks if there are new messages every 5 minutes. The application gets the messages list (with filter DateSent>=today) and then loops through the messages and copies the new ones into our scheduling database.
Is it possible to do a more efficient data pull for new SMS messages using VB.net only? Can I include a time filter in addition to current filter DateSent>=today to limit the result set? Any suggestions? (I don't do web coding unfortunately) Thanks.
Twilio evangelist here.
The best way to do this is just to use Twilios web hook to let Twilio proactively tell you each time its received a message. Whats a web hook you ask? Great question.
A webhook is simply an HTTP request that Twilio will make as soon as it received an inbound SMS messages to your Twilio phone number. You normally tell Twilio to make this HTTP request to a URL that you've created and published to a public website, which you can set up easily by using something like ASP.NET. In this scenario you can think of Twilio like a web browser that is making a request to a web application that you have created.
You can tell Twilio what URL it should request by opening the Numbers tab in your Twilio dashboard, and then locating and clicking the phone number you want to configure:
Now you set the URL you want Twilio to request in the Message Request URL field and click Save:
Now when Twilio requests this URL its going to pass a bunch of parameters with its request that you can use in your application logic. You can also do things like return TwiML back to Twilio in response to its HTTP request that tell it to do things like send an SMS right back to the person who just sent one to you.
If you're looking for a bit more of a step by step, the Quickstarts on our website are pretty easy to follow and will walk you through both sending an receiving text messages. The samples are in C# but are pretty straight forward so converting to VB.NET should be easy.
Hope that helps.
I am doing something similar with VB.Net and Twilio. My solution was to put up an Azure web site and an Azure SQL Database (the two can talk to each other). I set up my Twlio to call an .ashx asp.net web page on my Azure web site. Inside of that web page I have code that reads the incoming text message and saves it to my Azure SQL Database.
Works great, but my problem is the Azure database is in "the cloud" and my app\database that sends the original SMS is on mylocal network. Not sure how to cross that divide... (I should add that my local app can read the Azure SQL database, but seems ugly to have to call out to the Azure to get data. Would have preferred to have just saved it in my local db to begin with.)
Probably not a very helpful post, but maybe give you some architectural ideas. If you want to see my .ashx page just let me know.

How to implement a "timely query" using Apache+wsgi?

I am new to apache + wsgi programming and I am trying to implement a "email notify" service.
In this service, users will register their email address and interesting game players' name, and web server will timely (for example every 6 hours) query the players' information, if some new matches happen, then send a email to the users who register their email for this player.
Very straight forward approach, but I don't know how to timely invoke the service to query certain informations... I tried to do some Google, but basically I don't even know who should response for this functionality, Apache? or some configuration of mod_wsgi?
Could anyone give me some help?
Use a backend task queuing system like Celery and configure periodic tasks.
http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html
Do not try and do it as part of the web application.

Mail Notification service available in windows azure application

i m developing one application in that one user create one task and that notify to other users which are connected to that user so windows azure provide any notification service to implement this functionality?
Azure does not provide a mail relay service, but it does support the SMTP protocol and sending e-mail through external services ; here are a few options:
Sending Email using Microsoft
Exchange :
http://blogs.msdn.com/b/windowsazure/archive/2010/10/08/adoption-program-insights-sending-emails-from-windows-azure-part-1-of-2.aspx
Sending Email from Exchange Online :
http://blogs.msdn.com/b/windowsazure/archive/2010/10/15/adoption-program-insights-sending-emails-from-windows-azure-part-2-of-2.aspx
Sending Email using 3rd party
providers (e.g. SendGrid,
AuthSMTP...)
http://blog.smarx.com/posts/emailtheinternet-com-sending-and-receiving-email-in-windows-azure
This question is suspiciously similarly phrased to this one. The answer is, there are no notification services that would provide the functionality you seek out of the box.
It also links to the following answers:
http://blogs.msdn.com/b/windowsazure/archive/2010/10/08/adoption-program-insights-sending-emails-from-windows-azure-part-1-of-2.aspx?wa=wsignin1.0
http://blogs.msdn.com/b/davidlem/archive/2009/01/08/windows-azure-sending-smtp-emails.aspx
As for the notification service it depends on what you mean by notification. If you want to also pop-up a message, e.g. for chat, or a response to a query, your best bet would be to implement a storage-backed (e.g. Session store with a session state provider, or Azure Tables, even Azure SQL would do) and either print waiting notifications on each page refresh, or better yet, do that with an Ajax call. Take a look at his Stack Overflow question for some suggestions.
On a side note, if you mean notification of services, e.g. a mailer, or something else, that should fire when a user performs certain actions, you can implement the basic functionality using Azure Queues, or Azure AppFabric if you need more advanced stuff.

Building a GPS Tracking Web System

I'd like to develop a tracking system using an API of course (like the famous Orange API).
the idea is simple:
I send a SMS (from my Web interface) to the person i want to track
The person's mobile terminal (GPS like this) send me back automatically
the coordinates by SMS.
The sent information are displayed on the user's web interface.
The questions are simple:
How the terminal can send automatically the response?
How to indicate in the message that the information is for "user4655"?
How to make connection between the information and the database?
Thanks,
Regards.
* How the terminal can send automatically the response?
Ans: You set the gateway and the time intervals you want the device to send the sms to on the device itself.
* How to indicate in the message that the information is for "user4655"?
Ans: The gateway you use will have the API to determine that the number it is sent from. The device will use a registered phone number from either a sim or enabled by one of those cell providers.
* How to make connection between the information and the database?
Ans: I dont understand this. But I'm guessing you will have a database to keep track of the user data. You'll just probably need another table that is a child of the user, which has a list of the data and the time they came in.