Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (41 sloc) 1.5 KB
# Note: We don't need to call since our application is embedded within
# the App Engine WSGI application server.
# Twilio docs here:
from flask import Flask, request, redirect
import twilio.twiml
import socket
import ssl
from getmail import getmail
app = Flask(__name__)
# stores secrets:
callers = app.config.get('CALLERS')
email_address = app.config.get('EMAIL')
password = app.config.get('PASSWORD')
url = "/" + app.config.get('SECRET_URL')
# url is long random string to prevent a brute force attack
@app.route(url, methods=["GET", "POST"])
def mail_response():
"""Respond to incoming text with email content, if authorized"""
from_number = request.values.get("From", None)
if from_number in callers:
resp = twilio.twiml.Response()
content = getmail(email_address, password)
return str(resp)
return 'Sorry, Nothing at this URL.', 404
#Allow user to input 10-20 in the body of the text, respond with corresponding messages
#set max response to ~ 30, default is first 5 messages
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
def application_error(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500