telnyx

Telnyx WebSocket frame serializer for Pipecat.

class pipecat.serializers.telnyx.TelnyxFrameSerializer(stream_id: str, outbound_encoding: str, inbound_encoding: str, call_control_id: str | None = None, api_key: str | None = None, params: InputParams | None = None)[source]

Bases: FrameSerializer

Serializer for Telnyx WebSocket protocol.

This serializer handles converting between Pipecat frames and Telnyx’s WebSocket media streams protocol. It supports audio conversion, DTMF events, and automatic call termination.

When auto_hang_up is enabled (default), the serializer will automatically terminate the Telnyx call when an EndFrame or CancelFrame is processed, but requires Telnyx credentials to be provided.

class InputParams(*, ignore_rtvi_messages: bool = True, telnyx_sample_rate: int = 8000, sample_rate: int | None = None, inbound_encoding: str = 'PCMU', outbound_encoding: str = 'PCMU', auto_hang_up: bool = True)[source]

Bases: InputParams

Configuration parameters for TelnyxFrameSerializer.

Parameters:
  • telnyx_sample_rate – Sample rate used by Telnyx, defaults to 8000 Hz.

  • sample_rate – Optional override for pipeline input sample rate.

  • inbound_encoding – Audio encoding for data sent to Telnyx (e.g., “PCMU”).

  • outbound_encoding – Audio encoding for data received from Telnyx (e.g., “PCMU”).

  • auto_hang_up – Whether to automatically terminate call on EndFrame.

telnyx_sample_rate: int
sample_rate: int | None
inbound_encoding: str
outbound_encoding: str
auto_hang_up: bool
__init__(stream_id: str, outbound_encoding: str, inbound_encoding: str, call_control_id: str | None = None, api_key: str | None = None, params: InputParams | None = None)[source]

Initialize the TelnyxFrameSerializer.

Parameters:
  • stream_id – The Stream ID for Telnyx.

  • outbound_encoding – The encoding type for outbound audio (e.g., “PCMU”).

  • inbound_encoding – The encoding type for inbound audio (e.g., “PCMU”).

  • call_control_id – The Call Control ID for the Telnyx call (optional, but required for auto hang-up).

  • api_key – Your Telnyx API key (required for auto hang-up).

  • params – Configuration parameters.

async setup(frame: StartFrame)[source]

Sets up the serializer with pipeline configuration.

Parameters:

frame – The StartFrame containing pipeline configuration.

async serialize(frame: Frame) str | bytes | None[source]

Serializes a Pipecat frame to Telnyx WebSocket format.

Handles conversion of various frame types to Telnyx WebSocket messages. For EndFrames and CancelFrames, initiates call termination if auto_hang_up is enabled.

Parameters:

frame – The Pipecat frame to serialize.

Returns:

Serialized data as string or bytes, or None if the frame isn’t handled.

Raises:

ValueError – If an unsupported encoding is specified.

async deserialize(data: str | bytes) Frame | None[source]

Deserializes Telnyx WebSocket data to Pipecat frames.

Handles conversion of Telnyx media events to appropriate Pipecat frames, including audio data and DTMF keypresses.

Parameters:

data – The raw WebSocket data from Telnyx.

Returns:

A Pipecat frame corresponding to the Telnyx event, or None if unhandled.

Raises:

ValueError – If an unsupported encoding is specified.