sinch.domains.voice.api.v2 package

class sinch.domains.voice.api.v2.Batches(sinch)[source]

Bases: BaseVoice

start(commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], parameters: ~typing.List[~typing.Dict[str, str]], service_id: str | None = None, batch_options: ~sinch.domains.voice.models.v2.batches.types.batch_options_dict.BatchOptionsDict | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, idempotency_key: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) StartBatchResponse[source]

Create a batch of outbound calls, associated to the project’s default service or to the service specified in the serviceId query parameter.

Parameters:
  • commands (List[SvamlCommandDict]) – (required) SVAML commands describing the call flow.

  • parameters (List[Dict[str, str]]) – (required) Parameter sets for dynamic placeholders in the commands. One entry queues one call.

  • service_id (Optional[str]) – (optional) The ID of the service to use for the call. If omitted, the project’s default service is used.

  • batch_options (UnsetOr[Optional[BatchOptionsDict]]) – (optional) Options controlling how the batch is processed (maximum calls per second, time-to-live).

  • **kwargs

    Additional parameters for the request.

  • idempotency_key (str | None | Unset)

Returns:

The queued batch of call sessions.

Return type:

StartBatchResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

get(
batch_id: str,
**kwargs,
) BatchSummaryResponse[source]

Retrieve a summary of a batch call operation, including statistics on completed, failed, in-progress, and queued calls. This provides an overview of the batch execution state and individual call session states.

Parameters:
  • batch_id (str) – (required) The ID of the batch.

  • **kwargs

    Additional parameters for the request.

Returns:

The batch call summary.

Return type:

BatchSummaryResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

get_details(
batch_id: str,
**kwargs,
) BatchDetailsResponse[source]

Retrieve per-session details for a batch call operation, including the current state of each call session in the batch.

Use this endpoint when individual session-level visibility is needed (for example, to inspect which sessions are QUEUED, IN_PROGRESS or COMPLETED). EXPIRED sessions are never returned because they were never initiated.

Parameters:
  • batch_id (str) – (required) The ID of the batch.

  • **kwargs

    Additional parameters for the request.

Returns:

The per-session batch details.

Return type:

BatchDetailsResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

stop(
batch_id: str,
**kwargs,
) BatchStopResponse[source]

Stop processing a batch of call sessions. This will prevent any queued calls in the batch from being initiated. Calls that are already in progress will not be affected and will continue until completion.

Parameters:
  • batch_id (str) – (required) The ID of the batch.

  • **kwargs

    Additional parameters for the request.

Returns:

The state of the batch processing cancellation request.

Return type:

BatchStopResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

class sinch.domains.voice.api.v2.Calls(sinch)[source]

Bases: BaseVoice

start(commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], service_id: str | None = None, idempotency_key: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) StartCallResponse[source]

Create a new outbound call, associated to the project’s default service or to the service specified in the serviceId query parameter.

Parameters:
  • commands (List[SvamlCommandDict]) – (required) SVAML commands describing the call flow.

  • service_id (Optional[str]) – (optional) The ID of the service to use for the call. If omitted, the project’s default service is used.

  • idempotency_key (UnsetOr[Optional[str]]) – (optional) Client-generated idempotency key to safely retry requests. If a request with the same key is received within 10 minutes, the cached response from the original request is returned. Using a random UUID (v4) is strongly recommended.

  • **kwargs

    Additional parameters for the request.

Returns:

The created call session.

Return type:

StartCallResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

