Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2016 18:13
What would you like to do?
Simple Python & Flask app to respond to incoming SMS text messages
from flask import Flask, Response, request
from twilio import twiml
app = Flask(__name__)
def check_app():
# returns a simple string stating the app is working
return Response("It works!"), 200
@app.route("/twilio", methods=["POST"])
def inbound_sms():
response = twiml.Response()
# we get the SMS message from the request. we could also get the
# "To" and the "From" phone number as well
inbound_message = request.form.get("Body")
# we can now use the incoming message text in our Python application
if inbound_message == "Hello":
response.message("Hello back to you!")
response.message("Hi! Not quite sure what you meant, but okay.")
# we return back the mimetype because Twilio needs an XML response
return Response(str(response), mimetype="application/xml"), 200
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment