Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Sending Push Notifications

Sending Push Notifications

The send operation allows you to send either a generic push notification to all recipients or a customized, targeted push notification based on a JSON notification object.

Despite its name, the send operation only schedules push notifications for sending. If you have not specified sending time, the server dispatches the push notification immediately or almost immediately. If a sending time is available, the push notification is send accordingly.

You can choose between the following methods for sending push notifications:

Using the Portal

The Telerik Platform portal allows you to compose and target push notification using a graphical user interface (GUI). It provides a rich set of filtering and scheduling options, as well as tools to monitor the progress and the state of your push notifications. Filters and options that are not available in the GUI must be used through one of the client SDKs or the RESTful API.

The GUI is suitable for sending single push notification. When you need to send large numbers or regular push notifications, you may find it more convenient to use the other sending methods.

To create a push notification using the portal:

  1. Open you app.
  2. Navigate to Notifications > Push Notifications > Push Browser.
  3. Click the Send a push notification button.
  4. In the details panel that appears, fill in your details and select options.
  5. Click Send Now.

This adds a row to the push browser. Clicking it opens the details pane where you can track the state of the push notification.

Using the Backend Services .NET SDK

You can use the Backend Services .NET SDK to send push notifications from any platform that supports it.

The following example demonstrates how to use the Backend Services .NET SDK to send a simple push notification to all registered devices:

var notification = new PushNotification("Hi, I'm Push!");
await app.WorkWith().Push().Notifications().Create(notification).ExecuteAsync();
Dim notification = New PushNotification("Hi, I'm Push!")
Await app.WorkWith().Push().Notifications().Create(notification).ExecuteAsync()

If you want to target a subset of your devices or to specify advanced options, you need to construct the payload notification object accordingly:

// Create a push notification with a generic message
var notification = new PushNotification("A message");
// Define a filter property for the notification
var notificationFilter = new Dictionary<string, object>()
{
  { "PlatformType", 4 }, // select only iOS (code 4) users
  { "Parameters.Age", new Dictionary<string, object>() // select registrations that have a custom parameter "Age"
    {
      { "$gte", 20 } // whose value is greater than or equal to 20
    }
  }
};
// serialize the filter object and assign it to the "Filter" property
notification.Filter = Telerik.Newtonsoft.Json.JsonConvert.SerializeObject(notificationFilter);
// make a request to create the notification
app.WorkWith().Push().Notifications().Create(notification).ExecuteSync();
' Create a push notification with a generic message
Dim notification = New PushNotification("A message")
' Define a filter property for the notification
' select only iOS (code 4) users
' select registrations that have a custom parameter "Age"
' whose value is greater than or equal to 20
Dim notificationFilter = New Dictionary(Of String, Object)() From { _
    {"PlatformType", 4}, _
    {"Parameters.Age", New Dictionary(Of String, Object)() From { _
        {"$gte", 20} _
    }} _
}
' serialize the filter object and assign it to the "Filter" property
notification.Filter = Telerik.Newtonsoft.Json.JsonConvert.SerializeObject(notificationFilter)
' make a request to create the notification
app.WorkWith().Push().Notifications().Create(notification).ExecuteSync()

Constructing the notification object is discussed in detail in Constructing a Notification Object.

Using Cloud Code

Sending push notifications using Cloud Code has certain benefits compared to the other methods.

The benefits include:

  • You can use the Cloud Code for Data events to trigger automatic sending of push notifications when something in your data changes.

    Cloud Code for Data events are only triggered when data is changed trough the Backend Services APIs. For (Data Connectors, this means that no events will be triggered if you change the data directly in the connected database or through another application that does not utilize the Backend Services APIs.

  • When writing a Cloud Function to send push notifications you can safely use your master key to invoke operations that require it because it does not leave Telerik Platform. You can then invoke the Cloud Function's HTTP endpoint using only your App ID.

  • You can use the Backend Services JavaScript SDK or the RESTful API.

The following example demonstrates how to use the Backend Services JavaScript SDK to send a simple push notification from the beforeRead Cloud Code for Data event:

Everlive.Events.beforeRead(function(request, context, done) {
    Everlive.Sdk.$.push.notifications.create({ Message:'Hello' },
        function(error, response) {
            if (error){
                //Process the error here
            } else {
                //Process the response here
            }
            done();
        });
});

This code above schedules the "Hello" message for sending to all devices registered for push notifications in your application. If you want to target a subset of your devices or to specify advanced options, you need to construct the payload notification object accordingly:

Everlive.Events.beforeRead(function(request, context, done) {
    var notification = {
        //place targeting and other options here
    };
    Everlive.Sdk.$.push.notifications.create(notification,
        function(error, response) {
            if (error){
                //Process the error here
            } else {
                //Process the response here
            }
            done();
        });
});

Constructing the notification object is discussed in detail in Constructing a Notification Object.

You can find more information about using the RESTful API in the RESTful section of the documentation.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.