Skip to content

Instantly share code, notes, and snippets.

@mattmakai
Created June 5, 2016 16:50
Show Gist options
  • Save mattmakai/6ec3b46e40a1020a3ea9c772c601199a to your computer and use it in GitHub Desktop.
Save mattmakai/6ec3b46e40a1020a3ea9c772c601199a to your computer and use it in GitHub Desktop.
A simple Bottle web app for replying to SMS based on incoming HTTP POST requests from Twilio
from bottle import (post, request, response, route, run, )
from twilio import twiml
@route('/')
def check_app():
# returns a simple string stating the app is working
return "It works!"
@post('/twilio')
def inbound_sms():
twiml_response = twiml.Response()
# grab message from the request. could also get the "To" and
# "From" phone numbers as well from parameters with those names
inbound_message = request.forms.get("Body")
# we can now use the incoming message text in our Python application
if inbound_message == "Hello":
twiml_response.message("Hello from Bottle right back at you!")
else:
twiml_response.message("Hi! Not quite sure what you meant, but okay.")
# we return back the mimetype because Twilio needs an XML response
response.content_type = "application/xml"
return str(twiml_response)
if __name__ == '__main__':
run(host='127.0.0.1', port=5000, debug=True, reloader=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment