From 8f5646e05507a416e371b262bacb06386d42406c Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Mon, 20 Apr 2020 17:24:31 -0500 Subject: [PATCH 1/3] Code Exchange Upgrade --- .env.example | 21 +++++++++-- .github/workflows/flask.yml | 37 +++++++++++++++++++ .gitignore | 3 ++ .mergify.yml | 13 +++++++ CODE_OF_CONDUCT.md | 73 ++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 3 ++ LICENSE | 14 ++++--- README.md | 30 +++++++-------- app.py | 26 ++++++++++--- requirements.txt | 9 +++-- static/index.html | 4 +- static/quickstart.js | 74 ++++++++++++++++++++++++------------- tests/conftest.py | 13 +++++++ tests/test_routes.py | 26 +++++++++++++ 14 files changed, 284 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/flask.yml create mode 100644 .mergify.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 tests/conftest.py create mode 100644 tests/test_routes.py diff --git a/.env.example b/.env.example index 7b068e0..5d0e776 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,17 @@ -export TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -export TWILIO_AUTH_TOKEN=your_auth_token -export TWILIO_TWIML_APP_SID=APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -export TWILIO_CALLER_ID=+1XXXYYYZZZZ +TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +TWILIO_AUTH_TOKEN=your_auth_token +TWILIO_CALLER_ID=+1XXXYYYZZZZ + +# SID of your TwiML Application +# https://www.twilio.com/console/voice/twiml/apps +# OR +# twilio api:core:applications:create --friendly-name=voice-client-javascript +TWILIO_TWIML_APP_SID=APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + +# Your REST API Key information +# https://www.twilio.com/console/project/api-keys +# OR +# twilio api:core:keys:create --friendly-name=voice-client-javascript -o json +# NOTE: Make sure to copy the secret, it'll will only be displayed once +API_KEY=SKXXXXXXXXXXXX +API_SECRET=XXXXXXXXXXXXXX diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml new file mode 100644 index 0000000..0501620 --- /dev/null +++ b/.github/workflows/flask.yml @@ -0,0 +1,37 @@ +name: Flask + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python -m pytest + env: + TWILIO_ACCOUNT_SID: ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + TWILIO_AUTH_TOKEN: xxxxxxx + TWILIO_CALLER_ID: +1XXXYYYZZZZ + TWILIO_TWIML_APP_SID: APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + API_KEY: SKXXXXXXXXXXXX + API_SECRET: XXXXXXXXXXXXXX diff --git a/.gitignore b/.gitignore index 7fd2a8c..ffbaef8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ _mailinglist .env .env.ps1 venv +.vscode +__pycache__ +.pytest_cache diff --git a/.mergify.yml b/.mergify.yml new file mode 100644 index 0000000..0433495 --- /dev/null +++ b/.mergify.yml @@ -0,0 +1,13 @@ +pull_request_rules: + - name: automatic merge for Dependabot pull requests + conditions: + - author=dependabot-preview[bot] + - status-success=build (macos-latest, 10) + - status-success=build (macos-latest, 12) + - status-success=build (windows-latest, 10) + - status-success=build (windows-latest, 12) + - status-success=build (ubuntu-latest, 10) + - status-success=build (ubuntu-latest, 12) + actions: + merge: + method: squash diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..2f0727e --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at open-source@twilio.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ad3257e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing to Twilio + +All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under. diff --git a/LICENSE b/LICENSE index 4bcc4c2..2c3cf9d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,6 @@ -Copyright (c) 2015 Twilio Inc. +MIT License + +Copyright (c) 2020 Twilio Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 2544387..3279810 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,21 @@ # Twilio Client Quickstart for Python +![](https://github.com/TwilioDevEd/client-quickstart-python/workflows/Flask/badge.svg) + > We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you. This application should give you a ready-made starting point for writing your own voice apps with Twilio Client. Before we begin, we need to collect all the config values we need to run the application: -| Config Value | Description | +| Config Value | Description | | :------------- |:------------- | -Account SID | Your primary Twilio account identifier - find this [in the console here](https://www.twilio.com/console). -Auth Token | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). -TwiML App SID | The TwiML application with a voice URL configured to access your server running this app - create one [in the console here](https://www.twilio.com//console/phone-numbers/dev-tools/twiml-apps). Also, you will need to configure the Voice "REQUEST URL" on the TwiML app once you've got your server up and running. -Twilio Phone # | A Twilio phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164) - you can [get one here](https://www.twilio.com/console/phone-numbers/incoming) +`TWILIO_ACCOUNT_SID` | Your primary Twilio account identifier - find this [in the console here](https://www.twilio.com/console). +`TWILIO_AUTH_TOKEN` | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). +`TWILIO_TWIML_APP_SID` | The TwiML application with a voice URL configured to access your server running this app - create one [in the console here](https://www.twilio.com/console/voice/twiml/apps). Also, you will need to configure the Voice "REQUEST URL" on the TwiML app once you've got your server up and running. +`TWILIO_CALLER_ID` | A Twilio phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164) - you can [get one here](https://www.twilio.com/console/phone-numbers/incoming) +`API_KEY` / `API_SECRET` | Your REST API Key information needed to create an [Access Token](https://www.twilio.com/docs/iam/access-tokens) - create [one here](https://www.twilio.com/console/project/api-keys). ## Setting Up The Python Application @@ -29,13 +32,7 @@ Begin by creating a configuration file for your application: cp .env.example .env ``` -Edit `.env` with the four configuration parameters we gathered from above. Export -the configuration in this file as system environment variables like so on Unix -based systems: - -```bash -source .env -``` +Edit `.env` with the four configuration parameters we gathered from above. ### Windows (PowerShell) @@ -89,7 +86,7 @@ There's just a few more steps to get Twilio's voice infrastructure talking to yo 3. When ngrok starts up, it will assign a unique URL to your tunnel. It might be something like `https://asdf456.ngrok.io`. Take note of this. -4. [Configure your TwiML app](https://www.twilio.com/console/phone-numbers/dev-tools/twiml-apps)'s +4. [Configure your TwiML app](https://www.twilio.com/console/voice/twiml/apps)'s Voice "REQUEST URL" to be your ngrok URL plus `/voice`. For example: ![screenshot of twiml app](https://s3.amazonaws.com/com.twilio.prod.twilio-docs/images/TwilioClientRequestUrl.original.png) @@ -103,6 +100,9 @@ We'd recommend Google Chrome or Mozilla Firefox instead. ![screenshot of phone app](https://s3.amazonaws.com/com.twilio.prod.twilio-docs/images/TwilioClientQuickstart.original.png) -## License +## Meta -MIT +* No warranty expressed or implied. Software is as is. Diggity. +* The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/). +* [MIT License](http://www.opensource.org/licenses/mit-license.html) +* Lovingly crafted by Twilio Developer Education. diff --git a/app.py b/app.py index 423f542..4206d0f 100755 --- a/app.py +++ b/app.py @@ -4,9 +4,13 @@ import re from flask import Flask, jsonify, request, Response from faker import Faker -from twilio.jwt.client import ClientCapabilityToken +from twilio.jwt.access_token import AccessToken +from twilio.jwt.access_token.grants import VoiceGrant from twilio.twiml.voice_response import VoiceResponse, Dial +from dotenv import load_dotenv +load_dotenv() + app = Flask(__name__) fake = Faker() alphanumeric_only = re.compile('[\W_]+') @@ -24,15 +28,25 @@ def token(): account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] application_sid = os.environ['TWILIO_TWIML_APP_SID'] + api_key = os.environ['API_KEY'] + api_secret = os.environ['API_SECRET'] # Generate a random user name identity = alphanumeric_only.sub('', fake.user_name()) + + # Create access token with credentials + token = AccessToken(account_sid, api_key, api_secret, identity=identity) + + # Create a Voice grant and add to token + voice_grant = VoiceGrant( + outgoing_application_sid=application_sid, + incoming_allow=True, + ) + token.add_grant(voice_grant) + + # Return token info as JSON + token=token.to_jwt() - # Create a Capability Token - capability = ClientCapabilityToken(account_sid, auth_token) - capability.allow_client_outgoing(application_sid) - capability.allow_client_incoming(identity) - token = capability.to_jwt() # Return token info as JSON return jsonify(identity=identity, token=token.decode('utf-8')) diff --git a/requirements.txt b/requirements.txt index 3f8b457..1f4143e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -flask~=1.1.0 -twilio~=6.32.0 -faker~=2.0.3 -python-dotenv==0.10.3 +flask~=1.1.2 +twilio~=6.38.1 +faker~=4.0.3 +python-dotenv==0.13.0 +pytest==5.4.1 diff --git a/static/index.html b/static/index.html index afab83a..5c44b37 100644 --- a/static/index.html +++ b/static/index.html @@ -19,8 +19,8 @@
- - + + \ No newline at end of file diff --git a/static/quickstart.js b/static/quickstart.js index 4501b43..36cf50f 100644 --- a/static/quickstart.js +++ b/static/quickstart.js @@ -1,41 +1,56 @@ $(function () { log('Requesting Capability Token...'); $.getJSON('/token') - .done(function (data) { + .then(function (data) { log('Got a token.'); console.log('Token: ' + data.token); // Setup Twilio.Device - Twilio.Device.setup(data.token); + device = new Twilio.Device(data.token, { + // Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and + // providing better audio quality in restrained network conditions. Opus will be default in 2.0. + codecPreferences: ["opus", "pcmu"], + // Use fake DTMF tones client-side. Real tones are still sent to the other end of the call, + // but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone + // a second time and sending the tone twice. This will be default in 2.0. + fakeLocalDTMF: true, + // Use `enableRingingState` to enable the device to emit the `ringing` + // state. The TwiML backend also needs to have the attribute + // `answerOnBridge` also set to true in the `Dial` verb. This option + // changes the behavior of the SDK to consider a call `ringing` starting + // from the connection to the TwiML backend to when the recipient of + // the `Dial` verb answers. + enableRingingState: true + }); - Twilio.Device.ready(function (device) { - log('Twilio.Device Ready!'); - document.getElementById('call-controls').style.display = 'block'; + device.on("ready", function (device) { + log("Twilio.Device Ready!"); + document.getElementById("call-controls").style.display = "block"; }); - Twilio.Device.error(function (error) { - log('Twilio.Device Error: ' + error.message); + device.on("error", function (error) { + log("Twilio.Device Error: " + error.message); }); - Twilio.Device.connect(function (conn) { - log('Successfully established call!'); - document.getElementById('button-call').style.display = 'none'; - document.getElementById('button-hangup').style.display = 'inline'; + device.on("connect", function (conn) { + log("Successfully established call!"); + document.getElementById("button-call").style.display = "none"; + document.getElementById("button-hangup").style.display = "inline"; }); - Twilio.Device.disconnect(function (conn) { - log('Call ended.'); - document.getElementById('button-call').style.display = 'inline'; - document.getElementById('button-hangup').style.display = 'none'; + device.on("disconnect", function (conn) { + log("Call ended."); + document.getElementById("button-call").style.display = "inline"; + document.getElementById("button-hangup").style.display = "none"; }); - Twilio.Device.incoming(function (conn) { - log('Incoming connection from ' + conn.parameters.From); - var archEnemyPhoneNumber = '+12099517118'; + device.on("incoming", function (conn) { + log("Incoming connection from " + conn.parameters.From); + var archEnemyPhoneNumber = "+12093373517"; if (conn.parameters.From === archEnemyPhoneNumber) { conn.reject(); - log('It\'s your nemesis. Rejected call.'); + log("It's your nemesis. Rejected call."); } else { // accept the incoming connection and start two-way audio conn.accept(); @@ -43,11 +58,13 @@ }); setClientNameUI(data.identity); + }) - .fail(function () { - log('Could not get a token from server!'); + .catch(function (err) { + console.log(err); + log("Could not get a token from server!"); }); - + // Bind button to make call document.getElementById('button-call').onclick = function () { // get the phone number to connect the call to @@ -56,13 +73,20 @@ }; console.log('Calling ' + params.To + '...'); - Twilio.Device.connect(params); + if (device) { + var outgoingConnection = device.connect(params); + outgoingConnection.on("ringing", function () { + log("Ringing..."); + }); + } }; // Bind button to hangup call document.getElementById('button-hangup').onclick = function () { log('Hanging up...'); - Twilio.Device.disconnectAll(); + if (device) { + device.disconnectAll(); + } }; }); @@ -79,4 +103,4 @@ function setClientNameUI(clientName) { var div = document.getElementById('client-name'); div.innerHTML = 'Your client name: ' + clientName + ''; -} \ No newline at end of file +} diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..50a7f2e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +import os +import pytest + +from app import app as flask_app + + +@pytest.fixture +def app(): + yield flask_app + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/test_routes.py b/tests/test_routes.py new file mode 100644 index 0000000..7ccb6c8 --- /dev/null +++ b/tests/test_routes.py @@ -0,0 +1,26 @@ +from unittest.mock import patch + + +def test_index(app, client): + res = client.get('/') + assert res.status_code == 200 + assert 'Make a Call:' in res.get_data(as_text=True) + + +def test_voice_has_to_parameter(app, client): + res = client.post('/voice', data=dict(To='+593XXXXXXX')) + assert res.status_code == 200 + assert '+593XXXXXXX' in res.get_data(as_text=True) + + +def test_voice_has_not_to_parameter(app, client): + res = client.post('/voice') + assert res.status_code == 200 + assert 'Thanks for calling!' in res.get_data(as_text=True) + + +@patch('app.fake', **{'user_name.return_value': 'nezuko'}) +def test_generate_token(app, client): + res = client.get('/token') + assert '"identity":"nezuko"' in res.get_data(as_text=True) + assert '"token"' in res.get_data(as_text=True) From 5a1ba458f46ebc9297067d845dc73e704dc8b6e7 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Tue, 21 Apr 2020 10:34:23 -0500 Subject: [PATCH 2/3] Remove TWILIO_AUTH_TOKEN variable --- .env.example | 1 - .env.example.ps1 | 6 ++++-- .github/workflows/flask.yml | 1 - README.md | 3 +-- app.py | 1 - 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 5d0e776..d2dc9b2 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,4 @@ TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -TWILIO_AUTH_TOKEN=your_auth_token TWILIO_CALLER_ID=+1XXXYYYZZZZ # SID of your TwiML Application diff --git a/.env.example.ps1 b/.env.example.ps1 index 99a6735..ed7d9cd 100644 --- a/.env.example.ps1 +++ b/.env.example.ps1 @@ -1,7 +1,8 @@ $Env:TWILIO_ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -$Env:TWILIO_AUTH_TOKEN = "your_auth_token" $Env:TWILIO_TWIML_APP_SID = "APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" $Env:TWILIO_CALLER_ID = "+1XXXYYYZZZZ" +$Env:API_KEY = "SKXXXXXXXXXXXX" +$Env:API_SECRET = "XXXXXXXXXXXXXX" # Uncomment the following if you'd like the environment variables # to be permanently set on your user account for this machine. @@ -9,8 +10,9 @@ $Env:TWILIO_CALLER_ID = "+1XXXYYYZZZZ" <# [Environment]::SetEnvironmentVariable("TWILIO_ACCOUNT_SID", $Env:TWILIO_ACCOUNT_SID, "User") -[Environment]::SetEnvironmentVariable("TWILIO_AUTH_TOKEN", $Env:TWILIO_AUTH_TOKEN, "User") [Environment]::SetEnvironmentVariable("TWILIO_TWIML_APP_SID", $Env:TWILIO_TWIML_APP_SID, "User") [Environment]::SetEnvironmentVariable("TWILIO_CALLER_ID", $Env:TWILIO_CALLER_ID, "User") +[Environment]::SetEnvironmentVariable("API_KEY", $Env:API_KEY, "User") +[Environment]::SetEnvironmentVariable("API_SECRET", $Env:API_SECRET, "User") #> \ No newline at end of file diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 0501620..f97da29 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -30,7 +30,6 @@ jobs: python -m pytest env: TWILIO_ACCOUNT_SID: ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - TWILIO_AUTH_TOKEN: xxxxxxx TWILIO_CALLER_ID: +1XXXYYYZZZZ TWILIO_TWIML_APP_SID: APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX API_KEY: SKXXXXXXXXXXXX diff --git a/README.md b/README.md index 3279810..180e4b9 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ all the config values we need to run the application: | Config Value | Description | | :------------- |:------------- | `TWILIO_ACCOUNT_SID` | Your primary Twilio account identifier - find this [in the console here](https://www.twilio.com/console). -`TWILIO_AUTH_TOKEN` | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). `TWILIO_TWIML_APP_SID` | The TwiML application with a voice URL configured to access your server running this app - create one [in the console here](https://www.twilio.com/console/voice/twiml/apps). Also, you will need to configure the Voice "REQUEST URL" on the TwiML app once you've got your server up and running. `TWILIO_CALLER_ID` | A Twilio phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164) - you can [get one here](https://www.twilio.com/console/phone-numbers/incoming) `API_KEY` / `API_SECRET` | Your REST API Key information needed to create an [Access Token](https://www.twilio.com/docs/iam/access-tokens) - create [one here](https://www.twilio.com/console/project/api-keys). @@ -32,7 +31,7 @@ Begin by creating a configuration file for your application: cp .env.example .env ``` -Edit `.env` with the four configuration parameters we gathered from above. +Edit `.env` with the five configuration parameters we gathered from above. ### Windows (PowerShell) diff --git a/app.py b/app.py index 4206d0f..3df9c3e 100755 --- a/app.py +++ b/app.py @@ -26,7 +26,6 @@ def index(): def token(): # get credentials for environment variables account_sid = os.environ['TWILIO_ACCOUNT_SID'] - auth_token = os.environ['TWILIO_AUTH_TOKEN'] application_sid = os.environ['TWILIO_TWIML_APP_SID'] api_key = os.environ['API_KEY'] api_secret = os.environ['API_SECRET'] From 02a16c120e7dc1371d5a26d6f06d1894c2394f10 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 29 Apr 2020 09:32:06 -0500 Subject: [PATCH 3/3] Update Readme --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 180e4b9..918c57a 100644 --- a/README.md +++ b/README.md @@ -55,16 +55,23 @@ your user account. ## All Platforms +Create a new virtual environment. If using vanilla [virtualenv](https://virtualenv.pypa.io/en/latest/): + +``` +virtualenv venv +source venv/bin/activate +``` + Next, we need to install our depenedencies: ```bash -pip install -r requirements.txt +pip3 install -r requirements.txt ``` -Run the application using the `python` command. +Run the application using the `python3` command or the executable for Python 3. ```bash -python app.py +python3 app.py ``` Your application should now be running at http://localhost:5000.