How to use the twilio.RestClient function in twilio

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 TwilioDevEd / api-snippets / rest / outgoing-caller-ids / list-post-example-1 / list-post-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
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const Client = require('twilio').RestClient;

const client = new Client(accountSid, authToken);

client.outgoingCallerIds.create(
  {
    friendlyName: 'My Home Phone Number',
    phoneNumber: '+12349013030',
  },
  (err, callerId) => {
    if (err) {
      console.error(err);
    } else {
      console.log(callerId.sid);
    }
  }
);
github PacktPublishing / Building-Bots-with-Nodejs / Chapter01 / app.js View on Github external
var twilio = require("twilio");
var express = require('express');

var accountSid = '<< Your Twilio Account SID >>'; // Your Account SID from www.twilio.com/console
var authToken = '<< Your Twilio Auth Token >>';   // Your Auth Token from www.twilio.com/console

var client = new twilio.RestClient(accountSid, authToken);
var app = express();

app.post('/receive', function (request, response) {
  var twiml = new twilio.TwimlResponse();
  twiml.message(request.body.From);

  response.writeHead(200, {'Content-Type': 'text/xml'});
  response.end(twiml.toString());
});

app.get('/send', function (req, res) {
  client.messages.create({
      body: 'Hi, this is TwilioBot',
      to: '+14806000000',  // Text this number - please replace with your own
      from: '+14805000000' // From a valid Twilio number - please replace with your own
  }, function(err, message) {
github twilio / twilio-video.js / test / functional / endpoint.js View on Github external
endpoint.once('registered', function() {
      var rest = new twilio.RestClient(ACCOUNT_SID, AUTH_TOKEN, { host: API_HOST });
      rest.makeSession({
        from: '+16024925066',
        to: 'client:' + clientName,
        ApplicationSid: APP_SID
      }, function(error, session) {
        if (error)
          return done(error);
        sessionsid = session.sid;
      });
    });
github tejasmanohar / omnus / app.js View on Github external
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var bodyParser = require('body-parser');

app.use(express.static(__dirname + '/tmp'));
app.use(bodyParser.urlencoded({
  extended: true
}));

var request = require('superagent');
var twilio = require('twilio');

require('shelljs/global');
var client = new twilio.RestClient(process.env.TWILIO_AUTH_SID, process.env.TWILIO_AUTH_TOKEN);

var port = process.env.PORT || 3000;
server.listen(port);
console.log('Listening at port: ' + port);

app.post('/incoming', function(req, res) {
  startCall(req.body.Body, req.body.From);
  res.sendStatus(200);
});

app.post('/xml/:id', function(req, res) {
  res.set('Content-Type', 'text/xml');
  res.send('' + process.env.BASE_URL + '/' + req.params.id + '.mp3' + '');
});

function startCall(search, recipient) {
github c0nrad / sngglr / routes / notifications.js View on Github external
var twilio = require('twilio');

var secrets = {
  twilioSid: process.env.twilioSid,
  twilioAuth: process.env.twilioAuth,
  twilioNumber: process.env.twilioNumber,

  gmailEmail: process.env.gmailEmail,
  gmailPassword: process.env.gmailPassword,

  smsOn: process.env.smsOn,
  emailOn: process.env.emailOn
};

var client = new twilio.RestClient(secrets.twilioSid, secrets.twilioAuth);
var number = secrets.twilioNumber;

var sendgrid  = require('sendgrid')(process.env.SENDGRID_USERNAME, process.env.SENDGRID_PASSWORD);

exports.email = function(to, subject, body, next) {
  console.log(to, subject, body);
  sendgrid.send({
    to:       to,
    from:     'admin@sngglr.com',
    subject:  subject,
    text:     body
  }, function(err, json) {
    if (err) { return console.error(err); }
    console.log(json);
    next(err, json);
  });
github drobtravels / universal-contact-center-be / functions / sendSMSReply / src / index.js View on Github external
export default function(event, context) {
  if( validateUser(event.userToken, event.credentials.auth0Secret) ) {
    var client = new twilio.RestClient(event.credentials.accountSid, event.credentials.authToken)
    client.messages.create({
      body: event.message,
      to: event.phone,
      from: event.from
    }).then( (message) => {
      context.succeed(message);
    }, (error) => { context.fail(error) });
  } else {
    context.fail('unauthorized user');
  }
}
github broidHQ / integrations / broid-twilio / lib / core / Adapter.js View on Github external
connect() {
        if (this.connected) {
            return Rx_1.Observable.of({ type: 'connected', serviceID: this.serviceId() });
        }
        if (!this.token || !this.tokenSecret) {
            return Rx_1.Observable.throw(new Error('Credentials should exist.'));
        }
        this.session = new twilio.RestClient(this.token, this.tokenSecret);
        if (this.webhookServer) {
            this.webhookServer.listen();
        }
        this.connected = true;
        return Rx_1.Observable.of({ type: 'connected', serviceID: this.serviceId() });
    }
    disconnect() {
github broidHQ / integrations / integrations / broid-twilio / src / core / adapter.ts View on Github external
public connect(): Observable {
    if (this.connected) {
      return Observable.of({ type: "connected", serviceID: this.serviceId() });
    }
    this.connected = true;

    if (!this.token
      || !this.tokenSecret) {
      return Observable.throw(new Error("Credentials should exist."));
    }

    this.session = new twilio.RestClient(this.token, this.tokenSecret);
    this.webhookServer = new WebHookServer(this.HTTPOptions, this.logLevel);
    this.webhookServer.listen();

    return Observable.of({ type: "connected", serviceID: this.serviceId() });
  }
github ibm-watson-data-lab / cognitive-event-finder / app.js View on Github external
plugin:'promises'
    });
    cloudantDialogStore = new CloudantDialogStore(cloudantClient, process.env.CLOUDANT_DIALOG_DB_NAME);
    cloudantEventStore = new CloudantEventStore(cloudantClient, process.env.CLOUDANT_EVENT_DB_NAME || process.env.CLOUDANT_DB_NAME, maxSearchTimeHours, searchStartStart, searchTimeOffsetHours);
    cloudantUserStore = new CloudantUserStore(cloudantClient, process.env.CLOUDANT_USER_DB_NAME);
    eventBot = new EventBot(
        searchResultCount,
        searchTimeHours,
        suggestedSearchTerms,
        cloudantEventStore,
        cloudantUserStore,
        cloudantDialogStore,
        process.env.CONVERSATION_USERNAME,
        process.env.CONVERSATION_PASSWORD,
        process.env.CONVERSATION_WORKSPACE_ID,
        new TwilioRestClient(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN),
        process.env.TWILIO_PHONE_NUMBER,
        http,
        appUrl,
        process.env.BITLY_ACCESS_TOKEN
    );
    eventBot.run();
})();
github thegameofcode / resonator / lib / transport / twilio.js View on Github external
'use strict';
const config = require('config');
const twilio = require('twilio');

let TWILIO_ACCOUNT_SID = config.get('transport.twilio.account_sid');
let TWILIO_AUTH_TOKEN = config.get('transport.twilio.auth_token');

if (process.env.NODE_ENV === 'test') {
  TWILIO_ACCOUNT_SID = 'Some_random_account_sid';
  TWILIO_AUTH_TOKEN = 'Some_random_auth_token';
}
const messenger = new twilio.RestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

module.exports = messenger;