Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.91 KB

README.md

File metadata and controls

56 lines (38 loc) · 1.91 KB

twilio-caller

Calling using twilio API from the browser. Useful for testing when developing phone calling based software. Uses @twilio/voice-sdk.

Quick start

In twilio create a new number and an app, e.g. twilio-caller and link it to the number. Also create an API key.

Then create a Function in Twilio with path /twilio-caller/handle-call and set the app's Webhook (Request URL) to the full URL of the function. This function will simply forward the call to @twilio/voice-sdk in the browser:

const assert = require('node:assert');

exports.handler = function(context, event, callback) {
  const callerId = '+123456789'; // Update with your twilio number

  // Only handle outgoing calls
  assert(event.To !== callerId.replaceAll(/[^\d+]/g, ''));

  const twiml = new Twilio.twiml.VoiceResponse();

  // set the callerId (from)
  let dial = twiml.dial({ callerId });

  dial.number(event.To);

  callback(null, twiml);
};

Ref:

Make sure you have Node.js. Now check out this repo and run yarn. Make a .env file with data from Twilio admin:

  • TWILIO_ACCOUNT_SID
  • TWIML_APP_SID
  • TWILIO_API_KEY
  • TWILIO_API_SECRET

Next generate a token:

node --experimental-strip-types makeAccessToken.ts

Start the UI server and open it in your browser.

yarn dev

Useful links