Created
April 30, 2011 19:38
-
-
Save jvimal/949930 to your computer and use it in GitHub Desktop.
Integrating it with Flask App
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
# Change this function in app.py | |
CONNECT_SYNONYMS = ['connect', 'conn', 'login', 'register'] | |
DISCONNECT_SYNONYMS = ['disconnect', 'dc', 'logout'] | |
REFRESH_SYNONYMS = ['refresh', 'reload'] | |
CALL_SYNONYMS = ['call', 'share'] | |
STATS_SYNONYMS = ['stats'] | |
@app.route("/sms", methods=['GET']) | |
def sms(): | |
if request.method != "GET": | |
return make_sms_response("Invalid SMS.") | |
# Get our parameters from the query string | |
msg = request.args.get('Body') | |
from_number = request.args.get('From') | |
to_number = request.args.get('To') | |
# Just to debug | |
app.logger.warning("From: %s, To: %s, Message: %s\n" % (from_number, to_number, msg)) | |
cmd = msg.lower() | |
if cmd in CONNECT_SYNONYMS: | |
return users.connect(from_number) | |
elif cmd in DISCONNECT_SYNONYMS: | |
return users.disconnect(from_number) | |
elif cmd in REFRESH_SYNONYMS: | |
return users.refresh(from_number) | |
elif cmd in CALL_SYNONYMS: | |
return users.call(from_number) | |
elif cmd in STATS_SYNONYMS: | |
return users.stats(from_number) | |
else: | |
(peer_number, text) = users.msg(from_number, msg) | |
send_sms(peer_number, text) | |
# No response | |
return "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment