Upgradet twilio-python to 6.0.0

This commit is contained in:
José Oliveros
2017-03-30 17:02:38 -06:00
parent 9362e76310
commit 0efbb977dc
4 changed files with 29 additions and 25 deletions

View File

@@ -3,8 +3,6 @@ TWILIO_ACCOUNT_SID=
TWILIO_API_KEY= TWILIO_API_KEY=
TWILIO_API_SECRET= TWILIO_API_SECRET=
# Required for Video
TWILIO_CONFIGURATION_SID=
# Required for Chat # Required for Chat
TWILIO_CHAT_SERVICE_SID= TWILIO_CHAT_SERVICE_SID=

View File

@@ -1,3 +1,7 @@
<a href="https://www.twilio.com">
<img src="https://static0.twilio.com/marketing/bundles/marketing/img/logos/wordmark-red.svg" alt="Twilio" width="250" />
</a>
# Twilio SDK Starter Application for Python # Twilio SDK Starter Application for Python
This sample project demonstrates how to use Twilio APIs in a Python web This sample project demonstrates how to use Twilio APIs in a Python web
@@ -42,7 +46,6 @@ Depending on which demos you'd like to run, you'll need to configure a few more
| Config Value | Product Demo | Description | | Config Value | Product Demo | Description |
| :------------- |:------------- |:------------- | | :------------- |:------------- |:------------- |
`TWILIO_CHAT_SERVICE_SID` | Chat | Like a database for your Chat data - [generate one in the console here](https://www.twilio.com/console/chat/services) `TWILIO_CHAT_SERVICE_SID` | Chat | Like a database for your Chat data - [generate one in the console here](https://www.twilio.com/console/chat/services)
`TWILIO_CONFIGURATION_SID` | Video | Identifier for a set of config properties for your video application - [find yours here](https://www.twilio.com/console/video/profiles)
`TWILIO_SYNC_SERVICE_SID` | Sync (Preview) | Like a database for your Sync data - generate one with the curl command below. `TWILIO_SYNC_SERVICE_SID` | Sync (Preview) | Like a database for your Sync data - generate one with the curl command below.
`TWILIO_NOTIFICATION_SERVICE_SID` | Notify (Preview) | You will need to create a Notify service - [generate one here](https://www.twilio.com/console/notify/services) `TWILIO_NOTIFICATION_SERVICE_SID` | Notify (Preview) | You will need to create a Notify service - [generate one here](https://www.twilio.com/console/notify/services)

17
app.py
View File

@@ -2,7 +2,12 @@ import os
from flask import Flask, jsonify, request from flask import Flask, jsonify, request
from faker import Factory from faker import Factory
from twilio.rest import Client from twilio.rest import Client
from twilio.jwt.access_token import AccessToken, SyncGrant, ConversationsGrant, IpMessagingGrant from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import (
SyncGrant,
VideoGrant,
IpMessagingGrant
)
from dotenv import load_dotenv, find_dotenv from dotenv import load_dotenv, find_dotenv
from os.path import join, dirname from os.path import join, dirname
@@ -53,7 +58,6 @@ def token():
api_key = os.environ['TWILIO_API_KEY'] api_key = os.environ['TWILIO_API_KEY']
api_secret = os.environ['TWILIO_API_SECRET'] api_secret = os.environ['TWILIO_API_SECRET']
sync_service_sid = os.environ['TWILIO_SYNC_SERVICE_SID'] sync_service_sid = os.environ['TWILIO_SYNC_SERVICE_SID']
configuration_profile_sid = os.environ['TWILIO_CONFIGURATION_SID']
chat_service_sid = os.environ['TWILIO_CHAT_SERVICE_SID'] chat_service_sid = os.environ['TWILIO_CHAT_SERVICE_SID']
@@ -69,8 +73,7 @@ def token():
token.add_grant(sync_grant) token.add_grant(sync_grant)
# Create a Video grant and add to token # Create a Video grant and add to token
if configuration_profile_sid: video_grant = VideoGrant(room='default_room')
video_grant = ConversationsGrant(configuration_profile_sid=configuration_profile_sid)
token.add_grant(video_grant) token.add_grant(video_grant)
# Create an Chat grant and add to token # Create an Chat grant and add to token
@@ -97,7 +100,7 @@ def register():
content = request.get_json() content = request.get_json()
# Get a reference to the notification service # Get a reference to the notification service
service = client.notify.v1.services(service_sid) service = client.notify.services(service_sid)
# Create the binding # Create the binding
binding = service.bindings.create( binding = service.bindings.create(
@@ -106,7 +109,7 @@ def register():
binding_type=content["BindingType"], binding_type=content["BindingType"],
address=content["Address"]) address=content["Address"])
print binding print(binding)
# Return success message # Return success message
return jsonify(message="Binding created!") return jsonify(message="Binding created!")
@@ -123,7 +126,7 @@ def send_notification():
# Initialize the Twilio client # Initialize the Twilio client
client = Client(api_key, api_secret, account_sid) client = Client(api_key, api_secret, account_sid)
service = client.notify.v1.services(service_sid) service = client.notify.services(service_sid)
# Create a notification for a given identity # Create a notification for a given identity
identity = request.form.get('identity') identity = request.form.get('identity')

View File

@@ -1,4 +1,4 @@
Flask==0.10.1 Flask==0.10.1
fake-factory==0.5.3 fake-factory==0.5.3
twilio==6.0.0rc12 twilio>=6.0.0rc13,<6.1.0
python-dotenv==0.6.0 python-dotenv==0.6.0