Updated twilio API example
- Added number to text field and message field - Input validation
This commit is contained in:
@ -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);
|
||||
|
@ -3,7 +3,7 @@ extends ../layout
|
||||
block content
|
||||
.page-header
|
||||
h2
|
||||
i.fa.fa-phone
|
||||
i.fa.fa-phone(style='color: #f00')
|
||||
| Twilio API
|
||||
|
||||
.btn-group.btn-group-justified
|
||||
@ -17,13 +17,18 @@ block content
|
||||
i.fa.fa-code-fork
|
||||
| REST API
|
||||
|
||||
h4 Send a text message
|
||||
br
|
||||
|
||||
.row
|
||||
.col-sm-6
|
||||
form(role='form', method='POST')
|
||||
input(type='hidden', name='_csrf', value=_csrf)
|
||||
.form-group
|
||||
.input-group
|
||||
input.form-control(type='text', name='telephone', placeholder='Phone Number')
|
||||
span.input-group-btn
|
||||
button.btn.btn-success(type='submit') Send
|
||||
label.control-label Number to text
|
||||
input.form-control(type='text', name='number', autofocus)
|
||||
.form-group
|
||||
label.control-label Message
|
||||
input.form-control(type='text', name='message')
|
||||
button.btn.btn-default(type='submit')
|
||||
i.fa.fa-location-arrow
|
||||
| Send
|
||||
|
Reference in New Issue
Block a user