Skip to content

Instantly share code, notes, and snippets.

@RobSpectre
Created May 22, 2014 14:41
Show Gist options
  • Save RobSpectre/7ed01af70e8690358d53 to your computer and use it in GitHub Desktop.
Save RobSpectre/7ed01af70e8690358d53 to your computer and use it in GitHub Desktop.
Quick demo of phone trees in Python
from flask import Flask
from flask import request
from twilio import twiml
import requests
app = Flask(__name__)
@app.route('/voice', methods=['POST'])
def voice():
response = twiml.Response()
with response.gather(action='/handler', numDigits='1') as gather:
gather.say("For the Doubletree Hotel, press 1.")
gather.say("For Heathrow Airport, press 2.")
gather.say("For Eurostar, press 3.")
gather.say("For setting Doubletree as your preferred hotel, press 4.")
response.redirect('/voice')
return str(response)
@app.route('/handler', methods=['POST'])
def handler():
response = twiml.Response()
digits = request.form['Digits']
if digits == '1':
response.redirect('/doubletree')
elif digits == '2':
response.redirect('/heathrow')
elif digits == '3':
response.redirect('/eurostar')
elif digits == '4':
response.redirect('/preferred')
else:
response.redirect('/voice')
return str(response)
@app.route('/doubletree', methods=['POST'])
def doubletree():
response = twiml.Response()
response.say("Doubletree.")
return str(response)
@app.route('/heathrow', methods=['POST'])
def heathrow():
response = twiml.Response()
response.say("Heathrow.")
return str(response)
@app.route('/eurostar', methods=['POST'])
def eurostar():
response = twiml.Response()
response.say("Eurostar.")
return str(response)
@app.route('/preferred', methods=['POST'])
def preferred():
response = twiml.Response()
get_info = requests.get('http://info.ma002.com/anony/lbtest.asp')
text = get_info.text
text.replace('<b>', '')
text.replace('</b>', '')
response.say(text)
return str(response)
if __name__ == "__main__":
app.debug = True
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment