Testing Worklight push notifications over SMS
EtienneNoiret 270004RHC5 Comments (3) Visits (9549)
In addition to providing a cross platform API to send push notifications to mobile devices through the device vendors’ push networks (such as APNS, GCM), Worklight also allows you to send notifications as SMS messages. Although this kind of notification cannot interact directly with an app installed on the device, it is sometimes considered as more reliable and can be a good way to reach people who have not installed any app at all, such as users of a mobile web app.
In order to send an SMS message from a programmatic source, you usually need to contract with a telecommunication operator for access to an SMS gateway. The SMS Gateway provides a web interface for submitting messages, which are converted into SMS messages for direct delivery to devices over the cellular network. Access to the SMS gateway typically requires user credentials (username and password) so that each time you submit a request to send an SMS message through this gateway, your account can be charged according to your contract.
Before using such a billable service, it might be nice to test your program using a free gateway option. In this simple tutorial, I’ll show you how to use an app on your mobile device that acts as a SMS gateway and uses your own mobile subscription to send SMS messages to the device.
Architecturally, the Worklight SMS adapter will route the SMS packages to the SMS Gateway software running on the phone, using the devices IP address and the port that the SMS gateway is configured to use. The gateway will then convert them to standard SMS messages for delivery to the device’s SMS queue.
These tests were done on an Android device and require a standard SMS contract for the ability to send and receive SMS messages, and a data plan or wifi connection in order to receive the requests from the Worklight adapter acting as an SMS gateway client.
1) Configuring the gateway on your mobile device
Begin by downloading the free app called SMS
Once installed, launch the app and click on the “add” button in the toolbar in order to setup a new gateway. As described in the following picture, you just need to enter a port (or leave the default) number and give whatever name you want to your gateway:
Together with the port number, you’ll need this information to configure your gateway access on Worklight server side.
2) Configuring the gateway in your Worklight project
Download the sample SMS project from the Worklight getting started page and import it into Worklight Studio.
This project includes a client app that can register for SMS messages and a Worklight adapter to send messages to registered clients via an SMS gateway (address info must be added to the Worklight app’s config file).
Note the “smsto”, “smsbody” and “smstype” parameters, which are sent to the gateway.
3) Build, run & test your project
Build & deploy your Worklight project (including the adapter), deploy the app to a real device or an emulator and test subscribing to a SMS.
If you take a look at the Worklight console (htt
Now you need to actually send a SMS by invoking the adapter. From within Worklight Studio, right click on the SMSAdapter and choose Run as / Invoke Worklight procedure. Use the name you registered with during the subscription process and give a text to be sent by SMS:
On Worklight console you can also see that one message was sent in the “Push notifications” tab.