Class: TwilioMediaStreamParser<P>
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:14
Twilio media parser with an explicit documented carrier profile and a retained legacy profile. Carrier mode requires PCMU 8 kHz mono and preserves carrier timestamps and chunk counters. Legacy mode exists for existing callers and fixtures; it is not a live-carrier conformance claim.
Type Parameters
P
P extends "legacy" | "carrier" = "legacy"
Implements
Constructors
Constructor
new TwilioMediaStreamParser<
P>(options?):TwilioMediaStreamParser<P>
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:18
Selects documented carrier messages explicitly.
Parameters
options?
protocol?
P
Returns
TwilioMediaStreamParser<P>
Properties
protocol
readonlyprotocol:P
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:16
Selected once; the no-argument constructor preserves released behavior.
Implementation of
Methods
formatClear()
formatClear(
streamSid):string|null
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:159
Clears carrier output; compatibility clients have no mapped clear operation.
Parameters
streamSid
string
Returns
string | null
Implementation of
formatConnected()
formatConnected(
_streamSid):Pextends"carrier"?null:string
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:154
Carrier Twilio sends connected to us; only legacy clients receive the old acknowledgement.
Parameters
_streamSid
string
Returns
P extends "carrier" ? null : string
Implementation of
MediaStreamParser.formatConnected
formatMark()
formatMark(
streamSid,name):string|null
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:161
Marks carrier playback; compatibility clients have no mapped checkpoint operation.
Parameters
streamSid
string
name
string
Returns
string | null
Implementation of
formatOutgoing()
formatOutgoing(
audio,streamSid):string
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:149
Formats media for either the retained JSON protocol or the documented carrier profile.
Parameters
audio
Buffer
streamSid
string
Returns
string
Implementation of
MediaStreamParser.formatOutgoing
parseIncoming()
parseIncoming(
data):MediaStreamIncoming|null
Defined in: packages/agentos/src/io/channels/telephony/parsers/TwilioMediaStreamParser.ts:43
Parse a raw WebSocket frame from Twilio's media stream.
Supported Twilio event types:
start-- stream established, includes callSid and media format metadata.media-- audio chunk (inbound track only; outbound echoes are discarded to prevent feedback loops).dtmf-- DTMF keypress detected on the audio stream.stop-- stream ended (call hangup or stream disconnect).mark-- named synchronisation marker confirming playback reached a point.
Messages with missing event or streamSid fields, malformed JSON,
or unrecognised event types are silently dropped (return null).
In the carrier profile (parseCarrierMedia) a start must declare
PCMU at 8 kHz mono, the numeric strings sequenceNumber, media.chunk and
media.timestamp are read as integers, and a malformed payload is dropped;
an unsupported start format, an error event or an oversized frame throws.
Parameters
data
Raw WebSocket frame payload (always a JSON string from Twilio).
string | Buffer
Returns
MediaStreamIncoming | null
Normalised MediaStreamIncoming event, or null for
outbound audio tracks, unknown event types, or malformed messages.