Updated twilio API example

- Added number to text field and message field
- Input validation
This commit is contained in:
Sahat Yalkabov
2014-06-02 14:47:35 -04:00
parent d7de1cc9d5
commit d58ba076af
2 changed files with 26 additions and 10 deletions

View File

@@ -378,7 +378,7 @@ exports.postStripe = function(req, res, next) {
* Twilio API example.
*/
exports.getTwilio = function(req, res, next) {
exports.getTwilio = function(req, res) {
res.render('api/twilio', {
title: 'Twilio API'
});
@@ -387,14 +387,25 @@ exports.getTwilio = function(req, res, next) {
/**
* POST /api/twilio
* Twilio API example.
* @param telephone
* @param number
* @param message
*/
exports.postTwilio = function(req, res, next) {
req.assert('number', 'Phone number is required.').notEmpty();
req.assert('message', 'Message cannot be blank.').notEmpty();
var errors = req.validationErrors();
if (errors) {
req.flash('errors', errors);
return res.redirect('/api/twilio');
}
var message = {
to: req.body.telephone,
to: req.body.number,
from: '+13472235148',
body: 'Hello from the Hackathon Starter'
body: req.body.message
};
twilio.sendMessage(message, function(err, responseData) {
if (err) return next(err.message);