The ability to send push notifications has been a key Backendless feature for quite a while, but until now, it only had a basic set of actions such as sending to all devices in a specific channel and/or to a specific device type (Android/iOS). With the last changes it has grown into a powerful tool with a bunch of very flexible and convenient functionality. Now you can:
- send push notifications for a precisely defined group of recipients using not only filters by channel/device, but also BackendlessDataQuery, which allows you to select target devices using a query to the Users table;
- personalize your messages with smart-text – auto substitutions with the personal information from the Users table or any other related tables;
- construct and customize the styling of your messages in a new graphical interface;
- and construct interactive messages with actions mapped to Buttons / Inline reply / Tap.
In this article, we’re going to review the first two points and in the next article the last two.
First, let’s prepare the tables with relations. The tables we’ll be using are Users , Preferences , and Address . We’ve provided some fields for us to use. You can populate the tables with arbitrary values of your choice.
Now, let’s go to the Messaging tab.
You’ll see a wizard that will help you compose a new push template. Follow the numbers in red circles on the image above. On step 6, you need to enter the where clause (just as you would for a Data service). The request is made to the DeviceRegistration table.Here’s an example request:
user.address.street = 'New Avenue' and user.preferences.favorite_color = 'red'
If you have a user with those characteristics, you’ll see on the top right of the screen the estimated number of recipients (in my case, it is only one individual).
The button “See Devices” moves you to the Data tab, where you can see the listing of that devices. The button “Send Now” will immediately send your push notification message to the filtered recipients. It is not active now, because we haven’t configured the current template completely.
Now let’s look at how to configure the content of the message so that it contains user-specific information. We call this smart-text.
You can use substitution for fields such as Message, Title, Subtitle and header values. Clickable “add smart text” helps you construct a smart-text message using values from the tables (related to your Users table).
When you press “add smart text”, the popup window appears, where at the bottom you can choose the table and column from which the value will be inserted in the notification.
Here is an example with the values from related tables:
And this is the resulting push notification content:
Before sending, you should save the template. This will allow you to reuse this setup for future notifications and can be accessed in your Cloud Code to create automated personalized notifications. Once you save the template, the “Send Now” button will become active.
That’s all for today. In the next article in this series, we will take a look at customizing the appearance of your notifications and adding interactive buttons, inline reply capability, and notification tap functionality. Happy coding!