Our Blog

Simple REST API SMS App Integration with Telecom Provider

I have been building apps recently that integrate a REST API which subscribes users to a Drupal web app via SMS, they are simultaneously subscribed in the telecom operators database. Conditions must be checked to keep the users status in sync with Drupal and the operator. Other conditions that I won’t cover here include recurring billing or the free trial period.

This is a practical example of how using the REST protocol allows technologies that are completely different to communicate with each other. The technologies in our stack include SMS, mobile billing and a Drupal web app.

First create the URL endpoint with a callback function by using hook_menu

When a mobile originated text message “MO” is sent from the customer handset to the shortcode created for our app, a relay message is sent from the telecom integrator’s API and hits the endpoint created with hook_menu on our web app. We then use a GET request to get the values from the values posted to our endpoint url. Parameters include product identification information, partner ID, customer MSISDN and subscription method, as well as other info. We also run an additional API call to check if the MSISDN/phone number is valid and if there is enough money on the customer account.

Here we have the beginning of the callback function that runs when our endpoint is hit.

There are many conditions in the business requirements, which determine different messages in the $text variable to the customer. Success/failure, weekly/monthly, arabic/english, below is the case if success and weekly PricePointId is selected. There is also a check for what language is selected, here we use the language value in the user object, we get this from what language the user selects on the registration form. We then pass back the correct language in the $text variable in a post request using cURL with everything else. Here is some more of the callback function.