Created
September 11, 2011 16:07
-
-
Save gtracy/1209756 to your computer and use it in GitHub Desktop.
Signup handler function for a Twilio SMS interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CallHandler(webapp.RequestHandler): | |
def post(self): | |
# extract the message and phone | |
message = self.request.get('Body') | |
phone = self.request.get('From') | |
# the first word tells us everything... | |
first = message.lower().split()[0] | |
# the admin gets extra special commands to control the app | |
if phone == configuration.ADMIN_PHONE: | |
if first == 'stop': | |
systemSwitch(False) | |
elif first == 'start': | |
systemSwitch(True) | |
return | |
# interrogate the message to figure out what to do | |
if first == 'signup': | |
# if signup request, create a new user | |
signupUser(phone) | |
response = "Sweet - you're in! We'll send you schedule reminders all day." | |
elif first.isdigit() or first.find('#') > -1: | |
# if the first word is a number, assume it's feedback | |
storeFeedback(first,message,phone) | |
response = "Thanks for sharing your feedback!" | |
else: | |
# else, tell the caller we don't know what they're saying | |
response = "Snap! We don't know what to do with this. Any feedback should start with the session number" | |
sendEmail(message,phone) | |
r = twiml.Response() | |
r.sms(response) | |
self.response.out.write(str(r)) | |
## end CallHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment