I'm totally new to hybrid world so I have to ask first.
Can I send notifications through GCM without a server?
I mean, I'm building a SPA with AngularJS and Firebase, but my customer asked me to make a dashboard for Android, so every time an user makes an order, they (both dashboard administrators) receive a PUSH notification on their phone: "A new order has been created", and when they "tap", the application opens.
I've been reading something about /topic/ endpoint to notify both of them, but I think I still need a server to do it. Do I?
It would be great if I simply post a http query using something like AngularJS' $http service to tell GCM to send a notification for that topic/usergroup.
Is that possible? If so, any idea about how?
Thank you very much in advance!
Sending a downstream GCM message can be done "without a server". One option is to send an HTTP request to GCM containing the required fields. Topic Messaging is available with GCM which does make it easier to send downstream messages without a server. Your client apps can subscribe for messages from /topic/usergroup and then you can send an HTTP request with /topic/usergroup as your "to" value, and subscribed clients will get it.
Note that you will need to set up a Google Developer Console project to get the required API key.
Check here for more information on the structure of GCM HTTP downstream messages.
Related
I am storing the registration tokens in my database. I want to send push notifications to the single device by taking registration tokens from database but without using firebase console. How to do it?
You need an app server or some Google Chrome extention like PostMan.
First of all, you need to understand the differences between notification message and a data message, like how the app handles the incoming message if it is in the background state or on running on the foreground.
Secondly, create a payload and send a post request to FCM endpoint. It is well documented here.
Lastly, check the FCM response. Note that getting a success response doesn't mean that the message is already delivered to the app, but rather the FCM server accepted it for delivery.
If you would like to learn more about what parameters you can use and the definition of each response codes, check out the Firebase Cloud Messaging HTTP Protocol documentation.
I hope this helps.
If you are using Firebase database to store your tokens and intend to send the FCM notification during an event, I suggest making use of Cloud Functions for Firebase. See my answer here for an idea on how you might use it.
If you just want to send a simple downstream message, you could use Postman (also stated by #looptheloop88 in his answer) or cURL.
I've been doing so much research, but it seems like all the articles out there are either sending notifications from the console or sending a push notification to a single device.
All I want is to send a push notification using Firebase ON my client and not on the Console to everyone. Do I need a server? If so, what information do I need to retrieve from it?
If you simply want to send a downstream message, you don't really need a server. You can simply use Postman or cURL. Just specify the registration token(s)/topic you want to send your message payload to.
If you are aiming to send the downstream message from the client (Android app) itself, I would strongly advise not to. Quoting a portion of #FrankvanPuffelen's answer here:
Sending a message to devices (so-called downstream messages) requires a HTTP call that specifies the server key. As its name implies, this key should only be used in environments you can trust.
It is to avoid exposing the key to unauthorized users, preventing exploitation.
I'm new to push notifications and here's what I understood so far -
Client app will need to register with Google Cloud Connection Server (GCCS).
GCCS will return a registration ID back to the client.
Client will send the device id and registration ID to the app server.
App server will store device & registration in its database. This database could get huge depending on the number users.
The app server in my case comprises of a single HTML page, and a node.js script. Admin will get to the page, types in a message and hits Send.
The app server will make a POST call to GCCS with the Sender ID, API Token, array of registration ID's etc.
Message is received by the devices.
There is also this thing called as Topics that the client apps can subscribe to. Using Topics, you do not have to send registration ID's of all devices. All devices "subscribed" to this Topic will get the message. This is very useful if you have millions of users (depending on the popularity of the app) and you don't have to split the registration ID's into chunks of 1000s to send the message.
My questions are -
If we're using Topics, do we need to persist the Registration ID, Device ID to a database on the App server? It seems redundant.
Are there any ready-to-use/commercial GCM servers that can send Topic messages?
Is it easy enough to build on your own (since its a simple POST call)? If I'm going to use JavaScript, wouldn't I run into CORS issue?
Thanks for the help!
If we're using Topics, do we need to persist the Registration ID, Device ID to a database on the App server? It seems redundant.
Are you referring to C2DM implementations? Those are deprecated as shown on the GCM documentation. In relation to topics, they may not be necessary but are necessary to other message calls.
Based on the documentation, to needs to be set as topic/[yourTopic] with the necessary payload
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
Are there any ready-to-use/commercial GCM servers that can send Topic messages?
I can't find any sources about this, so I'm guessing we're left to implement it on our own application server. Google provided us with a sandbox project for us to play with.
Is it easy enough to build on your own (since its a simple POST call)? If I'm going to use JavaScript, wouldn't I run into CORS issue?
If you're talking about setting up the Client App (specifically Android), there's a setup guide on the documentation. But if its more on the application server, I can't comment on it really. XMPP libraries can be used to handle XMPP Connection Servers
Our organization has an Android app and an iOS app.
We want to start pushing notification to these apps.
Android has GCM.
Apple has APNS.
But we want to create an API which will work on both android and iOS.
What is the easiest way to setup a server so that when a push notification needs to be sent, it knows exactly which server to send the message to?
I use a service called Parse to do my notification pushes to both Android and iOS. They have great documentation and libraries available. You can get some details here: https://parse.com/products/push
As a little background this is for a university setting where multiple colleges apps as well as distance education may be using the service. Here is the approach that we are using in our organization. If you look at the way APNS works it can be used by just sending a web call to the APNS service with the token id. GCM is very close to the same type of system. Basically create a JSON package and send it to the desired service.
Here is our steps we used to create this service.
Server admins created a server and database that can be called that will collect the tokens from both android and ios devices. When the device registers we also send what type of device it is. This is possible since we are just sending data to the database that is has been created.
From here we then created a couple of python scripts that send the data do the desired service whether it is ios or android. These scripts gather the appropriate data from the database and sends the packaged data (JSON package) to APNS for ios message and GCM for google cloud.
We also created a web interface so that those who need to send messages to the devices can.
The rest of the implementation is up to you to decide the best way to utilize the service. For example when to check for invalid devices,
Because we are planning on using this same server for multiple applications we can send the type of device, token, application, or whatever else is needed for an application to distinguish it from others we produce so that each application that wants to use the service can. I hope this helps and gives you some idea on how to accomplish this.
For APNS, Maybe you may consider this forked version of PyAPNS that has enhanced message support.
https://github.com/jimhorng/PyAPNs
which means it will catch error response for failure messages and resent the message which are discarded by APNS while sending between failure messages and receiving error response.
Solution:
Non-blocking ssl socket connection to send notification without waiting for response.
A separate thread for constantly checking error-response from read connection.
A sent notification buffer used for re-sending notification that were sent after failed notification, or arbitrary connection close by apns.
(Reference to non-blocking apns pull request by minorblend, enhanced message by hagino3000)
Result:
Send notification at throughput of 1000/secs
In worse case of when 1st notification sent failed, error-response respond after 1 secs and 999 notification sent are discarded by APNS at the mean time, all discarded 999 notifications will be resent without loosing any of them. With the same logic, if notification resent failed, it will resent rest of resent notification after the failed one.
For GCM, you may consider https://github.com/geeknam/python-gcm
For generic wrapper that support both or more mobile provider:
https://github.com/Redth/PushSharp
Server authenticates against google client login to use app engine's C2DM server. I understand that. I will use .net here. When data changes, I will send push notification to client and client service will refresh the data in their device db and UI will be updated. I am expecting this way the whole thing will work
All clients needs to register to server for receiving C2DM calls. Here there are interesting scenarios.
In my app there is a login in order to manage authentication and authorization to filter out the data that is relevant to him only. so at the same time I have to register to C2DM server as well. Is that correct?
Let's take an example of task which is assigned to some user. If the
task is updated by user, it show send C2DM message to it's owner, and
it owner creates task it should send C2DM message to user who is
responsible for the task.
Is this practically possible? Is anything that I am missing or understanding wrong?
Yes this is practically possible, but remember
you can send only limited data in your payload.
you have to write all logics inside your app to change UI.
Payload message data can only pin the decision making process.