Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var twilio = require('twilio')(ACCOUNT_SID, AUTH_TOKEN);
- var qs = require('querystring');
- http.createServer(function (req, res) {
- var body = '';
- req.setEncoding('utf8');
- req.on('data', function(data) {
- body += data;
- });
- req.on('end', function() {
- var data = qs.parse(body);
- var jsonString = JSON.stringify(data);
- var jsonDataObject = JSON.parse(jsonString);
- // log the received message
- console.log(jsonDataObject.Body);
- twilio.messages.create({
- to:'MY_PHONE_NUMBER',
- from:'TWILIO_NUMBER',
- body:'Hello World'
- }, function(error, message) {
- if (error) {
- console.log('There was an error.')
- console.log(error.message);
- }
- });
- res.writeHead(200, {'Content-Type': 'text/xml'});
- res.end();
- });
- }).listen(1337, '127.0.0.1');
- console.log('TwiML servin' server running at http://127.0.0.1:1337/');
- var twilio = require("twilio");
- req.on('end', function() {
- var data = qs.parse(body);
- var jsonString = JSON.stringify(data);
- var jsonDataObject = JSON.parse(jsonString);
- // log the received message
- console.log(jsonDataObject.Body);
- var twiml = new twilio.TwimlResponse();
- twiml.message("Hello world");
- res.writeHead(200, {'Content-Type': 'text/xml'});
- res.end(twiml.toString());
- });
- var express = require('express');
- var app = express();
- var bodyParser = require('body-parser');
- const MessagingResponse = require('twilio').twiml.MessagingResponse;
- var server = app.listen(80, function () {
- var host = server.address().address
- var port = server.address().port
- console.log(" web app listening at http://%s:%s", host, port)
- })
- app.post('/txt', urlencodedParser,(req, res) => {
- const twiml = new MessagingResponse();
- twiml.message('Finally Twilio works!');
- res.status(200);
- res.send(twiml.toString());
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement