Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions voice/src/vonage_voice/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
Embedded,
HalLinks,
)
from .webhooks import AnswerWebhook

__all__ = [
'AdvancedMachineDetection',
'AppEndpoint',
'AudioStreamOptions',
'AnswerWebhook',
'CallInfo',
'CallList',
'CallMessage',
Expand Down
36 changes: 36 additions & 0 deletions voice/src/vonage_voice/models/webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class AnswerWebhook(BaseModel):
"""Model for the Voice API Answer webhook payload.

Args:
to (str, Optional): The number or endpoint that answered the call.
from_ (str, Optional): The number or endpoint that initiated the call.
from_user (str, Optional): The Client SDK user that initiated the call.
endpoint_type (str, Optional): The type of endpoint that answered the call.
uuid (str, Optional): The unique identifier for this call.
conversation_uuid (str, Optional): The unique identifier for this conversation.
region_url (str, Optional): Regional API endpoint to control the call.
custom_data (dict, Optional): Custom data object passed from the Client SDK.
sipheader_user_to_user (str, Optional): Content of the SIP User-to-User header,
received as the `SipHeader_User-to-User` parameter on the webhook.
"""

model_config = ConfigDict(populate_by_name=True)

to: Optional[str] = None
from_: Optional[str] = Field(None, alias='from')
from_user: Optional[str] = None
endpoint_type: Optional[str] = None
uuid: Optional[str] = None
conversation_uuid: Optional[str] = None
region_url: Optional[str] = None
custom_data: Optional[dict] = None
sipheader_user_to_user: Optional[str] = Field(
None,
validation_alias='SipHeader_User-to-User',
serialization_alias='SipHeader_User-to-User',
)
24 changes: 24 additions & 0 deletions voice/tests/test_answer_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from vonage_voice.models import AnswerWebhook


def test_answer_webhook_sipheader_user_to_user_alias():
payload = {
'to': '442079460000',
'from': '447700900000',
'uuid': 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
'conversation_uuid': 'CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
'SipHeader_User-to-User': '1234567890abcdef;encoding=hex',
}

hook = AnswerWebhook(**payload)

assert hook.to == '442079460000'
assert hook.from_ == '447700900000'
assert (
hook.sipheader_user_to_user == '1234567890abcdef;encoding=hex'
), 'Field should be populated from SipHeader_User-to-User'

dumped = hook.model_dump(by_alias=True, exclude_none=True)
assert (
dumped['SipHeader_User-to-User'] == '1234567890abcdef;encoding=hex'
), 'Field should serialize back with the SipHeader_User-to-User key'
3 changes: 1 addition & 2 deletions voice/tests/test_voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import responses
from pytest import raises
from responses.matchers import json_params_matcher
from testutils import build_response, get_mock_jwt_auth
from vonage_http_client.http_client import HttpClient
from vonage_voice import (
AudioStreamOptions,
Expand All @@ -17,8 +18,6 @@
from vonage_voice.models.responses import CreateCallResponse
from vonage_voice.voice import Voice

from testutils import build_response, get_mock_jwt_auth

path = abspath(__file__)


Expand Down