# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Dict, List, Union, Iterable from typing_extensions import Literal import httpx from ...types import ( StreamCodec, StreamBidirectionalMode, StreamBidirectionalCodec, StreamBidirectionalTargetLegs, StreamBidirectionalSamplingRate, ) from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given from ..._utils import path_template, maybe_transform, async_maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...types.calls import ( GoogleTranscriptionLanguage, ConversationRelayInterruptible, action_pay_params, action_refer_params, action_speak_params, action_answer_params, action_bridge_params, action_gather_params, action_hangup_params, action_reject_params, action_enqueue_params, action_transfer_params, action_send_dtmf_params, action_leave_queue_params, action_stop_gather_params, action_stop_siprec_params, action_start_siprec_params, action_stop_forking_params, action_send_sip_info_params, action_start_forking_params, action_stop_playback_params, action_start_playback_params, action_stop_recording_params, action_stop_streaming_params, action_gather_using_ai_params, action_pause_recording_params, action_start_recording_params, action_start_streaming_params, action_resume_recording_params, action_join_ai_assistant_params, action_stop_ai_assistant_params, action_gather_using_audio_params, action_gather_using_speak_params, action_start_ai_assistant_params, action_stop_transcription_params, action_start_transcription_params, action_update_client_state_params, action_stop_noise_suppression_params, action_switch_supervisor_role_params, action_start_noise_suppression_params, action_stop_conversation_relay_params, action_start_conversation_relay_params, action_add_ai_assistant_messages_params, ) from ..._base_client import make_request_options from ...types.stream_codec import StreamCodec from ...types.sip_header_param import SipHeaderParam from ...types.ai.assistant_param import AssistantParam from ...types.calls.loopcount_param import LoopcountParam from ...types.custom_sip_header_param import CustomSipHeaderParam from ...types.dialogflow_config_param import DialogflowConfigParam from ...types.calls.action_pay_response import ActionPayResponse from ...types.sound_modifications_param import SoundModificationsParam from ...types.stream_bidirectional_mode import StreamBidirectionalMode from ...types.stream_bidirectional_codec import StreamBidirectionalCodec from ...types.calls.action_refer_response import ActionReferResponse from ...types.calls.action_speak_response import ActionSpeakResponse from ...types.call_assistant_request_param import CallAssistantRequestParam from ...types.calls.action_answer_response import ActionAnswerResponse from ...types.calls.action_bridge_response import ActionBridgeResponse from ...types.calls.action_gather_response import ActionGatherResponse from ...types.calls.action_hangup_response import ActionHangupResponse from ...types.calls.action_reject_response import ActionRejectResponse from ...types.calls.action_enqueue_response import ActionEnqueueResponse from ...types.calls.action_transfer_response import ActionTransferResponse from ...types.calls.action_send_dtmf_response import ActionSendDtmfResponse from ...types.calls.transcription_config_param import TranscriptionConfigParam from ...types.stream_bidirectional_target_legs import StreamBidirectionalTargetLegs from ...types.calls.action_leave_queue_response import ActionLeaveQueueResponse from ...types.calls.action_stop_gather_response import ActionStopGatherResponse from ...types.calls.action_stop_siprec_response import ActionStopSiprecResponse from ...types.calls.interruption_settings_param import InterruptionSettingsParam from ...types.conversation_relay_language_param import ConversationRelayLanguageParam from ...types.calls.action_start_siprec_response import ActionStartSiprecResponse from ...types.calls.action_stop_forking_response import ActionStopForkingResponse from ...types.stream_bidirectional_sampling_rate import StreamBidirectionalSamplingRate from ...types.calls.action_send_sip_info_response import ActionSendSipInfoResponse from ...types.calls.action_start_forking_response import ActionStartForkingResponse from ...types.calls.action_stop_playback_response import ActionStopPlaybackResponse from ...types.calls.google_transcription_language import GoogleTranscriptionLanguage from ...types.calls.action_start_playback_response import ActionStartPlaybackResponse from ...types.calls.action_stop_recording_response import ActionStopRecordingResponse from ...types.calls.action_stop_streaming_response import ActionStopStreamingResponse from ...types.calls.action_gather_using_ai_response import ActionGatherUsingAIResponse from ...types.calls.action_pause_recording_response import ActionPauseRecordingResponse from ...types.calls.action_start_recording_response import ActionStartRecordingResponse from ...types.calls.action_start_streaming_response import ActionStartStreamingResponse from ...types.calls.action_resume_recording_response import ActionResumeRecordingResponse from ...types.calls.conversation_relay_interruptible import ConversationRelayInterruptible from ...types.calls.action_join_ai_assistant_response import ActionJoinAIAssistantResponse from ...types.calls.action_stop_ai_assistant_response import ActionStopAIAssistantResponse from ...types.calls.transcription_start_request_param import TranscriptionStartRequestParam from ...types.calls.action_gather_using_audio_response import ActionGatherUsingAudioResponse from ...types.calls.action_gather_using_speak_response import ActionGatherUsingSpeakResponse from ...types.calls.action_start_ai_assistant_response import ActionStartAIAssistantResponse from ...types.calls.action_stop_transcription_response import ActionStopTranscriptionResponse from ...types.conversation_relay_embedded_config_param import ConversationRelayEmbeddedConfigParam from ...types.calls.action_start_transcription_response import ActionStartTranscriptionResponse from ...types.calls.action_update_client_state_response import ActionUpdateClientStateResponse from ...types.calls.ai_assistant_join_participant_param import AIAssistantJoinParticipantParam from ...types.calls.action_stop_noise_suppression_response import ActionStopNoiseSuppressionResponse from ...types.calls.action_switch_supervisor_role_response import ActionSwitchSupervisorRoleResponse from ...types.calls.action_start_noise_suppression_response import ActionStartNoiseSuppressionResponse from ...types.calls.action_stop_conversation_relay_response import ActionStopConversationRelayResponse from ...types.calls.action_start_conversation_relay_response import ActionStartConversationRelayResponse from ...types.conversation_relay_interruption_settings_param import ConversationRelayInterruptionSettingsParam from ...types.calls.action_add_ai_assistant_messages_response import ActionAddAIAssistantMessagesResponse from ...types.calls.conversation_relay_transcription_engine_config_param import ( ConversationRelayTranscriptionEngineConfigParam, ) __all__ = ["ActionsResource", "AsyncActionsResource"] class ActionsResource(SyncAPIResource): """Call Control command operations""" @cached_property def with_raw_response(self) -> ActionsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return ActionsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ActionsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return ActionsResourceWithStreamingResponse(self) def add_ai_assistant_messages( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, messages: Iterable[action_add_ai_assistant_messages_params.Message] | Omit = omit, trigger_response: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionAddAIAssistantMessagesResponse: """ Add messages to the conversation started by an AI assistant on the call. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. messages: The messages to add to the conversation. trigger_response: When `true`, the injected messages immediately trigger an assistant response/turn instead of waiting for the next natural turn or idle timeout. This may interrupt a user who is still speaking. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template( "/calls/{call_control_id}/actions/ai_assistant_add_messages", call_control_id=call_control_id ), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "messages": messages, "trigger_response": trigger_response, }, action_add_ai_assistant_messages_params.ActionAddAIAssistantMessagesParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionAddAIAssistantMessagesResponse, ) def answer( self, call_control_id: str, *, assistant: CallAssistantRequestParam | Omit = omit, billing_group_id: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, conversation_relay_config: ConversationRelayEmbeddedConfigParam | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, deepfake_detection: action_answer_params.DeepfakeDetection | Omit = omit, preferred_codecs: Literal["G722,PCMU,PCMA,G729,OPUS,VP8,H264"] | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, send_silence_when_idle: bool | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, sound_modifications: SoundModificationsParam | Omit = omit, stream_bidirectional_codec: StreamBidirectionalCodec | Omit = omit, stream_bidirectional_mode: StreamBidirectionalMode | Omit = omit, stream_bidirectional_target_legs: StreamBidirectionalTargetLegs | Omit = omit, stream_codec: StreamCodec | Omit = omit, stream_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, stream_url: str | Omit = omit, transcription: bool | Omit = omit, transcription_config: TranscriptionStartRequestParam | Omit = omit, webhook_retries_policies: Dict[str, action_answer_params.WebhookRetriesPolicies] | Omit = omit, webhook_url: str | Omit = omit, webhook_url_method: Literal["POST", "GET"] | Omit = omit, webhook_urls: Dict[str, SequenceNotStr[str]] | Omit = omit, webhook_urls_method: Literal["POST", "GET"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionAnswerResponse: """Answer an incoming call. You must issue this command before executing subsequent commands on an incoming call. To answer with an AI assistant, include `assistant.id` and any per-call overrides in the `assistant` object. Telnyx attempts to warm up the assistant before answering the call, then starts the assistant automatically when the call is answered. Do not also send `ai_assistant_start` for this flow. The HTTP success response can arrive before the call is answered; use the `call.answered` webhook to track the answer. If warm-up fails, Telnyx falls back to starting the assistant after answering. When `assistant.id` is supplied, obtain the conversation ID from `data.payload.conversation_id` in the [call.conversation.created](/api-reference/callbacks/call-conversation-created) webhook and correlate it using `data.payload.call_control_id`. The `answer` HTTP response does not include `conversation_id`. The created event is emitted during assistant startup and does not indicate that the assistant is ready to speak. Set the assistant voice with `assistant.voice_settings.voice` and speech-to-text settings with `assistant.transcription`. You can reuse one stored assistant with different per-call settings. Warm-up prepares assistant configuration and dependencies; it does not wait for the greeting audio to be ready or guarantee zero silence after answer. A plain `answer` followed by `ai_assistant_start` performs assistant startup after the call has already been answered. **Expected Webhooks:** - `call.answered` - `call.conversation.created` when the requested assistant conversation is created - `call.hold` and `call.unhold` if the call is held/unheld - `call.deepfake_detection.result` if `deepfake_detection` was enabled - `call.deepfake_detection.error` if `deepfake_detection` was enabled and an error occurred - `streaming.started`, `streaming.stopped` or `streaming.failed` if `stream_url` was set When the `record` parameter is set to `record-from-answer`, the response will include a `recording_id` field. Args: assistant: AI Assistant configuration and per-call overrides. All fields except `id` are optional. Omitted assistant fields use the stored configuration. Supplied `voice_settings` and `transcription` objects replace their stored objects rather than merging individual settings; include every setting you want to retain. `dynamic_variables` are merged, with request values taking precedence. billing_group_id: Use this field to set the Billing Group ID for the call. Must be a valid and existing Billing Group ID. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. conversation_relay_config: Starts a Conversation Relay session automatically when the answered/dialed call is answered. This embedded shape is supported on `answer` and `dial`. It uses public field names (`url`, `dtmf_detection`, `greeting`, `voice`, `language`, etc.) and maps them to the underlying Conversation Relay action. `client_state`, `tts_language`, and `transcription_language` inside this object are ignored; use the parent command's `client_state` and `command_id` fields instead. custom_headers: Custom headers to be added to the SIP INVITE response. deepfake_detection: Enables deepfake detection on the call. When enabled, audio from the remote party is streamed to a detection service that analyzes whether the voice is AI-generated. Results are delivered via the `call.deepfake_detection.result` webhook. preferred_codecs: The list of comma-separated codecs in a preferred order for the forked media to be received. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. send_silence_when_idle: Generate silence RTP packets when no transmission available. sip_headers: SIP headers to be added to the SIP INVITE response. Currently only User-to-User header is supported. sound_modifications: Use this field to modify sound effects, for example adjust the pitch. stream_bidirectional_codec: Indicates codec for bidirectional streaming RTP payloads. Used only with stream_bidirectional_mode=rtp. Case sensitive. stream_bidirectional_mode: Configures method of bidirectional streaming (mp3, rtp). stream_bidirectional_target_legs: Specifies which call legs should receive the bidirectional stream audio. stream_codec: Specifies the codec to be used for the streamed audio. When set to 'default' or when transcoding is not possible, the codec from the call will be used. stream_track: Specifies which track should be streamed. stream_url: The destination WebSocket address where the stream is going to be delivered. transcription: Enable standalone call transcription upon call answer. The default value is false. Configure this feature with `transcription_config`. To configure speech recognition for an AI assistant, use `assistant.transcription` instead. webhook_retries_policies: A map of event types to retry policies. Each retry policy contains an array of `retries_ms` specifying the delays between retry attempts in milliseconds. Maximum 5 retries, total delay cannot exceed 60 seconds. webhook_url: Use this field to override the URL for which Telnyx will send subsequent webhooks to for this call. webhook_url_method: HTTP request type used for `webhook_url`. webhook_urls: A map of event types to arrays of webhook URLs. When an event of the specified type occurs, the webhook URLs associated with that event type will be called instead of `webhook_url`. Events not mapped here will use the default `webhook_url`. webhook_urls_method: HTTP request method to invoke `webhook_urls`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/answer", call_control_id=call_control_id), body=maybe_transform( { "assistant": assistant, "billing_group_id": billing_group_id, "client_state": client_state, "command_id": command_id, "conversation_relay_config": conversation_relay_config, "custom_headers": custom_headers, "deepfake_detection": deepfake_detection, "preferred_codecs": preferred_codecs, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "send_silence_when_idle": send_silence_when_idle, "sip_headers": sip_headers, "sound_modifications": sound_modifications, "stream_bidirectional_codec": stream_bidirectional_codec, "stream_bidirectional_mode": stream_bidirectional_mode, "stream_bidirectional_target_legs": stream_bidirectional_target_legs, "stream_codec": stream_codec, "stream_track": stream_track, "stream_url": stream_url, "transcription": transcription, "transcription_config": transcription_config, "webhook_retries_policies": webhook_retries_policies, "webhook_url": webhook_url, "webhook_url_method": webhook_url_method, "webhook_urls": webhook_urls, "webhook_urls_method": webhook_urls_method, }, action_answer_params.ActionAnswerParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionAnswerResponse, ) def bridge( self, call_control_id_to_bridge: str, *, call_control_id_to_bridge_with: str, client_state: str | Omit = omit, command_id: str | Omit = omit, hold_after_unbridge: bool | Omit = omit, mute_dtmf: Literal["none", "both", "self", "opposite"] | Omit = omit, park_after_unbridge: str | Omit = omit, play_ringtone: bool | Omit = omit, prevent_double_bridge: bool | Omit = omit, queue: str | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, ringtone: Literal[ "at", "au", "be", "bg", "br", "ch", "cl", "cn", "cz", "de", "dk", "ee", "es", "fi", "fr", "gr", "hu", "il", "in", "it", "jp", "lt", "mx", "my", "nl", "no", "nz", "ph", "pl", "pt", "ru", "se", "sg", "th", "tw", "uk", "us-old", "us", "ve", "za", ] | Omit = omit, video_room_context: str | Omit = omit, video_room_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionBridgeResponse: """ Bridge two call control calls. **Expected Webhooks:** - `call.bridged` for Leg A - `call.bridged` for Leg B Args: call_control_id_to_bridge_with: The Call Control ID of the call you want to bridge with, can't be used together with queue parameter or video_room_id parameter. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. hold_after_unbridge: Specifies behavior after the bridge ends. If set to `true`, the current leg will be put on hold after unbridge instead of being hung up. mute_dtmf: When enabled, DTMF tones are not passed to the call participant. The webhooks containing the DTMF information will be sent. park_after_unbridge: Specifies behavior after the bridge ends (i.e. the opposite leg either hangs up or is transferred). If supplied with the value `self`, the current leg will be parked after unbridge. If not set, the default behavior is to hang up the leg. play_ringtone: Specifies whether to play a ringtone if the call you want to bridge with has not yet been answered. prevent_double_bridge: When set to `true`, it prevents bridging if the target call is already bridged to another call. Disabled by default. queue: The name of the queue you want to bridge with, can't be used together with call_control_id parameter or video_room_id parameter. Bridging with a queue means bridging with the first call in the queue. The call will always be removed from the queue regardless of whether bridging succeeds. Returns an error when the queue is empty. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. ringtone: Specifies which country ringtone to play when `play_ringtone` is set to `true`. If not set, the US ringtone will be played. video_room_context: The additional parameter that will be passed to the video conference. It is a text field and the user can decide how to use it. For example, you can set the participant name or pass JSON text. It can be used only with video_room_id parameter. video_room_id: The ID of the video room you want to bridge with, can't be used together with call_control_id parameter or queue parameter. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id_to_bridge: raise ValueError( f"Expected a non-empty value for `call_control_id_to_bridge` but received {call_control_id_to_bridge!r}" ) return self._post( path_template( "/calls/{call_control_id_to_bridge}/actions/bridge", call_control_id_to_bridge=call_control_id_to_bridge ), body=maybe_transform( { "call_control_id_to_bridge_with": call_control_id_to_bridge_with, "client_state": client_state, "command_id": command_id, "hold_after_unbridge": hold_after_unbridge, "mute_dtmf": mute_dtmf, "park_after_unbridge": park_after_unbridge, "play_ringtone": play_ringtone, "prevent_double_bridge": prevent_double_bridge, "queue": queue, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "ringtone": ringtone, "video_room_context": video_room_context, "video_room_id": video_room_id, }, action_bridge_params.ActionBridgeParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionBridgeResponse, ) def enqueue( self, call_control_id: str, *, queue_name: str, client_state: str | Omit = omit, command_id: str | Omit = omit, keep_after_hangup: bool | Omit = omit, max_size: int | Omit = omit, max_wait_time_secs: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionEnqueueResponse: """ Places the call into a queue, where it waits until it is removed or bridged to another leg. Queue behavior is configured through the request body. Args: queue_name: The name of the queue the call should be put in. If a queue with a given name doesn't exist yet it will be created. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. keep_after_hangup: If set to true, the call will remain in the queue after hangup. In this case bridging to such call will fail with necessary information needed to re-establish the call. max_size: The maximum number of calls allowed in the queue at a given time. Can't be modified for an existing queue. max_wait_time_secs: The number of seconds after which the call will be removed from the queue. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/enqueue", call_control_id=call_control_id), body=maybe_transform( { "queue_name": queue_name, "client_state": client_state, "command_id": command_id, "keep_after_hangup": keep_after_hangup, "max_size": max_size, "max_wait_time_secs": max_wait_time_secs, }, action_enqueue_params.ActionEnqueueParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionEnqueueResponse, ) def gather( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, gather_id: str | Omit = omit, initial_timeout_millis: int | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, maximum_digits: int | Omit = omit, minimum_digits: int | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherResponse: """ Gather DTMF signals to build interactive menus. You can pass a list of valid digits. The `Answer` command must be issued before the `gather` command. **Expected Webhooks:** - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. gather_id: An id that will be sent back in the corresponding `call.gather.ended` webhook. Will be randomly generated if not specified. initial_timeout_millis: The number of milliseconds to wait for the first DTMF. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait to complete the request. valid_digits: A list of all digits accepted as valid. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/gather", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "gather_id": gather_id, "initial_timeout_millis": initial_timeout_millis, "inter_digit_timeout_millis": inter_digit_timeout_millis, "maximum_digits": maximum_digits, "minimum_digits": minimum_digits, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, }, action_gather_params.ActionGatherParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherResponse, ) def gather_using_ai( self, call_control_id: str, *, parameters: Dict[str, object], assistant: AssistantParam | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, gather_ended_speech: str | Omit = omit, greeting: str | Omit = omit, interruption_settings: InterruptionSettingsParam | Omit = omit, language: GoogleTranscriptionLanguage | Omit = omit, message_history: Iterable[action_gather_using_ai_params.MessageHistory] | Omit = omit, send_message_history_updates: bool | Omit = omit, send_partial_results: bool | Omit = omit, transcription: TranscriptionConfigParam | Omit = omit, user_response_timeout_ms: int | Omit = omit, voice: str | Omit = omit, voice_settings: action_gather_using_ai_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingAIResponse: """ Gather parameters defined in the request payload using a voice assistant. You can pass parameters described as a JSON Schema object and the voice assistant will attempt to gather these informations. **Expected Webhooks:** - [`call.conversation.created`](/api-reference/callbacks/call-conversation-created) includes `conversation_id` during startup - `call.ai_gather.ended` - `call.conversation.ended` - `call.ai_gather.partial_results` (if `send_partial_results` is set to `true`) - `call.ai_gather.message_history_updated` (if `send_message_history_updates` is set to `true`) Args: parameters: The parameters described as a JSON Schema object that needs to be gathered by the voice assistant. See the [JSON Schema reference](https://json-schema.org/understanding-json-schema) for documentation about the format assistant: Assistant configuration including choice of LLM, custom instructions, and tools. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. gather_ended_speech: Text that will be played when the gathering has finished. There is a 3,000 character limit. greeting: Text that will be played when the gathering starts, if none then nothing will be played when the gathering starts. The greeting can be text for any voice or SSML for `AWS.Polly.` voices. There is a 3,000 character limit. interruption_settings: Settings for handling user interruptions during assistant speech language: Language to use for speech recognition message_history: The message history you want the voice assistant to be aware of, this can be useful to keep the context of the conversation, or to pass additional information to the voice assistant. send_message_history_updates: Default is `false`. If set to `true`, the voice assistant will send updates to the message history via the `call.ai_gather.message_history_updated` callback in real time as the message history is updated. send_partial_results: Default is `false`. If set to `true`, the voice assistant will send partial results via the `call.ai_gather.partial_results` callback in real time as individual fields are gathered. If set to `false`, the voice assistant will only send the final result via the `call.ai_gather.ended` callback. transcription: The settings associated with speech to text for the voice assistant. This is only relevant if the assistant uses a text-to-text language model. Any assistant using a model with native audio support (e.g. `fixie-ai/ultravox-v0_4`) will ignore this field. user_response_timeout_ms: The maximum time in milliseconds to wait for user response before timing out. voice: The voice to be used by the voice assistant. Currently we support ElevenLabs, Telnyx and AWS voices. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-CA-LiamNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.BaseModel.John`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration secret under `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/gather_using_ai", call_control_id=call_control_id), body=maybe_transform( { "parameters": parameters, "assistant": assistant, "client_state": client_state, "command_id": command_id, "gather_ended_speech": gather_ended_speech, "greeting": greeting, "interruption_settings": interruption_settings, "language": language, "message_history": message_history, "send_message_history_updates": send_message_history_updates, "send_partial_results": send_partial_results, "transcription": transcription, "user_response_timeout_ms": user_response_timeout_ms, "voice": voice, "voice_settings": voice_settings, }, action_gather_using_ai_params.ActionGatherUsingAIParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingAIResponse, ) def gather_using_audio( self, call_control_id: str, *, audio_url: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, invalid_audio_url: str | Omit = omit, invalid_media_name: str | Omit = omit, maximum_digits: int | Omit = omit, maximum_tries: int | Omit = omit, media_name: str | Omit = omit, minimum_digits: int | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingAudioResponse: """ Play an audio file on the call until the required DTMF signals are gathered to build interactive menus. You can pass a list of valid digits along with an 'invalid_audio_url', which will be played back at the beginning of each prompt. Playback will be interrupted when a DTMF signal is received. The `Answer command must be issued before the `gather_using_audio` command. **Expected Webhooks:** - `call.playback.started` - `call.playback.ended` - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: audio_url: The URL of a file to be played back at the beginning of each prompt. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. invalid_audio_url: The URL of a file to play when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. The URL can point to either a WAV or MP3 file. invalid_media_name and invalid_audio_url cannot be used together in one request. invalid_media_name: The media_name of a file to be played back when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. maximum_tries: The maximum number of times the file should be played if there is no input from the user on the call. media_name: The media_name of a file to be played back at the beginning of each prompt. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait for a DTMF response after file playback ends before a replaying the sound file. valid_digits: A list of all digits accepted as valid. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/gather_using_audio", call_control_id=call_control_id), body=maybe_transform( { "audio_url": audio_url, "client_state": client_state, "command_id": command_id, "inter_digit_timeout_millis": inter_digit_timeout_millis, "invalid_audio_url": invalid_audio_url, "invalid_media_name": invalid_media_name, "maximum_digits": maximum_digits, "maximum_tries": maximum_tries, "media_name": media_name, "minimum_digits": minimum_digits, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, }, action_gather_using_audio_params.ActionGatherUsingAudioParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingAudioResponse, ) def gather_using_speak( self, call_control_id: str, *, payload: str, voice: str, client_state: str | Omit = omit, command_id: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, invalid_payload: str | Omit = omit, language: Literal[ "arb", "cmn-CN", "cy-GB", "da-DK", "de-DE", "en-AU", "en-GB", "en-GB-WLS", "en-IN", "en-US", "es-ES", "es-MX", "es-US", "fr-CA", "fr-FR", "hi-IN", "is-IS", "it-IT", "ja-JP", "ko-KR", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sv-SE", "tr-TR", ] | Omit = omit, maximum_digits: int | Omit = omit, maximum_tries: int | Omit = omit, minimum_digits: int | Omit = omit, payload_type: Literal["text", "ssml"] | Omit = omit, service_level: Literal["basic", "premium"] | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, voice_settings: action_gather_using_speak_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingSpeakResponse: """ Convert text to speech and play it on the call until the required DTMF signals are gathered to build interactive menus. You can pass a list of valid digits along with an 'invalid_payload', which will be played back at the beginning of each prompt. Speech will be interrupted when a DTMF signal is received. The `Answer` command must be issued before the `gather_using_speak` command. **Expected Webhooks:** - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: payload: The text or SSML to be converted into speech. There is a 3,000 character limit. voice: Specifies the voice used in speech synthesis. - Define voices using the format `..`. Specifying only the provider will give default values for voice_id and model_id. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). Use `voice_settings` to configure custom deployments, regions, or API keys. - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.eleven_multilingual_v2.21m00Tcm4TlvDq8ikWAM`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration identifier secret in `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` (e.g., `Telnyx.KokoroTTS.af`). Use `voice_settings` to configure voice_speed and other synthesis parameters. `Bayan` provides Arabic (multiple dialects) and English voices (e.g., `Telnyx.Bayan.Ahmed`, `Telnyx.Bayan.Amanda`). `Sukhan` provides Urdu voices (e.g., `Telnyx.Sukhan.urdu-professor`); `voice_speed` is not supported. - **Minimax:** Use `Minimax..` (e.g., `Minimax.speech-02-hd.Wise_Woman`). Supported models: `speech-02-turbo`, `speech-02-hd`, `speech-2.6-turbo`, `speech-2.8-turbo`. Use `voice_settings` to configure speed, volume, pitch, and language_boost. - **Resemble:** Use `Resemble..` (e.g., `Resemble.Turbo.Aaron_en-US`). Supported models: `Pro`, `Turbo`, `Urdu`. `` is a stock voice name or the ID of a Resemble voice clone. Use `voice_settings` to configure precision, sample_rate, and format. - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. Use `voice_settings` to configure `delivery_mode` (`STABLE`, `BALANCED`, `CREATIVE`), supported by `TTS2` only. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. For service_level basic, you may define the gender of the speaker (male or female). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. invalid_payload: The text or SSML to be converted into speech when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. There is a 3,000 character limit. language: The language you want spoken. This parameter is ignored when a `Polly.*` voice is specified. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. maximum_tries: The maximum number of times that a file should be played back if there is no input from the user on the call. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. payload_type: The type of the provided payload. The payload can either be plain text, or Speech Synthesis Markup Language (SSML). service_level: This parameter impacts speech quality, language options and payload types. When using `basic`, only the `en-US` language and payload type `text` are allowed. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait for a DTMF response after speak ends before a replaying the sound file. valid_digits: A list of all digits accepted as valid. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/gather_using_speak", call_control_id=call_control_id), body=maybe_transform( { "payload": payload, "voice": voice, "client_state": client_state, "command_id": command_id, "inter_digit_timeout_millis": inter_digit_timeout_millis, "invalid_payload": invalid_payload, "language": language, "maximum_digits": maximum_digits, "maximum_tries": maximum_tries, "minimum_digits": minimum_digits, "payload_type": payload_type, "service_level": service_level, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, "voice_settings": voice_settings, }, action_gather_using_speak_params.ActionGatherUsingSpeakParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingSpeakResponse, ) def hangup( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, reason: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionHangupResponse: """ Hang up the call. **Expected Webhooks:** - `call.hangup` - `call.recording.saved` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_headers: Custom headers to be added to the SIP BYE message. reason: Text for the SIP `Reason` header (RFC 3326) sent when cancelling an unanswered outbound leg. The SIP CANCEL carries `Reason: SIP;cause=200;text=""`; phones such as Poly and Yealink use it to suppress the missed-call entry for a call answered elsewhere. Has no effect on an answered leg or an inbound leg. A hangup sent before the leg's `call.initiated` webhook still hangs up the leg, but without the `Reason` header. Must not contain `"`, `\\``, control characters, or characters outside the Basic Multilingual Plane (such as emoji); invalid values are rejected with a 422. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/hangup", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "reason": reason, }, action_hangup_params.ActionHangupParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionHangupResponse, ) def join_ai_assistant( self, call_control_id: str, *, conversation_id: str, participant: AIAssistantJoinParticipantParam, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionJoinAIAssistantResponse: """Add a participant to an existing AI assistant conversation. Use this command to bring an additional call leg into a running AI conversation. Args: conversation_id: The ID of the AI assistant conversation to join. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_join", call_control_id=call_control_id), body=maybe_transform( { "conversation_id": conversation_id, "participant": participant, "client_state": client_state, "command_id": command_id, }, action_join_ai_assistant_params.ActionJoinAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionJoinAIAssistantResponse, ) def leave_queue( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionLeaveQueueResponse: """Removes the call from the queue it is currently waiting in. The call remains active and can be directed with further call commands. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/leave_queue", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_leave_queue_params.ActionLeaveQueueParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionLeaveQueueResponse, ) def pause_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionPauseRecordingResponse: """Pause recording the call. Recording can be resumed via Resume recording command. **Expected Webhooks:** There are no webhooks associated with this command. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/record_pause", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_pause_recording_params.ActionPauseRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionPauseRecordingResponse, ) def pay( self, call_control_id: str, *, amount: float | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, connector_name: str | Omit = omit, currency: Literal["USD", "usd"] | Omit = omit, description: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, language: str | Omit = omit, max_attempts: int | Omit = omit, metadata: Dict[str, object] | Omit = omit, min_postal_code_length: int | Omit = omit, parameters: Dict[str, object] | Omit = omit, payment_method: Literal["credit-card", "ach-debit"] | Omit = omit, payment_token: str | Omit = omit, postal_code: Union[str, bool] | Omit = omit, prompts: action_pay_params.Prompts | Omit = omit, service_level: str | Omit = omit, timeout_millis: int | Omit = omit, transaction_type: Literal["charge", "tokenize"] | Omit = omit, valid_card_types: List[ Literal["visa", "mastercard", "amex", "maestro", "discover", "optima", "jcb", "diners-club", "enroute"] ] | Omit = omit, voice: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionPayResponse: """ Collect payment details from the caller using DTMF and either charge or tokenize the payment method through a configured Pay connector. Pay pauses active call recordings while sensitive payment details are collected. When `payment_token` is supplied, the DTMF collection steps are skipped and the existing token is sent to the connector. **Expected Webhooks:** - `call.payment.progress` - `call.payment.completed` **Test mode card numbers:** `4111111111111111` (Visa), `5555555555554444` (Mastercard), `378282246310005` (American Express), `6011111111111117` (Discover), `3065930009020004` (Diners Club), `3566002020360505` (JCB), `6200000000000005` (UnionPay), and `6771798021000008` (Maestro). Test-mode connectors reject other card numbers before contacting the configured processor. The UnionPay and Maestro numbers are accepted for processor testing, but Pay currently does not emit a card type for them. Args: amount: Amount to charge. Required when `transaction_type` is `charge`. client_state: Base64-encoded state included in subsequent webhooks. command_id: Idempotency key for the command. Telnyx ignores a duplicate command with the same `command_id` for the same `call_control_id`. connector_name: Name of the Pay connector used to process the transaction. currency: Currency used for the transaction. Pay currently supports USD only. description: Optional description forwarded with the payment transaction. inter_digit_timeout_millis: Time in milliseconds to wait between consecutive DTMF digits. language: Language used for payment prompts. max_attempts: Maximum number of attempts for each payment collection step. metadata: Metadata forwarded to the Pay connector. min_postal_code_length: Minimum number of digits the caller must enter when collecting a credit-card billing postal code. Applies only when `postal_code` is `true` or `"true"` and no `payment_token` is supplied. The default is 1. The maximum number of digits collected is the greater of 10 and this value. This does not validate the length of a postal code supplied directly in `postal_code`. parameters: Additional parameters forwarded to the Pay connector. payment_method: Payment method to collect. payment_token: Existing payment token. When supplied, payment-detail collection is skipped. postal_code: Controls billing postal code collection for credit-card payments when no `payment_token` is supplied. Set to `true` or the string `"true"` (the default) to prompt the caller for a postal code. Set to `false` or the string `"false"` to skip the postal code prompt without supplying a postal code to the payment connector. Supply any other non-empty string, such as `"90210"`, to use that postal code without prompting. Empty or whitespace-only strings are rejected. This option does not affect ACH debit payments or payments using an existing token. prompts: Custom text-to-speech prompts keyed by payment collection step. service_level: Speech synthesis service level used for payment prompts. Pay defaults to `premium`. timeout_millis: Time in milliseconds to wait for DTMF input for each collection step. transaction_type: Transaction to perform. If omitted, Pay infers `tokenize` when `amount` is absent or zero and `charge` when `amount` is positive. valid_card_types: Restricts accepted card numbers to the listed card types. When the caller enters a card number that does not match one of the listed types, Pay treats the input as invalid and re-prompts for the card number. Cannot be used together with `payment_token`. voice: Voice used for payment prompts. Accepts `male`, `female`, or a provider voice in `..` format, for example `AWS.Polly.Joanna` or `Telnyx.KokoroTTS.af`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/pay", call_control_id=call_control_id), body=maybe_transform( { "amount": amount, "client_state": client_state, "command_id": command_id, "connector_name": connector_name, "currency": currency, "description": description, "inter_digit_timeout_millis": inter_digit_timeout_millis, "language": language, "max_attempts": max_attempts, "metadata": metadata, "min_postal_code_length": min_postal_code_length, "parameters": parameters, "payment_method": payment_method, "payment_token": payment_token, "postal_code": postal_code, "prompts": prompts, "service_level": service_level, "timeout_millis": timeout_millis, "transaction_type": transaction_type, "valid_card_types": valid_card_types, "voice": voice, }, action_pay_params.ActionPayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionPayResponse, ) def refer( self, call_control_id: str, *, sip_address: str, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionReferResponse: """Initiate a SIP Refer on a Call Control call. You can initiate a SIP Refer at any point in the duration of a call. **Expected Webhooks:** - `call.refer.started` - `call.refer.completed` - `call.refer.failed` Args: sip_address: The SIP URI to which the call will be referred to. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid execution of duplicate commands. Telnyx will ignore subsequent commands with the same `command_id` as one that has already been executed. custom_headers: Custom headers to be added to the SIP INVITE. sip_auth_password: SIP Authentication password used for SIP challenges. sip_auth_username: SIP Authentication username used for SIP challenges. sip_headers: SIP headers to be added to the request. Currently only User-to-User header is supported. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/refer", call_control_id=call_control_id), body=maybe_transform( { "sip_address": sip_address, "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_headers": sip_headers, }, action_refer_params.ActionReferParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionReferResponse, ) def reject( self, call_control_id: str, *, cause: Literal["CALL_REJECTED", "NOT_FOUND", "TEMPORARILY_UNAVAILABLE", "USER_BUSY"], client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionRejectResponse: """ Reject an incoming call. **Expected Webhooks:** - `call.hangup` Args: cause: Cause for call rejection. The cause sets the SIP response the caller receives: `USER_BUSY` sends 486 User Busy, `CALL_REJECTED` sends 603 Decline, `NOT_FOUND` sends 404 Not Found, and `TEMPORARILY_UNAVAILABLE` sends 480 Temporarily Unavailable. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/reject", call_control_id=call_control_id), body=maybe_transform( { "cause": cause, "client_state": client_state, "command_id": command_id, }, action_reject_params.ActionRejectParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionRejectResponse, ) def resume_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionResumeRecordingResponse: """ Resume recording the call. **Expected Webhooks:** There are no webhooks associated with this command. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/record_resume", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_resume_recording_params.ActionResumeRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionResumeRecordingResponse, ) def send_dtmf( self, call_control_id: str, *, digits: str, client_state: str | Omit = omit, command_id: str | Omit = omit, duration_millis: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSendDtmfResponse: """Sends DTMF tones from this leg. DTMF tones will be heard by the other end of the call. **Expected Webhooks:** There are no webhooks associated with this command. Args: digits: DTMF digits to send. Valid digits are 0-9, A-D, \\**, and #. Pauses can be added using w (0.5s) and W (1s). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. duration_millis: Specifies for how many milliseconds each digit will be played in the audio stream. Ranges from 100 to 500ms extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/send_dtmf", call_control_id=call_control_id), body=maybe_transform( { "digits": digits, "client_state": client_state, "command_id": command_id, "duration_millis": duration_millis, }, action_send_dtmf_params.ActionSendDtmfParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSendDtmfResponse, ) def send_sip_info( self, call_control_id: str, *, body: str, content_type: str, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSendSipInfoResponse: """ Sends SIP info from this leg. **Expected Webhooks:** - `call.sip_info.received` (to be received on the target call leg) Args: body: Content of the SIP INFO content_type: Content type of the INFO body. Must be MIME type compliant. There is a 1,400 bytes limit client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/send_sip_info", call_control_id=call_control_id), body=maybe_transform( { "body": body, "content_type": content_type, "client_state": client_state, "command_id": command_id, }, action_send_sip_info_params.ActionSendSipInfoParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSendSipInfoResponse, ) def speak( self, call_control_id: str, *, payload: str, voice: str, client_state: str | Omit = omit, command_id: str | Omit = omit, language: Literal[ "arb", "cmn-CN", "cy-GB", "da-DK", "de-DE", "en-AU", "en-GB", "en-GB-WLS", "en-IN", "en-US", "es-ES", "es-MX", "es-US", "fr-CA", "fr-FR", "hi-IN", "is-IS", "it-IT", "ja-JP", "ko-KR", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sv-SE", "tr-TR", ] | Omit = omit, loop: LoopcountParam | Omit = omit, payload_type: Literal["text", "ssml"] | Omit = omit, service_level: Literal["basic", "premium"] | Omit = omit, stop: str | Omit = omit, target_legs: Literal["self", "opposite", "both"] | Omit = omit, voice_settings: action_speak_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSpeakResponse: """Convert text to speech and play it back on the call. If multiple speak text commands are issued consecutively, the audio files will be placed in a queue awaiting playback. **Expected Webhooks:** - `call.speak.started` - `call.speak.ended` Args: payload: The text or SSML to be converted into speech. There is a 3,000 character limit. voice: Specifies the voice used in speech synthesis. - Define voices using the format `..`. Specifying only the provider will give default values for voice_id and model_id. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). Use `voice_settings` to configure custom deployments, regions, or API keys. - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.eleven_multilingual_v2.21m00Tcm4TlvDq8ikWAM`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration identifier secret in `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` (e.g., `Telnyx.KokoroTTS.af`). Use `voice_settings` to configure voice_speed and other synthesis parameters. `Bayan` provides Arabic (multiple dialects) and English voices (e.g., `Telnyx.Bayan.Ahmed`, `Telnyx.Bayan.Amanda`). `Sukhan` provides Urdu voices (e.g., `Telnyx.Sukhan.urdu-professor`); `voice_speed` is not supported. - **Minimax:** Use `Minimax..` (e.g., `Minimax.speech-02-hd.Wise_Woman`). Supported models: `speech-02-turbo`, `speech-02-hd`, `speech-2.6-turbo`, `speech-2.8-turbo`. Use `voice_settings` to configure speed, volume, pitch, and language_boost. - **Resemble:** Use `Resemble..` (e.g., `Resemble.Turbo.Aaron_en-US`). Supported models: `Pro`, `Turbo`, `Urdu`. `` is a stock voice name or the ID of a Resemble voice clone. Use `voice_settings` to configure precision, sample_rate, and format. - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. Use `voice_settings` to configure `delivery_mode` (`STABLE`, `BALANCED`, `CREATIVE`), supported by `TTS2` only. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. For service_level basic, you may define the gender of the speaker (male or female). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. language: The language you want spoken. This parameter is ignored when a `Polly.*` voice is specified. loop: The number of times to play the audio file. Use `infinity` to loop indefinitely. Defaults to 1. payload_type: The type of the provided payload. The payload can either be plain text, or Speech Synthesis Markup Language (SSML). service_level: This parameter impacts speech quality, language options and payload types. When using `basic`, only the `en-US` language and payload type `text` are allowed. stop: When specified, it stops the current audio being played. Specify `current` to stop the current audio being played, and to play the next file in the queue. Specify `all` to stop the current audio file being played and to also clear all audio files from the queue. target_legs: Specifies which legs of the call should receive the spoken audio. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/speak", call_control_id=call_control_id), body=maybe_transform( { "payload": payload, "voice": voice, "client_state": client_state, "command_id": command_id, "language": language, "loop": loop, "payload_type": payload_type, "service_level": service_level, "stop": stop, "target_legs": target_legs, "voice_settings": voice_settings, }, action_speak_params.ActionSpeakParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSpeakResponse, ) def start_ai_assistant( self, call_control_id: str, *, assistant: CallAssistantRequestParam | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, greeting: str | Omit = omit, interruption_settings: InterruptionSettingsParam | Omit = omit, message_history: Iterable[action_start_ai_assistant_params.MessageHistory] | Omit = omit, participants: Iterable[AIAssistantJoinParticipantParam] | Omit = omit, send_message_history_updates: bool | Omit = omit, transcription: TranscriptionConfigParam | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartAIAssistantResponse: """ Start an AI assistant on the call. **Expected Webhooks:** - [`call.conversation.created`](/api-reference/callbacks/call-conversation-created) includes `conversation_id` during startup - `call.conversation.ended` - `call.conversation_insights.generated` Args: assistant: AI Assistant configuration and per-call overrides. All fields except `id` are optional. Omitted assistant fields use the stored configuration. Supplied `voice_settings` and `transcription` objects replace their stored objects rather than merging individual settings; include every setting you want to retain. `dynamic_variables` are merged, with request values taking precedence. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. greeting: Text that will be played when the assistant starts, if none then nothing will be played when the assistant starts. The greeting can be text for any voice or SSML for `AWS.Polly.` voices. There is a 3,000 character limit. interruption_settings: Settings for handling user interruptions during assistant speech message_history: A list of messages to seed the conversation history before the assistant starts. Follows the same message format as the `ai_assistant_add_messages` command. participants: A list of participants to add to the conversation when it starts. send_message_history_updates: When `true`, a `call.ai_gather.message_history_updated` webhook carrying the full message history is sent each time the conversation message history is updated. The assistant's own `telephony_settings.send_message_history_updates` overrides this value when it is set. transcription: The settings associated with speech to text for the voice assistant. This is only relevant if the assistant uses a text-to-text language model. Any assistant using a model with native audio support (e.g. `fixie-ai/ultravox-v0_4`) will ignore this field. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_start", call_control_id=call_control_id), body=maybe_transform( { "assistant": assistant, "client_state": client_state, "command_id": command_id, "greeting": greeting, "interruption_settings": interruption_settings, "message_history": message_history, "participants": participants, "send_message_history_updates": send_message_history_updates, "transcription": transcription, }, action_start_ai_assistant_params.ActionStartAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartAIAssistantResponse, ) def start_conversation_relay( self, call_control_id: str, *, assistant: action_start_conversation_relay_params.Assistant | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, conversation_relay_dtmf_detection: bool | Omit = omit, conversation_relay_settings: action_start_conversation_relay_params.ConversationRelaySettings | Omit = omit, conversation_relay_url: str | Omit = omit, custom_parameters: Dict[str, object] | Omit = omit, dtmf_detection: bool | Omit = omit, greeting: str | Omit = omit, interruptible: ConversationRelayInterruptible | Omit = omit, interruptible_greeting: ConversationRelayInterruptible | Omit = omit, interruption_settings: ConversationRelayInterruptionSettingsParam | Omit = omit, language: str | Omit = omit, languages: Iterable[ConversationRelayLanguageParam] | Omit = omit, provider: str | Omit = omit, structured_provider: Dict[str, object] | Omit = omit, transcription: Dict[str, object] | Omit = omit, transcription_engine: Literal[ "Google", "Telnyx", "Deepgram", "Azure", "xAI", "AssemblyAI", "Speechmatics", "Soniox", "A", "B" ] | Omit = omit, transcription_engine_config: ConversationRelayTranscriptionEngineConfigParam | Omit = omit, tts_provider: str | Omit = omit, url: str | Omit = omit, voice: str | Omit = omit, voice_settings: action_start_conversation_relay_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartConversationRelayResponse: """Start a Conversation Relay session on an active call. Conversation Relay connects the call audio to your WebSocket so your application can exchange realtime messages with the caller while Telnyx handles speech recognition and text-to-speech. Only one AI Assistant or Conversation Relay session can be active on a call at a time. **Expected Webhooks:** - `call.conversation.ended` - Sent when the Conversation Relay session ends. If the customer WebSocket disconnects, the webhook payload `reason` is `customer_disconnect`. Args: assistant: Custom parameters for the Conversation Relay session. Pass key-value data as `assistant.dynamic_variables` to make it available to the relay session. client_state: Use this field to add state to subsequent webhooks. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. conversation_relay_dtmf_detection: Enable DTMF detection for the relay session. conversation_relay_settings: Conversation Relay connection settings. This object can provide `url`, `dtmf_detection`, `interruptible`, `interruptible_greeting`, and `languages`. Top-level aliases override nested values when both are present. conversation_relay_url: WebSocket URL for your Conversation Relay server. Must start with `ws://` or `wss://`. custom_parameters: Custom key-value parameters forwarded to the relay session as `assistant.dynamic_variables`. If `assistant.dynamic_variables` is also present, these values are merged in. dtmf_detection: Public alias for `conversation_relay_dtmf_detection`. If both are present, this value wins. greeting: Text played when the relay session starts. interruptible: Controls when caller input can interrupt assistant speech. `any` allows speech or DTMF interruptions; `none` disables interruptions; `speech` allows speech only; `dtmf` allows DTMF only. interruptible_greeting: Controls when caller input can interrupt assistant speech. `any` allows speech or DTMF interruptions; `none` disables interruptions; `speech` allows speech only; `dtmf` allows DTMF only. interruption_settings: Settings for handling caller interruptions during Conversation Relay speech. language: Default language for the relay session. This value is used for both text-to-speech and speech recognition. languages: Per-language TTS and transcription settings. provider: Structured voice provider. Must be supplied together with `structured_provider`. structured_provider: Provider-specific structured voice settings. Must be supplied together with `provider`; Telnyx sends the value as the nested provider configuration for Conversation Relay. transcription: Not supported for Conversation Relay start requests. Use `transcription_engine` and `transcription_engine_config` instead. transcription_engine: Engine to use for speech recognition. Legacy values `A` - `Google`, `B` - `Telnyx` are supported for backward compatibility. For Conversation Relay, use this field with `transcription_engine_config`; the `transcription` object is not supported. transcription_engine_config: Engine-specific transcription settings for Conversation Relay. This accepts the same provider-specific options used by the Call Transcription Start command, such as `transcription_model`, without requiring the engine discriminator to be repeated inside this object. With Deepgram Flux (`deepgram/flux`), `interim_results`, `eot_threshold` and `eager_eot_threshold` control the interim prompts and the `eagerEndOfTurn` and `turnResumed` frames sent to your WebSocket server. tts_provider: Text-to-speech provider. If omitted, Telnyx derives it from `voice` or `provider`. url: Public alias for `conversation_relay_url`. Must start with `ws://` or `wss://`. If both are present, this value wins. voice: The voice to be used by the voice assistant. Currently we support ElevenLabs, Telnyx and AWS voices. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-CA-LiamNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.BaseModel.John`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration secret under `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/conversation_relay_start", call_control_id=call_control_id), body=maybe_transform( { "assistant": assistant, "client_state": client_state, "command_id": command_id, "conversation_relay_dtmf_detection": conversation_relay_dtmf_detection, "conversation_relay_settings": conversation_relay_settings, "conversation_relay_url": conversation_relay_url, "custom_parameters": custom_parameters, "dtmf_detection": dtmf_detection, "greeting": greeting, "interruptible": interruptible, "interruptible_greeting": interruptible_greeting, "interruption_settings": interruption_settings, "language": language, "languages": languages, "provider": provider, "structured_provider": structured_provider, "transcription": transcription, "transcription_engine": transcription_engine, "transcription_engine_config": transcription_engine_config, "tts_provider": tts_provider, "url": url, "voice": voice, "voice_settings": voice_settings, }, action_start_conversation_relay_params.ActionStartConversationRelayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartConversationRelayResponse, ) def start_forking( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, rx: str | Omit = omit, stream_type: Literal["decrypted"] | Omit = omit, tx: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartForkingResponse: """ Call forking allows you to stream the media from a call to a specific target in realtime. This stream can be used to enable realtime audio analysis to support a variety of use cases, including fraud detection, or the creation of AI-generated audio responses. Requests must specify either the `target` attribute or the `rx` and `tx` attributes. **Expected Webhooks:** - `call.fork.started` - `call.fork.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. rx: The network target, , where the call's incoming RTP media packets should be forwarded. stream_type: Optionally specify a media type to stream. If `decrypted` selected, Telnyx will decrypt incoming SIP media before forking to the target. `rx` and `tx` are required fields if `decrypted` selected. tx: The network target, , where the call's outgoing RTP media packets should be forwarded. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/fork_start", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "rx": rx, "stream_type": stream_type, "tx": tx, }, action_start_forking_params.ActionStartForkingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartForkingResponse, ) def start_noise_suppression( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, direction: Literal["inbound", "outbound", "both"] | Omit = omit, noise_suppression_engine: Literal[ "Denoiser", "DeepFilterNet", "Krisp", "AiCoustics", "aic_l_quail", "aic_l_rook", "aic_s_quail", "aic_s_rook", "quail_voice_focus_s", "quail_voice_focus_xs", ] | Omit = omit, noise_suppression_engine_config: action_start_noise_suppression_params.NoiseSuppressionEngineConfig | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartNoiseSuppressionResponse: """Start noise suppression on an active call to reduce background noise. This feature is currently in beta. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. direction: The direction of the audio stream to be noise suppressed. noise_suppression_engine: The engine to use for noise suppression. For backward compatibility, engines A, B, C, and D are also supported, but are deprecated: A - Denoiser B - DeepFilterNet C - Krisp D - AiCoustics noise_suppression_engine_config: Configuration parameters for noise suppression engines. Different engines support different parameters. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/suppression_start", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "direction": direction, "noise_suppression_engine": noise_suppression_engine, "noise_suppression_engine_config": noise_suppression_engine_config, }, action_start_noise_suppression_params.ActionStartNoiseSuppressionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartNoiseSuppressionResponse, ) def start_playback( self, call_control_id: str, *, audio_type: Literal["mp3", "wav"] | Omit = omit, audio_url: str | Omit = omit, cache_audio: bool | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, loop: LoopcountParam | Omit = omit, media_name: str | Omit = omit, overlay: bool | Omit = omit, playback_content: str | Omit = omit, stop: str | Omit = omit, target_legs: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartPlaybackResponse: """Play an audio file on the call. If multiple play audio commands are issued consecutively, the audio files will be placed in a queue awaiting playback. _Notes:_ - When `overlay` is enabled, `target_legs` is limited to `self`. - A customer cannot Play Audio with `overlay=true` unless there is a Play Audio with `overlay=false` actively playing. **Expected Webhooks:** - `call.playback.started` - `call.playback.ended` Args: audio_type: Specifies the type of audio provided in `audio_url` or `playback_content`. audio_url: The URL of a file to be played back on the call. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. cache_audio: Caches the audio file. Useful when playing the same audio file multiple times during the call. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. loop: The number of times the audio file should be played. If supplied, the value must be an integer between 1 and 100, or the special string `infinity` for an endless loop. media_name: The media_name of a file to be played back on the call. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. overlay: When enabled, audio will be mixed on top of any other audio that is actively being played back. Note that `overlay: true` will only work if there is another audio file already being played on the call. playback_content: Allows a user to provide base64 encoded mp3 or wav. Note: when using this parameter, `media_url` and `media_name` in the `playback_started` and `playback_ended` webhooks will be empty stop: When specified, it stops the current audio being played. Specify `current` to stop the current audio being played, and to play the next file in the queue. Specify `all` to stop the current audio file being played and to also clear all audio files from the queue. target_legs: Specifies the leg or legs on which audio will be played. If supplied, the value must be either `self`, `opposite` or `both`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/playback_start", call_control_id=call_control_id), body=maybe_transform( { "audio_type": audio_type, "audio_url": audio_url, "cache_audio": cache_audio, "client_state": client_state, "command_id": command_id, "loop": loop, "media_name": media_name, "overlay": overlay, "playback_content": playback_content, "stop": stop, "target_legs": target_legs, }, action_start_playback_params.ActionStartPlaybackParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartPlaybackResponse, ) def start_recording( self, call_control_id: str, *, channels: Literal["single", "dual"], format: Literal["wav", "mp3"], client_state: str | Omit = omit, command_id: str | Omit = omit, custom_file_name: str | Omit = omit, max_length: int | Omit = omit, play_beep: bool | Omit = omit, recording_track: Literal["both", "inbound", "outbound"] | Omit = omit, timeout_secs: int | Omit = omit, transcription: bool | Omit = omit, transcription_engine: Literal["A", "B", "deepgram/nova-3"] | Omit = omit, transcription_language: Literal[ "af", "af-ZA", "am", "am-ET", "ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IL", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-MA", "ar-MR", "ar-OM", "ar-PS", "ar-QA", "ar-SA", "ar-TN", "ar-YE", "as", "auto_detect", "az", "az-AZ", "ba", "be", "bg", "bg-BG", "bn", "bn-BD", "bn-IN", "bo", "br", "bs", "bs-BA", "ca", "ca-ES", "cs", "cs-CZ", "cy", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", "el", "el-GR", "en", "en-AU", "en-CA", "en-GB", "en-GH", "en-HK", "en-IE", "en-IN", "en-KE", "en-NG", "en-NZ", "en-PH", "en-PK", "en-SG", "en-TZ", "en-US", "en-ZA", "es", "es-419", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et", "et-EE", "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", "fil-PH", "fo", "fr", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "gl", "gl-ES", "gu", "gu-IN", "ha", "haw", "he", "hi", "hi-IN", "hr", "hr-HR", "ht", "hu", "hu-HU", "hy", "hy-AM", "id", "id-ID", "is", "is-IS", "it", "it-CH", "it-IT", "iw-IL", "ja", "ja-JP", "jv-ID", "jw", "ka", "ka-GE", "kk", "kk-KZ", "km", "km-KH", "kn", "kn-IN", "ko", "ko-KR", "la", "lb", "ln", "lo", "lo-LA", "lt", "lt-LT", "lv", "lv-LV", "mg", "mi", "mk", "mk-MK", "ml", "ml-IN", "mn", "mn-MN", "mr", "mr-IN", "ms", "ms-MY", "mt", "my", "my-MM", "ne", "ne-NP", "nl", "nl-BE", "nl-NL", "nn", "no", "no-NO", "oc", "pa", "pa-Guru-IN", "pl", "pl-PL", "ps", "pt", "pt-BR", "pt-PT", "ro", "ro-RO", "ru", "ru-RU", "rw-RW", "sa", "sd", "si", "si-LK", "sk", "sk-SK", "sl", "sl-SI", "sn", "so", "sq", "sq-AL", "sr", "sr-RS", "ss-latn-za", "st-ZA", "su", "su-ID", "sv", "sv-SE", "sw", "sw-KE", "sw-TZ", "ta", "ta-IN", "ta-LK", "ta-MY", "ta-SG", "te", "te-IN", "tg", "th", "th-TH", "tk", "tl", "tn-latn-za", "tr", "tr-TR", "ts-ZA", "tt", "uk", "uk-UA", "ur", "ur-IN", "ur-PK", "uz", "uz-UZ", "ve-ZA", "vi", "vi-VN", "xh-ZA", "yi", "yo", "yue-Hant-HK", "zh", "zh-TW", "zu-ZA", ] | Omit = omit, transcription_max_speaker_count: int | Omit = omit, transcription_min_speaker_count: int | Omit = omit, transcription_profanity_filter: bool | Omit = omit, transcription_speaker_diarization: bool | Omit = omit, trim: Literal["trim-silence"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartRecordingResponse: """Start recording the call. Recording will stop on call hang-up, or can be initiated via the Stop Recording command. **Expected Webhooks:** - `call.recording.saved` - `call.recording.transcription.saved` - `call.recording.error` Args: channels: When `dual`, final audio file will be stereo recorded with the first leg on channel A, and the rest on channel B. format: The audio file format used when storing the call recording. Can be either `mp3` or `wav`. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. max_length: Defines the maximum length for the recording in seconds. The minimum value is 0. The maximum value is 14400. The default value is 0 (infinite) play_beep: If enabled, a beep sound will be played at the start of a recording. recording_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite) transcription: Enable post recording transcription. The default value is false. transcription_engine: Engine to use for speech recognition. `A` - `Google`, `B` - `Telnyx`, `deepgram/nova-3` - `Deepgram Nova-3`. Note: `deepgram/nova-3` supports only `en` and `en-{Region}` languages. transcription_language: Language code for transcription. Note: Not all languages are supported by all transcription engines (google, telnyx, deepgram). See engine-specific documentation for supported values. transcription_max_speaker_count: Defines maximum number of speakers in the conversation. Applies to `google` engine only. transcription_min_speaker_count: Defines minimum number of speakers in the conversation. Applies to `google` engine only. transcription_profanity_filter: Enables profanity_filter. Applies to `google` engine only. transcription_speaker_diarization: Enables speaker diarization. Applies to `google` engine only. trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/record_start", call_control_id=call_control_id), body=maybe_transform( { "channels": channels, "format": format, "client_state": client_state, "command_id": command_id, "custom_file_name": custom_file_name, "max_length": max_length, "play_beep": play_beep, "recording_track": recording_track, "timeout_secs": timeout_secs, "transcription": transcription, "transcription_engine": transcription_engine, "transcription_language": transcription_language, "transcription_max_speaker_count": transcription_max_speaker_count, "transcription_min_speaker_count": transcription_min_speaker_count, "transcription_profanity_filter": transcription_profanity_filter, "transcription_speaker_diarization": transcription_speaker_diarization, "trim": trim, }, action_start_recording_params.ActionStartRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartRecordingResponse, ) def start_siprec( self, call_control_id: str, *, client_state: str | Omit = omit, connector_name: str | Omit = omit, include_metadata_custom_headers: Literal[True, False] | Omit = omit, secure: Literal[True, False] | Omit = omit, session_timeout_secs: int | Omit = omit, sip_transport: Literal["udp", "tcp", "tls"] | Omit = omit, siprec_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartSiprecResponse: """ Start siprec session to configured in SIPREC connector SRS. **Expected Webhooks:** - `siprec.started` - `siprec.stopped` - `siprec.failed` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. connector_name: Name of configured SIPREC connector to be used. include_metadata_custom_headers: When set, custom parameters will be added as metadata (recording.session.ExtensionParameters). Otherwise, they’ll be added to sip headers. secure: Controls whether to encrypt media sent to your SRS using SRTP and TLS. When set you need to configure SRS port in your connector to 5061. session_timeout_secs: Sets `Session-Expires` header to the INVITE. A reinvite is sent every half the value set. Usefull for session keep alive. Minimum value is 90, set to 0 to disable. sip_transport: Specifies SIP transport protocol. siprec_track: Specifies which track should be sent on siprec session. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/siprec_start", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "connector_name": connector_name, "include_metadata_custom_headers": include_metadata_custom_headers, "secure": secure, "session_timeout_secs": session_timeout_secs, "sip_transport": sip_transport, "siprec_track": siprec_track, }, action_start_siprec_params.ActionStartSiprecParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartSiprecResponse, ) def start_streaming( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_parameters: Iterable[action_start_streaming_params.CustomParameter] | Omit = omit, dialogflow_config: DialogflowConfigParam | Omit = omit, enable_dialogflow: bool | Omit = omit, stream_auth_token: str | Omit = omit, stream_bidirectional_codec: StreamBidirectionalCodec | Omit = omit, stream_bidirectional_mode: StreamBidirectionalMode | Omit = omit, stream_bidirectional_sampling_rate: StreamBidirectionalSamplingRate | Omit = omit, stream_bidirectional_target_legs: StreamBidirectionalTargetLegs | Omit = omit, stream_codec: StreamCodec | Omit = omit, stream_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, stream_url: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartStreamingResponse: """ Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime. Audio will be delivered as base64-encoded RTP payload (raw audio), wrapped in JSON payloads. Please find more details about media streaming messages specification under the [link](https://developers.telnyx.com/docs/voice/programmable-voice/media-streaming). Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_parameters: Custom parameters to be sent as part of the WebSocket connection. enable_dialogflow: Enables Dialogflow for the current call. The default value is false. stream_auth_token: An authentication token to be sent as part of the WebSocket connection. Maximum length is 4000 characters. stream_bidirectional_codec: Indicates codec for bidirectional streaming RTP payloads. Used only with stream_bidirectional_mode=rtp. Case sensitive. stream_bidirectional_mode: Configures method of bidirectional streaming (mp3, rtp). stream_bidirectional_sampling_rate: Audio sampling rate. stream_bidirectional_target_legs: Specifies which call legs should receive the bidirectional stream audio. stream_codec: Specifies the codec to be used for the streamed audio. When set to 'default' or when transcoding is not possible, the codec from the call will be used. stream_track: Specifies which track should be streamed. stream_url: The destination WebSocket address where the stream is going to be delivered. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/streaming_start", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "custom_parameters": custom_parameters, "dialogflow_config": dialogflow_config, "enable_dialogflow": enable_dialogflow, "stream_auth_token": stream_auth_token, "stream_bidirectional_codec": stream_bidirectional_codec, "stream_bidirectional_mode": stream_bidirectional_mode, "stream_bidirectional_sampling_rate": stream_bidirectional_sampling_rate, "stream_bidirectional_target_legs": stream_bidirectional_target_legs, "stream_codec": stream_codec, "stream_track": stream_track, "stream_url": stream_url, }, action_start_streaming_params.ActionStartStreamingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartStreamingResponse, ) def start_transcription( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, transcription_engine: Literal[ "Google", "Telnyx", "Deepgram", "Azure", "xAI", "AssemblyAI", "Speechmatics", "Soniox", "Parakeet", "Humain", "Reson8", "Cohere", "A", "B", ] | Omit = omit, transcription_engine_config: action_start_transcription_params.TranscriptionEngineConfig | Omit = omit, transcription_tracks: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartTranscriptionResponse: """Start real-time transcription. Transcription will stop on call hang-up, or can be initiated via the Transcription stop command. **Expected Webhooks:** - `call.transcription` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. transcription_engine: Engine to use for speech recognition. Legacy values `A` - `Google`, `B` - `Telnyx` are supported for backward compatibility. transcription_tracks: Indicates which leg of the call will be transcribed. Use `inbound` for the leg that requested the transcription, `outbound` for the other leg, and `both` for both legs of the call. Will default to `inbound`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/transcription_start", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "transcription_engine": transcription_engine, "transcription_engine_config": transcription_engine_config, "transcription_tracks": transcription_tracks, }, action_start_transcription_params.ActionStartTranscriptionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartTranscriptionResponse, ) def stop_ai_assistant( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopAIAssistantResponse: """Stops the AI assistant currently engaged on the call. The call remains active and can continue with other call control commands. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_ai_assistant_params.ActionStopAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopAIAssistantResponse, ) def stop_conversation_relay( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopConversationRelayResponse: """ Stop the active Conversation Relay session on a call. Args: client_state: Use this field to add state to subsequent webhooks. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/conversation_relay_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_conversation_relay_params.ActionStopConversationRelayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopConversationRelayResponse, ) def stop_forking( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, stream_type: Literal["raw", "decrypted"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopForkingResponse: """ Stop forking a call. **Expected Webhooks:** - `call.fork.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. stream_type: Optionally specify a `stream_type`. This should match the `stream_type` that was used in `fork_start` command to properly stop the fork. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/fork_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "stream_type": stream_type, }, action_stop_forking_params.ActionStopForkingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopForkingResponse, ) def stop_gather( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopGatherResponse: """ Stop current gather. **Expected Webhooks:** - `call.gather.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/gather_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_gather_params.ActionStopGatherParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopGatherResponse, ) def stop_noise_suppression( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopNoiseSuppressionResponse: """Stop noise suppression previously started on an active call. This feature is currently in beta. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/suppression_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_noise_suppression_params.ActionStopNoiseSuppressionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopNoiseSuppressionResponse, ) def stop_playback( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, overlay: bool | Omit = omit, stop: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopPlaybackResponse: """ Stop audio being played on the call. **Expected Webhooks:** - `call.playback.ended` or `call.speak.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. overlay: When enabled, it stops the audio being played in the overlay queue. stop: Use `current` to stop the current audio being played. Use `all` to stop the current audio file being played and clear all audio files from the queue. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/playback_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "overlay": overlay, "stop": stop, }, action_stop_playback_params.ActionStopPlaybackParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopPlaybackResponse, ) def stop_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopRecordingResponse: """ Stop recording the call. **Expected Webhooks:** - `call.recording.saved` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/record_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_stop_recording_params.ActionStopRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopRecordingResponse, ) def stop_siprec( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopSiprecResponse: """ Stop SIPREC session. **Expected Webhooks:** - `siprec.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/siprec_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_siprec_params.ActionStopSiprecParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopSiprecResponse, ) def stop_streaming( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, stream_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopStreamingResponse: """ Stop streaming a call to a WebSocket. **Expected Webhooks:** - `streaming.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. stream_id: Identifies the stream. If the `stream_id` is not provided the command stops all streams associated with a given `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/streaming_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, "stream_id": stream_id, }, action_stop_streaming_params.ActionStopStreamingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopStreamingResponse, ) def stop_transcription( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopTranscriptionResponse: """Stops real-time transcription on the call. Transcription webhooks cease once the command takes effect; the call itself is unaffected. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/transcription_stop", call_control_id=call_control_id), body=maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_transcription_params.ActionStopTranscriptionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopTranscriptionResponse, ) def switch_supervisor_role( self, call_control_id: str, *, role: Literal["barge", "whisper", "monitor"], # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSwitchSupervisorRoleResponse: """Switch the supervisor role for a bridged call. This allows switching between different supervisor modes during an active call Args: role: The supervisor role to switch to. 'barge' allows speaking to both parties, 'whisper' allows speaking to caller only, 'monitor' allows listening only. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/switch_supervisor_role", call_control_id=call_control_id), body=maybe_transform({"role": role}, action_switch_supervisor_role_params.ActionSwitchSupervisorRoleParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSwitchSupervisorRoleResponse, ) def transfer( self, call_control_id: str, *, to: str, answering_machine_detection: Literal[ "premium", "premium_ios_call_screening_detection", "detect", "detect_beep", "detect_words", "greeting_end", "disabled", ] | Omit = omit, answering_machine_detection_config: action_transfer_params.AnsweringMachineDetectionConfig | Omit = omit, audio_url: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, diversion: str | Omit = omit, early_media: bool | Omit = omit, from_: str | Omit = omit, from_display_name: str | Omit = omit, media_encryption: Literal["disabled", "SRTP", "DTLS"] | Omit = omit, media_name: str | Omit = omit, mute_dtmf: Literal["none", "both", "self", "opposite"] | Omit = omit, park_after_unbridge: str | Omit = omit, preferred_codecs: str | Omit = omit, privacy: Literal["id", "none"] | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, route_to_mobile: bool | Omit = omit, send_digits_on_answer: str | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, sip_region: Literal["US", "Europe", "Canada", "Australia", "Middle East"] | Omit = omit, sip_transport_protocol: Literal["UDP", "TCP", "TLS"] | Omit = omit, sound_modifications: SoundModificationsParam | Omit = omit, target_leg_client_state: str | Omit = omit, time_limit_secs: int | Omit = omit, timeout_secs: int | Omit = omit, webhook_retries_policies: Dict[str, action_transfer_params.WebhookRetriesPolicies] | Omit = omit, webhook_url: str | Omit = omit, webhook_url_method: Literal["POST", "GET"] | Omit = omit, webhook_urls: Dict[str, SequenceNotStr[str]] | Omit = omit, webhook_urls_method: Literal["POST", "GET"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionTransferResponse: """Transfer a call to a new destination. If the transfer is unsuccessful, a `call.hangup` webhook for the other call (Leg B) will be sent indicating that the transfer could not be completed. The original call will remain active and may be issued additional commands, potentially transfering the call to an alternate destination. **Expected Webhooks:** - `call.initiated` - `call.bridged` to Leg B - `call.answered` or `call.hangup` - `call.machine.detection.ended` if `answering_machine_detection` was requested - `call.machine.greeting.ended` if `answering_machine_detection` was requested to detect the end of machine greeting - `call.machine.premium.detection.ended` if `answering_machine_detection=premium` was requested - `call.machine.premium.greeting.ended` if `answering_machine_detection=premium` was requested and a beep was detected - `call.machine.premium.call_screening.detected` if `answering_machine_detection=premium_ios_call_screening_detection` was requested and an Apple Call Screening tone was detected Args: to: The DID or SIP URI to dial out to. For SIP URI destinations, append `;secure=true` or `;secure=srtp` to enable SRTP media encryption for that endpoint, or `;secure=dtls` to enable DTLS media encryption for that endpoint. If `media_encryption` is set to `SRTP` or `DTLS`, it takes precedence over any per-endpoint `secure` URI parameter. You may also append a comma followed by DTMF digits (e.g. `+18004247767,200`) to play those digits as DTMF once the transfer destination answers — equivalent to setting `send_digits_on_answer` separately. If both are present, the explicit `send_digits_on_answer` parameter takes precedence. answering_machine_detection: Enables Answering Machine Detection. When a call is answered, Telnyx runs real-time detection to determine if it was picked up by a human or a machine and sends an `call.machine.detection.ended` webhook with the analysis result. If 'greeting_end' or 'detect_words' is used and a 'machine' is detected, you will receive another 'call.machine.greeting.ended' webhook when the answering machine greeting ends with a beep or silence. If `detect_beep` is used, you will only receive 'call.machine.greeting.ended' if a beep is detected. If `answering_machine_detection` is set to `premium_ios_call_screening_detection`, Premium AMD runs with iOS Call Screening support: after an initial `machine` result, Telnyx listens for the iOS call-screening prompt to end or for an Apple Call Screening tone, sends `call.machine.premium.greeting.ended` with `result=prompt_ended` or `call.machine.premium.call_screening.detected` with `result=screening` respectively. When the Apple Call Screening tone is detected, Premium AMD is restarted on the screened call and a `call.machine.premium.detection.ended` webhook with the post-screening classification follows. answering_machine_detection_config: Optional configuration parameters to modify 'answering_machine_detection' performance. Only `total_analysis_time_millis` and `greeting_duration_millis` parameters are applicable when `premium` is selected as answering_machine_detection. `prompt_end_timeout_millis` is additionally applicable when `premium_ios_call_screening_detection` is selected. audio_url: The URL of a file to be played back when the transfer destination answers before bridging the call. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_headers: Custom headers to be added to the SIP INVITE. diversion: The `to` number of an active inbound call, in +E164 format. Telnyx checks whether there is currently an active inbound call where `to` matches this `diversion` value and `from` matches the `from` number supplied for this request. If such a call exists, the `from` number is treated as verified (since it is already on an active inbound call to you) and can be used as the caller id for this outbound call. early_media: If set to false, early media will not be passed to the originating leg. from_: The `from` number to be used as the caller id presented to the destination (`to` number). The number should be in +E164 format. This attribute will default to the `to` number of the original call if omitted. from_display_name: The `from_display_name` string to be used as the caller id name (SIP From Display Name) presented to the destination (`to` number). The string should have a maximum of 128 characters, containing only letters, numbers, spaces, and -\\__~!.+ special characters. If ommited, the display name will be the same as the number in the `from` field. media_encryption: Defines whether media should be encrypted on the new call leg. For SIP URI destinations, media encryption can also be requested per endpoint with the `secure` URI parameter: `;secure=true` or `;secure=srtp` enables SRTP, and `;secure=dtls` enables DTLS. This parameter, when set to `SRTP` or `DTLS`, takes precedence over the per-endpoint `secure` value. media_name: The media_name of a file to be played back when the transfer destination answers before bridging the call. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. mute_dtmf: When enabled, DTMF tones are not passed to the call participant. The webhooks containing the DTMF information will be sent. park_after_unbridge: Specifies behavior after the bridge ends (i.e. the opposite leg either hangs up or is transferred). If supplied with the value `self`, the current leg will be parked after unbridge. If not set, the default behavior is to hang up the leg. preferred_codecs: The list of comma-separated codecs in order of preference to be used during the call. The codecs supported are `G722`, `PCMU`, `PCMA`, `G729`, `OPUS`, `VP8`, `H264`, `AMR-WB`. privacy: Indicates the privacy level to be used for the call. When set to `id`, caller ID information (name and number) will be hidden from the called party. When set to `none` or omitted, caller ID will be shown normally. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. route_to_mobile: When set to true, routes the call directly to the mobile device associated with the destination Telnyx Mobile number, bypassing Inbound Calls Interception configured in the Telnyx Portal under Mobile Numbers → select the number → Voice → Call Interception. Use this when transferring an intercepted call to the mobile device to prevent the call from being intercepted again. Defaults to false. send_digits_on_answer: DTMF digits to send automatically after the transfer destination answers. Useful for reaching an extension behind an IVR (e.g. `"200"` to dial extension 200 once the called party picks up). Allowed characters: `0-9`, `A-D`, `w` (0.5s pause), `W` (1s pause), `*`, `#`. Maximum 64 characters. When omitted, no automatic DTMF is sent. May also be supplied inline by appending `,` to `to` (e.g. `to=+18004247767,200`); if both forms are present, this explicit field takes precedence. sip_auth_password: SIP Authentication password used for SIP challenges. sip_auth_username: SIP Authentication username used for SIP challenges. sip_headers: SIP headers to be added to the SIP INVITE. Currently only User-to-User header is supported. sip_region: Defines the SIP region to be used for the call. sip_transport_protocol: Defines SIP transport protocol to be used on the call. sound_modifications: Use this field to modify sound effects, for example adjust the pitch. target_leg_client_state: Use this field to add state to every subsequent webhook for the new leg. It must be a valid Base-64 encoded string. time_limit_secs: Sets the maximum duration of a Call Control Leg in seconds. If the time limit is reached, the call will hangup and a `call.hangup` webhook with a `hangup_cause` of `time_limit` will be sent. For example, by setting a time limit of 120 seconds, a Call Leg will be automatically terminated two minutes after being answered. The default time limit is 14400 seconds or 4 hours and this is also the maximum allowed call length. timeout_secs: The number of seconds that Telnyx will wait for the call to be answered by the destination to which it is being transferred. If the timeout is reached before an answer is received, the call will hangup and a `call.hangup` webhook with a `hangup_cause` of `timeout` will be sent. Minimum value is 5 seconds. Maximum value is 600 seconds. webhook_retries_policies: A map of event types to retry policies. Each retry policy contains an array of `retries_ms` specifying the delays between retry attempts in milliseconds. Maximum 5 retries, total delay cannot exceed 60 seconds. webhook_url: Use this field to override the URL for which Telnyx will send subsequent webhooks to for this call. webhook_url_method: HTTP request type used for `webhook_url`. webhook_urls: A map of event types to arrays of webhook URLs. When an event of the specified type occurs, the webhook URLs associated with that event type will be called instead of `webhook_url`. Events not mapped here will use the default `webhook_url`. webhook_urls_method: HTTP request method to invoke `webhook_urls`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._post( path_template("/calls/{call_control_id}/actions/transfer", call_control_id=call_control_id), body=maybe_transform( { "to": to, "answering_machine_detection": answering_machine_detection, "answering_machine_detection_config": answering_machine_detection_config, "audio_url": audio_url, "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "diversion": diversion, "early_media": early_media, "from_": from_, "from_display_name": from_display_name, "media_encryption": media_encryption, "media_name": media_name, "mute_dtmf": mute_dtmf, "park_after_unbridge": park_after_unbridge, "preferred_codecs": preferred_codecs, "privacy": privacy, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "route_to_mobile": route_to_mobile, "send_digits_on_answer": send_digits_on_answer, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_headers": sip_headers, "sip_region": sip_region, "sip_transport_protocol": sip_transport_protocol, "sound_modifications": sound_modifications, "target_leg_client_state": target_leg_client_state, "time_limit_secs": time_limit_secs, "timeout_secs": timeout_secs, "webhook_retries_policies": webhook_retries_policies, "webhook_url": webhook_url, "webhook_url_method": webhook_url_method, "webhook_urls": webhook_urls, "webhook_urls_method": webhook_urls_method, }, action_transfer_params.ActionTransferParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionTransferResponse, ) def update_client_state( self, call_control_id: str, *, client_state: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionUpdateClientStateResponse: """Updates the client state associated with the call. Client state is an opaque value echoed back in subsequent webhooks for the call, letting you correlate events with your application's state. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return self._put( path_template("/calls/{call_control_id}/actions/client_state_update", call_control_id=call_control_id), body=maybe_transform( {"client_state": client_state}, action_update_client_state_params.ActionUpdateClientStateParams ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionUpdateClientStateResponse, ) class AsyncActionsResource(AsyncAPIResource): """Call Control command operations""" @cached_property def with_raw_response(self) -> AsyncActionsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncActionsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncActionsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncActionsResourceWithStreamingResponse(self) async def add_ai_assistant_messages( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, messages: Iterable[action_add_ai_assistant_messages_params.Message] | Omit = omit, trigger_response: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionAddAIAssistantMessagesResponse: """ Add messages to the conversation started by an AI assistant on the call. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. messages: The messages to add to the conversation. trigger_response: When `true`, the injected messages immediately trigger an assistant response/turn instead of waiting for the next natural turn or idle timeout. This may interrupt a user who is still speaking. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template( "/calls/{call_control_id}/actions/ai_assistant_add_messages", call_control_id=call_control_id ), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "messages": messages, "trigger_response": trigger_response, }, action_add_ai_assistant_messages_params.ActionAddAIAssistantMessagesParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionAddAIAssistantMessagesResponse, ) async def answer( self, call_control_id: str, *, assistant: CallAssistantRequestParam | Omit = omit, billing_group_id: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, conversation_relay_config: ConversationRelayEmbeddedConfigParam | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, deepfake_detection: action_answer_params.DeepfakeDetection | Omit = omit, preferred_codecs: Literal["G722,PCMU,PCMA,G729,OPUS,VP8,H264"] | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, send_silence_when_idle: bool | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, sound_modifications: SoundModificationsParam | Omit = omit, stream_bidirectional_codec: StreamBidirectionalCodec | Omit = omit, stream_bidirectional_mode: StreamBidirectionalMode | Omit = omit, stream_bidirectional_target_legs: StreamBidirectionalTargetLegs | Omit = omit, stream_codec: StreamCodec | Omit = omit, stream_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, stream_url: str | Omit = omit, transcription: bool | Omit = omit, transcription_config: TranscriptionStartRequestParam | Omit = omit, webhook_retries_policies: Dict[str, action_answer_params.WebhookRetriesPolicies] | Omit = omit, webhook_url: str | Omit = omit, webhook_url_method: Literal["POST", "GET"] | Omit = omit, webhook_urls: Dict[str, SequenceNotStr[str]] | Omit = omit, webhook_urls_method: Literal["POST", "GET"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionAnswerResponse: """Answer an incoming call. You must issue this command before executing subsequent commands on an incoming call. To answer with an AI assistant, include `assistant.id` and any per-call overrides in the `assistant` object. Telnyx attempts to warm up the assistant before answering the call, then starts the assistant automatically when the call is answered. Do not also send `ai_assistant_start` for this flow. The HTTP success response can arrive before the call is answered; use the `call.answered` webhook to track the answer. If warm-up fails, Telnyx falls back to starting the assistant after answering. When `assistant.id` is supplied, obtain the conversation ID from `data.payload.conversation_id` in the [call.conversation.created](/api-reference/callbacks/call-conversation-created) webhook and correlate it using `data.payload.call_control_id`. The `answer` HTTP response does not include `conversation_id`. The created event is emitted during assistant startup and does not indicate that the assistant is ready to speak. Set the assistant voice with `assistant.voice_settings.voice` and speech-to-text settings with `assistant.transcription`. You can reuse one stored assistant with different per-call settings. Warm-up prepares assistant configuration and dependencies; it does not wait for the greeting audio to be ready or guarantee zero silence after answer. A plain `answer` followed by `ai_assistant_start` performs assistant startup after the call has already been answered. **Expected Webhooks:** - `call.answered` - `call.conversation.created` when the requested assistant conversation is created - `call.hold` and `call.unhold` if the call is held/unheld - `call.deepfake_detection.result` if `deepfake_detection` was enabled - `call.deepfake_detection.error` if `deepfake_detection` was enabled and an error occurred - `streaming.started`, `streaming.stopped` or `streaming.failed` if `stream_url` was set When the `record` parameter is set to `record-from-answer`, the response will include a `recording_id` field. Args: assistant: AI Assistant configuration and per-call overrides. All fields except `id` are optional. Omitted assistant fields use the stored configuration. Supplied `voice_settings` and `transcription` objects replace their stored objects rather than merging individual settings; include every setting you want to retain. `dynamic_variables` are merged, with request values taking precedence. billing_group_id: Use this field to set the Billing Group ID for the call. Must be a valid and existing Billing Group ID. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. conversation_relay_config: Starts a Conversation Relay session automatically when the answered/dialed call is answered. This embedded shape is supported on `answer` and `dial`. It uses public field names (`url`, `dtmf_detection`, `greeting`, `voice`, `language`, etc.) and maps them to the underlying Conversation Relay action. `client_state`, `tts_language`, and `transcription_language` inside this object are ignored; use the parent command's `client_state` and `command_id` fields instead. custom_headers: Custom headers to be added to the SIP INVITE response. deepfake_detection: Enables deepfake detection on the call. When enabled, audio from the remote party is streamed to a detection service that analyzes whether the voice is AI-generated. Results are delivered via the `call.deepfake_detection.result` webhook. preferred_codecs: The list of comma-separated codecs in a preferred order for the forked media to be received. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. send_silence_when_idle: Generate silence RTP packets when no transmission available. sip_headers: SIP headers to be added to the SIP INVITE response. Currently only User-to-User header is supported. sound_modifications: Use this field to modify sound effects, for example adjust the pitch. stream_bidirectional_codec: Indicates codec for bidirectional streaming RTP payloads. Used only with stream_bidirectional_mode=rtp. Case sensitive. stream_bidirectional_mode: Configures method of bidirectional streaming (mp3, rtp). stream_bidirectional_target_legs: Specifies which call legs should receive the bidirectional stream audio. stream_codec: Specifies the codec to be used for the streamed audio. When set to 'default' or when transcoding is not possible, the codec from the call will be used. stream_track: Specifies which track should be streamed. stream_url: The destination WebSocket address where the stream is going to be delivered. transcription: Enable standalone call transcription upon call answer. The default value is false. Configure this feature with `transcription_config`. To configure speech recognition for an AI assistant, use `assistant.transcription` instead. webhook_retries_policies: A map of event types to retry policies. Each retry policy contains an array of `retries_ms` specifying the delays between retry attempts in milliseconds. Maximum 5 retries, total delay cannot exceed 60 seconds. webhook_url: Use this field to override the URL for which Telnyx will send subsequent webhooks to for this call. webhook_url_method: HTTP request type used for `webhook_url`. webhook_urls: A map of event types to arrays of webhook URLs. When an event of the specified type occurs, the webhook URLs associated with that event type will be called instead of `webhook_url`. Events not mapped here will use the default `webhook_url`. webhook_urls_method: HTTP request method to invoke `webhook_urls`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/answer", call_control_id=call_control_id), body=await async_maybe_transform( { "assistant": assistant, "billing_group_id": billing_group_id, "client_state": client_state, "command_id": command_id, "conversation_relay_config": conversation_relay_config, "custom_headers": custom_headers, "deepfake_detection": deepfake_detection, "preferred_codecs": preferred_codecs, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "send_silence_when_idle": send_silence_when_idle, "sip_headers": sip_headers, "sound_modifications": sound_modifications, "stream_bidirectional_codec": stream_bidirectional_codec, "stream_bidirectional_mode": stream_bidirectional_mode, "stream_bidirectional_target_legs": stream_bidirectional_target_legs, "stream_codec": stream_codec, "stream_track": stream_track, "stream_url": stream_url, "transcription": transcription, "transcription_config": transcription_config, "webhook_retries_policies": webhook_retries_policies, "webhook_url": webhook_url, "webhook_url_method": webhook_url_method, "webhook_urls": webhook_urls, "webhook_urls_method": webhook_urls_method, }, action_answer_params.ActionAnswerParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionAnswerResponse, ) async def bridge( self, call_control_id_to_bridge: str, *, call_control_id_to_bridge_with: str, client_state: str | Omit = omit, command_id: str | Omit = omit, hold_after_unbridge: bool | Omit = omit, mute_dtmf: Literal["none", "both", "self", "opposite"] | Omit = omit, park_after_unbridge: str | Omit = omit, play_ringtone: bool | Omit = omit, prevent_double_bridge: bool | Omit = omit, queue: str | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, ringtone: Literal[ "at", "au", "be", "bg", "br", "ch", "cl", "cn", "cz", "de", "dk", "ee", "es", "fi", "fr", "gr", "hu", "il", "in", "it", "jp", "lt", "mx", "my", "nl", "no", "nz", "ph", "pl", "pt", "ru", "se", "sg", "th", "tw", "uk", "us-old", "us", "ve", "za", ] | Omit = omit, video_room_context: str | Omit = omit, video_room_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionBridgeResponse: """ Bridge two call control calls. **Expected Webhooks:** - `call.bridged` for Leg A - `call.bridged` for Leg B Args: call_control_id_to_bridge_with: The Call Control ID of the call you want to bridge with, can't be used together with queue parameter or video_room_id parameter. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. hold_after_unbridge: Specifies behavior after the bridge ends. If set to `true`, the current leg will be put on hold after unbridge instead of being hung up. mute_dtmf: When enabled, DTMF tones are not passed to the call participant. The webhooks containing the DTMF information will be sent. park_after_unbridge: Specifies behavior after the bridge ends (i.e. the opposite leg either hangs up or is transferred). If supplied with the value `self`, the current leg will be parked after unbridge. If not set, the default behavior is to hang up the leg. play_ringtone: Specifies whether to play a ringtone if the call you want to bridge with has not yet been answered. prevent_double_bridge: When set to `true`, it prevents bridging if the target call is already bridged to another call. Disabled by default. queue: The name of the queue you want to bridge with, can't be used together with call_control_id parameter or video_room_id parameter. Bridging with a queue means bridging with the first call in the queue. The call will always be removed from the queue regardless of whether bridging succeeds. Returns an error when the queue is empty. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. ringtone: Specifies which country ringtone to play when `play_ringtone` is set to `true`. If not set, the US ringtone will be played. video_room_context: The additional parameter that will be passed to the video conference. It is a text field and the user can decide how to use it. For example, you can set the participant name or pass JSON text. It can be used only with video_room_id parameter. video_room_id: The ID of the video room you want to bridge with, can't be used together with call_control_id parameter or queue parameter. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id_to_bridge: raise ValueError( f"Expected a non-empty value for `call_control_id_to_bridge` but received {call_control_id_to_bridge!r}" ) return await self._post( path_template( "/calls/{call_control_id_to_bridge}/actions/bridge", call_control_id_to_bridge=call_control_id_to_bridge ), body=await async_maybe_transform( { "call_control_id_to_bridge_with": call_control_id_to_bridge_with, "client_state": client_state, "command_id": command_id, "hold_after_unbridge": hold_after_unbridge, "mute_dtmf": mute_dtmf, "park_after_unbridge": park_after_unbridge, "play_ringtone": play_ringtone, "prevent_double_bridge": prevent_double_bridge, "queue": queue, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "ringtone": ringtone, "video_room_context": video_room_context, "video_room_id": video_room_id, }, action_bridge_params.ActionBridgeParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionBridgeResponse, ) async def enqueue( self, call_control_id: str, *, queue_name: str, client_state: str | Omit = omit, command_id: str | Omit = omit, keep_after_hangup: bool | Omit = omit, max_size: int | Omit = omit, max_wait_time_secs: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionEnqueueResponse: """ Places the call into a queue, where it waits until it is removed or bridged to another leg. Queue behavior is configured through the request body. Args: queue_name: The name of the queue the call should be put in. If a queue with a given name doesn't exist yet it will be created. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. keep_after_hangup: If set to true, the call will remain in the queue after hangup. In this case bridging to such call will fail with necessary information needed to re-establish the call. max_size: The maximum number of calls allowed in the queue at a given time. Can't be modified for an existing queue. max_wait_time_secs: The number of seconds after which the call will be removed from the queue. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/enqueue", call_control_id=call_control_id), body=await async_maybe_transform( { "queue_name": queue_name, "client_state": client_state, "command_id": command_id, "keep_after_hangup": keep_after_hangup, "max_size": max_size, "max_wait_time_secs": max_wait_time_secs, }, action_enqueue_params.ActionEnqueueParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionEnqueueResponse, ) async def gather( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, gather_id: str | Omit = omit, initial_timeout_millis: int | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, maximum_digits: int | Omit = omit, minimum_digits: int | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherResponse: """ Gather DTMF signals to build interactive menus. You can pass a list of valid digits. The `Answer` command must be issued before the `gather` command. **Expected Webhooks:** - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. gather_id: An id that will be sent back in the corresponding `call.gather.ended` webhook. Will be randomly generated if not specified. initial_timeout_millis: The number of milliseconds to wait for the first DTMF. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait to complete the request. valid_digits: A list of all digits accepted as valid. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/gather", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "gather_id": gather_id, "initial_timeout_millis": initial_timeout_millis, "inter_digit_timeout_millis": inter_digit_timeout_millis, "maximum_digits": maximum_digits, "minimum_digits": minimum_digits, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, }, action_gather_params.ActionGatherParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherResponse, ) async def gather_using_ai( self, call_control_id: str, *, parameters: Dict[str, object], assistant: AssistantParam | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, gather_ended_speech: str | Omit = omit, greeting: str | Omit = omit, interruption_settings: InterruptionSettingsParam | Omit = omit, language: GoogleTranscriptionLanguage | Omit = omit, message_history: Iterable[action_gather_using_ai_params.MessageHistory] | Omit = omit, send_message_history_updates: bool | Omit = omit, send_partial_results: bool | Omit = omit, transcription: TranscriptionConfigParam | Omit = omit, user_response_timeout_ms: int | Omit = omit, voice: str | Omit = omit, voice_settings: action_gather_using_ai_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingAIResponse: """ Gather parameters defined in the request payload using a voice assistant. You can pass parameters described as a JSON Schema object and the voice assistant will attempt to gather these informations. **Expected Webhooks:** - [`call.conversation.created`](/api-reference/callbacks/call-conversation-created) includes `conversation_id` during startup - `call.ai_gather.ended` - `call.conversation.ended` - `call.ai_gather.partial_results` (if `send_partial_results` is set to `true`) - `call.ai_gather.message_history_updated` (if `send_message_history_updates` is set to `true`) Args: parameters: The parameters described as a JSON Schema object that needs to be gathered by the voice assistant. See the [JSON Schema reference](https://json-schema.org/understanding-json-schema) for documentation about the format assistant: Assistant configuration including choice of LLM, custom instructions, and tools. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. gather_ended_speech: Text that will be played when the gathering has finished. There is a 3,000 character limit. greeting: Text that will be played when the gathering starts, if none then nothing will be played when the gathering starts. The greeting can be text for any voice or SSML for `AWS.Polly.` voices. There is a 3,000 character limit. interruption_settings: Settings for handling user interruptions during assistant speech language: Language to use for speech recognition message_history: The message history you want the voice assistant to be aware of, this can be useful to keep the context of the conversation, or to pass additional information to the voice assistant. send_message_history_updates: Default is `false`. If set to `true`, the voice assistant will send updates to the message history via the `call.ai_gather.message_history_updated` callback in real time as the message history is updated. send_partial_results: Default is `false`. If set to `true`, the voice assistant will send partial results via the `call.ai_gather.partial_results` callback in real time as individual fields are gathered. If set to `false`, the voice assistant will only send the final result via the `call.ai_gather.ended` callback. transcription: The settings associated with speech to text for the voice assistant. This is only relevant if the assistant uses a text-to-text language model. Any assistant using a model with native audio support (e.g. `fixie-ai/ultravox-v0_4`) will ignore this field. user_response_timeout_ms: The maximum time in milliseconds to wait for user response before timing out. voice: The voice to be used by the voice assistant. Currently we support ElevenLabs, Telnyx and AWS voices. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-CA-LiamNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.BaseModel.John`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration secret under `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/gather_using_ai", call_control_id=call_control_id), body=await async_maybe_transform( { "parameters": parameters, "assistant": assistant, "client_state": client_state, "command_id": command_id, "gather_ended_speech": gather_ended_speech, "greeting": greeting, "interruption_settings": interruption_settings, "language": language, "message_history": message_history, "send_message_history_updates": send_message_history_updates, "send_partial_results": send_partial_results, "transcription": transcription, "user_response_timeout_ms": user_response_timeout_ms, "voice": voice, "voice_settings": voice_settings, }, action_gather_using_ai_params.ActionGatherUsingAIParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingAIResponse, ) async def gather_using_audio( self, call_control_id: str, *, audio_url: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, invalid_audio_url: str | Omit = omit, invalid_media_name: str | Omit = omit, maximum_digits: int | Omit = omit, maximum_tries: int | Omit = omit, media_name: str | Omit = omit, minimum_digits: int | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingAudioResponse: """ Play an audio file on the call until the required DTMF signals are gathered to build interactive menus. You can pass a list of valid digits along with an 'invalid_audio_url', which will be played back at the beginning of each prompt. Playback will be interrupted when a DTMF signal is received. The `Answer command must be issued before the `gather_using_audio` command. **Expected Webhooks:** - `call.playback.started` - `call.playback.ended` - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: audio_url: The URL of a file to be played back at the beginning of each prompt. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. invalid_audio_url: The URL of a file to play when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. The URL can point to either a WAV or MP3 file. invalid_media_name and invalid_audio_url cannot be used together in one request. invalid_media_name: The media_name of a file to be played back when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. maximum_tries: The maximum number of times the file should be played if there is no input from the user on the call. media_name: The media_name of a file to be played back at the beginning of each prompt. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait for a DTMF response after file playback ends before a replaying the sound file. valid_digits: A list of all digits accepted as valid. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/gather_using_audio", call_control_id=call_control_id), body=await async_maybe_transform( { "audio_url": audio_url, "client_state": client_state, "command_id": command_id, "inter_digit_timeout_millis": inter_digit_timeout_millis, "invalid_audio_url": invalid_audio_url, "invalid_media_name": invalid_media_name, "maximum_digits": maximum_digits, "maximum_tries": maximum_tries, "media_name": media_name, "minimum_digits": minimum_digits, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, }, action_gather_using_audio_params.ActionGatherUsingAudioParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingAudioResponse, ) async def gather_using_speak( self, call_control_id: str, *, payload: str, voice: str, client_state: str | Omit = omit, command_id: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, invalid_payload: str | Omit = omit, language: Literal[ "arb", "cmn-CN", "cy-GB", "da-DK", "de-DE", "en-AU", "en-GB", "en-GB-WLS", "en-IN", "en-US", "es-ES", "es-MX", "es-US", "fr-CA", "fr-FR", "hi-IN", "is-IS", "it-IT", "ja-JP", "ko-KR", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sv-SE", "tr-TR", ] | Omit = omit, maximum_digits: int | Omit = omit, maximum_tries: int | Omit = omit, minimum_digits: int | Omit = omit, payload_type: Literal["text", "ssml"] | Omit = omit, service_level: Literal["basic", "premium"] | Omit = omit, terminating_digit: str | Omit = omit, timeout_millis: int | Omit = omit, valid_digits: str | Omit = omit, voice_settings: action_gather_using_speak_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionGatherUsingSpeakResponse: """ Convert text to speech and play it on the call until the required DTMF signals are gathered to build interactive menus. You can pass a list of valid digits along with an 'invalid_payload', which will be played back at the beginning of each prompt. Speech will be interrupted when a DTMF signal is received. The `Answer` command must be issued before the `gather_using_speak` command. **Expected Webhooks:** - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended` Args: payload: The text or SSML to be converted into speech. There is a 3,000 character limit. voice: Specifies the voice used in speech synthesis. - Define voices using the format `..`. Specifying only the provider will give default values for voice_id and model_id. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). Use `voice_settings` to configure custom deployments, regions, or API keys. - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.eleven_multilingual_v2.21m00Tcm4TlvDq8ikWAM`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration identifier secret in `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` (e.g., `Telnyx.KokoroTTS.af`). Use `voice_settings` to configure voice_speed and other synthesis parameters. `Bayan` provides Arabic (multiple dialects) and English voices (e.g., `Telnyx.Bayan.Ahmed`, `Telnyx.Bayan.Amanda`). `Sukhan` provides Urdu voices (e.g., `Telnyx.Sukhan.urdu-professor`); `voice_speed` is not supported. - **Minimax:** Use `Minimax..` (e.g., `Minimax.speech-02-hd.Wise_Woman`). Supported models: `speech-02-turbo`, `speech-02-hd`, `speech-2.6-turbo`, `speech-2.8-turbo`. Use `voice_settings` to configure speed, volume, pitch, and language_boost. - **Resemble:** Use `Resemble..` (e.g., `Resemble.Turbo.Aaron_en-US`). Supported models: `Pro`, `Turbo`, `Urdu`. `` is a stock voice name or the ID of a Resemble voice clone. Use `voice_settings` to configure precision, sample_rate, and format. - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. Use `voice_settings` to configure `delivery_mode` (`STABLE`, `BALANCED`, `CREATIVE`), supported by `TTS2` only. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. For service_level basic, you may define the gender of the speaker (male or female). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. inter_digit_timeout_millis: The number of milliseconds to wait for input between digits. invalid_payload: The text or SSML to be converted into speech when digits don't match the `valid_digits` parameter or the number of digits is not between `min` and `max`. There is a 3,000 character limit. language: The language you want spoken. This parameter is ignored when a `Polly.*` voice is specified. maximum_digits: The maximum number of digits to fetch. This parameter has a maximum value of 128. maximum_tries: The maximum number of times that a file should be played back if there is no input from the user on the call. minimum_digits: The minimum number of digits to fetch. This parameter has a minimum value of 1. payload_type: The type of the provided payload. The payload can either be plain text, or Speech Synthesis Markup Language (SSML). service_level: This parameter impacts speech quality, language options and payload types. When using `basic`, only the `en-US` language and payload type `text` are allowed. terminating_digit: The digit used to terminate input if fewer than `maximum_digits` digits have been gathered. Set to an empty string to disable the terminating digit entirely, so that a digit such as `#` can be collected as input per `valid_digits`. timeout_millis: The number of milliseconds to wait for a DTMF response after speak ends before a replaying the sound file. valid_digits: A list of all digits accepted as valid. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/gather_using_speak", call_control_id=call_control_id), body=await async_maybe_transform( { "payload": payload, "voice": voice, "client_state": client_state, "command_id": command_id, "inter_digit_timeout_millis": inter_digit_timeout_millis, "invalid_payload": invalid_payload, "language": language, "maximum_digits": maximum_digits, "maximum_tries": maximum_tries, "minimum_digits": minimum_digits, "payload_type": payload_type, "service_level": service_level, "terminating_digit": terminating_digit, "timeout_millis": timeout_millis, "valid_digits": valid_digits, "voice_settings": voice_settings, }, action_gather_using_speak_params.ActionGatherUsingSpeakParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionGatherUsingSpeakResponse, ) async def hangup( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, reason: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionHangupResponse: """ Hang up the call. **Expected Webhooks:** - `call.hangup` - `call.recording.saved` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_headers: Custom headers to be added to the SIP BYE message. reason: Text for the SIP `Reason` header (RFC 3326) sent when cancelling an unanswered outbound leg. The SIP CANCEL carries `Reason: SIP;cause=200;text=""`; phones such as Poly and Yealink use it to suppress the missed-call entry for a call answered elsewhere. Has no effect on an answered leg or an inbound leg. A hangup sent before the leg's `call.initiated` webhook still hangs up the leg, but without the `Reason` header. Must not contain `"`, `\\``, control characters, or characters outside the Basic Multilingual Plane (such as emoji); invalid values are rejected with a 422. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/hangup", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "reason": reason, }, action_hangup_params.ActionHangupParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionHangupResponse, ) async def join_ai_assistant( self, call_control_id: str, *, conversation_id: str, participant: AIAssistantJoinParticipantParam, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionJoinAIAssistantResponse: """Add a participant to an existing AI assistant conversation. Use this command to bring an additional call leg into a running AI conversation. Args: conversation_id: The ID of the AI assistant conversation to join. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_join", call_control_id=call_control_id), body=await async_maybe_transform( { "conversation_id": conversation_id, "participant": participant, "client_state": client_state, "command_id": command_id, }, action_join_ai_assistant_params.ActionJoinAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionJoinAIAssistantResponse, ) async def leave_queue( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionLeaveQueueResponse: """Removes the call from the queue it is currently waiting in. The call remains active and can be directed with further call commands. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/leave_queue", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_leave_queue_params.ActionLeaveQueueParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionLeaveQueueResponse, ) async def pause_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionPauseRecordingResponse: """Pause recording the call. Recording can be resumed via Resume recording command. **Expected Webhooks:** There are no webhooks associated with this command. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/record_pause", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_pause_recording_params.ActionPauseRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionPauseRecordingResponse, ) async def pay( self, call_control_id: str, *, amount: float | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, connector_name: str | Omit = omit, currency: Literal["USD", "usd"] | Omit = omit, description: str | Omit = omit, inter_digit_timeout_millis: int | Omit = omit, language: str | Omit = omit, max_attempts: int | Omit = omit, metadata: Dict[str, object] | Omit = omit, min_postal_code_length: int | Omit = omit, parameters: Dict[str, object] | Omit = omit, payment_method: Literal["credit-card", "ach-debit"] | Omit = omit, payment_token: str | Omit = omit, postal_code: Union[str, bool] | Omit = omit, prompts: action_pay_params.Prompts | Omit = omit, service_level: str | Omit = omit, timeout_millis: int | Omit = omit, transaction_type: Literal["charge", "tokenize"] | Omit = omit, valid_card_types: List[ Literal["visa", "mastercard", "amex", "maestro", "discover", "optima", "jcb", "diners-club", "enroute"] ] | Omit = omit, voice: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionPayResponse: """ Collect payment details from the caller using DTMF and either charge or tokenize the payment method through a configured Pay connector. Pay pauses active call recordings while sensitive payment details are collected. When `payment_token` is supplied, the DTMF collection steps are skipped and the existing token is sent to the connector. **Expected Webhooks:** - `call.payment.progress` - `call.payment.completed` **Test mode card numbers:** `4111111111111111` (Visa), `5555555555554444` (Mastercard), `378282246310005` (American Express), `6011111111111117` (Discover), `3065930009020004` (Diners Club), `3566002020360505` (JCB), `6200000000000005` (UnionPay), and `6771798021000008` (Maestro). Test-mode connectors reject other card numbers before contacting the configured processor. The UnionPay and Maestro numbers are accepted for processor testing, but Pay currently does not emit a card type for them. Args: amount: Amount to charge. Required when `transaction_type` is `charge`. client_state: Base64-encoded state included in subsequent webhooks. command_id: Idempotency key for the command. Telnyx ignores a duplicate command with the same `command_id` for the same `call_control_id`. connector_name: Name of the Pay connector used to process the transaction. currency: Currency used for the transaction. Pay currently supports USD only. description: Optional description forwarded with the payment transaction. inter_digit_timeout_millis: Time in milliseconds to wait between consecutive DTMF digits. language: Language used for payment prompts. max_attempts: Maximum number of attempts for each payment collection step. metadata: Metadata forwarded to the Pay connector. min_postal_code_length: Minimum number of digits the caller must enter when collecting a credit-card billing postal code. Applies only when `postal_code` is `true` or `"true"` and no `payment_token` is supplied. The default is 1. The maximum number of digits collected is the greater of 10 and this value. This does not validate the length of a postal code supplied directly in `postal_code`. parameters: Additional parameters forwarded to the Pay connector. payment_method: Payment method to collect. payment_token: Existing payment token. When supplied, payment-detail collection is skipped. postal_code: Controls billing postal code collection for credit-card payments when no `payment_token` is supplied. Set to `true` or the string `"true"` (the default) to prompt the caller for a postal code. Set to `false` or the string `"false"` to skip the postal code prompt without supplying a postal code to the payment connector. Supply any other non-empty string, such as `"90210"`, to use that postal code without prompting. Empty or whitespace-only strings are rejected. This option does not affect ACH debit payments or payments using an existing token. prompts: Custom text-to-speech prompts keyed by payment collection step. service_level: Speech synthesis service level used for payment prompts. Pay defaults to `premium`. timeout_millis: Time in milliseconds to wait for DTMF input for each collection step. transaction_type: Transaction to perform. If omitted, Pay infers `tokenize` when `amount` is absent or zero and `charge` when `amount` is positive. valid_card_types: Restricts accepted card numbers to the listed card types. When the caller enters a card number that does not match one of the listed types, Pay treats the input as invalid and re-prompts for the card number. Cannot be used together with `payment_token`. voice: Voice used for payment prompts. Accepts `male`, `female`, or a provider voice in `..` format, for example `AWS.Polly.Joanna` or `Telnyx.KokoroTTS.af`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/pay", call_control_id=call_control_id), body=await async_maybe_transform( { "amount": amount, "client_state": client_state, "command_id": command_id, "connector_name": connector_name, "currency": currency, "description": description, "inter_digit_timeout_millis": inter_digit_timeout_millis, "language": language, "max_attempts": max_attempts, "metadata": metadata, "min_postal_code_length": min_postal_code_length, "parameters": parameters, "payment_method": payment_method, "payment_token": payment_token, "postal_code": postal_code, "prompts": prompts, "service_level": service_level, "timeout_millis": timeout_millis, "transaction_type": transaction_type, "valid_card_types": valid_card_types, "voice": voice, }, action_pay_params.ActionPayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionPayResponse, ) async def refer( self, call_control_id: str, *, sip_address: str, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionReferResponse: """Initiate a SIP Refer on a Call Control call. You can initiate a SIP Refer at any point in the duration of a call. **Expected Webhooks:** - `call.refer.started` - `call.refer.completed` - `call.refer.failed` Args: sip_address: The SIP URI to which the call will be referred to. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid execution of duplicate commands. Telnyx will ignore subsequent commands with the same `command_id` as one that has already been executed. custom_headers: Custom headers to be added to the SIP INVITE. sip_auth_password: SIP Authentication password used for SIP challenges. sip_auth_username: SIP Authentication username used for SIP challenges. sip_headers: SIP headers to be added to the request. Currently only User-to-User header is supported. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/refer", call_control_id=call_control_id), body=await async_maybe_transform( { "sip_address": sip_address, "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_headers": sip_headers, }, action_refer_params.ActionReferParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionReferResponse, ) async def reject( self, call_control_id: str, *, cause: Literal["CALL_REJECTED", "NOT_FOUND", "TEMPORARILY_UNAVAILABLE", "USER_BUSY"], client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionRejectResponse: """ Reject an incoming call. **Expected Webhooks:** - `call.hangup` Args: cause: Cause for call rejection. The cause sets the SIP response the caller receives: `USER_BUSY` sends 486 User Busy, `CALL_REJECTED` sends 603 Decline, `NOT_FOUND` sends 404 Not Found, and `TEMPORARILY_UNAVAILABLE` sends 480 Temporarily Unavailable. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/reject", call_control_id=call_control_id), body=await async_maybe_transform( { "cause": cause, "client_state": client_state, "command_id": command_id, }, action_reject_params.ActionRejectParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionRejectResponse, ) async def resume_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionResumeRecordingResponse: """ Resume recording the call. **Expected Webhooks:** There are no webhooks associated with this command. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/record_resume", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_resume_recording_params.ActionResumeRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionResumeRecordingResponse, ) async def send_dtmf( self, call_control_id: str, *, digits: str, client_state: str | Omit = omit, command_id: str | Omit = omit, duration_millis: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSendDtmfResponse: """Sends DTMF tones from this leg. DTMF tones will be heard by the other end of the call. **Expected Webhooks:** There are no webhooks associated with this command. Args: digits: DTMF digits to send. Valid digits are 0-9, A-D, \\**, and #. Pauses can be added using w (0.5s) and W (1s). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. duration_millis: Specifies for how many milliseconds each digit will be played in the audio stream. Ranges from 100 to 500ms extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/send_dtmf", call_control_id=call_control_id), body=await async_maybe_transform( { "digits": digits, "client_state": client_state, "command_id": command_id, "duration_millis": duration_millis, }, action_send_dtmf_params.ActionSendDtmfParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSendDtmfResponse, ) async def send_sip_info( self, call_control_id: str, *, body: str, content_type: str, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSendSipInfoResponse: """ Sends SIP info from this leg. **Expected Webhooks:** - `call.sip_info.received` (to be received on the target call leg) Args: body: Content of the SIP INFO content_type: Content type of the INFO body. Must be MIME type compliant. There is a 1,400 bytes limit client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/send_sip_info", call_control_id=call_control_id), body=await async_maybe_transform( { "body": body, "content_type": content_type, "client_state": client_state, "command_id": command_id, }, action_send_sip_info_params.ActionSendSipInfoParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSendSipInfoResponse, ) async def speak( self, call_control_id: str, *, payload: str, voice: str, client_state: str | Omit = omit, command_id: str | Omit = omit, language: Literal[ "arb", "cmn-CN", "cy-GB", "da-DK", "de-DE", "en-AU", "en-GB", "en-GB-WLS", "en-IN", "en-US", "es-ES", "es-MX", "es-US", "fr-CA", "fr-FR", "hi-IN", "is-IS", "it-IT", "ja-JP", "ko-KR", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sv-SE", "tr-TR", ] | Omit = omit, loop: LoopcountParam | Omit = omit, payload_type: Literal["text", "ssml"] | Omit = omit, service_level: Literal["basic", "premium"] | Omit = omit, stop: str | Omit = omit, target_legs: Literal["self", "opposite", "both"] | Omit = omit, voice_settings: action_speak_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSpeakResponse: """Convert text to speech and play it back on the call. If multiple speak text commands are issued consecutively, the audio files will be placed in a queue awaiting playback. **Expected Webhooks:** - `call.speak.started` - `call.speak.ended` Args: payload: The text or SSML to be converted into speech. There is a 3,000 character limit. voice: Specifies the voice used in speech synthesis. - Define voices using the format `..`. Specifying only the provider will give default values for voice_id and model_id. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). Use `voice_settings` to configure custom deployments, regions, or API keys. - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.eleven_multilingual_v2.21m00Tcm4TlvDq8ikWAM`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration identifier secret in `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` (e.g., `Telnyx.KokoroTTS.af`). Use `voice_settings` to configure voice_speed and other synthesis parameters. `Bayan` provides Arabic (multiple dialects) and English voices (e.g., `Telnyx.Bayan.Ahmed`, `Telnyx.Bayan.Amanda`). `Sukhan` provides Urdu voices (e.g., `Telnyx.Sukhan.urdu-professor`); `voice_speed` is not supported. - **Minimax:** Use `Minimax..` (e.g., `Minimax.speech-02-hd.Wise_Woman`). Supported models: `speech-02-turbo`, `speech-02-hd`, `speech-2.6-turbo`, `speech-2.8-turbo`. Use `voice_settings` to configure speed, volume, pitch, and language_boost. - **Resemble:** Use `Resemble..` (e.g., `Resemble.Turbo.Aaron_en-US`). Supported models: `Pro`, `Turbo`, `Urdu`. `` is a stock voice name or the ID of a Resemble voice clone. Use `voice_settings` to configure precision, sample_rate, and format. - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. Use `voice_settings` to configure `delivery_mode` (`STABLE`, `BALANCED`, `CREATIVE`), supported by `TTS2` only. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. For service_level basic, you may define the gender of the speaker (male or female). client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. language: The language you want spoken. This parameter is ignored when a `Polly.*` voice is specified. loop: The number of times to play the audio file. Use `infinity` to loop indefinitely. Defaults to 1. payload_type: The type of the provided payload. The payload can either be plain text, or Speech Synthesis Markup Language (SSML). service_level: This parameter impacts speech quality, language options and payload types. When using `basic`, only the `en-US` language and payload type `text` are allowed. stop: When specified, it stops the current audio being played. Specify `current` to stop the current audio being played, and to play the next file in the queue. Specify `all` to stop the current audio file being played and to also clear all audio files from the queue. target_legs: Specifies which legs of the call should receive the spoken audio. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/speak", call_control_id=call_control_id), body=await async_maybe_transform( { "payload": payload, "voice": voice, "client_state": client_state, "command_id": command_id, "language": language, "loop": loop, "payload_type": payload_type, "service_level": service_level, "stop": stop, "target_legs": target_legs, "voice_settings": voice_settings, }, action_speak_params.ActionSpeakParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSpeakResponse, ) async def start_ai_assistant( self, call_control_id: str, *, assistant: CallAssistantRequestParam | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, greeting: str | Omit = omit, interruption_settings: InterruptionSettingsParam | Omit = omit, message_history: Iterable[action_start_ai_assistant_params.MessageHistory] | Omit = omit, participants: Iterable[AIAssistantJoinParticipantParam] | Omit = omit, send_message_history_updates: bool | Omit = omit, transcription: TranscriptionConfigParam | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartAIAssistantResponse: """ Start an AI assistant on the call. **Expected Webhooks:** - [`call.conversation.created`](/api-reference/callbacks/call-conversation-created) includes `conversation_id` during startup - `call.conversation.ended` - `call.conversation_insights.generated` Args: assistant: AI Assistant configuration and per-call overrides. All fields except `id` are optional. Omitted assistant fields use the stored configuration. Supplied `voice_settings` and `transcription` objects replace their stored objects rather than merging individual settings; include every setting you want to retain. `dynamic_variables` are merged, with request values taking precedence. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. greeting: Text that will be played when the assistant starts, if none then nothing will be played when the assistant starts. The greeting can be text for any voice or SSML for `AWS.Polly.` voices. There is a 3,000 character limit. interruption_settings: Settings for handling user interruptions during assistant speech message_history: A list of messages to seed the conversation history before the assistant starts. Follows the same message format as the `ai_assistant_add_messages` command. participants: A list of participants to add to the conversation when it starts. send_message_history_updates: When `true`, a `call.ai_gather.message_history_updated` webhook carrying the full message history is sent each time the conversation message history is updated. The assistant's own `telephony_settings.send_message_history_updates` overrides this value when it is set. transcription: The settings associated with speech to text for the voice assistant. This is only relevant if the assistant uses a text-to-text language model. Any assistant using a model with native audio support (e.g. `fixie-ai/ultravox-v0_4`) will ignore this field. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_start", call_control_id=call_control_id), body=await async_maybe_transform( { "assistant": assistant, "client_state": client_state, "command_id": command_id, "greeting": greeting, "interruption_settings": interruption_settings, "message_history": message_history, "participants": participants, "send_message_history_updates": send_message_history_updates, "transcription": transcription, }, action_start_ai_assistant_params.ActionStartAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartAIAssistantResponse, ) async def start_conversation_relay( self, call_control_id: str, *, assistant: action_start_conversation_relay_params.Assistant | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, conversation_relay_dtmf_detection: bool | Omit = omit, conversation_relay_settings: action_start_conversation_relay_params.ConversationRelaySettings | Omit = omit, conversation_relay_url: str | Omit = omit, custom_parameters: Dict[str, object] | Omit = omit, dtmf_detection: bool | Omit = omit, greeting: str | Omit = omit, interruptible: ConversationRelayInterruptible | Omit = omit, interruptible_greeting: ConversationRelayInterruptible | Omit = omit, interruption_settings: ConversationRelayInterruptionSettingsParam | Omit = omit, language: str | Omit = omit, languages: Iterable[ConversationRelayLanguageParam] | Omit = omit, provider: str | Omit = omit, structured_provider: Dict[str, object] | Omit = omit, transcription: Dict[str, object] | Omit = omit, transcription_engine: Literal[ "Google", "Telnyx", "Deepgram", "Azure", "xAI", "AssemblyAI", "Speechmatics", "Soniox", "A", "B" ] | Omit = omit, transcription_engine_config: ConversationRelayTranscriptionEngineConfigParam | Omit = omit, tts_provider: str | Omit = omit, url: str | Omit = omit, voice: str | Omit = omit, voice_settings: action_start_conversation_relay_params.VoiceSettings | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartConversationRelayResponse: """Start a Conversation Relay session on an active call. Conversation Relay connects the call audio to your WebSocket so your application can exchange realtime messages with the caller while Telnyx handles speech recognition and text-to-speech. Only one AI Assistant or Conversation Relay session can be active on a call at a time. **Expected Webhooks:** - `call.conversation.ended` - Sent when the Conversation Relay session ends. If the customer WebSocket disconnects, the webhook payload `reason` is `customer_disconnect`. Args: assistant: Custom parameters for the Conversation Relay session. Pass key-value data as `assistant.dynamic_variables` to make it available to the relay session. client_state: Use this field to add state to subsequent webhooks. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. conversation_relay_dtmf_detection: Enable DTMF detection for the relay session. conversation_relay_settings: Conversation Relay connection settings. This object can provide `url`, `dtmf_detection`, `interruptible`, `interruptible_greeting`, and `languages`. Top-level aliases override nested values when both are present. conversation_relay_url: WebSocket URL for your Conversation Relay server. Must start with `ws://` or `wss://`. custom_parameters: Custom key-value parameters forwarded to the relay session as `assistant.dynamic_variables`. If `assistant.dynamic_variables` is also present, these values are merged in. dtmf_detection: Public alias for `conversation_relay_dtmf_detection`. If both are present, this value wins. greeting: Text played when the relay session starts. interruptible: Controls when caller input can interrupt assistant speech. `any` allows speech or DTMF interruptions; `none` disables interruptions; `speech` allows speech only; `dtmf` allows DTMF only. interruptible_greeting: Controls when caller input can interrupt assistant speech. `any` allows speech or DTMF interruptions; `none` disables interruptions; `speech` allows speech only; `dtmf` allows DTMF only. interruption_settings: Settings for handling caller interruptions during Conversation Relay speech. language: Default language for the relay session. This value is used for both text-to-speech and speech recognition. languages: Per-language TTS and transcription settings. provider: Structured voice provider. Must be supplied together with `structured_provider`. structured_provider: Provider-specific structured voice settings. Must be supplied together with `provider`; Telnyx sends the value as the nested provider configuration for Conversation Relay. transcription: Not supported for Conversation Relay start requests. Use `transcription_engine` and `transcription_engine_config` instead. transcription_engine: Engine to use for speech recognition. Legacy values `A` - `Google`, `B` - `Telnyx` are supported for backward compatibility. For Conversation Relay, use this field with `transcription_engine_config`; the `transcription` object is not supported. transcription_engine_config: Engine-specific transcription settings for Conversation Relay. This accepts the same provider-specific options used by the Call Transcription Start command, such as `transcription_model`, without requiring the engine discriminator to be repeated inside this object. With Deepgram Flux (`deepgram/flux`), `interim_results`, `eot_threshold` and `eager_eot_threshold` control the interim prompts and the `eagerEndOfTurn` and `turnResumed` frames sent to your WebSocket server. tts_provider: Text-to-speech provider. If omitted, Telnyx derives it from `voice` or `provider`. url: Public alias for `conversation_relay_url`. Must start with `ws://` or `wss://`. If both are present, this value wins. voice: The voice to be used by the voice assistant. Currently we support ElevenLabs, Telnyx and AWS voices. **Supported Providers:** - **AWS:** Use `AWS.Polly.` (e.g., `AWS.Polly.Joanna`). For neural voices, which provide more realistic, human-like speech, append `-Neural` to the `VoiceId` (e.g., `AWS.Polly.Joanna-Neural`). Check the [available voices](https://docs.aws.amazon.com/polly/latest/dg/available-voices.html) for compatibility. - **Azure:** Use `Azure.` (e.g., `Azure.en-CA-ClaraNeural`, `Azure.en-CA-LiamNeural`, `Azure.en-US-BrianMultilingualNeural`, `Azure.en-US-Ava:DragonHDLatestNeural`). For a complete list of voices, go to [Azure Voice Gallery](https://speech.microsoft.com/portal/voicegallery). - **ElevenLabs:** Use `ElevenLabs..` (e.g., `ElevenLabs.BaseModel.John`). The `ModelId` part is optional. To use ElevenLabs, you must provide your ElevenLabs API key as an integration secret under `"voice_settings": {"api_key_ref": ""}`. See [integration secrets documentation](https://developers.telnyx.com/api/secrets-manager/integration-secrets/create-integration-secret) for details. Check [available voices](https://elevenlabs.io/docs/api-reference/get-voices). - **Telnyx:** Use `Telnyx..` - **Inworld:** Use `Inworld..` (e.g., `Inworld.Mini.Loretta`, `Inworld.Max.Oliver`, `Inworld.TTS2.Loretta`). Supported models: `Mini`, `Max`, `TTS2`. - **Fish Audio:** Use `FishAudio..` (e.g., `FishAudio.s2.1-pro.`). Supported models: `s2.1-pro`, `s2-pro`, `s1`. `VoiceId` is a Fish Voice-Library reference ID. - **Soniox:** Use `Soniox..` (e.g., `Soniox.tts-rt-v2.Emma`). Supported model: `tts-rt-v2`. Browse the catalog via the [Voices API](https://developers.telnyx.com/api-reference/text-to-speech-commands/list-available-voices). Every voice speaks all supported languages; set `language` to the two-letter ISO 639-1 code of the text, for example `it`. SSML is not supported. Use `voice_settings` to configure `speed` (0.7 to 1.3) and `reduce_silence`. - **xAI:** Use `xAI.` (e.g., `xAI.eve`). Available voices: `eve`, `ara`, `rex`, `sal`, `leo`. - **Humain:** Use `Humain.` (e.g., `Humain.sara-ar`). Available voices: `sara-en`, `abdulaziz-en`, `sara-ar`, `abdulaziz-ar`, `nourah-ar`, `abdullah-ar`. Native Arabic (Saudi dialect) and English voices only — no `ModelId` segment. voice_settings: The settings associated with the voice selected extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/conversation_relay_start", call_control_id=call_control_id), body=await async_maybe_transform( { "assistant": assistant, "client_state": client_state, "command_id": command_id, "conversation_relay_dtmf_detection": conversation_relay_dtmf_detection, "conversation_relay_settings": conversation_relay_settings, "conversation_relay_url": conversation_relay_url, "custom_parameters": custom_parameters, "dtmf_detection": dtmf_detection, "greeting": greeting, "interruptible": interruptible, "interruptible_greeting": interruptible_greeting, "interruption_settings": interruption_settings, "language": language, "languages": languages, "provider": provider, "structured_provider": structured_provider, "transcription": transcription, "transcription_engine": transcription_engine, "transcription_engine_config": transcription_engine_config, "tts_provider": tts_provider, "url": url, "voice": voice, "voice_settings": voice_settings, }, action_start_conversation_relay_params.ActionStartConversationRelayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartConversationRelayResponse, ) async def start_forking( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, rx: str | Omit = omit, stream_type: Literal["decrypted"] | Omit = omit, tx: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartForkingResponse: """ Call forking allows you to stream the media from a call to a specific target in realtime. This stream can be used to enable realtime audio analysis to support a variety of use cases, including fraud detection, or the creation of AI-generated audio responses. Requests must specify either the `target` attribute or the `rx` and `tx` attributes. **Expected Webhooks:** - `call.fork.started` - `call.fork.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. rx: The network target, , where the call's incoming RTP media packets should be forwarded. stream_type: Optionally specify a media type to stream. If `decrypted` selected, Telnyx will decrypt incoming SIP media before forking to the target. `rx` and `tx` are required fields if `decrypted` selected. tx: The network target, , where the call's outgoing RTP media packets should be forwarded. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/fork_start", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "rx": rx, "stream_type": stream_type, "tx": tx, }, action_start_forking_params.ActionStartForkingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartForkingResponse, ) async def start_noise_suppression( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, direction: Literal["inbound", "outbound", "both"] | Omit = omit, noise_suppression_engine: Literal[ "Denoiser", "DeepFilterNet", "Krisp", "AiCoustics", "aic_l_quail", "aic_l_rook", "aic_s_quail", "aic_s_rook", "quail_voice_focus_s", "quail_voice_focus_xs", ] | Omit = omit, noise_suppression_engine_config: action_start_noise_suppression_params.NoiseSuppressionEngineConfig | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartNoiseSuppressionResponse: """Start noise suppression on an active call to reduce background noise. This feature is currently in beta. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. direction: The direction of the audio stream to be noise suppressed. noise_suppression_engine: The engine to use for noise suppression. For backward compatibility, engines A, B, C, and D are also supported, but are deprecated: A - Denoiser B - DeepFilterNet C - Krisp D - AiCoustics noise_suppression_engine_config: Configuration parameters for noise suppression engines. Different engines support different parameters. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/suppression_start", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "direction": direction, "noise_suppression_engine": noise_suppression_engine, "noise_suppression_engine_config": noise_suppression_engine_config, }, action_start_noise_suppression_params.ActionStartNoiseSuppressionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartNoiseSuppressionResponse, ) async def start_playback( self, call_control_id: str, *, audio_type: Literal["mp3", "wav"] | Omit = omit, audio_url: str | Omit = omit, cache_audio: bool | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, loop: LoopcountParam | Omit = omit, media_name: str | Omit = omit, overlay: bool | Omit = omit, playback_content: str | Omit = omit, stop: str | Omit = omit, target_legs: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartPlaybackResponse: """Play an audio file on the call. If multiple play audio commands are issued consecutively, the audio files will be placed in a queue awaiting playback. _Notes:_ - When `overlay` is enabled, `target_legs` is limited to `self`. - A customer cannot Play Audio with `overlay=true` unless there is a Play Audio with `overlay=false` actively playing. **Expected Webhooks:** - `call.playback.started` - `call.playback.ended` Args: audio_type: Specifies the type of audio provided in `audio_url` or `playback_content`. audio_url: The URL of a file to be played back on the call. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. cache_audio: Caches the audio file. Useful when playing the same audio file multiple times during the call. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. loop: The number of times the audio file should be played. If supplied, the value must be an integer between 1 and 100, or the special string `infinity` for an endless loop. media_name: The media_name of a file to be played back on the call. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. overlay: When enabled, audio will be mixed on top of any other audio that is actively being played back. Note that `overlay: true` will only work if there is another audio file already being played on the call. playback_content: Allows a user to provide base64 encoded mp3 or wav. Note: when using this parameter, `media_url` and `media_name` in the `playback_started` and `playback_ended` webhooks will be empty stop: When specified, it stops the current audio being played. Specify `current` to stop the current audio being played, and to play the next file in the queue. Specify `all` to stop the current audio file being played and to also clear all audio files from the queue. target_legs: Specifies the leg or legs on which audio will be played. If supplied, the value must be either `self`, `opposite` or `both`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/playback_start", call_control_id=call_control_id), body=await async_maybe_transform( { "audio_type": audio_type, "audio_url": audio_url, "cache_audio": cache_audio, "client_state": client_state, "command_id": command_id, "loop": loop, "media_name": media_name, "overlay": overlay, "playback_content": playback_content, "stop": stop, "target_legs": target_legs, }, action_start_playback_params.ActionStartPlaybackParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartPlaybackResponse, ) async def start_recording( self, call_control_id: str, *, channels: Literal["single", "dual"], format: Literal["wav", "mp3"], client_state: str | Omit = omit, command_id: str | Omit = omit, custom_file_name: str | Omit = omit, max_length: int | Omit = omit, play_beep: bool | Omit = omit, recording_track: Literal["both", "inbound", "outbound"] | Omit = omit, timeout_secs: int | Omit = omit, transcription: bool | Omit = omit, transcription_engine: Literal["A", "B", "deepgram/nova-3"] | Omit = omit, transcription_language: Literal[ "af", "af-ZA", "am", "am-ET", "ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IL", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-MA", "ar-MR", "ar-OM", "ar-PS", "ar-QA", "ar-SA", "ar-TN", "ar-YE", "as", "auto_detect", "az", "az-AZ", "ba", "be", "bg", "bg-BG", "bn", "bn-BD", "bn-IN", "bo", "br", "bs", "bs-BA", "ca", "ca-ES", "cs", "cs-CZ", "cy", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", "el", "el-GR", "en", "en-AU", "en-CA", "en-GB", "en-GH", "en-HK", "en-IE", "en-IN", "en-KE", "en-NG", "en-NZ", "en-PH", "en-PK", "en-SG", "en-TZ", "en-US", "en-ZA", "es", "es-419", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et", "et-EE", "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", "fil-PH", "fo", "fr", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "gl", "gl-ES", "gu", "gu-IN", "ha", "haw", "he", "hi", "hi-IN", "hr", "hr-HR", "ht", "hu", "hu-HU", "hy", "hy-AM", "id", "id-ID", "is", "is-IS", "it", "it-CH", "it-IT", "iw-IL", "ja", "ja-JP", "jv-ID", "jw", "ka", "ka-GE", "kk", "kk-KZ", "km", "km-KH", "kn", "kn-IN", "ko", "ko-KR", "la", "lb", "ln", "lo", "lo-LA", "lt", "lt-LT", "lv", "lv-LV", "mg", "mi", "mk", "mk-MK", "ml", "ml-IN", "mn", "mn-MN", "mr", "mr-IN", "ms", "ms-MY", "mt", "my", "my-MM", "ne", "ne-NP", "nl", "nl-BE", "nl-NL", "nn", "no", "no-NO", "oc", "pa", "pa-Guru-IN", "pl", "pl-PL", "ps", "pt", "pt-BR", "pt-PT", "ro", "ro-RO", "ru", "ru-RU", "rw-RW", "sa", "sd", "si", "si-LK", "sk", "sk-SK", "sl", "sl-SI", "sn", "so", "sq", "sq-AL", "sr", "sr-RS", "ss-latn-za", "st-ZA", "su", "su-ID", "sv", "sv-SE", "sw", "sw-KE", "sw-TZ", "ta", "ta-IN", "ta-LK", "ta-MY", "ta-SG", "te", "te-IN", "tg", "th", "th-TH", "tk", "tl", "tn-latn-za", "tr", "tr-TR", "ts-ZA", "tt", "uk", "uk-UA", "ur", "ur-IN", "ur-PK", "uz", "uz-UZ", "ve-ZA", "vi", "vi-VN", "xh-ZA", "yi", "yo", "yue-Hant-HK", "zh", "zh-TW", "zu-ZA", ] | Omit = omit, transcription_max_speaker_count: int | Omit = omit, transcription_min_speaker_count: int | Omit = omit, transcription_profanity_filter: bool | Omit = omit, transcription_speaker_diarization: bool | Omit = omit, trim: Literal["trim-silence"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartRecordingResponse: """Start recording the call. Recording will stop on call hang-up, or can be initiated via the Stop Recording command. **Expected Webhooks:** - `call.recording.saved` - `call.recording.transcription.saved` - `call.recording.error` Args: channels: When `dual`, final audio file will be stereo recorded with the first leg on channel A, and the rest on channel B. format: The audio file format used when storing the call recording. Can be either `mp3` or `wav`. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. max_length: Defines the maximum length for the recording in seconds. The minimum value is 0. The maximum value is 14400. The default value is 0 (infinite) play_beep: If enabled, a beep sound will be played at the start of a recording. recording_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite) transcription: Enable post recording transcription. The default value is false. transcription_engine: Engine to use for speech recognition. `A` - `Google`, `B` - `Telnyx`, `deepgram/nova-3` - `Deepgram Nova-3`. Note: `deepgram/nova-3` supports only `en` and `en-{Region}` languages. transcription_language: Language code for transcription. Note: Not all languages are supported by all transcription engines (google, telnyx, deepgram). See engine-specific documentation for supported values. transcription_max_speaker_count: Defines maximum number of speakers in the conversation. Applies to `google` engine only. transcription_min_speaker_count: Defines minimum number of speakers in the conversation. Applies to `google` engine only. transcription_profanity_filter: Enables profanity_filter. Applies to `google` engine only. transcription_speaker_diarization: Enables speaker diarization. Applies to `google` engine only. trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/record_start", call_control_id=call_control_id), body=await async_maybe_transform( { "channels": channels, "format": format, "client_state": client_state, "command_id": command_id, "custom_file_name": custom_file_name, "max_length": max_length, "play_beep": play_beep, "recording_track": recording_track, "timeout_secs": timeout_secs, "transcription": transcription, "transcription_engine": transcription_engine, "transcription_language": transcription_language, "transcription_max_speaker_count": transcription_max_speaker_count, "transcription_min_speaker_count": transcription_min_speaker_count, "transcription_profanity_filter": transcription_profanity_filter, "transcription_speaker_diarization": transcription_speaker_diarization, "trim": trim, }, action_start_recording_params.ActionStartRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartRecordingResponse, ) async def start_siprec( self, call_control_id: str, *, client_state: str | Omit = omit, connector_name: str | Omit = omit, include_metadata_custom_headers: Literal[True, False] | Omit = omit, secure: Literal[True, False] | Omit = omit, session_timeout_secs: int | Omit = omit, sip_transport: Literal["udp", "tcp", "tls"] | Omit = omit, siprec_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartSiprecResponse: """ Start siprec session to configured in SIPREC connector SRS. **Expected Webhooks:** - `siprec.started` - `siprec.stopped` - `siprec.failed` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. connector_name: Name of configured SIPREC connector to be used. include_metadata_custom_headers: When set, custom parameters will be added as metadata (recording.session.ExtensionParameters). Otherwise, they’ll be added to sip headers. secure: Controls whether to encrypt media sent to your SRS using SRTP and TLS. When set you need to configure SRS port in your connector to 5061. session_timeout_secs: Sets `Session-Expires` header to the INVITE. A reinvite is sent every half the value set. Usefull for session keep alive. Minimum value is 90, set to 0 to disable. sip_transport: Specifies SIP transport protocol. siprec_track: Specifies which track should be sent on siprec session. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/siprec_start", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "connector_name": connector_name, "include_metadata_custom_headers": include_metadata_custom_headers, "secure": secure, "session_timeout_secs": session_timeout_secs, "sip_transport": sip_transport, "siprec_track": siprec_track, }, action_start_siprec_params.ActionStartSiprecParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartSiprecResponse, ) async def start_streaming( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_parameters: Iterable[action_start_streaming_params.CustomParameter] | Omit = omit, dialogflow_config: DialogflowConfigParam | Omit = omit, enable_dialogflow: bool | Omit = omit, stream_auth_token: str | Omit = omit, stream_bidirectional_codec: StreamBidirectionalCodec | Omit = omit, stream_bidirectional_mode: StreamBidirectionalMode | Omit = omit, stream_bidirectional_sampling_rate: StreamBidirectionalSamplingRate | Omit = omit, stream_bidirectional_target_legs: StreamBidirectionalTargetLegs | Omit = omit, stream_codec: StreamCodec | Omit = omit, stream_track: Literal["inbound_track", "outbound_track", "both_tracks"] | Omit = omit, stream_url: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartStreamingResponse: """ Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime. Audio will be delivered as base64-encoded RTP payload (raw audio), wrapped in JSON payloads. Please find more details about media streaming messages specification under the [link](https://developers.telnyx.com/docs/voice/programmable-voice/media-streaming). Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_parameters: Custom parameters to be sent as part of the WebSocket connection. enable_dialogflow: Enables Dialogflow for the current call. The default value is false. stream_auth_token: An authentication token to be sent as part of the WebSocket connection. Maximum length is 4000 characters. stream_bidirectional_codec: Indicates codec for bidirectional streaming RTP payloads. Used only with stream_bidirectional_mode=rtp. Case sensitive. stream_bidirectional_mode: Configures method of bidirectional streaming (mp3, rtp). stream_bidirectional_sampling_rate: Audio sampling rate. stream_bidirectional_target_legs: Specifies which call legs should receive the bidirectional stream audio. stream_codec: Specifies the codec to be used for the streamed audio. When set to 'default' or when transcoding is not possible, the codec from the call will be used. stream_track: Specifies which track should be streamed. stream_url: The destination WebSocket address where the stream is going to be delivered. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/streaming_start", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "custom_parameters": custom_parameters, "dialogflow_config": dialogflow_config, "enable_dialogflow": enable_dialogflow, "stream_auth_token": stream_auth_token, "stream_bidirectional_codec": stream_bidirectional_codec, "stream_bidirectional_mode": stream_bidirectional_mode, "stream_bidirectional_sampling_rate": stream_bidirectional_sampling_rate, "stream_bidirectional_target_legs": stream_bidirectional_target_legs, "stream_codec": stream_codec, "stream_track": stream_track, "stream_url": stream_url, }, action_start_streaming_params.ActionStartStreamingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartStreamingResponse, ) async def start_transcription( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, transcription_engine: Literal[ "Google", "Telnyx", "Deepgram", "Azure", "xAI", "AssemblyAI", "Speechmatics", "Soniox", "Parakeet", "Humain", "Reson8", "Cohere", "A", "B", ] | Omit = omit, transcription_engine_config: action_start_transcription_params.TranscriptionEngineConfig | Omit = omit, transcription_tracks: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStartTranscriptionResponse: """Start real-time transcription. Transcription will stop on call hang-up, or can be initiated via the Transcription stop command. **Expected Webhooks:** - `call.transcription` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. transcription_engine: Engine to use for speech recognition. Legacy values `A` - `Google`, `B` - `Telnyx` are supported for backward compatibility. transcription_tracks: Indicates which leg of the call will be transcribed. Use `inbound` for the leg that requested the transcription, `outbound` for the other leg, and `both` for both legs of the call. Will default to `inbound`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/transcription_start", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "transcription_engine": transcription_engine, "transcription_engine_config": transcription_engine_config, "transcription_tracks": transcription_tracks, }, action_start_transcription_params.ActionStartTranscriptionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStartTranscriptionResponse, ) async def stop_ai_assistant( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopAIAssistantResponse: """Stops the AI assistant currently engaged on the call. The call remains active and can continue with other call control commands. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/ai_assistant_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_ai_assistant_params.ActionStopAIAssistantParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopAIAssistantResponse, ) async def stop_conversation_relay( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopConversationRelayResponse: """ Stop the active Conversation Relay session on a call. Args: client_state: Use this field to add state to subsequent webhooks. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/conversation_relay_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_conversation_relay_params.ActionStopConversationRelayParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopConversationRelayResponse, ) async def stop_forking( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, stream_type: Literal["raw", "decrypted"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopForkingResponse: """ Stop forking a call. **Expected Webhooks:** - `call.fork.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. stream_type: Optionally specify a `stream_type`. This should match the `stream_type` that was used in `fork_start` command to properly stop the fork. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/fork_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "stream_type": stream_type, }, action_stop_forking_params.ActionStopForkingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopForkingResponse, ) async def stop_gather( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopGatherResponse: """ Stop current gather. **Expected Webhooks:** - `call.gather.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/gather_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_gather_params.ActionStopGatherParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopGatherResponse, ) async def stop_noise_suppression( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopNoiseSuppressionResponse: """Stop noise suppression previously started on an active call. This feature is currently in beta. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/suppression_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_noise_suppression_params.ActionStopNoiseSuppressionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopNoiseSuppressionResponse, ) async def stop_playback( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, overlay: bool | Omit = omit, stop: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopPlaybackResponse: """ Stop audio being played on the call. **Expected Webhooks:** - `call.playback.ended` or `call.speak.ended` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. overlay: When enabled, it stops the audio being played in the overlay queue. stop: Use `current` to stop the current audio being played. Use `all` to stop the current audio file being played and clear all audio files from the queue. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/playback_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "overlay": overlay, "stop": stop, }, action_stop_playback_params.ActionStopPlaybackParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopPlaybackResponse, ) async def stop_recording( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, recording_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopRecordingResponse: """ Stop recording the call. **Expected Webhooks:** - `call.recording.saved` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. recording_id: Uniquely identifies the resource. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/record_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "recording_id": recording_id, }, action_stop_recording_params.ActionStopRecordingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopRecordingResponse, ) async def stop_siprec( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopSiprecResponse: """ Stop SIPREC session. **Expected Webhooks:** - `siprec.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/siprec_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_siprec_params.ActionStopSiprecParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopSiprecResponse, ) async def stop_streaming( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, stream_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopStreamingResponse: """ Stop streaming a call to a WebSocket. **Expected Webhooks:** - `streaming.stopped` Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. stream_id: Identifies the stream. If the `stream_id` is not provided the command stops all streams associated with a given `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/streaming_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, "stream_id": stream_id, }, action_stop_streaming_params.ActionStopStreamingParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopStreamingResponse, ) async def stop_transcription( self, call_control_id: str, *, client_state: str | Omit = omit, command_id: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionStopTranscriptionResponse: """Stops real-time transcription on the call. Transcription webhooks cease once the command takes effect; the call itself is unaffected. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/transcription_stop", call_control_id=call_control_id), body=await async_maybe_transform( { "client_state": client_state, "command_id": command_id, }, action_stop_transcription_params.ActionStopTranscriptionParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionStopTranscriptionResponse, ) async def switch_supervisor_role( self, call_control_id: str, *, role: Literal["barge", "whisper", "monitor"], # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionSwitchSupervisorRoleResponse: """Switch the supervisor role for a bridged call. This allows switching between different supervisor modes during an active call Args: role: The supervisor role to switch to. 'barge' allows speaking to both parties, 'whisper' allows speaking to caller only, 'monitor' allows listening only. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/switch_supervisor_role", call_control_id=call_control_id), body=await async_maybe_transform( {"role": role}, action_switch_supervisor_role_params.ActionSwitchSupervisorRoleParams ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionSwitchSupervisorRoleResponse, ) async def transfer( self, call_control_id: str, *, to: str, answering_machine_detection: Literal[ "premium", "premium_ios_call_screening_detection", "detect", "detect_beep", "detect_words", "greeting_end", "disabled", ] | Omit = omit, answering_machine_detection_config: action_transfer_params.AnsweringMachineDetectionConfig | Omit = omit, audio_url: str | Omit = omit, client_state: str | Omit = omit, command_id: str | Omit = omit, custom_headers: Iterable[CustomSipHeaderParam] | Omit = omit, diversion: str | Omit = omit, early_media: bool | Omit = omit, from_: str | Omit = omit, from_display_name: str | Omit = omit, media_encryption: Literal["disabled", "SRTP", "DTLS"] | Omit = omit, media_name: str | Omit = omit, mute_dtmf: Literal["none", "both", "self", "opposite"] | Omit = omit, park_after_unbridge: str | Omit = omit, preferred_codecs: str | Omit = omit, privacy: Literal["id", "none"] | Omit = omit, record: Literal["record-from-answer"] | Omit = omit, record_channels: Literal["single", "dual"] | Omit = omit, record_custom_file_name: str | Omit = omit, record_format: Literal["wav", "mp3"] | Omit = omit, record_max_length: int | Omit = omit, record_timeout_secs: int | Omit = omit, record_track: Literal["both", "inbound", "outbound"] | Omit = omit, record_trim: Literal["trim-silence"] | Omit = omit, route_to_mobile: bool | Omit = omit, send_digits_on_answer: str | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_headers: Iterable[SipHeaderParam] | Omit = omit, sip_region: Literal["US", "Europe", "Canada", "Australia", "Middle East"] | Omit = omit, sip_transport_protocol: Literal["UDP", "TCP", "TLS"] | Omit = omit, sound_modifications: SoundModificationsParam | Omit = omit, target_leg_client_state: str | Omit = omit, time_limit_secs: int | Omit = omit, timeout_secs: int | Omit = omit, webhook_retries_policies: Dict[str, action_transfer_params.WebhookRetriesPolicies] | Omit = omit, webhook_url: str | Omit = omit, webhook_url_method: Literal["POST", "GET"] | Omit = omit, webhook_urls: Dict[str, SequenceNotStr[str]] | Omit = omit, webhook_urls_method: Literal["POST", "GET"] | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionTransferResponse: """Transfer a call to a new destination. If the transfer is unsuccessful, a `call.hangup` webhook for the other call (Leg B) will be sent indicating that the transfer could not be completed. The original call will remain active and may be issued additional commands, potentially transfering the call to an alternate destination. **Expected Webhooks:** - `call.initiated` - `call.bridged` to Leg B - `call.answered` or `call.hangup` - `call.machine.detection.ended` if `answering_machine_detection` was requested - `call.machine.greeting.ended` if `answering_machine_detection` was requested to detect the end of machine greeting - `call.machine.premium.detection.ended` if `answering_machine_detection=premium` was requested - `call.machine.premium.greeting.ended` if `answering_machine_detection=premium` was requested and a beep was detected - `call.machine.premium.call_screening.detected` if `answering_machine_detection=premium_ios_call_screening_detection` was requested and an Apple Call Screening tone was detected Args: to: The DID or SIP URI to dial out to. For SIP URI destinations, append `;secure=true` or `;secure=srtp` to enable SRTP media encryption for that endpoint, or `;secure=dtls` to enable DTLS media encryption for that endpoint. If `media_encryption` is set to `SRTP` or `DTLS`, it takes precedence over any per-endpoint `secure` URI parameter. You may also append a comma followed by DTMF digits (e.g. `+18004247767,200`) to play those digits as DTMF once the transfer destination answers — equivalent to setting `send_digits_on_answer` separately. If both are present, the explicit `send_digits_on_answer` parameter takes precedence. answering_machine_detection: Enables Answering Machine Detection. When a call is answered, Telnyx runs real-time detection to determine if it was picked up by a human or a machine and sends an `call.machine.detection.ended` webhook with the analysis result. If 'greeting_end' or 'detect_words' is used and a 'machine' is detected, you will receive another 'call.machine.greeting.ended' webhook when the answering machine greeting ends with a beep or silence. If `detect_beep` is used, you will only receive 'call.machine.greeting.ended' if a beep is detected. If `answering_machine_detection` is set to `premium_ios_call_screening_detection`, Premium AMD runs with iOS Call Screening support: after an initial `machine` result, Telnyx listens for the iOS call-screening prompt to end or for an Apple Call Screening tone, sends `call.machine.premium.greeting.ended` with `result=prompt_ended` or `call.machine.premium.call_screening.detected` with `result=screening` respectively. When the Apple Call Screening tone is detected, Premium AMD is restarted on the screened call and a `call.machine.premium.detection.ended` webhook with the post-screening classification follows. answering_machine_detection_config: Optional configuration parameters to modify 'answering_machine_detection' performance. Only `total_analysis_time_millis` and `greeting_duration_millis` parameters are applicable when `premium` is selected as answering_machine_detection. `prompt_end_timeout_millis` is additionally applicable when `premium_ios_call_screening_detection` is selected. audio_url: The URL of a file to be played back when the transfer destination answers before bridging the call. The URL can point to either a WAV or MP3 file. media_name and audio_url cannot be used together in one request. client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. command_id: Use this field to avoid duplicate commands. Telnyx will ignore any command with the same `command_id` for the same `call_control_id`. custom_headers: Custom headers to be added to the SIP INVITE. diversion: The `to` number of an active inbound call, in +E164 format. Telnyx checks whether there is currently an active inbound call where `to` matches this `diversion` value and `from` matches the `from` number supplied for this request. If such a call exists, the `from` number is treated as verified (since it is already on an active inbound call to you) and can be used as the caller id for this outbound call. early_media: If set to false, early media will not be passed to the originating leg. from_: The `from` number to be used as the caller id presented to the destination (`to` number). The number should be in +E164 format. This attribute will default to the `to` number of the original call if omitted. from_display_name: The `from_display_name` string to be used as the caller id name (SIP From Display Name) presented to the destination (`to` number). The string should have a maximum of 128 characters, containing only letters, numbers, spaces, and -\\__~!.+ special characters. If ommited, the display name will be the same as the number in the `from` field. media_encryption: Defines whether media should be encrypted on the new call leg. For SIP URI destinations, media encryption can also be requested per endpoint with the `secure` URI parameter: `;secure=true` or `;secure=srtp` enables SRTP, and `;secure=dtls` enables DTLS. This parameter, when set to `SRTP` or `DTLS`, takes precedence over the per-endpoint `secure` value. media_name: The media_name of a file to be played back when the transfer destination answers before bridging the call. The media_name must point to a file previously uploaded to api.telnyx.com/v2/media by the same user/organization. The file must either be a WAV or MP3 file. mute_dtmf: When enabled, DTMF tones are not passed to the call participant. The webhooks containing the DTMF information will be sent. park_after_unbridge: Specifies behavior after the bridge ends (i.e. the opposite leg either hangs up or is transferred). If supplied with the value `self`, the current leg will be parked after unbridge. If not set, the default behavior is to hang up the leg. preferred_codecs: The list of comma-separated codecs in order of preference to be used during the call. The codecs supported are `G722`, `PCMU`, `PCMA`, `G729`, `OPUS`, `VP8`, `H264`, `AMR-WB`. privacy: Indicates the privacy level to be used for the call. When set to `id`, caller ID information (name and number) will be hidden from the called party. When set to `none` or omitted, caller ID will be shown normally. record: Start recording automatically after an event. Disabled by default. record_channels: Defines which channel should be recorded ('single' or 'dual') when `record` is specified. record_custom_file_name: The custom recording file name to be used instead of the default `call_leg_id`. Telnyx will still add a Unix timestamp suffix. record_format: Defines the format of the recording ('wav' or 'mp3') when `record` is specified. record_max_length: Defines the maximum length for the recording in seconds when `record` is specified. The minimum value is 0. The maximum value is 43200. The default value is 0 (infinite). record_timeout_secs: The number of seconds that Telnyx will wait for the recording to be stopped if silence is detected when `record` is specified. The timer only starts when the speech is detected. Please note that call transcription is used to detect silence and the related charge will be applied. The minimum value is 0. The default value is 0 (infinite). record_track: The audio track to be recorded. Can be either `both`, `inbound` or `outbound`. If only single track is specified (`inbound`, `outbound`), `channels` configuration is ignored and it will be recorded as mono (single channel). record_trim: When set to `trim-silence`, silence will be removed from the beginning and end of the recording. route_to_mobile: When set to true, routes the call directly to the mobile device associated with the destination Telnyx Mobile number, bypassing Inbound Calls Interception configured in the Telnyx Portal under Mobile Numbers → select the number → Voice → Call Interception. Use this when transferring an intercepted call to the mobile device to prevent the call from being intercepted again. Defaults to false. send_digits_on_answer: DTMF digits to send automatically after the transfer destination answers. Useful for reaching an extension behind an IVR (e.g. `"200"` to dial extension 200 once the called party picks up). Allowed characters: `0-9`, `A-D`, `w` (0.5s pause), `W` (1s pause), `*`, `#`. Maximum 64 characters. When omitted, no automatic DTMF is sent. May also be supplied inline by appending `,` to `to` (e.g. `to=+18004247767,200`); if both forms are present, this explicit field takes precedence. sip_auth_password: SIP Authentication password used for SIP challenges. sip_auth_username: SIP Authentication username used for SIP challenges. sip_headers: SIP headers to be added to the SIP INVITE. Currently only User-to-User header is supported. sip_region: Defines the SIP region to be used for the call. sip_transport_protocol: Defines SIP transport protocol to be used on the call. sound_modifications: Use this field to modify sound effects, for example adjust the pitch. target_leg_client_state: Use this field to add state to every subsequent webhook for the new leg. It must be a valid Base-64 encoded string. time_limit_secs: Sets the maximum duration of a Call Control Leg in seconds. If the time limit is reached, the call will hangup and a `call.hangup` webhook with a `hangup_cause` of `time_limit` will be sent. For example, by setting a time limit of 120 seconds, a Call Leg will be automatically terminated two minutes after being answered. The default time limit is 14400 seconds or 4 hours and this is also the maximum allowed call length. timeout_secs: The number of seconds that Telnyx will wait for the call to be answered by the destination to which it is being transferred. If the timeout is reached before an answer is received, the call will hangup and a `call.hangup` webhook with a `hangup_cause` of `timeout` will be sent. Minimum value is 5 seconds. Maximum value is 600 seconds. webhook_retries_policies: A map of event types to retry policies. Each retry policy contains an array of `retries_ms` specifying the delays between retry attempts in milliseconds. Maximum 5 retries, total delay cannot exceed 60 seconds. webhook_url: Use this field to override the URL for which Telnyx will send subsequent webhooks to for this call. webhook_url_method: HTTP request type used for `webhook_url`. webhook_urls: A map of event types to arrays of webhook URLs. When an event of the specified type occurs, the webhook URLs associated with that event type will be called instead of `webhook_url`. Events not mapped here will use the default `webhook_url`. webhook_urls_method: HTTP request method to invoke `webhook_urls`. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._post( path_template("/calls/{call_control_id}/actions/transfer", call_control_id=call_control_id), body=await async_maybe_transform( { "to": to, "answering_machine_detection": answering_machine_detection, "answering_machine_detection_config": answering_machine_detection_config, "audio_url": audio_url, "client_state": client_state, "command_id": command_id, "custom_headers": custom_headers, "diversion": diversion, "early_media": early_media, "from_": from_, "from_display_name": from_display_name, "media_encryption": media_encryption, "media_name": media_name, "mute_dtmf": mute_dtmf, "park_after_unbridge": park_after_unbridge, "preferred_codecs": preferred_codecs, "privacy": privacy, "record": record, "record_channels": record_channels, "record_custom_file_name": record_custom_file_name, "record_format": record_format, "record_max_length": record_max_length, "record_timeout_secs": record_timeout_secs, "record_track": record_track, "record_trim": record_trim, "route_to_mobile": route_to_mobile, "send_digits_on_answer": send_digits_on_answer, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_headers": sip_headers, "sip_region": sip_region, "sip_transport_protocol": sip_transport_protocol, "sound_modifications": sound_modifications, "target_leg_client_state": target_leg_client_state, "time_limit_secs": time_limit_secs, "timeout_secs": timeout_secs, "webhook_retries_policies": webhook_retries_policies, "webhook_url": webhook_url, "webhook_url_method": webhook_url_method, "webhook_urls": webhook_urls, "webhook_urls_method": webhook_urls_method, }, action_transfer_params.ActionTransferParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionTransferResponse, ) async def update_client_state( self, call_control_id: str, *, client_state: str, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ActionUpdateClientStateResponse: """Updates the client state associated with the call. Client state is an opaque value echoed back in subsequent webhooks for the call, letting you correlate events with your application's state. Args: client_state: Use this field to add state to every subsequent webhook. It must be a valid Base-64 encoded string. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not call_control_id: raise ValueError(f"Expected a non-empty value for `call_control_id` but received {call_control_id!r}") return await self._put( path_template("/calls/{call_control_id}/actions/client_state_update", call_control_id=call_control_id), body=await async_maybe_transform( {"client_state": client_state}, action_update_client_state_params.ActionUpdateClientStateParams ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=ActionUpdateClientStateResponse, ) class ActionsResourceWithRawResponse: def __init__(self, actions: ActionsResource) -> None: self._actions = actions self.add_ai_assistant_messages = to_raw_response_wrapper( actions.add_ai_assistant_messages, ) self.answer = to_raw_response_wrapper( actions.answer, ) self.bridge = to_raw_response_wrapper( actions.bridge, ) self.enqueue = to_raw_response_wrapper( actions.enqueue, ) self.gather = to_raw_response_wrapper( actions.gather, ) self.gather_using_ai = to_raw_response_wrapper( actions.gather_using_ai, ) self.gather_using_audio = to_raw_response_wrapper( actions.gather_using_audio, ) self.gather_using_speak = to_raw_response_wrapper( actions.gather_using_speak, ) self.hangup = to_raw_response_wrapper( actions.hangup, ) self.join_ai_assistant = to_raw_response_wrapper( actions.join_ai_assistant, ) self.leave_queue = to_raw_response_wrapper( actions.leave_queue, ) self.pause_recording = to_raw_response_wrapper( actions.pause_recording, ) self.pay = to_raw_response_wrapper( actions.pay, ) self.refer = to_raw_response_wrapper( actions.refer, ) self.reject = to_raw_response_wrapper( actions.reject, ) self.resume_recording = to_raw_response_wrapper( actions.resume_recording, ) self.send_dtmf = to_raw_response_wrapper( actions.send_dtmf, ) self.send_sip_info = to_raw_response_wrapper( actions.send_sip_info, ) self.speak = to_raw_response_wrapper( actions.speak, ) self.start_ai_assistant = to_raw_response_wrapper( actions.start_ai_assistant, ) self.start_conversation_relay = to_raw_response_wrapper( actions.start_conversation_relay, ) self.start_forking = to_raw_response_wrapper( actions.start_forking, ) self.start_noise_suppression = to_raw_response_wrapper( actions.start_noise_suppression, ) self.start_playback = to_raw_response_wrapper( actions.start_playback, ) self.start_recording = to_raw_response_wrapper( actions.start_recording, ) self.start_siprec = to_raw_response_wrapper( actions.start_siprec, ) self.start_streaming = to_raw_response_wrapper( actions.start_streaming, ) self.start_transcription = to_raw_response_wrapper( actions.start_transcription, ) self.stop_ai_assistant = to_raw_response_wrapper( actions.stop_ai_assistant, ) self.stop_conversation_relay = to_raw_response_wrapper( actions.stop_conversation_relay, ) self.stop_forking = to_raw_response_wrapper( actions.stop_forking, ) self.stop_gather = to_raw_response_wrapper( actions.stop_gather, ) self.stop_noise_suppression = to_raw_response_wrapper( actions.stop_noise_suppression, ) self.stop_playback = to_raw_response_wrapper( actions.stop_playback, ) self.stop_recording = to_raw_response_wrapper( actions.stop_recording, ) self.stop_siprec = to_raw_response_wrapper( actions.stop_siprec, ) self.stop_streaming = to_raw_response_wrapper( actions.stop_streaming, ) self.stop_transcription = to_raw_response_wrapper( actions.stop_transcription, ) self.switch_supervisor_role = to_raw_response_wrapper( actions.switch_supervisor_role, ) self.transfer = to_raw_response_wrapper( actions.transfer, ) self.update_client_state = to_raw_response_wrapper( actions.update_client_state, ) class AsyncActionsResourceWithRawResponse: def __init__(self, actions: AsyncActionsResource) -> None: self._actions = actions self.add_ai_assistant_messages = async_to_raw_response_wrapper( actions.add_ai_assistant_messages, ) self.answer = async_to_raw_response_wrapper( actions.answer, ) self.bridge = async_to_raw_response_wrapper( actions.bridge, ) self.enqueue = async_to_raw_response_wrapper( actions.enqueue, ) self.gather = async_to_raw_response_wrapper( actions.gather, ) self.gather_using_ai = async_to_raw_response_wrapper( actions.gather_using_ai, ) self.gather_using_audio = async_to_raw_response_wrapper( actions.gather_using_audio, ) self.gather_using_speak = async_to_raw_response_wrapper( actions.gather_using_speak, ) self.hangup = async_to_raw_response_wrapper( actions.hangup, ) self.join_ai_assistant = async_to_raw_response_wrapper( actions.join_ai_assistant, ) self.leave_queue = async_to_raw_response_wrapper( actions.leave_queue, ) self.pause_recording = async_to_raw_response_wrapper( actions.pause_recording, ) self.pay = async_to_raw_response_wrapper( actions.pay, ) self.refer = async_to_raw_response_wrapper( actions.refer, ) self.reject = async_to_raw_response_wrapper( actions.reject, ) self.resume_recording = async_to_raw_response_wrapper( actions.resume_recording, ) self.send_dtmf = async_to_raw_response_wrapper( actions.send_dtmf, ) self.send_sip_info = async_to_raw_response_wrapper( actions.send_sip_info, ) self.speak = async_to_raw_response_wrapper( actions.speak, ) self.start_ai_assistant = async_to_raw_response_wrapper( actions.start_ai_assistant, ) self.start_conversation_relay = async_to_raw_response_wrapper( actions.start_conversation_relay, ) self.start_forking = async_to_raw_response_wrapper( actions.start_forking, ) self.start_noise_suppression = async_to_raw_response_wrapper( actions.start_noise_suppression, ) self.start_playback = async_to_raw_response_wrapper( actions.start_playback, ) self.start_recording = async_to_raw_response_wrapper( actions.start_recording, ) self.start_siprec = async_to_raw_response_wrapper( actions.start_siprec, ) self.start_streaming = async_to_raw_response_wrapper( actions.start_streaming, ) self.start_transcription = async_to_raw_response_wrapper( actions.start_transcription, ) self.stop_ai_assistant = async_to_raw_response_wrapper( actions.stop_ai_assistant, ) self.stop_conversation_relay = async_to_raw_response_wrapper( actions.stop_conversation_relay, ) self.stop_forking = async_to_raw_response_wrapper( actions.stop_forking, ) self.stop_gather = async_to_raw_response_wrapper( actions.stop_gather, ) self.stop_noise_suppression = async_to_raw_response_wrapper( actions.stop_noise_suppression, ) self.stop_playback = async_to_raw_response_wrapper( actions.stop_playback, ) self.stop_recording = async_to_raw_response_wrapper( actions.stop_recording, ) self.stop_siprec = async_to_raw_response_wrapper( actions.stop_siprec, ) self.stop_streaming = async_to_raw_response_wrapper( actions.stop_streaming, ) self.stop_transcription = async_to_raw_response_wrapper( actions.stop_transcription, ) self.switch_supervisor_role = async_to_raw_response_wrapper( actions.switch_supervisor_role, ) self.transfer = async_to_raw_response_wrapper( actions.transfer, ) self.update_client_state = async_to_raw_response_wrapper( actions.update_client_state, ) class ActionsResourceWithStreamingResponse: def __init__(self, actions: ActionsResource) -> None: self._actions = actions self.add_ai_assistant_messages = to_streamed_response_wrapper( actions.add_ai_assistant_messages, ) self.answer = to_streamed_response_wrapper( actions.answer, ) self.bridge = to_streamed_response_wrapper( actions.bridge, ) self.enqueue = to_streamed_response_wrapper( actions.enqueue, ) self.gather = to_streamed_response_wrapper( actions.gather, ) self.gather_using_ai = to_streamed_response_wrapper( actions.gather_using_ai, ) self.gather_using_audio = to_streamed_response_wrapper( actions.gather_using_audio, ) self.gather_using_speak = to_streamed_response_wrapper( actions.gather_using_speak, ) self.hangup = to_streamed_response_wrapper( actions.hangup, ) self.join_ai_assistant = to_streamed_response_wrapper( actions.join_ai_assistant, ) self.leave_queue = to_streamed_response_wrapper( actions.leave_queue, ) self.pause_recording = to_streamed_response_wrapper( actions.pause_recording, ) self.pay = to_streamed_response_wrapper( actions.pay, ) self.refer = to_streamed_response_wrapper( actions.refer, ) self.reject = to_streamed_response_wrapper( actions.reject, ) self.resume_recording = to_streamed_response_wrapper( actions.resume_recording, ) self.send_dtmf = to_streamed_response_wrapper( actions.send_dtmf, ) self.send_sip_info = to_streamed_response_wrapper( actions.send_sip_info, ) self.speak = to_streamed_response_wrapper( actions.speak, ) self.start_ai_assistant = to_streamed_response_wrapper( actions.start_ai_assistant, ) self.start_conversation_relay = to_streamed_response_wrapper( actions.start_conversation_relay, ) self.start_forking = to_streamed_response_wrapper( actions.start_forking, ) self.start_noise_suppression = to_streamed_response_wrapper( actions.start_noise_suppression, ) self.start_playback = to_streamed_response_wrapper( actions.start_playback, ) self.start_recording = to_streamed_response_wrapper( actions.start_recording, ) self.start_siprec = to_streamed_response_wrapper( actions.start_siprec, ) self.start_streaming = to_streamed_response_wrapper( actions.start_streaming, ) self.start_transcription = to_streamed_response_wrapper( actions.start_transcription, ) self.stop_ai_assistant = to_streamed_response_wrapper( actions.stop_ai_assistant, ) self.stop_conversation_relay = to_streamed_response_wrapper( actions.stop_conversation_relay, ) self.stop_forking = to_streamed_response_wrapper( actions.stop_forking, ) self.stop_gather = to_streamed_response_wrapper( actions.stop_gather, ) self.stop_noise_suppression = to_streamed_response_wrapper( actions.stop_noise_suppression, ) self.stop_playback = to_streamed_response_wrapper( actions.stop_playback, ) self.stop_recording = to_streamed_response_wrapper( actions.stop_recording, ) self.stop_siprec = to_streamed_response_wrapper( actions.stop_siprec, ) self.stop_streaming = to_streamed_response_wrapper( actions.stop_streaming, ) self.stop_transcription = to_streamed_response_wrapper( actions.stop_transcription, ) self.switch_supervisor_role = to_streamed_response_wrapper( actions.switch_supervisor_role, ) self.transfer = to_streamed_response_wrapper( actions.transfer, ) self.update_client_state = to_streamed_response_wrapper( actions.update_client_state, ) class AsyncActionsResourceWithStreamingResponse: def __init__(self, actions: AsyncActionsResource) -> None: self._actions = actions self.add_ai_assistant_messages = async_to_streamed_response_wrapper( actions.add_ai_assistant_messages, ) self.answer = async_to_streamed_response_wrapper( actions.answer, ) self.bridge = async_to_streamed_response_wrapper( actions.bridge, ) self.enqueue = async_to_streamed_response_wrapper( actions.enqueue, ) self.gather = async_to_streamed_response_wrapper( actions.gather, ) self.gather_using_ai = async_to_streamed_response_wrapper( actions.gather_using_ai, ) self.gather_using_audio = async_to_streamed_response_wrapper( actions.gather_using_audio, ) self.gather_using_speak = async_to_streamed_response_wrapper( actions.gather_using_speak, ) self.hangup = async_to_streamed_response_wrapper( actions.hangup, ) self.join_ai_assistant = async_to_streamed_response_wrapper( actions.join_ai_assistant, ) self.leave_queue = async_to_streamed_response_wrapper( actions.leave_queue, ) self.pause_recording = async_to_streamed_response_wrapper( actions.pause_recording, ) self.pay = async_to_streamed_response_wrapper( actions.pay, ) self.refer = async_to_streamed_response_wrapper( actions.refer, ) self.reject = async_to_streamed_response_wrapper( actions.reject, ) self.resume_recording = async_to_streamed_response_wrapper( actions.resume_recording, ) self.send_dtmf = async_to_streamed_response_wrapper( actions.send_dtmf, ) self.send_sip_info = async_to_streamed_response_wrapper( actions.send_sip_info, ) self.speak = async_to_streamed_response_wrapper( actions.speak, ) self.start_ai_assistant = async_to_streamed_response_wrapper( actions.start_ai_assistant, ) self.start_conversation_relay = async_to_streamed_response_wrapper( actions.start_conversation_relay, ) self.start_forking = async_to_streamed_response_wrapper( actions.start_forking, ) self.start_noise_suppression = async_to_streamed_response_wrapper( actions.start_noise_suppression, ) self.start_playback = async_to_streamed_response_wrapper( actions.start_playback, ) self.start_recording = async_to_streamed_response_wrapper( actions.start_recording, ) self.start_siprec = async_to_streamed_response_wrapper( actions.start_siprec, ) self.start_streaming = async_to_streamed_response_wrapper( actions.start_streaming, ) self.start_transcription = async_to_streamed_response_wrapper( actions.start_transcription, ) self.stop_ai_assistant = async_to_streamed_response_wrapper( actions.stop_ai_assistant, ) self.stop_conversation_relay = async_to_streamed_response_wrapper( actions.stop_conversation_relay, ) self.stop_forking = async_to_streamed_response_wrapper( actions.stop_forking, ) self.stop_gather = async_to_streamed_response_wrapper( actions.stop_gather, ) self.stop_noise_suppression = async_to_streamed_response_wrapper( actions.stop_noise_suppression, ) self.stop_playback = async_to_streamed_response_wrapper( actions.stop_playback, ) self.stop_recording = async_to_streamed_response_wrapper( actions.stop_recording, ) self.stop_siprec = async_to_streamed_response_wrapper( actions.stop_siprec, ) self.stop_streaming = async_to_streamed_response_wrapper( actions.stop_streaming, ) self.stop_transcription = async_to_streamed_response_wrapper( actions.stop_transcription, ) self.switch_supervisor_role = async_to_streamed_response_wrapper( actions.switch_supervisor_role, ) self.transfer = async_to_streamed_response_wrapper( actions.transfer, ) self.update_client_state = async_to_streamed_response_wrapper( actions.update_client_state, )