Skip to content

Instantly share code, notes, and snippets.

@glennblock
Created September 21, 2017 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennblock/eaa3427994acee6ac1b13d9dd5afe049 to your computer and use it in GitHub Desktop.
Save glennblock/eaa3427994acee6ac1b13d9dd5afe049 to your computer and use it in GitHub Desktop.
var express = require('express');
var fromExpress = require('webtask-tools').fromExpress;
var bodyParser = require('body-parser');
var nexmo = require('nexmo');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/send', (req,res) => {
var ctx = req.webtaskContext;
var secrets = ctx.secrets;
var api_key = secrets.api_key;
var api_secret = secrets.api_secret;
var from = secrets.from;
/*
var STRIPE_SECRET_KEY = ctx.secrets.STRIPE_SECRET_KEY;
console.log(req.body);
stripe(STRIPE_SECRET_KEY).charges.create({
amount: req.query.amount,
currency: req.query.currency,
source: req.body.stripeToken,
description: req.query.description
}, (err, charge) => {
const status = err ? 400 : 200;
const message = err ? err.message : 'Sent!';
res.writeHead(status, { 'Content-Type': 'text/html' });
return res.end('<h1>' + message + '</h1>');
});
*/
});
// comment this to disable the test form
app.get('/', (req, res) => {
var ctx = req.webtaskContext;
res.send(renderView(ctx));
});
function renderView(ctx) {
return `
<h1>Serverless SMS</h1>
<form action="/webtasks-nodejs-dev-smssend/send"" method="POST">
<input name="dest" type="text">Destination Number</input>
<input name="message" type="text">Message</input>
<input type="submit">Send</input>
<form>
`;
}
module.exports = fromExpress(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment