Skip to content

Commit 18c4466

Browse files
committed
feat(voice): add AnswerWebhook support
1 parent c82446d commit 18c4466

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

voice/src/vonage_voice/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ToPhone,
2424
TtsStreamOptions,
2525
)
26+
from .webhooks import AnswerWebhook
2627
from .responses import (
2728
CallInfo,
2829
CallList,
@@ -36,6 +37,7 @@
3637
'AdvancedMachineDetection',
3738
'AppEndpoint',
3839
'AudioStreamOptions',
40+
'AnswerWebhook',
3941
'CallInfo',
4042
'CallList',
4143
'CallMessage',
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import Optional
2+
3+
from pydantic import BaseModel, Field
4+
5+
6+
class AnswerWebhook(BaseModel):
7+
"""Model for the Voice API Answer webhook payload.
8+
9+
Args:
10+
to (str, Optional): The number or endpoint that answered the call.
11+
from_ (str, Optional): The number or endpoint that initiated the call.
12+
from_user (str, Optional): The Client SDK user that initiated the call.
13+
endpoint_type (str, Optional): The type of endpoint that answered the call.
14+
uuid (str, Optional): The unique identifier for this call.
15+
conversation_uuid (str, Optional): The unique identifier for this conversation.
16+
region_url (str, Optional): Regional API endpoint to control the call.
17+
custom_data (dict, Optional): Custom data object passed from the Client SDK.
18+
sipheader_user_to_user (str, Optional): Content of the SIP User-to-User header,
19+
received as the `SipHeader_User-to-User` parameter on the webhook.
20+
"""
21+
22+
to: Optional[str] = None
23+
from_: Optional[str] = Field(None, alias='from')
24+
from_user: Optional[str] = None
25+
endpoint_type: Optional[str] = None
26+
uuid: Optional[str] = None
27+
conversation_uuid: Optional[str] = None
28+
region_url: Optional[str] = None
29+
custom_data: Optional[dict] = None
30+
sipheader_user_to_user: Optional[str] = Field(
31+
None, serialization_alias='SipHeader_User-to-User'
32+
)
33+

voice/tests/test_answer_webhook.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from vonage_voice.models import AnswerWebhook
2+
3+
4+
def test_answer_webhook_sipheader_user_to_user_alias():
5+
payload = {
6+
'to': '442079460000',
7+
'from': '447700900000',
8+
'uuid': 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
9+
'conversation_uuid': 'CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
10+
'SipHeader_User-to-User': '1234567890abcdef;encoding=hex',
11+
}
12+
13+
hook = AnswerWebhook(**payload)
14+
15+
assert hook.to == '442079460000'
16+
assert hook.from_ == '447700900000'
17+
assert (
18+
hook.sipheader_user_to_user == '1234567890abcdef;encoding=hex'
19+
), 'Field should be populated from SipHeader_User-to-User'
20+
21+
dumped = hook.model_dump(by_alias=True, exclude_none=True)
22+
assert (
23+
dumped['SipHeader_User-to-User'] == '1234567890abcdef;encoding=hex'
24+
), 'Field should serialize back with the SipHeader_User-to-User key'
25+

0 commit comments

Comments
 (0)