Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created August 25, 2015 16:54
Show Gist options
  • Save kwhinnery/903b25f4a5291c9ef947 to your computer and use it in GitHub Desktop.
Save kwhinnery/903b25f4a5291c9ef947 to your computer and use it in GitHub Desktop.
var sa = require('superagent');
sa.post('https://ip-messaging.twilio.com/v1/Services')
.auth(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
.type('form')
.send({
FriendlyName: 'Super Awesome App'
})
.end(function(err, res) {
console.log(res.body.sid);
});
var express = require('express');
var twilio = require('twilio');
var app = express();
app.use(express.static(__dirname+'/public'));
app.get('/token', function(request, response) {
var capability = new twilio.Capability();
capability.allowClientOutgoing('', {
service_sid: 'ISeaea27ce5b404009a7a316e9eb57d003',
identity: request.query.id,
endpoint_id: 'MyChat:browser:' + request.query.id
});
response.send(capability.generate());
});
app.get('/message', function(request, response) {
var sa = require('superagent');
sa.post('https://ip-messaging.twilio.com/v1/Services/ISeaea27ce5b404009a7a316e9eb57d003/Channels/CH45149a05faeb49b0a68107d9d3903f4a/Messages')
.auth(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN)
.type('form')
.send({
Body: request.query.Body
})
.end(function(err, res) {
console.log(res.body.sid);
});
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment