Member Junction
    Preparing search index...

    The minimal Twilio client surface TwilioCallSdk drives. A production deployment implements this over the real twilio SDK (REST) + a Media-Streams websocket handler; this package never imports twilio so it builds and tests with no network. When no bindings are supplied, TwilioCallSdk throws the explicit "bind the real Twilio client" error from every operation.

    The shapes are intentionally tiny and provider-neutral at the value level (strings / byte buffers) so the Twilio SDK's types do not leak into the bridge package.

    interface ITwilioClientBindings {
        acceptInbound(callSid: string): Promise<void>;
        completeCall(callSid: string): Promise<void>;
        createCall(
            toNumber: string,
            fromNumber: string,
            args?: Record<string, unknown>,
        ): Promise<string>;
        onCallStatus(callSid: string, cb: () => void): void;
        onDigits(callSid: string, cb: (digits: string) => void): void;
        onStreamAudio(callSid: string, cb: (pcm: ArrayBuffer) => void): void;
        playDigits(callSid: string, digits: string): Promise<void>;
        pushStreamAudio(callSid: string, pcm: ArrayBuffer): void;
        redirectCall(callSid: string, toNumber: string): Promise<void>;
    }

    Implemented by

    Index

    Methods

    • Accepts the Media-Streams websocket for an inbound call already delivered by the voice webhook.

      Parameters

      • callSid: string

        The inbound Call SID from the webhook.

      Returns Promise<void>

    • Ends the call (REST calls(sid).update({ status: 'completed' })).

      Parameters

      • callSid: string

        The Call SID to complete.

      Returns Promise<void>

    • Places an outbound call via the Twilio REST API (calls.create) with TwiML that opens a bidirectional Media-Streams <Connect><Stream> to the agent's websocket.

      Parameters

      • toNumber: string

        Destination number (E.164).

      • fromNumber: string

        The agent's Twilio number / verified caller-id the call originates from.

      • Optionalargs: Record<string, unknown>

        Provider-specific options (status-callback URL, stream URL, recording flags, …).

      Returns Promise<string>

      The created Call SID.

    • Registers the call-ended callback (status-callback completed/failed/canceled or stream stop).

      Parameters

      • callSid: string

        The Call SID.

      • cb: () => void

        Invoked when the call ends.

      Returns void

    • Registers the inbound DTMF callback (<Gather> webhook results or Media-Streams dtmf events).

      Parameters

      • callSid: string

        The Call SID.

      • cb: (digits: string) => void

        Invoked with each received DTMF digit string.

      Returns void

    • Registers the inbound Media-Streams audio callback for the call (what the agent hears).

      Parameters

      • callSid: string

        The Call SID whose inbound stream to subscribe to.

      • cb: (pcm: ArrayBuffer) => void

        Invoked with each inbound PCM audio frame.

      Returns void

    • Sends DTMF digits on the call (REST calls(sid).update with <Play digits> / <Dial sendDigits>).

      Parameters

      • callSid: string

        The Call SID.

      • digits: string

        The DTMF digit string.

      Returns Promise<void>

    • Pushes one outbound audio payload onto the call's Media-Streams websocket (the agent's voice).

      Parameters

      • callSid: string

        The Call SID whose stream to write to.

      • pcm: ArrayBuffer

        The audio bytes (the adapter encodes to the Media-Streams μ-law/PCM media frame).

      Returns void

    • Transfers the live call (REST calls(sid).update({ twiml: '<Dial>...' })).

      Parameters

      • callSid: string

        The Call SID to redirect.

      • toNumber: string

        The transfer destination.

      Returns Promise<void>