list(
service_id: str | None = None,
from_: str | None = None,
to: str | None = None,
call_type: Literal['PHONE', 'SIP', 'STREAM', 'VOICE_RELAY'] | Annotated[str, Strict(strict=True)] | None = None,
start_time: datetime | None = None,
end_time: datetime | None = None,
call_result: Literal['QUEUED', 'INITIATED', 'IN_PROGRESS', 'COMPLETED', 'REJECTED', 'NO_ANSWER', 'CANCEL', 'BUSY', 'FAILED'] | Annotated[str, Strict(strict=True)] | None = None,
call_reason: Literal['OK', 'NOT_AVAILABLE', 'CALLER_HANGUP', 'CALLEE_HANGUP', 'MANAGER_HANGUP', 'DID_NOT_FOUND', 'INVALID_SCRIPT', 'UNKNOWN_PRODUCT', 'NO_MORE_ROUTES', 'ERROR'] | Annotated[str, Strict(strict=True)] | None = None,
page_size: int | None = None,
page: int | None = None,
**kwargs,
) Paginator[ListCallsResponse, Call][source]

List and filter calls made with Sinch

Parameters:
  • service_id (Optional[str]) – (optional) The ID of the service.

  • from (Optional[str]) – (optional) Only include calls where from matches this origin. For inbound calls, this is the caller; for outbound calls, this is the calling party.

  • to (Optional[str]) – (optional) Only include calls where to matches this destination. For inbound calls, this is the called party; for outbound calls, this is the callee/recipient.

  • call_type (Optional[CallType]) – (optional) Only include calls of the specified type. If omitted, calls of all types are included.

  • start_time (Optional[datetime]) – (optional) Only include calls that started at or after this timestamp.

  • end_time (Optional[datetime]) – (optional) Only include calls that ended before this timestamp (exclusive).

  • call_result (Optional[CallResult]) – (optional) Filter results to only include calls whose call result matches the specified value. If omitted, calls with any result are included.

  • call_reason (Optional[CallReason]) – (optional) Filter results to only include calls whose call reason matches the specified value. If omitted, calls with any reason are included.

  • page_size (Optional[int]) – (optional) Number of items to be returned on each page.

  • page (Optional[int]) – (optional) Page number (1-based).

  • **kwargs

    Additional parameters for the request.

  • from_ (str | None)

Returns:

LinkBasedPaginator with Call items

Return type:

Paginator[ListCallsResponse,Call]

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

get(call_id: str, **kwargs) Call[source]

Retrieve detailed information about a specific call using its unique identifier.

Parameters:
  • call_id (str) – (required) The ID of the call.

  • **kwargs

    Additional parameters for the request.

Returns:

The call details.

Return type:

Call

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

interact_by_call_id(call_id: str, commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], idempotency_key: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) None[source]

Interact with an ongoing call by submitting a set of SVAML commands. Use this to force disconnect, play messages, bridge with another call, or perform other call control actions.

Parameters:
  • call_id (str) – (required) The ID of the call.

  • commands (List[SvamlCommandDict]) – (required) SVAML commands describing the call flow.

  • idempotency_key (UnsetOr[Optional[str]]) – (optional) Client-generated idempotency key to safely retry requests. If a request with the same key is received within 10 minutes, the cached response from the original request is returned. Using a random UUID (v4) is strongly recommended.

  • **kwargs

    Additional parameters for the request.

Returns:

None

Return type:

None

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

interact_by_call_name(session_id: str, call_name: str, commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], idempotency_key: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) None[source]

Interact with an ongoing call identified by its session and call name by submitting a set of SVAML commands. Use this to force disconnect, play messages, bridge with another call, or perform other call control actions.

Parameters:
  • session_id (str) – (required) The ID of the session.

  • call_name (str) – (required) The name of the call leg within the session, as assigned by the callName property in the dial command.

  • commands (List[SvamlCommandDict]) – (required) SVAML commands describing the call flow.

  • idempotency_key (UnsetOr[Optional[str]]) – (optional) Client-generated idempotency key to safely retry requests. If a request with the same key is received within 10 minutes, the cached response from the original request is returned. Using a random UUID (v4) is strongly recommended.

  • **kwargs

    Additional parameters for the request.

Returns:

None

Return type:

None

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

class sinch.domains.voice.api.v2.Services(sinch)[source]

Bases: BaseVoice

