Created
March 22, 2015 17:05
-
-
Save juliedavila/6e533365c70dc31a1571 to your computer and use it in GitHub Desktop.
views for interactive prez blog
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
# Copyright (c) 2014, Matt Makai | |
# All rights reserved. | |
# Full License can be read here: http://bit.ly/1qBgqzn | |
import cgi | |
from flask import render_template, abort, request | |
from jinja2 import TemplateNotFound | |
from twilio import twiml | |
from twilio.rest import TwilioRestClient | |
from .config import TWILIO_NUMBER | |
from . import app, redis_db, socketio | |
client = TwilioRestClient() | |
@app.route('/<presentation_name>/', methods=['GET']) | |
def landing(presentation_name): | |
try: | |
return render_template(presentation_name + '.html') | |
except TemplateNotFound: | |
abort(404) | |
@app.route('/presentation/twilio/webhook/', methods=['POST']) | |
def twilio_callback(): | |
to = request.form.get('To', '') | |
from_ = request.form.get('From', '') | |
message = request.form.get('Body', '').lower() | |
if to == TWILIO_NUMBER: | |
redis_db.incr(cgi.escape(message)) | |
socketio.emit('msg', {'div': cgi.escape(message), | |
'val': redis_db.get(message)}, | |
namespace='/presentation') | |
resp = twiml.Response() | |
resp.message("Thanks for your vote! Whatever message you want attendees to see goes here") | |
return str(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment