Member Junction
    Preparing search index...

    Realtime Bridge driver for Twilio telephony (Programmable Voice + Media Streams).

    Construct the driver with the default constructor (the engine's ClassFactory path); it binds the TwilioCallSdkFactory so a real deployment only needs to wire the Twilio client behind it (or a test injects a FakeTwilioCallSdk via BaseTelephonyBridge.SetSdkFactory). Everything else is inherited from BaseTelephonyBridge.

    Registered via @RegisterClass(BaseRealtimeBridge, 'TwilioBridge') — the engine resolves any bridge driver against the BaseRealtimeBridge root, so a telephony driver registers under that same root.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    callId: string

    The platform-native call identifier for the live call (set at Connect).

    carrierSampleRate: number

    The carrier's PCM16 media rate (Hz) — what the SDK seam sends/receives audio at, between which and the model rate the bridge resamples. Defaults to TELEPHONY_SAMPLE_RATE (8 kHz); a wideband SIP/RTP driver overrides it per-call via CARRIER_SAMPLE_RATE_CONFIG_KEY.

    The direction this call was established with.

    The capability flags for the provider this bridge instance serves. Populated from the RealtimeBridgeContext at BaseRealtimeBridge.Connect time (and may be set by the engine immediately after construction). Drives BaseRealtimeBridge.RequireFeature.

    fromNumber: string

    The agent's own number this call originates from / is answered on.

    modelInputRate: number

    The realtime model's INPUT rate (Hz) — inbound 8 kHz caller audio is resampled UP to this.

    modelOutputRate: number

    The realtime model's OUTPUT rate (Hz) — outbound model audio is resampled DOWN to the carrier rate from this.

    providerName: string

    The provider's display name for this bridge instance, used in capability-error messages. Populated from the RealtimeBridgeContext; falls back to the driver class name.

    remoteNumber: string

    The remote party's number (outbound: the dialled number; inbound: best-effort caller-id).

    The live telephony SDK seam for this call, created at Connect.

    The SDK creation seam. Defaults to a factory that throws an explicit "bind the real telephony client" error, since the base ships WITHOUT a concrete provider adapter. A concrete driver (or a deployment) binds a real factory via SetSdkFactory; tests inject a fake.

    AGENT_PARTICIPANT_ID: "agent"

    The synthetic external id used for the agent's own leg on the roster. Subclasses may override.

    REMOTE_PARTICIPANT_ID: "caller"

    The synthetic external id used for the single remote caller on the roster. Stable for the life of the call so AIAgentSessionBridgeParticipant upserts are idempotent. Subclasses may override.

    Accessors

    • get CallId(): string

      The live call's platform-native identifier (or null before Connect).

      Returns string

    Methods

    • Establishes the call. Outbound (the default) places a call via ITelephonyCallSdk.dial; inbound answers a routed call via ITelephonyCallSdk.answer. Wires the inbound-audio and DTMF paths and the call-ended callback, seeds the single-party roster, and returns the bot leg + call identifiers the engine persists.

      Direction comes from ctx.Configuration[DIRECTION_CONFIG_KEY] (defaults 'Outbound'); the agent's caller-id from FromNumber; the address (RealtimeBridgeContext.Address) is the destination number (outbound) and an inbound call id arrives via InboundCallId.

      Parameters

      Returns Promise<BridgeConnectResult>

      The bot participant + call (external connection) identifiers.

      when the required audio / direction features are off.

      when no SDK factory is bound, or an inbound connect has no InboundCallId.

    • Hangs up the call and releases all SDK resources. Tolerant of teardown errors.

      Parameters

      • _reason: BridgeDisconnectReason

        Why the disconnect happened (telephony teardown is uniform — the bot hangs up).

      Returns Promise<void>

    • Flushes the agent's queued outbound voice on barge-in by delegating to the SDK's ITelephonyCallSdk.flushOutbound (e.g. Vonage's {"action":"clear"} websocket command). The engine calls this from OnInterruption; for carriers that buffer outbound audio (notably Vonage's ~60s queue) this is what stops the agent talking over itself after the caller cuts in. A no-op when the SDK doesn't implement flush (its media path has no client-side queue).

      Returns void

    • Returns the call's "roster": the single remote caller plus the agent. Telephony has no diarization roster — there is exactly one human on the line — so this is the trivial two-entry list. Not gated by SpeakerDiarization (a 1:1 call needs none); always available once connected.

      Returns Promise<BridgeParticipantInfo[]>

      The caller + agent participants.

    • Registers a callback the bridge invokes when the underlying call ends (remote hangup / carrier drop). The engine uses this to transition the bridge row to a terminal state. "Latest handler wins."

      Parameters

      • handler: () => void

        Invoked when the call has ended.

      Returns void

    • Registers an inbound-DTMF handler (gated by DTMF). The driver fires it from the SDK's DTMF stream.

      Parameters

      • handler: (digits: string) => void

        Invoked with each received DTMF digit string.

      Returns void

      when DTMF is not enabled.

    • Registers the inbound-media handler. The driver forwards each inbound audio frame (stamped with the single caller's label) to it; the engine routes it to IRealtimeSession.SendInput.

      Parameters

      • handler: (frame: BridgeMediaFrame) => void

        Invoked with each inbound media frame.

      Returns void

    • Registers a roster-change handler. On a 1:1 call the roster changes only at connect (caller joins) and at end (caller leaves), so this fires once at connect with the full roster.

      Parameters

      Returns void

    • Sends DTMF tones on the call (gated by DTMF). Re-asserts the flag (defense-in-depth) so even an engine-bypassing caller cannot send tones a disabled provider forbids.

      Parameters

      • digits: string

        The DTMF digit string to send (e.g. '1234#').

      Returns Promise<void>

      when DTMF is not enabled for the provider.

    • Sends an outbound media frame into the call. Audio is fed to the SDK's media-stream path; video and screen tracks are n/a for telephony and silently dropped (a phone call carries audio only, and a telephony provider's SupportedFeatures does not enable the video/screen flags).

      Parameters

      Returns void

    • Requests that the platform begin recording the session.

      Capability-gated by SupportedFeatures.Recording (and subject to per-jurisdiction consent handling upstream). Throws unless overridden.

      Returns Promise<void>

      A promise that resolves once recording has started.

      when not overridden.

    • Transfers the live call to another party (gated by CallTransfer). Re-asserts the flag.

      Parameters

      • target: string

        The transfer destination (a phone number or platform endpoint identifier).

      Returns Promise<void>

      when CallTransfer is not enabled.