list(
filter: str | None = None,
is_default: bool | None = None,
page_size: int | None = None,
page: int | None = None,
**kwargs,
) Paginator[ListServicesResponse, ServiceShortResponse][source]

List and filter the services configured for a project.

Parameters:
  • filter (Optional[str]) – (optional) Filter services by name or description. Returns all services where either the name or description contains the specified value (case-insensitive partial match).

  • is_default (Optional[bool]) – (optional) Return only the default service.

  • page_size (Optional[int]) – (optional) Number of items to be returned on each page.

  • page (Optional[int]) – (optional) Page number (1-based).

  • **kwargs

    Additional parameters for the request.

Returns:

LinkBasedPaginator with ServiceShortResponse items

Return type:

Paginator[ListServicesResponse,ServiceShortResponse]

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

create(
name: str,
description: str | None | Unset = <sinch.core.sentinel.Unset object>,
is_default: bool | None | Unset = <sinch.core.sentinel.Unset object>,
call_behavior: StaticCallBehaviorDict,
FieldInfo(annotation=NoneType,
required=True,
discriminator='type')] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>,
idempotency_key: str | None | Unset = <sinch.core.sentinel.Unset object>,
**kwargs,
) ServiceResponse[source]

Creates a new voice service.

Parameters:
  • name (str) – (required) The name of the service. Must be 1-64 characters, with no leading, trailing, or repeated whitespace. Regex pattern: ^S+(s+S+)*$.

  • description (UnsetOr[Optional[str]]) – (optional) A description of the service. Must be at most 255 characters, with no leading, trailing, or repeated whitespace. Regex pattern: ^S+(s+S+)*$.

  • is_default (UnsetOr[Optional[bool]]) – (optional) Whether this service is the project default. The default service is used when no specific service is specified in API requests

  • call_behavior (UnsetOr[Optional[CallBehaviorDict]]) – (optional) Defines how calls are handled for this service.

  • idempotency_key (UnsetOr[Optional[str]]) – (optional) Client-generated idempotency key to safely retry requests. If a request with the same key is received within 10 minutes, the cached response from the original request is returned. Using a random UUID (v4) is strongly recommended.

  • **kwargs

    Additional parameters for the request.

Returns:

The created service.

Return type:

ServiceResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

get(
service_id: str,
**kwargs,
) ServiceResponse[source]

Retrieve detailed information about a specific service using its unique identifier.

Parameters:
  • service_id (str) – (required) The ID of the service.

  • **kwargs

    Additional parameters for the request.

Returns:

The service details.

Return type:

ServiceResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

update(
service_id: str,
name: str | None | Unset = <sinch.core.sentinel.Unset object>,
description: str | None | Unset = <sinch.core.sentinel.Unset object>,
is_default: Literal[True] | None | Unset = <sinch.core.sentinel.Unset object>,
call_behavior: StaticCallBehaviorDict,
FieldInfo(annotation=NoneType,
required=True,
discriminator='type')] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>,
idempotency_key: str | None | Unset = <sinch.core.sentinel.Unset object>,
**kwargs,
) ServiceResponse[source]

Updates an existing service resource with the provided properties. Only the fields included in the request body will be modified; omitted fields remain unchanged.

To set a service as the default for the project, include is_default=True. Note that each project can have only one default service. Setting a new default will automatically remove the default status from the previously designated service.

Parameters:
  • service_id (str) – (required) The ID of the service.

  • name (str) – (optional) The name of the service. Must be 1-64 characters, with no leading, trailing, or repeated whitespace. Regex pattern: ^S+(s+S+)*$.

  • description (UnsetOr[Optional[str]]) – (optional) A description of the service. Must be at most 255 characters, with no leading, trailing, or repeated whitespace. Regex pattern: ^S+(s+S+)*$.

  • is_default (UnsetOr[Optional[Literal[True]]]) – (optional) Whether this service is the project default. Setting this to false is invalid.

  • call_behavior (UnsetOr[Optional[CallBehaviorDict]]) – (optional) Defines how calls are handled for this service.

  • idempotency_key (UnsetOr[Optional[str]]) – (optional) Client-generated idempotency key to safely retry requests. If a request with the same key is received within 10 minutes, the cached response from the original request is returned. Using a random UUID (v4) is strongly recommended.

  • **kwargs

    Additional parameters for the request.

