Skip to content

Instantly share code, notes, and snippets.

@jaxatax
Created April 24, 2019 01:03
Show Gist options
  • Save jaxatax/a390d36eca16767207b5c92bb1863160 to your computer and use it in GitHub Desktop.
Save jaxatax/a390d36eca16767207b5c92bb1863160 to your computer and use it in GitHub Desktop.
Getting the value of the message with Twilio and PythonAnywhere.
from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/sms", methods=['GET', 'POST'])
def incoming_sms():
"""Send a dynamic reply to an incoming text message"""
# Get the message the user sent our Twilio number
body = request.values.get('Body', None)
# Start our TwiML response
resp = MessagingResponse()
# Determine the right reply for this message
if body == 'hello':
resp.message("Hi!")
elif body == 'bye':
resp.message("Goodbye")
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment