Build

Real-time SMS Alerts for Offline Users with RingCentral

3 min read Michael Carroll on Nov 18, 2016

RingCentral provides a wide variety of cloud-based phone communication APIs, so naturally we’re excited to announce that RingCentral is now a PubNub BLOCKS partner. That means you can harness RingCentral’s powerful APIs, and execute them while your real-time data is in-motion over PubNub. In this tutorial, we’ll show you how to trigger a SMS message when a user receives a message, but is offline.

The use cases are endless, and show the flexibility of sending SMS programmatically. Beyond SMS alerts for chat, we can extend this functionality even to IoT, where a sensor monitoring values would trigger an SMS if those values went above or below a certain threshold.

It’s SMS alerts, sent programmatically, all in your real-time data streams.

Getting Started with RingCentral SMS

First, create your free RingCentral account. If you don’t have a PubNub account, you’ll need to create one as well. Once you’ve created your RingCentral account, get your keys and the new phone number generated by their system. Also, be sure to check your email after you sign up to activate your new account. Log in using the new number they gave you and create an app on their system. Leave the oauth field empty.

Next get your app key and app secret. Creating an account will also create a ‘sandbox’ account, with its own phone number and password that you must set. Use this as the number and password in the block. Make sure you have the password for the sandbox account as well. You’ll need it later.

PubNub BLOCKS and RingCentral

Go to the Settings tab and make sure you have the SMS permissions set under OAuth Settings.

PubNub BLOCKS and RingCentral

We’ll be using the RingCentral Offline Notifier Block. Click ‘try it now’ (make sure you are already logged into your PubNub account). Follow the prompts to create a copy of the template block, then modify a few lines. Set the appKey and appSecret variables to the one from your RingCentral dashboard page.

Set the senderPhone and senderPassword to the values from the sandbox environment.

Now go to the bottom of the block code. This block is designed to monitor when someone is on or offline. Instead we want to send notifications when a value is beyond a certain threshold. Remove all the code starting at the comment: //extract from request, channel on which the message was published all the way to the end. Replace it with this code:

   if(request.message.value > 100) {
       console.log("sending a warning");
       sendSms("707-509-9627",
           "warning, possible fire at sensor" + request.message.sensor,
           "warning-channel");
   } else {
       console.log("not sending anything");
   }
   return request.ok();
};

This will trigger an SMS if the value of the incoming message is above 100.

Now save the code and start the block. It make take a few moments the first time. Send a test message form the Test Payload tool in the lower left corner of the page, using this data.

{
   "value": 50,
   "sensor": "good-sensor"
}

When you send the payload, you should see the message “not sending anything” in the console. Change it to:

{
   "value": 150,
   "sensor": "bad-sensor"
}

This time it should login to RingCentral and send a real SMS to your phone.

And that’s it! Sending real-time SMS with RingCentral is easy. RingCentral also has many other cool APIs for controlling phone calls, call forwarding, automated assistants, and much more.  And of course RingCentral is just one of our many API partners you can see in the BLOCKS catalog.

0