Class TwilioVoiceProvider

Twilio voice call provider.

Uses the Twilio REST API 2010-04-01 for outbound call control and HMAC-SHA1 for inbound webhook signature verification.

Example

const provider = new TwilioVoiceProvider({
accountSid: process.env.TWILIO_ACCOUNT_SID!,
authToken: process.env.TWILIO_AUTH_TOKEN!,
});

Implements

Accessors

Constructors

Methods

  • Verify an incoming Twilio webhook request using HMAC-SHA1.

    Algorithm (step by step)

    1. Extract the X-Twilio-Signature header from the request.
    2. Parse the request body as URL-encoded form data.
    3. Sort the keys in case-sensitive code-unit order, as twilio-node's getExpectedTwilioSignature does. A locale-aware sort puts Called before CallSid and fails every real voice webhook.
    4. Build the signed string: start with the full URL, then append each key + value (no delimiters between pairs). A repeated key contributes each distinct value, sorted, so a webhook whose CallSid, CallStatus, Digits, SequenceNumber or Timestamp repeats with different values is refused.
    5. Compute HMAC-SHA1 of the signed string using the auth token as the key.
    6. Base64-encode the digest and compare it to the header value.
    7. Repeat with the URL with and without its port, as twilio-node does (see twilioUrlVariants); any match is valid.

    Parameters

    Returns WebhookVerificationResult

    Verification result with valid: true if the signature matches.

  • Parse a Twilio webhook body into normalized NormalizedCallEvents.

    Twilio sends webhooks with a form-encoded body containing CallSid, CallStatus, and optionally Digits (for DTMF input from <Gather>). Each webhook may produce one or two events (status + optional DTMF).

    In carrier mode a request other than POST yields no events (Twilio signs a GET by its URL alone, so a body there carries nothing Twilio signed), and each event carries a stable id from stableCarrierEvents: a DTMF event's occurrence is the signed SequenceNumber or Timestamp, else the callback URL's event_key, and a DTMF event with none throws.

    Parameters

    Returns WebhookParseResult

    Parsed result containing zero or more normalized events.

  • Initiate an outbound call via the Twilio Calls API.

    Posts to /Accounts/{accountSid}/Calls.json with a form-encoded body (not JSON -- this is Twilio's 2010-era API convention). All four status callback events (initiated, ringing, answered, completed) are requested so the CallManager receives the full state progression.

    Parameters

    Returns Promise<InitiateCallResult>

    Result containing the Twilio CallSid on success.

    Throws

    Never throws; returns { success: false, error: '...' } on failure.

Properties

name: "twilio" = ...

Provider identifier, always 'twilio'.