Skip to content

Instantly share code, notes, and snippets.

@RobSpectre
Created February 15, 2014 17:05
Show Gist options
  • Save RobSpectre/9022044 to your computer and use it in GitHub Desktop.
Save RobSpectre/9022044 to your computer and use it in GitHub Desktop.
Quick sketch of your use case
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