sinch.domains.voice.api.v2.sinch_events module
- class sinch.domains.voice.api.v2.sinch_events.SinchEvents[source]
Bases:
objectHandler 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,
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,
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:
- 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],
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:
- 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:
- Returns:
The sinch event response, ready to be serialized.
- Return type:
- serialize_response(
- response: VoiceSinchEventResponse,
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]