# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Dict, Iterable from typing_extensions import Literal import httpx from .calls import ( CallsResource, AsyncCallsResource, CallsResourceWithRawResponse, AsyncCallsResourceWithRawResponse, CallsResourceWithStreamingResponse, AsyncCallsResourceWithStreamingResponse, ) from ...types import texml_secrets_params, texml_initiate_ai_call_params 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 ..._base_client import make_request_options from .accounts.accounts import ( AccountsResource, AsyncAccountsResource, AccountsResourceWithRawResponse, AsyncAccountsResourceWithRawResponse, AccountsResourceWithStreamingResponse, AsyncAccountsResourceWithStreamingResponse, ) from ...types.texml_secrets_response import TexmlSecretsResponse from ...types.texml_initiate_ai_call_response import TexmlInitiateAICallResponse __all__ = ["TexmlResource", "AsyncTexmlResource"] class TexmlResource(SyncAPIResource): """TeXML REST Commands""" @cached_property def calls(self) -> CallsResource: """TeXML REST Commands""" return CallsResource(self._client) @cached_property def accounts(self) -> AccountsResource: """TeXML REST Commands""" return AccountsResource(self._client) @cached_property def with_raw_response(self) -> TexmlResourceWithRawResponse: """ 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 TexmlResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> TexmlResourceWithStreamingResponse: """ 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 TexmlResourceWithStreamingResponse(self) def initiate_ai_call( self, connection_id: str, *, ai_assistant_id: str, from_: str, to: str, ai_assistant_dynamic_variables: Dict[str, str] | Omit = omit, ai_assistant_version: str | Omit = omit, async_amd: bool | Omit = omit, async_amd_status_callback: str | Omit = omit, async_amd_status_callback_method: Literal["GET", "POST"] | Omit = omit, caller_id: str | Omit = omit, conversation_callback: str | Omit = omit, conversation_callback_method: Literal["GET", "POST"] | Omit = omit, conversation_callbacks: SequenceNotStr[str] | Omit = omit, custom_headers: Iterable[texml_initiate_ai_call_params.CustomHeader] | Omit = omit, detection_mode: Literal["Premium", "Regular", "PremiumCallScreening"] | Omit = omit, machine_detection: Literal["Enable", "Disable", "DetectMessageEnd"] | Omit = omit, machine_detection_beep_max_frequency: int | Omit = omit, machine_detection_beep_min_frequency: int | Omit = omit, machine_detection_beep_min_tone_duration: int | Omit = omit, machine_detection_beep_profile: Literal["both", "freq_only"] | Omit = omit, machine_detection_beep_spectral_confirmation: bool | Omit = omit, machine_detection_beep_spectral_min_purity: float | Omit = omit, machine_detection_beep_spectral_reject_fax_cng: bool | Omit = omit, machine_detection_beep_spectral_window: int | Omit = omit, machine_detection_prompt_end_timeout: int | Omit = omit, machine_detection_silence_timeout: int | Omit = omit, machine_detection_speech_end_threshold: int | Omit = omit, machine_detection_speech_threshold: int | Omit = omit, machine_detection_timeout: int | Omit = omit, passports: str | Omit = omit, preferred_codecs: str | Omit = omit, record: bool | Omit = omit, recording_channels: Literal["mono", "dual"] | Omit = omit, recording_status_callback: str | Omit = omit, recording_status_callback_event: str | Omit = omit, recording_status_callback_method: Literal["GET", "POST"] | Omit = omit, recording_timeout: int | Omit = omit, recording_track: Literal["inbound", "outbound", "both"] | Omit = omit, send_recording_url: bool | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_region: Literal["US", "Europe", "Canada", "Australia", "Middle East"] | Omit = omit, status_callback: str | Omit = omit, status_callback_event: str | Omit = omit, status_callback_method: Literal["GET", "POST"] | Omit = omit, status_callbacks: SequenceNotStr[str] | Omit = omit, time_limit: int | Omit = omit, timeout_seconds: int | Omit = omit, trim: Literal["trim-silence", "do-not-trim"] | 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, ) -> TexmlInitiateAICallResponse: """ Initiate an outbound AI call with warm-up support: Telnyx attempts to warm up the assistant identified by `AIAssistantId` before placing the call and starts it automatically when the called party answers. Validates parameters, builds an internal TeXML with an AI Assistant configuration, encodes instructions into client state, and calls the dial API. The Twiml, Texml, and Url parameters are not allowed and will result in a 422 error. **Expected callback events:** Status callbacks: `initiated`, `ringing`, `answered`, one terminal status (`completed`, `no-answer`, `busy`, `canceled`, or `failed`), then `analyzed` after post-call processing completes. Conversation callbacks: `conversation_created` and `conversation_ended`. Recording, AMD, transcription, and deepfake detection callbacks are only sent when those features are enabled. Args: ai_assistant_id: The ID of the AI assistant to use for the call. Telnyx attempts to warm up this assistant before the call is placed and starts it automatically when the called party answers. from_: The phone number of the party initiating the call. Phone numbers are formatted with a `+` and country code. to: The phone number of the called party. Phone numbers are formatted with a `+` and country code. ai_assistant_dynamic_variables: Key-value map of dynamic variables to pass to the AI assistant. ai_assistant_version: The version of the AI assistant to use. async_amd: Select whether to perform answering machine detection in the background. By default execution is blocked until Answering Machine Detection is completed. async_amd_status_callback: URL destination for Telnyx to send AMD callback events to for the call. async_amd_status_callback_method: HTTP request type used for `AsyncAmdStatusCallback`. caller_id: 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 omitted, the display name will be the same as the number in the `From` field. conversation_callback: URL destination for Telnyx to send AI conversation callback events for this call. Events include `conversation_created` and `conversation_ended`. conversation_callback_method: HTTP request type used for `ConversationCallback` and `ConversationCallbacks`. conversation_callbacks: Array of URL destinations for AI conversation callback events for this call. Events include `conversation_created` and `conversation_ended`. custom_headers: Custom HTTP headers to be sent with the call. Each header should be an object with 'name' and 'value' properties. detection_mode: Allows you to choose between Regular, Premium, and PremiumCallScreening detections. See https://developers.telnyx.com/docs/voice/programmable-voice/answering-machine-detection machine_detection: Enables Answering Machine Detection. machine_detection_beep_max_frequency: Highest frequency, in Hz, that a tone can reach and still be treated as a beep. Only used when MachineDetection is enabled. machine_detection_beep_min_frequency: Lowest frequency, in Hz, that a tone must reach to be treated as a beep. Raising it above 480 excludes North American ringback (440 + 480 Hz), which can otherwise be reported as a beep when the `freq_only` profile is in use. Only used when MachineDetection is enabled. machine_detection_beep_min_tone_duration: Shortest tone, in milliseconds, that can be treated as a beep. Raising it rejects brief tones such as call-progress blips. Only used when MachineDetection is enabled. machine_detection_beep_profile: Selects which detectors must validate a beep. `both` requires the amplitude and frequency detectors to agree. `freq_only` uses the frequency detector alone, for beeps whose volume is too unsteady for the default profile. Only used when MachineDetection is enabled. machine_detection_beep_spectral_confirmation: When enabled, a candidate beep must pass an additional spectral check before it is reported. Only used when MachineDetection is enabled. machine_detection_beep_spectral_min_purity: Minimum spectral purity, from 0 to 1, for a tone to be treated as a beep. Raising it rejects mixed tones such as ringback, which combines two frequencies. Only used when MachineDetection is enabled. machine_detection_beep_spectral_reject_fax_cng: When enabled, the fax CNG tone is rejected rather than reported as a beep. Only used when MachineDetection is enabled. machine_detection_beep_spectral_window: Length of the spectral confirmation window, in milliseconds. Only used when MachineDetection is enabled. machine_detection_prompt_end_timeout: Silence duration threshold after a call screening prompt before ending prompt detection, in milliseconds. Used when `DetectionMode` is `PremiumCallScreening`. machine_detection_silence_timeout: If initial silence duration is greater than this value, consider it a machine. Ignored when `premium` detection is used. machine_detection_speech_end_threshold: Silence duration threshold after a greeting message or voice for it be considered human. Ignored when `premium` detection is used. machine_detection_speech_threshold: Maximum threshold of a human greeting. If greeting longer than this value, considered machine. Ignored when `premium` detection is used. machine_detection_timeout: Maximum timeout threshold in milliseconds for overall detection. passports: A string of passport identifiers to associate with the call. preferred_codecs: The list of comma-separated codecs to be offered on a call. record: Whether to record the entire participant's call leg. Defaults to `false`. recording_channels: The number of channels in the final recording. Defaults to `mono`. recording_status_callback: The URL the recording callbacks will be sent to. recording_status_callback_event: The changes to the recording's state that should generate a call to `RecordingStatusCallback`. Can be: `in-progress`, `completed` and `absent`. Separate multiple values with a space. Defaults to `completed`. recording_status_callback_method: HTTP request type used for `RecordingStatusCallback`. Defaults to `POST`. recording_timeout: 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. The minimum value is 0. The default value is 0 (infinite). recording_track: The audio track to record for the call. The default is `both`. send_recording_url: Whether to send RecordingUrl in webhooks. sip_auth_password: The password to use for SIP authentication. sip_auth_username: The username to use for SIP authentication. sip_region: Defines the SIP region to be used for the call. status_callback: URL destination for Telnyx to send status callback events for this AI call. When provided, this per-call value overrides the status callback URL configured on the TeXML application/connection. status_callback_event: The status callback events for which Telnyx should send a webhook for this AI call. Multiple events can be defined when separated by a space. Valid values: initiated, ringing, answered, completed, no-answer, busy, canceled, failed, analyzed. When provided, this per-call value overrides the status callback events configured on the TeXML application/connection. status_callback_method: HTTP request type used for `StatusCallback` and `StatusCallbacks` for this AI call. When provided, this per-call value overrides the status callback method configured on the TeXML application/connection. status_callbacks: Array of URL destinations for Telnyx to send status callback events for this AI call. When provided, these per-call values override the status callback URL configured on the TeXML application/connection. time_limit: The maximum duration of the call in seconds. The minimum value is 30 and the maximum value is 14400 (4 hours). Default is 14400 seconds. timeout_seconds: The number of seconds to wait for the called party to answer the call before the call is canceled. The minimum value is 5 and the maximum value is 120. Default is 30 seconds. trim: Whether to trim any leading and trailing silence from the recording. Defaults to `trim-silence`. 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 connection_id: raise ValueError(f"Expected a non-empty value for `connection_id` but received {connection_id!r}") return self._post( path_template("/texml/ai_calls/{connection_id}", connection_id=connection_id), body=maybe_transform( { "ai_assistant_id": ai_assistant_id, "from_": from_, "to": to, "ai_assistant_dynamic_variables": ai_assistant_dynamic_variables, "ai_assistant_version": ai_assistant_version, "async_amd": async_amd, "async_amd_status_callback": async_amd_status_callback, "async_amd_status_callback_method": async_amd_status_callback_method, "caller_id": caller_id, "conversation_callback": conversation_callback, "conversation_callback_method": conversation_callback_method, "conversation_callbacks": conversation_callbacks, "custom_headers": custom_headers, "detection_mode": detection_mode, "machine_detection": machine_detection, "machine_detection_beep_max_frequency": machine_detection_beep_max_frequency, "machine_detection_beep_min_frequency": machine_detection_beep_min_frequency, "machine_detection_beep_min_tone_duration": machine_detection_beep_min_tone_duration, "machine_detection_beep_profile": machine_detection_beep_profile, "machine_detection_beep_spectral_confirmation": machine_detection_beep_spectral_confirmation, "machine_detection_beep_spectral_min_purity": machine_detection_beep_spectral_min_purity, "machine_detection_beep_spectral_reject_fax_cng": machine_detection_beep_spectral_reject_fax_cng, "machine_detection_beep_spectral_window": machine_detection_beep_spectral_window, "machine_detection_prompt_end_timeout": machine_detection_prompt_end_timeout, "machine_detection_silence_timeout": machine_detection_silence_timeout, "machine_detection_speech_end_threshold": machine_detection_speech_end_threshold, "machine_detection_speech_threshold": machine_detection_speech_threshold, "machine_detection_timeout": machine_detection_timeout, "passports": passports, "preferred_codecs": preferred_codecs, "record": record, "recording_channels": recording_channels, "recording_status_callback": recording_status_callback, "recording_status_callback_event": recording_status_callback_event, "recording_status_callback_method": recording_status_callback_method, "recording_timeout": recording_timeout, "recording_track": recording_track, "send_recording_url": send_recording_url, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_region": sip_region, "status_callback": status_callback, "status_callback_event": status_callback_event, "status_callback_method": status_callback_method, "status_callbacks": status_callbacks, "time_limit": time_limit, "timeout_seconds": timeout_seconds, "trim": trim, }, texml_initiate_ai_call_params.TexmlInitiateAICallParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TexmlInitiateAICallResponse, ) def secrets( self, *, name: str, value: 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, ) -> TexmlSecretsResponse: """ Create a TeXML secret which can be later used as a Dynamic Parameter for TeXML when using Mustache Templates in your TeXML. In your TeXML you will be able to use your secret name, and this name will be replaced by the actual secret value when processing the TeXML on Telnyx side. The secrets are not visible in any logs. Args: name: Name used as a reference for the secret, if the name already exists within the account its value will be replaced value: Secret value which will be used when rendering the TeXML template 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 """ return self._post( "/texml/secrets", body=maybe_transform( { "name": name, "value": value, }, texml_secrets_params.TexmlSecretsParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TexmlSecretsResponse, ) class AsyncTexmlResource(AsyncAPIResource): """TeXML REST Commands""" @cached_property def calls(self) -> AsyncCallsResource: """TeXML REST Commands""" return AsyncCallsResource(self._client) @cached_property def accounts(self) -> AsyncAccountsResource: """TeXML REST Commands""" return AsyncAccountsResource(self._client) @cached_property def with_raw_response(self) -> AsyncTexmlResourceWithRawResponse: """ 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 AsyncTexmlResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncTexmlResourceWithStreamingResponse: """ 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 AsyncTexmlResourceWithStreamingResponse(self) async def initiate_ai_call( self, connection_id: str, *, ai_assistant_id: str, from_: str, to: str, ai_assistant_dynamic_variables: Dict[str, str] | Omit = omit, ai_assistant_version: str | Omit = omit, async_amd: bool | Omit = omit, async_amd_status_callback: str | Omit = omit, async_amd_status_callback_method: Literal["GET", "POST"] | Omit = omit, caller_id: str | Omit = omit, conversation_callback: str | Omit = omit, conversation_callback_method: Literal["GET", "POST"] | Omit = omit, conversation_callbacks: SequenceNotStr[str] | Omit = omit, custom_headers: Iterable[texml_initiate_ai_call_params.CustomHeader] | Omit = omit, detection_mode: Literal["Premium", "Regular", "PremiumCallScreening"] | Omit = omit, machine_detection: Literal["Enable", "Disable", "DetectMessageEnd"] | Omit = omit, machine_detection_beep_max_frequency: int | Omit = omit, machine_detection_beep_min_frequency: int | Omit = omit, machine_detection_beep_min_tone_duration: int | Omit = omit, machine_detection_beep_profile: Literal["both", "freq_only"] | Omit = omit, machine_detection_beep_spectral_confirmation: bool | Omit = omit, machine_detection_beep_spectral_min_purity: float | Omit = omit, machine_detection_beep_spectral_reject_fax_cng: bool | Omit = omit, machine_detection_beep_spectral_window: int | Omit = omit, machine_detection_prompt_end_timeout: int | Omit = omit, machine_detection_silence_timeout: int | Omit = omit, machine_detection_speech_end_threshold: int | Omit = omit, machine_detection_speech_threshold: int | Omit = omit, machine_detection_timeout: int | Omit = omit, passports: str | Omit = omit, preferred_codecs: str | Omit = omit, record: bool | Omit = omit, recording_channels: Literal["mono", "dual"] | Omit = omit, recording_status_callback: str | Omit = omit, recording_status_callback_event: str | Omit = omit, recording_status_callback_method: Literal["GET", "POST"] | Omit = omit, recording_timeout: int | Omit = omit, recording_track: Literal["inbound", "outbound", "both"] | Omit = omit, send_recording_url: bool | Omit = omit, sip_auth_password: str | Omit = omit, sip_auth_username: str | Omit = omit, sip_region: Literal["US", "Europe", "Canada", "Australia", "Middle East"] | Omit = omit, status_callback: str | Omit = omit, status_callback_event: str | Omit = omit, status_callback_method: Literal["GET", "POST"] | Omit = omit, status_callbacks: SequenceNotStr[str] | Omit = omit, time_limit: int | Omit = omit, timeout_seconds: int | Omit = omit, trim: Literal["trim-silence", "do-not-trim"] | 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, ) -> TexmlInitiateAICallResponse: """ Initiate an outbound AI call with warm-up support: Telnyx attempts to warm up the assistant identified by `AIAssistantId` before placing the call and starts it automatically when the called party answers. Validates parameters, builds an internal TeXML with an AI Assistant configuration, encodes instructions into client state, and calls the dial API. The Twiml, Texml, and Url parameters are not allowed and will result in a 422 error. **Expected callback events:** Status callbacks: `initiated`, `ringing`, `answered`, one terminal status (`completed`, `no-answer`, `busy`, `canceled`, or `failed`), then `analyzed` after post-call processing completes. Conversation callbacks: `conversation_created` and `conversation_ended`. Recording, AMD, transcription, and deepfake detection callbacks are only sent when those features are enabled. Args: ai_assistant_id: The ID of the AI assistant to use for the call. Telnyx attempts to warm up this assistant before the call is placed and starts it automatically when the called party answers. from_: The phone number of the party initiating the call. Phone numbers are formatted with a `+` and country code. to: The phone number of the called party. Phone numbers are formatted with a `+` and country code. ai_assistant_dynamic_variables: Key-value map of dynamic variables to pass to the AI assistant. ai_assistant_version: The version of the AI assistant to use. async_amd: Select whether to perform answering machine detection in the background. By default execution is blocked until Answering Machine Detection is completed. async_amd_status_callback: URL destination for Telnyx to send AMD callback events to for the call. async_amd_status_callback_method: HTTP request type used for `AsyncAmdStatusCallback`. caller_id: 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 omitted, the display name will be the same as the number in the `From` field. conversation_callback: URL destination for Telnyx to send AI conversation callback events for this call. Events include `conversation_created` and `conversation_ended`. conversation_callback_method: HTTP request type used for `ConversationCallback` and `ConversationCallbacks`. conversation_callbacks: Array of URL destinations for AI conversation callback events for this call. Events include `conversation_created` and `conversation_ended`. custom_headers: Custom HTTP headers to be sent with the call. Each header should be an object with 'name' and 'value' properties. detection_mode: Allows you to choose between Regular, Premium, and PremiumCallScreening detections. See https://developers.telnyx.com/docs/voice/programmable-voice/answering-machine-detection machine_detection: Enables Answering Machine Detection. machine_detection_beep_max_frequency: Highest frequency, in Hz, that a tone can reach and still be treated as a beep. Only used when MachineDetection is enabled. machine_detection_beep_min_frequency: Lowest frequency, in Hz, that a tone must reach to be treated as a beep. Raising it above 480 excludes North American ringback (440 + 480 Hz), which can otherwise be reported as a beep when the `freq_only` profile is in use. Only used when MachineDetection is enabled. machine_detection_beep_min_tone_duration: Shortest tone, in milliseconds, that can be treated as a beep. Raising it rejects brief tones such as call-progress blips. Only used when MachineDetection is enabled. machine_detection_beep_profile: Selects which detectors must validate a beep. `both` requires the amplitude and frequency detectors to agree. `freq_only` uses the frequency detector alone, for beeps whose volume is too unsteady for the default profile. Only used when MachineDetection is enabled. machine_detection_beep_spectral_confirmation: When enabled, a candidate beep must pass an additional spectral check before it is reported. Only used when MachineDetection is enabled. machine_detection_beep_spectral_min_purity: Minimum spectral purity, from 0 to 1, for a tone to be treated as a beep. Raising it rejects mixed tones such as ringback, which combines two frequencies. Only used when MachineDetection is enabled. machine_detection_beep_spectral_reject_fax_cng: When enabled, the fax CNG tone is rejected rather than reported as a beep. Only used when MachineDetection is enabled. machine_detection_beep_spectral_window: Length of the spectral confirmation window, in milliseconds. Only used when MachineDetection is enabled. machine_detection_prompt_end_timeout: Silence duration threshold after a call screening prompt before ending prompt detection, in milliseconds. Used when `DetectionMode` is `PremiumCallScreening`. machine_detection_silence_timeout: If initial silence duration is greater than this value, consider it a machine. Ignored when `premium` detection is used. machine_detection_speech_end_threshold: Silence duration threshold after a greeting message or voice for it be considered human. Ignored when `premium` detection is used. machine_detection_speech_threshold: Maximum threshold of a human greeting. If greeting longer than this value, considered machine. Ignored when `premium` detection is used. machine_detection_timeout: Maximum timeout threshold in milliseconds for overall detection. passports: A string of passport identifiers to associate with the call. preferred_codecs: The list of comma-separated codecs to be offered on a call. record: Whether to record the entire participant's call leg. Defaults to `false`. recording_channels: The number of channels in the final recording. Defaults to `mono`. recording_status_callback: The URL the recording callbacks will be sent to. recording_status_callback_event: The changes to the recording's state that should generate a call to `RecordingStatusCallback`. Can be: `in-progress`, `completed` and `absent`. Separate multiple values with a space. Defaults to `completed`. recording_status_callback_method: HTTP request type used for `RecordingStatusCallback`. Defaults to `POST`. recording_timeout: 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. The minimum value is 0. The default value is 0 (infinite). recording_track: The audio track to record for the call. The default is `both`. send_recording_url: Whether to send RecordingUrl in webhooks. sip_auth_password: The password to use for SIP authentication. sip_auth_username: The username to use for SIP authentication. sip_region: Defines the SIP region to be used for the call. status_callback: URL destination for Telnyx to send status callback events for this AI call. When provided, this per-call value overrides the status callback URL configured on the TeXML application/connection. status_callback_event: The status callback events for which Telnyx should send a webhook for this AI call. Multiple events can be defined when separated by a space. Valid values: initiated, ringing, answered, completed, no-answer, busy, canceled, failed, analyzed. When provided, this per-call value overrides the status callback events configured on the TeXML application/connection. status_callback_method: HTTP request type used for `StatusCallback` and `StatusCallbacks` for this AI call. When provided, this per-call value overrides the status callback method configured on the TeXML application/connection. status_callbacks: Array of URL destinations for Telnyx to send status callback events for this AI call. When provided, these per-call values override the status callback URL configured on the TeXML application/connection. time_limit: The maximum duration of the call in seconds. The minimum value is 30 and the maximum value is 14400 (4 hours). Default is 14400 seconds. timeout_seconds: The number of seconds to wait for the called party to answer the call before the call is canceled. The minimum value is 5 and the maximum value is 120. Default is 30 seconds. trim: Whether to trim any leading and trailing silence from the recording. Defaults to `trim-silence`. 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 connection_id: raise ValueError(f"Expected a non-empty value for `connection_id` but received {connection_id!r}") return await self._post( path_template("/texml/ai_calls/{connection_id}", connection_id=connection_id), body=await async_maybe_transform( { "ai_assistant_id": ai_assistant_id, "from_": from_, "to": to, "ai_assistant_dynamic_variables": ai_assistant_dynamic_variables, "ai_assistant_version": ai_assistant_version, "async_amd": async_amd, "async_amd_status_callback": async_amd_status_callback, "async_amd_status_callback_method": async_amd_status_callback_method, "caller_id": caller_id, "conversation_callback": conversation_callback, "conversation_callback_method": conversation_callback_method, "conversation_callbacks": conversation_callbacks, "custom_headers": custom_headers, "detection_mode": detection_mode, "machine_detection": machine_detection, "machine_detection_beep_max_frequency": machine_detection_beep_max_frequency, "machine_detection_beep_min_frequency": machine_detection_beep_min_frequency, "machine_detection_beep_min_tone_duration": machine_detection_beep_min_tone_duration, "machine_detection_beep_profile": machine_detection_beep_profile, "machine_detection_beep_spectral_confirmation": machine_detection_beep_spectral_confirmation, "machine_detection_beep_spectral_min_purity": machine_detection_beep_spectral_min_purity, "machine_detection_beep_spectral_reject_fax_cng": machine_detection_beep_spectral_reject_fax_cng, "machine_detection_beep_spectral_window": machine_detection_beep_spectral_window, "machine_detection_prompt_end_timeout": machine_detection_prompt_end_timeout, "machine_detection_silence_timeout": machine_detection_silence_timeout, "machine_detection_speech_end_threshold": machine_detection_speech_end_threshold, "machine_detection_speech_threshold": machine_detection_speech_threshold, "machine_detection_timeout": machine_detection_timeout, "passports": passports, "preferred_codecs": preferred_codecs, "record": record, "recording_channels": recording_channels, "recording_status_callback": recording_status_callback, "recording_status_callback_event": recording_status_callback_event, "recording_status_callback_method": recording_status_callback_method, "recording_timeout": recording_timeout, "recording_track": recording_track, "send_recording_url": send_recording_url, "sip_auth_password": sip_auth_password, "sip_auth_username": sip_auth_username, "sip_region": sip_region, "status_callback": status_callback, "status_callback_event": status_callback_event, "status_callback_method": status_callback_method, "status_callbacks": status_callbacks, "time_limit": time_limit, "timeout_seconds": timeout_seconds, "trim": trim, }, texml_initiate_ai_call_params.TexmlInitiateAICallParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TexmlInitiateAICallResponse, ) async def secrets( self, *, name: str, value: 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, ) -> TexmlSecretsResponse: """ Create a TeXML secret which can be later used as a Dynamic Parameter for TeXML when using Mustache Templates in your TeXML. In your TeXML you will be able to use your secret name, and this name will be replaced by the actual secret value when processing the TeXML on Telnyx side. The secrets are not visible in any logs. Args: name: Name used as a reference for the secret, if the name already exists within the account its value will be replaced value: Secret value which will be used when rendering the TeXML template 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 """ return await self._post( "/texml/secrets", body=await async_maybe_transform( { "name": name, "value": value, }, texml_secrets_params.TexmlSecretsParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TexmlSecretsResponse, ) class TexmlResourceWithRawResponse: def __init__(self, texml: TexmlResource) -> None: self._texml = texml self.initiate_ai_call = to_raw_response_wrapper( texml.initiate_ai_call, ) self.secrets = to_raw_response_wrapper( texml.secrets, ) @cached_property def calls(self) -> CallsResourceWithRawResponse: """TeXML REST Commands""" return CallsResourceWithRawResponse(self._texml.calls) @cached_property def accounts(self) -> AccountsResourceWithRawResponse: """TeXML REST Commands""" return AccountsResourceWithRawResponse(self._texml.accounts) class AsyncTexmlResourceWithRawResponse: def __init__(self, texml: AsyncTexmlResource) -> None: self._texml = texml self.initiate_ai_call = async_to_raw_response_wrapper( texml.initiate_ai_call, ) self.secrets = async_to_raw_response_wrapper( texml.secrets, ) @cached_property def calls(self) -> AsyncCallsResourceWithRawResponse: """TeXML REST Commands""" return AsyncCallsResourceWithRawResponse(self._texml.calls) @cached_property def accounts(self) -> AsyncAccountsResourceWithRawResponse: """TeXML REST Commands""" return AsyncAccountsResourceWithRawResponse(self._texml.accounts) class TexmlResourceWithStreamingResponse: def __init__(self, texml: TexmlResource) -> None: self._texml = texml self.initiate_ai_call = to_streamed_response_wrapper( texml.initiate_ai_call, ) self.secrets = to_streamed_response_wrapper( texml.secrets, ) @cached_property def calls(self) -> CallsResourceWithStreamingResponse: """TeXML REST Commands""" return CallsResourceWithStreamingResponse(self._texml.calls) @cached_property def accounts(self) -> AccountsResourceWithStreamingResponse: """TeXML REST Commands""" return AccountsResourceWithStreamingResponse(self._texml.accounts) class AsyncTexmlResourceWithStreamingResponse: def __init__(self, texml: AsyncTexmlResource) -> None: self._texml = texml self.initiate_ai_call = async_to_streamed_response_wrapper( texml.initiate_ai_call, ) self.secrets = async_to_streamed_response_wrapper( texml.secrets, ) @cached_property def calls(self) -> AsyncCallsResourceWithStreamingResponse: """TeXML REST Commands""" return AsyncCallsResourceWithStreamingResponse(self._texml.calls) @cached_property def accounts(self) -> AsyncAccountsResourceWithStreamingResponse: """TeXML REST Commands""" return AsyncAccountsResourceWithStreamingResponse(self._texml.accounts)