Building a phone verificator with the Bandwidth Python SDK
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.
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.
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.
Flask also has it’s own rendering definitions, so it can easily render HTML, which is also similar to how Spark would render.
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.
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.
To bring this two part article to a conclusion, this is what I learned:
- How APIs work and how HTTP requests interact with them.
- Between the basic functions of the SDKs and BXML, most any standard task can be accomplished.
- Micro frameworks are a thing.
- CSS is one of the most aggravating “languages” to work with, but at least it looks pretty.
Try out the app!