

We will discuss python_call_screening.py below. We can skip the README.md file and save the requirements.txt file for when we are running the app. After starting the tunnel, you can use the URL you receive from ngrok in your webhook configuration for your phone number. You may need to use an SSH tunnel for testing this code – we recommend ngrok. To run the application, execute export FLASK_APP=python_call_screening.py then run flask run. To install prerequisites, run pip install -r requirements.txt. You will need a SignalWire phone number as well as your API Credentials ( API Token, Space URL, and Project ID) which can all be found in an easily copyable format within the API tab of your SignalWire portal. You will need the Python SDK and Flask framework to run this code. As you can see below, it is very simple to implement such a call flow with SignalWire and SignalWire Compatibility XML. However, depending on your needs, this can point at an XML bin, another webhook, or another part of the code within the same document. In this case, I have redirected to an XML Bin.

You can parse individual number strings and test them for validity: > import phonenumbers > print (phonenumbers.parse (' (541) 754-3010', 'US')) Country Code: 1 National Number: 5417543010 > phonenumbers.isvalidnumber (phonenumbers. The from number is our Twilio phone number. Install it with pip install phonenumbers. If the number is not in the block list, the call flow moves on to the next segment. The code in the following widget starts a phone call between the two phone numbers that we pass as arguments. When a call comes in, the From number will be cross-checked with the block list to see if it is one of the blocked numbers. This guide implements a call screening system based on the concept of a blocklist containing offending numbers.

Screen Calls Based on a Block List - Python Overview
