twilio and parse: rich experiences in & out of native clients
Post on 16-Jul-2015
193 Views
Preview:
TRANSCRIPT
What is an App?
Think outside the 4” box
Modern apps are in the cloud
The cloud has no home button
The cloud never sleeps
The cloud is complicated
Your App Here
Twilio + Parse
Cross platform clouds are awesome
Cross-media clouds are awesomer
Twilio provides reach, delivery, and events
Parse provides persistence, logic, and native
apps
SMS or App
Apps have a custom experience
Apps are bespoke
Apps have high acquisition costs
SMS is universal
SMS is far reaching
SMS is guaranteed
Four different ways
SMS or App
Exclusive SMS is the App
Hybrid Apps require SMS for core features
Parity SMS or App are portals to the same
experience
Segmentation Different roles have different
environments
AnyQs: A Twilio + Parse app to handle Q&A
Building a Segmented App
A quick afternoon hack on Twilio + Parse
Audience members ask questions via SMS
Web app allows moderators to approve or reject
Native app for presenter to review questions
Data Model
Pending
Class Structure State Machine
RejectedAccepted
Answered
Question
to: string
from: string
prompt: string
state: string
Set up Twilio and Express
Asking Questions
var twilio = require("twilio");
twilio.initialize(account SID, auth token);
var Question = Parse.Object.extend("Question");
var express = require("express");
var app = express();
app.use(express.bodyParser);
app.listen();
app.post("/questions", function(request, response) {
// TODO: stuff... (next slide)
});
Implementing /questions
Asking Questions
var question = new Question({
from: request.body.From,
to: request.body.To,
status: "pending",
prompt: request.body.Body
});
question.save().then(function() {
response.send("");
}, function(error) {
response.status(500);
response.send(error);
});
Get Pending Questions
Moderating Questions
var Question = Parse.Object.extend("Question");
var query = new Parse.Query(Question);
query.equalTo("status", "pending");
query.find().then(function(results) {
table.empty();
_.each(results, function(question) {
addRow(question.id, question.get("prompt"));
});
});
Modifying Questions
Moderating Questions
function updateQuestion(id, status) {
}
var row = $("#question" + id);
row.children("button").attr("disabled", "disabled");
var question = new Question();
question.id = id;
question.set("status", status);
question.save().then(function() {
row.remove();
});
Responding to Users
Moderating Questions
Parse.Cloud.beforeSave("Question", function(req, resp) {
var q = request.object;
var promise = Parse.Promise.as(); // already fulfilled
if (q.dirty("status") &&
q.get("status") === "rejected") {
promise = twilio.sendSMS({
From: q.get("to"),
To: q.get("from"),
Body: "Being off topic makes me a sad panda."
});
}
promise.then(function() { resp.success(); },
function(error) { resp.error(error) });
});
top related