Browse Source

twilio/cors

windhamdavid 9 years ago
parent
commit
644b8ec36c
4 changed files with 43 additions and 1 deletions
  1. 19 0
      inbound.js
  2. 2 1
      package.json
  3. 6 0
      server.js
  4. 16 0
      sms.js

+ 19 - 0
inbound.js

@@ -0,0 +1,19 @@
+var twilio = require('twilio'),
+    http = require('http');
+
+http.createServer(function (req, res) {
+    var resp = new twilio.TwimlResponse();
+    resp.say({voice:'woman'}, 'Welcome to the office of David A. Windham. David is not available at this time.');
+ 
+    resp.gather({ timeout:30 }, function() {
+        this.say('To Leave a messaage, press 1. For immediate support, press 2.');
+    });
+ 
+    res.writeHead(200, {
+        'Content-Type':'text/xml'
+    });
+    res.end(resp.toString());
+ 
+}).listen(1337);
+ 
+console.log('Twiml Server started on port 1337');

+ 2 - 1
package.json

@@ -12,6 +12,7 @@
     "webrtc.io": "latest",
     "webrtc.io-client": "latest",
     "express": "latest",
-    "ws": "latest"
+    "ws": "latest",
+	"twilio": "latest"
   }
 }

+ 6 - 0
server.js

@@ -2,6 +2,12 @@ var app = require('express')();
 var server = require('http').createServer(app);
 var webRTC = require('webrtc.io').listen(server);
 
+app.all('/*', function(req, res, next) {
+  res.header("Access-Control-Allow-Origin", "*");
+  res.header("Access-Control-Allow-Headers", "X-Requested-With");
+  next();
+});
+
 var port = process.env.PORT || 8080;
 server.listen(port);
 

+ 16 - 0
sms.js

@@ -0,0 +1,16 @@
+var client = require('twilio')(process.env.account_sid, process.env.auth_token)
+
+client.sms.messages.create({
+    to:'+18037123283',
+    from:'8037124787',
+    body:'$person wants to chat'
+}, function(error, message) {
+    if (!error) {
+        console.log('Success! SID:');
+        console.log(message.sid);
+        console.log('Message sent on:');
+        console.log(message.dateCreated);
+    } else {
+        console.log('Error!');
+    }
+});