Advertisement
dhillonsh

Twilio server

May 28th, 2020
2,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Download the helper library from https://www.twilio.com/docs/node/install
  2. // Your Account Sid and Auth Token from twilio.com/console
  3. // DANGER! This is insecure. See http://twil.io/secure
  4.  
  5. const accountSid = '<Redacted>'; // IMPORTANT! Follow the instructions above to get this, and replace <Redacted>
  6. const authToken = '<Redacted>'; // IMPORTANT! Follow the instructions above to get this, and replace <Redacted>
  7. const client = require('twilio')(accountSid, authToken);
  8.  
  9. const http = require('http');
  10. const url = require('url');
  11.  
  12. const requestListener = function (req, res) {
  13.     res.writeHead(200);
  14.     res.end('Hello, World!');
  15.  
  16.     if(req.url !== '/favicon.ico') {
  17.         const queryObject = url.parse(req.url, true).query;
  18.         if('title' in queryObject) {
  19.             var body = queryObject.title;
  20.         } else {
  21.             var body = "Item Alert";
  22.         }
  23.        
  24.         client.messages
  25.         .create({
  26.             body: body,
  27.             from: '+<Redacted>', // IMPORTANT! Put your twilio phone number here, replacing <Redacted>
  28.             to: '+<Redacted>' // IMPORTANT! Put your phone number here, replacing <Redacted>
  29.         })
  30.         .then(message => console.log(message.sid));
  31.     }
  32. }
  33.  
  34. const server = http.createServer(requestListener);
  35. server.listen(8080);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement