Skip to content

TwilioDevEd/airtng-masked-numbers-flask

Repository files navigation

Twilio

Airtng App: Part 2 - Workflow Automation with Twilio Python | Flask

Protect your customers' privacy by creating a seamless interaction by provisioning Twilio numbers on the fly. Route all voice calls and messages through your very own 3rd party. This allows you to control the interaction between your customers, while putting your customer's privacy first.

Configure Twilio to call your webhooks

You will need to configure Twilio to send requests to your application when SMSs are received.

You will need to provision at least one Twilio number with SMS capabilities so the application's users can make property reservations. You can buy a number right here. Once you have a number you need to configure it to work with your application. Open the number management page and open a number's configuration by clicking on it.

Remember that the number where you change the SMS webhook must be the same one you set on the TwilioPhoneNumber settings.

Learn how to configure a Twilio phone number for Programmable Voice

To start using ngrok in our project you'll have execute to the following line in the command prompt.

ngrok http 5000 -host-header="localhost:5000"

Keep in mind that our endpoint is:

http://<your-ngrok-subdomain>.ngrok.io/reservations/confirm

Create a TwiML App

This project is configured to use a TwiML App that allows us to easily set the voice URLs for all Twilio phone numbers we purchase in this app.

Create a new TwiML app and use its Sid as the TwiMLApplicationSID application setting.

Learn more about creating a TwiML app here

Once you have created your TwiML app, configure your Twilio phone number to use it (instructions here).

If you don't have a Twilio phone number yet, you can purchase a new number in your Twilio Account Dashboard.

You'll need to update your TwiML app's voice and SMS URL setting to use your ngrok hostname. It will look something like this:

http://<your-ngrok-subdomain>.ngrok.io/exchange/sms
http://<your-ngrok-subdomain>.ngrok.io/exchange/voice

Local Development

  1. Clone this repository and cd into it.

    git clone [email protected]:TwilioDevEd/airtng-flask.git
  2. Create a new virtual environment.

  3. Install the requirements.

    pip install -r requirements.txt
  4. Edit the following keys/values for the config.py file inside the airtng_flask/ directory. Be sure to replace the place holders and connection strings with real information or reuse the provided one, like the connection string.

    TWILIO_ACCOUNT_SID = 'your_twilio_account_sid'
    TWILIO_AUTH_TOKEN = 'your_twilio_auth_token'
    TWILIO_NUMBER = 'your_twilio_phone_number'
    APPLICATION_SID = 'your_application_sid'
    
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'dev.sqlite')
    
  5. Run the migrations.

    python manage.py db upgrade
  6. Start the development server.

    python manage.py runserver
  7. Check it out at http://localhost:5000

Run the tests

You can run the tests locally through coverage:

  1. Run the tests.

    $ coverage run manage.py test

You can then view the results with coverage report or build an HTML report with coverage html.

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.