Skip to content

Instantly share code, notes, and snippets.

@atbaker
Last active November 3, 2015 22:56
Show Gist options
  • Save atbaker/74a54a2331cca23a0d9a to your computer and use it in GitHub Desktop.
Save atbaker/74a54a2331cca23a0d9a to your computer and use it in GitHub Desktop.
A Flask application that supports Twilio webhooks
from flask import Flask
from twilio import twiml
app = Flask(__name__)
@app.route('/voice', methods=['POST'])
def incoming_call():
"""Twilio Voice URL - receives incoming calls from Twilio"""
# Create a new TwiML response
resp = twiml.Response()
# <Say> a message to the caller
resp.say("Thanks for calling! I got your call because of Twilio's webhook. Goodbye!")
# Return the TwiML
return str(resp)
@app.route('/message', methods=['POST'])
def incoming_message():
"""Twilio Messaging URL - receives incoming messages from Twilio"""
# Create a new TwiML response
resp = twiml.Response()
# <Say> a message to the caller
resp.message("Thanks for your text! Webhooks are neat :)")
# Return the TwiML
return str(resp)
if __name__ == '__main__':
app.run()
Flask==0.10.1
twilio==4.9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment