Created
December 20, 2016 18:16
-
-
Save dukky/65f8db31ea2919f55d451820e5c79c7c to your computer and use it in GitHub Desktop.
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
var http = require('http'); | |
var express = require('express'); | |
var twilio = require('twilio'); | |
var app = express(); | |
app.post('/sms', function(req, res) { | |
var twilio = require('twilio'); | |
console.log("Req : " + req.body); | |
var twiml = new twilio.TwimlResponse(); | |
var request = require('request'); | |
request('https://newsapi.org/v1/articles?source=bbc-news&apiKey=xxx', (e, r, b) => { | |
var newsjson = JSON.parse(b); | |
var url = newsjson.articles[0].url; | |
request( | |
'http://api.smmry.com/&SM_API_KEY=xxx&SM_LENGTH=5&SM_URL=' + url, | |
(error, response, body) => | |
{ | |
var jsonres = JSON.parse(body); | |
twiml.message(jsonres.sm_api_content); | |
res.writeHead(200, {'Content-Type': 'text/xml'}); | |
res.end(twiml.toString()); | |
});}); | |
}); | |
http.createServer(app).listen(1337, function () { | |
console.log("Express server listening on port 1337"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment