How to use twilio - 10 common examples

To help you get started, we’ve selected a few twilio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twilio / twilio-video.js / test / lib / token.js View on Github external
apiKeySid,
    apiKeySecret,
    { ttl });

  accessToken.identity = identity;

  let grant = options.grant;
  switch (grant) {
    case 'conversations':
      grant = new AccessToken.ConversationsGrant({
        identity,
        configurationProfileSid
      });
      break;
    case 'video':
      grant = new AccessToken.VideoGrant({
        identity
      });
      break;
    default:
      // Do nothing.
  }

  if (grant) {
    accessToken.addGrant(grant);
  }

  return accessToken.toJwt('HS256');
}
github chrisl8 / ArloBot / server / index.js View on Github external
app.post('/twilio', function (request, response) {
    if (twilio.validateExpressRequest(request, personalData.twilio.auth_token, {url: personalData.twilio.smsWebhook})) {
        var messageForRedis = {
            smsText: request.body.Body,
            smsTo: request.body.To,
            smsFrom: request.body.From
        };
        console.log(messageForRedis.smsFrom, messageForRedis.smsText);
        messageForRedis = JSON.stringify(messageForRedis);
        // Tell Twilio we got the message, and reply to the sender
        response.header('Content-Type', 'text/xml');
        if (robotSubscribers.length > 0) {
            socket.sockets.emit('newMessage', messageForRedis);
            response.send('Got it!');
        } else {
            // Save the message in REDIS
            client.rpush("twilio", messageForRedis);
            response.send('Sorry, nobody is home, try again later.');
github TwilioDevEd / api-snippets / wireless / devices / usage / instance-get-example-1 / instance-get-example-1.3.x.js View on Github external
// Download the **Next-Gen** twilio-node library from:
// twilio.com/docs/libraries/node#installation-nextgen
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Your Account SID from www.twilio.com/console
var authToken = 'your_auth_token';   // Your Auth Token from www.twilio.com/console

var twilioLibrary = require('twilio');
var client = new twilioLibrary.Twilio(accountSid, authToken);

client.preview.wireless.devices('DEb8eff34b248d066a31c4a953134e183e')
  .usage().fetch(function(err, usage) {
    console.log(usage.period.start);
    console.log(usage.period.end);
    console.log(usage.dataCosts.total);
  });
github TwilioDevEd / api-snippets / sync / rest / streams / update-stream / update-stream.3.x.js View on Github external
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const Twilio = require('twilio').Twilio;

const client = new Twilio(accountSid, authToken);
const service = client.sync.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');

service.syncStreams('MyStream')
  .update({
    ttl: 864000 // expires in 10 days
  })
  .then(stream => {
    console.log(stream.dateExpires);
  })
  .catch(error => {
    console.log(error);
  });
github TwilioDevEd / api-snippets / client / response-twiml-client / response-twiml-client.2.x.js View on Github external
app.post('/voice', function (req, res) {
    // Create TwiML response
    var twiml = new twilio.TwimlResponse();
    
    if(req.body.To) {
      twiml.dial({ callerId: '+15017250604'}, function() {
        // wrap the phone number or client name in the appropriate TwiML verb
        // by checking if the number given has only digits and format symbols
        if (/^[\d\+\-\(\) ]+$/.test(req.body.To)) {
          this.number(req.body.To);
        } else {
          this.client(req.body.To);
        }
      });
    } else {
      twiml.say("Thanks for calling!");
    }

    res.set('Content-Type', 'text/xml');
github TwilioDevEd / api-snippets / rest / taskrouter / worker-reservations / call / example-1.2.x.js View on Github external
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var twilio = require('twilio');

var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var workerSid = "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var reservationSid = "WRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid);

// call using a reservation
client.workspace.workers(workerSid).reservations(reservationSid).update({
    instruction: 'call',
    callFrom: '+15558675309',
    callUrl: 'http://example.com/agent_answer',
    callStatusCallbackUrl: 'http://example.com/agent_answer_status_callback',
    callAccept: 'true'
}, function(err, reservation) {
    console.log(reservation.reservation_status);
    console.log(reservation.worker_name);
});
github TwilioDevEd / api-snippets / rest / taskrouter / statistics / workers / example-1 / example-1.2.x.js View on Github external
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var twilio = require('twilio');

var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid);

client.workspace.workers.statistics.get({}, function(err, responseData) {
    if(!err) {
        console.log(responseData.cumulative.reservations_accepted);
    }
});
github TwilioDevEd / api-snippets / rest / taskrouter / workspaces / list / get / example-1 / example-1.2.x.js View on Github external
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var twilio = require('twilio');

var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid);

client.workspaces.list(function(err, data) {
    data.workspaces.forEach(function(workspace) {
        console.log(workspace.friendly_name);
    });
});
github TwilioDevEd / api-snippets / rest / taskrouter / statistics / workflow / example-1 / example-1.2.x.js View on Github external
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var twilio = require('twilio');

var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var workflowSid = "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid);

client.workspace.workflows(workflowSid).statistics.get({}, function(err, responseData) {
    if(!err) {
        console.log(responseData.cumulative.avg_task_acceptance_time);
        console.log(responseData.cumulative.tasks_created);
        console.log(responseData.realtime.tasks_by_status.pending);
        console.log(responseData.realtime.tasks_by_status.assigned);
    }
});
github TwilioDevEd / api-snippets / rest / taskrouter / workers / list / get / example-1 / example-1.2.x.js View on Github external
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var twilio = require('twilio');

var accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var authToken = "your_auth_token";
var workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

var client = new twilio.TaskRouterClient(accountSid, authToken, workspaceSid);

client.workspace.workers.list(function(err, data) {
    data.workers.forEach(function(worker) {
        console.log(worker.friendly_name);
    })
});