RingCentral SMS app

I wanted to learn how to receive an SMS using Ring Central’s API and write about my experience, I thought of how a simple idea of communication between integrations can benefit any person in numerous ways.

I had many ideas on my mind and I will probably be using them in the future, for example: Receive an SMS when a security camera in my house is activated by motion or sound by my curious golden retriever Floki, or a SMS when a door sensor is activated, when a light turns on inside the house, or maybe even get a SMS when someone pushes code to a repository.

Floki don’t be sad, I will be back in a few hours.

For the SMS API example I wanted to test something simple and that could be very productive, that is why I chose to integrate SMS Ring Central’s API with Formstack.

Formstack is a workplace productivity solution built to transform the way people collect information and put it to work, so what If I could use a Formstack form to collect data and depending on the submit response I got from a user, I could trigger an SMS using Ring Central’s API?

Ingredients needed :

STEPS:

1 Create a simple form in Formstack.

For this example I only used a Name and a Rating field.

Need help creating a form…
https://help.formstack.com/hc/en-us/articles/360019520271-Creating-a-New-Form

2 Install and run temporarily ngrok

Download the package and unzip it, then run:
./ngrok http 8080 (or any other port you would like to use)

It should look something like this:

Need more help using Ngrok:
https://ngrok.com/docs

We are now ready to tunnel:

3 Back in Formstack:

Go to Settings -> Emails & Actions and let’s supercharge this form by adding a Webhook, copy the ngrok forwarding IP to the Webhook URL, select Post with sub-field names and Post with API-friendly keys.

Need more help on webhooks:
https://help.formstack.com/hc/en-us/articles/360019516191-WebHook-Submit-Actions

4 Run a temp PHP web server

For this test, I created a folder named RingCentral, and added a php file named index.php

Inside that folder I ran the following command to start my php web server:

php -S localhost:8080

Sample content of the file:

<?php
echo 'hello Blog API Test';

We can make a quick test, to make sure we communicate with our localhost when submitting a form, so go ahead and submit your test form.

You can check the request data sent in http://127.0.0.1:4040/inspect/http

As you can see, I got my 5 star response value from the Rating field did_you_like_this_blog_tutorial and the name field with value Test1, and we can also see that my local web server responded with hello Blog API Test.

5 Setup RingCentral SMS API

And now for the most interesting part, we can now use the data submitted by the Formstack form that was sent to the localhost through ngrok and send a SMS with RIngCentral’s API.

First we need a developer account for Ring Central’s API, you should be able to create an account here: https://developers.ringcentral.com/

Once you have created an account simply create an SMP APP with one click:

Don’t have the link?
Don’t worry here it is:
https://developer.ringcentral.com/new-app?name=SMS+Quick+Start+App&desc=A+simple+app+to+demo+sending+an+SMS+on+RingCentral&public=false&type=ServerOther&carriers=7710,7310,3420&permissions=SMS,ReadMessages&redirectUri=

Now that your sandbox app is created we need to download the PHP SDK to get started: (Make sure to download to the same directory where you started your php web server and where the file index.php is located.

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require ringcentral/ringcentral-php

Now simply edit the index.php file we created earlier and enter this code:

<?php
require('vendor/autoload.php');

$RECIPIENT = '<ENTER PHONE NUMBER>';

$RINGCENTRAL_CLIENTID = '<ENTER CLIENT ID>';
$RINGCENTRAL_CLIENTSECRET = '<ENTER CLIENT SECRET>';
$RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com';

$RINGCENTRAL_USERNAME = '<YOUR ACCOUNT PHONE NUMBER>';
$RINGCENTRAL_PASSWORD = '<YOUR ACCOUNT PASSWORD>';
$RINGCENTRAL_EXTENSION = '<YOUR EXTENSION, PROBABLY "101">';

$rcsdk = new RingCentral\SDK\SDK($RINGCENTRAL_CLIENTID, $RINGCENTRAL_CLIENTSECRET, $RINGCENTRAL_SERVER);

$platform = $rcsdk->platform();
$platform->login($RINGCENTRAL_USERNAME, $RINGCENTRAL_EXTENSION, $RINGCENTRAL_PASSWORD);

$resp = $platform->post('/account/~/extension/~/sms',
    array(
       'from' => array ('phoneNumber' => $RINGCENTRAL_USERNAME),
       'to' => array(array('phoneNumber' => $RECIPIENT)),
       'text' => 'Hello World from PHP'
     ));
print_r ("SMS sent. Message status: " . $resp->json()->messageStatus);
?>

Submit another form, check the request at: http://127.0.0.1:4040/inspect/http

And you should see a response like this one:

And immediately receive an sms that says:

Now to integrate everything together, just add this to the code before your credentials:

$find      = ['first =','last ='];
$name      = str_replace($find,'',$_REQUEST['name']);
$stars     = $_REQUEST['did_you_like_this_blog_tutorial'];
$message   = 'You received '. $stars . ' stars from'. $name;

And replace the $resp array text value to: $message

$resp = $platform->post('/account/~/extension/~/sms',
    array(
        'from' => array ('phoneNumber' => $RINGCENTRAL_USERNAME),
        'to'   => array(array('phoneNumber' => $RECIPIENT)),
        'text' => $message
    ));
Looks like someone rated me with 5 stars!

And that is it for now. I hope you enjoyed learning how to integrate Formstack, ngrok and RingCentral’s SMS API, because I sured did.

Leave a Reply

Your email address will not be published. Required fields are marked *