Merge pull request #9 from TwilioDevEd/upgrade-twilio-python-to-6.0.0
Upgraded twilio-python to 6.0.0
This commit is contained in:
@@ -3,8 +3,6 @@ TWILIO_ACCOUNT_SID=
|
||||
TWILIO_API_KEY=
|
||||
TWILIO_API_SECRET=
|
||||
|
||||
# Required for Video
|
||||
TWILIO_CONFIGURATION_SID=
|
||||
|
||||
# Required for Chat
|
||||
TWILIO_CHAT_SERVICE_SID=
|
||||
|
||||
@@ -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
|
||||
|
||||
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 |
|
||||
| :------------- |:------------- |:------------- |
|
||||
`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_NOTIFICATION_SERVICE_SID` | Notify (Preview) | You will need to create a Notify service - [generate one here](https://www.twilio.com/console/notify/services)
|
||||
|
||||
|
||||
19
app.py
19
app.py
@@ -2,7 +2,12 @@ import os
|
||||
from flask import Flask, jsonify, request
|
||||
from faker import Factory
|
||||
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 os.path import join, dirname
|
||||
|
||||
@@ -53,7 +58,6 @@ def token():
|
||||
api_key = os.environ['TWILIO_API_KEY']
|
||||
api_secret = os.environ['TWILIO_API_SECRET']
|
||||
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']
|
||||
|
||||
|
||||
@@ -61,7 +65,7 @@ def token():
|
||||
identity = fake.user_name()
|
||||
|
||||
# Create access token with credentials
|
||||
token = AccessToken(account_sid, api_key, api_secret, identity)
|
||||
token = AccessToken(account_sid, api_key, api_secret, identity=identity)
|
||||
|
||||
# Create a Sync grant and add to token
|
||||
if sync_service_sid:
|
||||
@@ -69,8 +73,7 @@ def token():
|
||||
token.add_grant(sync_grant)
|
||||
|
||||
# Create a Video grant and add to token
|
||||
if configuration_profile_sid:
|
||||
video_grant = ConversationsGrant(configuration_profile_sid=configuration_profile_sid)
|
||||
video_grant = VideoGrant(room='default_room')
|
||||
token.add_grant(video_grant)
|
||||
|
||||
# Create an Chat grant and add to token
|
||||
@@ -97,7 +100,7 @@ def register():
|
||||
content = request.get_json()
|
||||
|
||||
# Get a reference to the notification service
|
||||
service = client.notify.v1.services(service_sid)
|
||||
service = client.notify.services(service_sid)
|
||||
|
||||
# Create the binding
|
||||
binding = service.bindings.create(
|
||||
@@ -106,7 +109,7 @@ def register():
|
||||
binding_type=content["BindingType"],
|
||||
address=content["Address"])
|
||||
|
||||
print binding
|
||||
print(binding)
|
||||
|
||||
# Return success message
|
||||
return jsonify(message="Binding created!")
|
||||
@@ -123,7 +126,7 @@ def send_notification():
|
||||
# Initialize the Twilio client
|
||||
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
|
||||
identity = request.form.get('identity')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Flask==0.10.1
|
||||
fake-factory==0.5.3
|
||||
twilio==6.0.0rc12
|
||||
twilio>=6.0.0rc13,<6.1.0
|
||||
python-dotenv==0.6.0
|
||||
|
||||
Reference in New Issue
Block a user