Returns:

The updated service.

Return type:

ServiceResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

delete(service_id: str, **kwargs) None[source]

Deletes a service permanently.

Important: The default service cannot be deleted. To delete the current default service, a different service must first be designated as the default using the PATCH endpoint.

Parameters:
  • service_id (str) – (required) The ID of the service.

  • **kwargs

    Additional parameters for the request.

Returns:

None

Return type:

None

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

class sinch.domains.voice.api.v2.Sessions(sinch)[source]

Bases: BaseVoice

get(
session_id: str,
**kwargs,
) SessionResponse[source]

Retrieve detailed information about a specific session, including all associated calls and their current states. Sessions represent the complete interaction lifecycle and can contain multiple related calls.

Parameters:
  • session_id (str) – (required) The ID of the session.

  • **kwargs

    Additional parameters for the request.

Returns:

The session details.

Return type:

SessionResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

class sinch.domains.voice.api.v2.Svaml(sinch)[source]

Bases: BaseVoice

describe(commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], call_name: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, on_hangup: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) DescribeSvamlResponse[source]

Describe the call flow from the SVAML payload. This endpoint is useful for understanding the structure and flow of a SVAML payload without executing it. It provides a detailed description of the commands, events, and messages defined in the SVAML.

Parameters:
  • commands (List[SvamlCommandDict]) – (required) The ordered list of SVAML commands to describe.

  • call_name (UnsetOr[Optional[str]]) – (optional) Name of the call.

  • on_hangup (UnsetOr[Optional[List[SvamlCommandDict]]]) – (optional) Commands to describe when the call is hung up.

  • **kwargs

    Additional parameters for the request.

Returns:

A human-readable description of the SVAML call flow.

Return type:

DescribeSvamlResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

validate(commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], call_name: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, on_hangup: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, validation_type: ~typing.Literal['NORMAL', 'STRICT'] | ~typing.Annotated[str, ~pydantic.types.Strict(strict=True)] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, **kwargs) ValidateSvamlResponse[source]

Validate a SVAML payload. This endpoint checks the structure and content of the SVAML commands to ensure they conform to the expected schema and rules. It can operate in different validation modes, such as strict or lenient, depending on the requirements.

Parameters:
  • commands (List[SvamlCommandDict]) – (required) The ordered list of SVAML commands to validate.

  • call_name (UnsetOr[Optional[str]]) – (optional) Name of the call.

  • on_hangup (UnsetOr[Optional[List[SvamlCommandDict]]]) – (optional) Commands to validate when the call is hung up.

  • validation_type (UnsetOr[Optional[ValidationType]]) – (optional) Controls how strictly the SVAML payload is validated. If omitted, the server applies the default value NORMAL.

  • **kwargs

    Additional parameters for the request.

Returns:

The result of the SVAML validation.

Return type:

ValidateSvamlResponse

For detailed documentation, visit https://developers.sinch.com/docs/voice-2.0.

class sinch.domains.voice.api.v2.SinchEvents[source]

Bases: object

Handler for Voice API v2 Sinch Events.

validate_authentication_header(
method: str,
path: str,
headers: Dict[str, str],
body: str | bytes,
service_id: str,
service_secret: str,
) bool[source]

Validate the Authorization header of an incoming Sinch Event request.

Parameters:
  • method (str) – (required) HTTP method of the incoming request.

  • path (str) – (required) Canonicalized resource path of the incoming request.

  • headers (Dict[str, str]) – (required) Incoming request’s headers.

  • body (Union[str, bytes]) – (required) Incoming request’s raw body.

  • service_secret (str) – (required) The service secret used to validate the authentication header.

  • service_id (str) – (required) The service key used to validate the authentication header.

