TxClient
TelnyxRTC client connects your application to the Telnyx backend,
enabling you to make outgoing calls and handle incoming calls.
Examples
Connect and login:
Listen TxClient delegate events.
Properties
calls
delegate
aiAssistantManager
isSpeakerEnabled
isAudioDeviceEnabled
- Set to
trueinprovider(_:didActivate:)to enable audio - Set to
falseinprovider(_:didDeactivate:)to disable audio
isRegistered
Methods
enableAudioSession(audioSession:)
- Parameter audioSession: The AVAudioSession instance to configure
- Important: This method MUST be called from the CXProviderDelegate’s
provider(_:didActivate:)callback to properly handle audio routing when using CallKit integration.
Parameters
| Name | Description |
|---|---|
| audioSession | The AVAudioSession instance to configure |
disableAudioSession(audioSession:)
- Parameter audioSession: The AVAudioSession instance to reset
- Important: This method MUST be called from the CXProviderDelegate’s
provider(_:didDeactivate:)callback to properly clean up audio resources when using CallKit integration.
Parameters
| Name | Description |
|---|---|
| audioSession | The AVAudioSession instance to reset |
init()
deinit
connect(txConfig:serverConfiguration:)
- Parameters:
- txConfig: The desired login credentials. See TxConfig docummentation for more information.
- serverConfiguration: (Optional) To define a custom
signaling serverandTURN/ STUN servers. As default we use the internal Telnyx Production servers.
- Throws: TxConfig parameters errors
Parameters
| Name | Description |
|---|---|
| txConfig | The desired login credentials. See TxConfig docummentation for more information. |
| serverConfiguration | (Optional) To define a custom signaling server and TURN/ STUN servers. As default we use the internal Telnyx Production servers. |
disconnect()
isConnected()
- Returns:
trueif TxClient socket is connected,falseotherwise.
answerFromCallkit(answerAction:customHeaders:debug:)
provider(_:perform:) method
when handling a CXAnswerCallAction. It properly integrates with CallKit to answer incoming calls.
Examples:
- Parameters:
- answerAction: The
CXAnswerCallActionprovided by CallKit’s provider delegate. - customHeaders: (optional) Custom Headers to be passed over webRTC Messages.
Headers should be in the format
X-key:ValuewhereX-prefix is required for custom headers. When calling AI Agents, headers with theX-prefix will be mapped to dynamic variables (e.g.,X-Account-Numberbecomes{{account_number}}). Hyphens in header names are converted to underscores in variable names. - debug: (optional) Enable debug mode for call quality metrics and WebRTC statistics.
When enabled, real-time call quality metrics will be available through the call’s
onCallQualityChangecallback.
- answerAction: The
Parameters
| Name | Description |
|---|---|
| answerAction | The CXAnswerCallAction provided by CallKit’s provider delegate. |
| customHeaders | (optional) Custom Headers to be passed over webRTC Messages. Headers should be in the format X-key:Value where X- prefix is required for custom headers. When calling AI Agents, headers with the X- prefix will be mapped to dynamic variables (e.g., X-Account-Number becomes {{account_number}}). Hyphens in header names are converted to underscores in variable names. |
| debug | (optional) Enable debug mode for call quality metrics and WebRTC statistics. When enabled, real-time call quality metrics will be available through the call’s onCallQualityChange callback. |
endCallFromCallkit(endAction:callId:)
disablePushNotifications()
getSessionId()
- Returns: The current sessionId. If this value is empty, that means that the client is not connected to Telnyx server.
anonymousLogin(targetId:targetType:targetVersionId:userVariables:reconnection:serverConfiguration:)
- Parameters:
- targetId: The target ID for the AI assistant
- targetType: The target type (defaults to “ai_assistant”)
- targetVersionId: Optional target version ID
- userVariables: Optional user variables to include in the login
- reconnection: Whether this is a reconnection attempt (defaults to false)
- serverConfiguration: Server configuration to use for connection (defaults to TxServerConfiguration())
Parameters
| Name | Description |
|---|---|
| targetId | The target ID for the AI assistant |
| targetType | The target type (defaults to “ai_assistant”) |
| targetVersionId | Optional target version ID |
| userVariables | Optional user variables to include in the login |
| reconnection | Whether this is a reconnection attempt (defaults to false) |
| serverConfiguration | Server configuration to use for connection (defaults to TxServerConfiguration()) |
sendRingingAck(callId:)
- Parameter callId: The call ID to acknowledge
Parameters
| Name | Description |
|---|---|
| callId | The call ID to acknowledge |
sendAIAssistantMessage(_:)
- Parameter message: The text message to send to AI assistant
- Returns: True if message was sent successfully, false otherwise
Parameters
| Name | Description |
|---|---|
| message | The text message to send to AI assistant |
sendAIAssistantMessage(_:base64Images:imageFormat:)
- Parameters:
- message: The text message to send to AI assistant
- base64Images: Optional array of Base64 encoded image data (without data URL prefix)
- imageFormat: Image format (jpeg, png, etc.). Defaults to “jpeg”
- Returns: True if message was sent successfully, false otherwise
Parameters
| Name | Description |
|---|---|
| message | The text message to send to AI assistant |
| base64Images | Optional array of Base64 encoded image data (without data URL prefix) |
| imageFormat | Image format (jpeg, png, etc.). Defaults to “jpeg” |