Created
February 15, 2014 17:05
-
-
Save RobSpectre/9022044 to your computer and use it in GitHub Desktop.
Quick sketch of your use case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import request | |
from twilio import twiml | |
from twilio.rest import TwilioRestClient | |
# Declare and configure application | |
app = Flask(__name__, static_url_path='/static') | |
app.config.from_pyfile('local_settings.py') | |
users = [ | |
'+12152758878', | |
'+12153501452', | |
'+15855209040'] | |
user_balances = { | |
'+12152758878': 0, | |
'+12153501452': 25, | |
'+15855209040': 1000000} | |
@app.route('/sms', methods=['POST']) | |
def sms(): | |
body = request.form['Body'] | |
client = TwilioRestClient() | |
response = twiml.Response() | |
if 'BALANCE' in body: | |
trimmed_body = body.replace('BALANCE', '') | |
trimmed_body = trimmed_body.strip() | |
response.message("User's balance is: %i" % user_balances[trimmed_body]) | |
else: | |
for user in users: | |
client.messages.create(from_='+16176069190', to=user, | |
body=body) | |
response.message('Message sent.') | |
return str(response) | |
from flask import Flask | |
from flask import request | |
from twilio import twiml | |
from twilio.rest import TwilioRestClient | |
# Declare and configure application | |
app = Flask(__name__, static_url_path='/static') | |
app.config.from_pyfile('local_settings.py') | |
users = [ | |
'+12152758878', | |
'+12153501452', | |
'+15855209040'] | |
user_balances = { | |
'+12152758878': 0, | |
'+12153501452': 25, | |
'+15855209040': 1000000} | |
@app.route('/sms', methods=['POST']) | |
def sms(): | |
body = request.form['Body'] | |
client = TwilioRestClient() | |
response = twiml.Response() | |
if 'BALANCE' in body: | |
trimmed_body = body.replace('BALANCE', '') | |
trimmed_body = trimmed_body.strip() | |
response.message("User's balance is: %i" % user_balances[trimmed_body]) | |
else: | |
for user in users: | |
client.messages.create(from_='+16176069190', to=user, | |
body=body) | |
response.message('Message sent.') | |
return str(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment