Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create a simple SMS delivery notification system (Python)

Customer Engagement doesn’t stop once an order is received. Some argue it might even be the beginning of it. Clients must be kept in the loop at all times and quite often, emails are not enough. Why not switch to their preferred channels instead? SMS has been boasting record-high open rates since its inception.

So, here’s our goal for today’s cookbook: learn how to build a basic SMS notification system to be used for delivery notifications or anything else you might need to keep your clients informed about.

To keep it simple, our goal here today is to build a status update notification system that will:

  • Given a database of the customers (we’ll create it from scratch for the example’s sake)
  • Go through this database entry by entry and send to each an SMS giving them an update and ETA on their order.

The whole thing can be done in four simple steps and should not take more than 10 minutes.

We’ll detail the process step by step. If you are only looking for the code, you can find the full script here.


Sending SMS from the web

Communication Platforms as a Service (CPaaS) greatly ease the integration of telecom solutions in web and mobile apps. Indeed, CPaaS APIs such as CALLR take care of all the tedious details you need to juggle when initiating a phone call or sending an SMS.

  • You don’t have to integrate with every telecom carrier in the world. The API does that for you. You only need to say “CALLR, send this text to this number, with these options” and the API does the rest.

Do it your way

CALLR is completely language agnostic. Essentially, an API call is an HTTP request, SDKs are just here for convenience and ease of implementation.

Yet, SDKs are more than welcomed as they allow you to initiate phone calls and send SMS very easily. You just parse to CALLR’s API your target number, message and options and the API does the rest. It will also return the hash ID of the call initiated / sent SMS to confirm its execution and track it.

CALLR’s SDK is available in 9 languages to ease its implementation:

For this tutorial, we’ll detail the steps to build an SMS notification system in Python.


1/ Install CALLR’s Python SDK

CALLR is available with pip, you can easily install it by entering the following command in your terminal:

2/ Fetch credentials and login

Go to callr.com and create an account. You will receive your credentials shortly on the email address you specified during registration (or LinkedIn email).

Once you have your credentials, you’ll be able to initialize an API instance and start using CALLR. Try it out with a simple SMS!

3/ Create your sample list

To keep things simple, each customer is defined according to four data points:

  • Name: the customer name
  • Phone number: his phone number.
  • Order: item ordered
  • Dtime: expected time of delivery

NB: As you could have seen in the sample example at the previous step, numbers are written in the international format (E.164 with a + prefix). For a French mobile number, that is +33 6/7 XX.XX.XX.XX (without any spaces, slashes or dots) such as +33644630378.

Hence, we define our list with Python as it follows. Two entries should be enough to try it out:

4/ Create a function to loop through our recipient_list and send a contextualized status update to each

The SendSMS() function does the bulk of the job, so let’s break it down:

We define the recipient as the i “phonumber”entry of the list. We do the same for the message including three variables so everyone has a message adapted to his data.

Then, we call the sms.send method to send the SMS, and since we’re notifying customers we can tag the traffic as ALERTING (SMSOption).

Finally, we wrap the whole thing in a loop that will go through each entry of the list with the enumerate method.

Then, we run our newly defined function, and that’s all we need for our simple sms delivery notification system.

The limits of simplicity

We chose a simple use case with a straightforward scenario. It will not always be this easy.

Moreover, the scenario we created is not failproof. What if your client signed up with a geographic number (01-05)? Some geographic numbers are still able to receive SMS: they are read to them with Text-to-Speech.

However, only some carriers support this function so your message might literally get lost in translation.

To prevent this issue, you could add a simple voice failover scenario:

  • If the phonenumber does no match 06.XX.XX.XX.XX or 07.XX.XX.XX.XX
  • Use the send/simple.broadcast_1 method to play your message with TTS (Python SDK link) instead of sms.send.

Besides, this script only runs locally and manually. It would be a good follow-up exercise to deploy it to a server (Heroku for instance) and have the script autorun.

We hope you enjoyed this little tutorial. Feel free to give feedback or ask questions if anything is not clear enough.

Looking for a smart and accessible Python SMS solution?

Check out our API

Here are some useful links to go further:

The full code of this tutorial

CALLR’s Python SDK

CALLR’s website

The Knowledge Base

The post Create a simple SMS delivery notification system (Python) appeared first on CALLR Blog.



This post first appeared on CALLR's, please read the originial post: here

Share the post

Create a simple SMS delivery notification system (Python)

×

Subscribe to Callr's

Get updates delivered right to your inbox!

Thank you for your subscription

×