Building a Phone Verificator with the Bandwidth Python SDK

blog-python-1

20 Sep

During my Summer internship, I tried using the Bandwidth Python SDK.  The app was smaller in scope than the first app I built and is just a phone verificator.  All the user does is put in their number, receive a call/text with a code, and it checks if the user puts in the correct code.

image-1

The biggest difference for making this phone verificator app versus the previous simple phone app was the emphasis on CSS.  Since this is the case, this post will mostly focus on the app.py file, but all files are available to see on github.  For further information about my process with getting started with using services like heroku, micro frameworks, etc I recommend my previous blogpost.

python-blogpost

Again, since this was a project small in scope, I chose to use Flask, a microframework for python.  If you’re reading this after my previous blogpost, then you’ll notice that Spark and Flask have roughly similar ways of defining endpoints.

image-3

image-4

Flask also has it’s own rendering definitions, so it can easily render html, which is also similar to how Spark would render.

base.html

image-5

index.html

image-6

Some notes about working with the Bandwidth Python SDK.  Callback events, like the “answer event”, will work the same as they did in java.  Meaning you’ll need a callbackUrl defined when creating the call.

image-7

Overall, the python part of the app is fairly simple.  An important part of the setup that is worth remarking, is to pay attention to the Procfile.  The Procfile should be set to have only 1 worker for Gunicorn, otherwise there will be issues with multiple threads and the app will be inaccurately keeping track of the verification code.

image-8

To bring this two part article to a conclusion, this is what I learned:

  1. How APIs work and how HTTP requests interact with them.
  2. Between the basic functions of the SDKs and BXML, most any standard task can be accomplished.
  3. Micro frameworks are a thing.
  4. CSS is one of the most aggravating “languages” to work with, but at least it looks pretty.

 

Try out the app!

image-9

Niko Reingold
Niko Reingold
nreingold@bandwidth.com

Niko is a senior at UNC Chapel Hill majoring in Computer Science and works for the student non-profit, Carolina for the Kids. At Bandwidth, he works with the Communications API platform team as a Product Management Intern improving documentation and creating example applications. Enjoys running, listening to music, and lists of three.

No Comments

Post A Comment