Returns:

True if the Authorization header is valid.

Return type:

bool

Raises:

ValueError – If no service secret is available.

parse_event(
event_body: str | bytes | Dict[str, Any],
headers: Dict[str, str] | None = None,
) VoiceSinchEventRequest[source]

Parse an incoming sinch event request body into a typed event.

Parameters:
  • event_body (Union[str, bytes, Dict[str, Any]]) – The event payload (JSON string, raw bytes, or dict).

  • headers (Optional[Dict[str, str]]) – Request headers (used to decode charset when event_body is bytes).

Returns:

The parsed sinch event request.

Return type:

VoiceSinchEventRequest

Raises:

ValueError – If JSON parsing fails or the payload is invalid.

build_response(
commands: List[AmdCommandDict | DialCommandDict | MessagesCommandDict | StopMessagesCommandDict | CustomEventCommandDict | HangupCommandDict | AnswerCommandDict | PauseCommandDict | StartRecordingCommandDict | StopRecordingCommandDict | BridgeCallCommandDict | MenuCommandDict | GotoMenuCommandDict],
) VoiceSinchEventResponse[source]

Build the SVAML response to return from a sinch event handler.

Parameters:

commands (List[SvamlCommandDict]) – (required) The ordered list of SVAML commands to execute.

Returns:

The sinch event response, ready to be serialized.

Return type:

VoiceSinchEventResponse

build_incoming_call_response(commands: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict], call_name: str | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>, on_hangup: ~typing.List[~sinch.domains.voice.models.v2.svaml.types.amd_command_dict.AmdCommandDict | ~sinch.domains.voice.models.v2.svaml.types.dial_command_dict.DialCommandDict | ~sinch.domains.voice.models.v2.svaml.types.messages_command_dict.MessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_messages_command_dict.StopMessagesCommandDict | ~sinch.domains.voice.models.v2.svaml.types.custom_event_command_dict.CustomEventCommandDict | ~sinch.domains.voice.models.v2.svaml.types.hangup_command_dict.HangupCommandDict | ~sinch.domains.voice.models.v2.svaml.types.answer_command_dict.AnswerCommandDict | ~sinch.domains.voice.models.v2.svaml.types.pause_command_dict.PauseCommandDict | ~sinch.domains.voice.models.v2.svaml.types.start_recording_command_dict.StartRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.stop_recording_command_dict.StopRecordingCommandDict | ~sinch.domains.voice.models.v2.svaml.types.bridge_call_command_dict.BridgeCallCommandDict | ~sinch.domains.voice.models.v2.svaml.types.menu_command_dict.MenuCommandDict | ~sinch.domains.voice.models.v2.svaml.types.goto_menu_command_dict.GotoMenuCommandDict] | None | ~sinch.core.sentinel.Unset = <sinch.core.sentinel.Unset object>) VoiceSinchEventResponse[source]

Build the SVAML response to return from the handler for a call.incoming sinch event.

Parameters:
  • commands (List[SvamlCommandDict]) – (required) The ordered list of SVAML commands to execute.

  • call_name (UnsetOr[Optional[str]]) – (optional) Name of the call.

  • on_hangup (UnsetOr[Optional[List[SvamlCommandDict]]]) – (optional) Commands to execute when the call is hung up.

Returns:

The sinch event response, ready to be serialized.

Return type:

VoiceSinchEventResponse

serialize_response(
response: VoiceSinchEventResponse,
) Dict[str, Any][source]

Serialize a sinch event response into a JSON-ready dict.

Parameters:

response (VoiceSinchEventResponse) – The sinch event response to serialize.

Returns:

The response body to return from the sinch event handler.

Return type:

Dict[str, Any]

exception sinch.domains.voice.api.v2.VoiceException(message, response, is_from_server, error_type=None, instance=None)[source]

Bases: SinchException