In this post, you will learn how to receive an SMS using RingCentral when a user submits a Form with Formstack. This will be demonstrated by integrating Formstack, ngrok and RingCentral’s SMS API.
Introduction
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 in 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.
Background
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?
Using the Code
1. Create a Simple Form in Formstack
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)
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.
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:
$ 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
));
And that is it for now. I hope you enjoyed learning how to integrate Formstack, ngrok and RingCentral’s SMS API, because I sure did.
History
- 23rd February, 2020: Initial version