Skip to content

Commit ff25ff3

Browse files
committed
finish adding NCCO actions and add tests
1 parent 5e7d13e commit ff25ff3

File tree

12 files changed

+564
-202
lines changed

12 files changed

+564
-202
lines changed

messages/tests/BUILD

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
python_tests(dependencies=['messages', 'testutils'])
2-
3-
python_sources(
4-
name="tests0",
5-
)

voice/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@ This package contains the code to use [Vonage's Voice API](https://developer.von
77
It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`.
88

99
### Create a Call
10+
11+
12+
### Note on URLs
13+
14+
The Voice API requires most URLs to be passed in a list with only one element. When creating models, simply pass the url and the model will marshal it into the correct structure for you.
15+
16+
e.g.
17+
18+
```python
19+
# Don't do this
20+
21+
22+
# Do this
23+
24+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_sources()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from .common import AdvancedMachineDetection
2+
from .connect_endpoints import (
3+
AppEndpoint,
4+
OnAnswer,
5+
PhoneEndpoint,
6+
SipEndpoint,
7+
VbcEndpoint,
8+
WebsocketEndpoint,
9+
)
10+
from .enums import Channel, ConnectEndpointType, NccoActionType
11+
from .input_types import Dtmf, Speech
12+
from .ncco import Connect, Conversation, Input, NccoAction, Notify, Record, Stream, Talk
13+
from .requests import Call, NccoAction, Phone, Sip, ToPhone, Vbc, Websocket
14+
from .responses import CallStatus, CreateCallResponse
15+
16+
__all__ = [
17+
'AdvancedMachineDetection',
18+
'Call',
19+
'ToPhone',
20+
'Sip',
21+
'Websocket',
22+
'Vbc',
23+
'Phone',
24+
'NccoAction',
25+
'Channel',
26+
'NccoActionType',
27+
'ConnectEndpointType',
28+
'OnAnswer',
29+
'PhoneEndpoint',
30+
'AppEndpoint',
31+
'WebsocketEndpoint',
32+
'SipEndpoint',
33+
'VbcEndpoint',
34+
'Dtmf',
35+
'Speech',
36+
'CreateCallResponse',
37+
'CallStatus',
38+
'Record',
39+
'Conversation',
40+
'Connect',
41+
'Talk',
42+
'Stream',
43+
'Input',
44+
'Notify',
45+
]

voice/src/vonage_voice/models/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
class AdvancedMachineDetection(BaseModel):
77
behavior: Optional[Literal['continue', 'hangup']] = None
8-
mode: Optional[Literal['default', 'detect', 'detect_beep']] = 'detect'
8+
mode: Optional[Literal['default', 'detect', 'detect_beep']] = None
99
beep_timeout: Optional[int] = Field(None, ge=45, le=120)
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
1-
from pydantic import BaseModel, AnyUrl, Field
21
from typing import Optional
3-
from typing_extensions import Literal
4-
5-
from .enums import ConnectEndpointType
62

3+
from pydantic import BaseModel, Field
4+
from typing_extensions import Literal
75
from vonage_utils.types import Dtmf, PhoneNumber, SipUri
86

9-
10-
class BaseEndpoint(BaseModel):
11-
"""Base Endpoint model for use with the NCCO Connect action."""
7+
from .enums import ConnectEndpointType
128

139

1410
class OnAnswer(BaseModel):
15-
url: AnyUrl
16-
ringbackTone: Optional[AnyUrl] = None
11+
url: str
12+
ringbackTone: Optional[str] = None
1713

1814

19-
class PhoneEndpoint(BaseEndpoint):
15+
class PhoneEndpoint(BaseModel):
2016
number: PhoneNumber
2117
dtmfAnswer: Optional[Dtmf] = None
2218
onAnswer: Optional[OnAnswer] = None
2319
type: ConnectEndpointType = ConnectEndpointType.PHONE
2420

2521

26-
class AppEndpoint(BaseEndpoint):
22+
class AppEndpoint(BaseModel):
2723
user: str
2824
type: ConnectEndpointType = ConnectEndpointType.APP
2925

3026

31-
class WebsocketEndpoint(BaseEndpoint):
32-
uri: AnyUrl
27+
class WebsocketEndpoint(BaseModel):
28+
uri: str
3329
contentType: Literal['audio/l16;rate=16000', 'audio/l16;rate=8000'] = Field(
34-
'audio/l16;rate=16000', serialization_alias='content-type'
30+
None, serialization_alias='content-type'
3531
)
36-
headers: Optional[dict] = {}
32+
headers: Optional[dict] = None
3733
type: ConnectEndpointType = ConnectEndpointType.WEBSOCKET
3834

3935

40-
class SipEndpoint(BaseEndpoint):
36+
class SipEndpoint(BaseModel):
4137
uri: SipUri
42-
headers: Optional[dict] = {}
38+
headers: Optional[dict] = None
4339
type: ConnectEndpointType = ConnectEndpointType.SIP
4440

4541

46-
class VbcEndpoint(BaseEndpoint):
42+
class VbcEndpoint(BaseModel):
4743
extension: str
4844
type: ConnectEndpointType = ConnectEndpointType.VBC

voice/src/vonage_voice/models/enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from enum import Enum
22

33

4-
class Channel(Enum, str):
4+
class Channel(str, Enum):
55
PHONE = 'phone'
66
SIP = 'sip'
77
WEBSOCKET = 'websocket'
88
VBC = 'vbc'
99

1010

11-
class NccoActionType(Enum, str):
11+
class NccoActionType(str, Enum):
1212
RECORD = 'record'
1313
CONVERSATION = 'conversation'
1414
CONNECT = 'connect'
@@ -18,7 +18,7 @@ class NccoActionType(Enum, str):
1818
NOTIFY = 'notify'
1919

2020

21-
class ConnectEndpointType(Enum, str):
21+
class ConnectEndpointType(str, Enum):
2222
PHONE = 'phone'
2323
APP = 'app'
2424
WEBSOCKET = 'websocket'
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
from pydantic import BaseModel, confloat, conint
2-
from typing import Optional, List
1+
from typing import List, Optional
32

3+
from pydantic import BaseModel, Field
44

5-
class InputTypes:
6-
class Dtmf(BaseModel):
7-
timeOut: Optional[conint(ge=0, le=10)]
8-
maxDigits: Optional[conint(ge=1, le=20)]
9-
submitOnHash: Optional[bool]
105

11-
class Speech(BaseModel):
12-
uuid: Optional[str]
13-
endOnSilence: Optional[confloat(ge=0.4, le=10.0)]
14-
language: Optional[str]
15-
context: Optional[List[str]]
16-
startTimeout: Optional[conint(ge=1, le=60)]
17-
maxDuration: Optional[conint(ge=1, le=60)]
18-
saveAudio: Optional[bool]
6+
class Dtmf(BaseModel):
7+
timeOut: Optional[int] = Field(None, ge=0, le=10)
8+
maxDigits: Optional[int] = Field(None, ge=1, le=20)
9+
submitOnHash: Optional[bool] = None
1910

20-
@classmethod
21-
def create_dtmf_model(cls, dict) -> Dtmf:
22-
return cls.Dtmf.parse_obj(dict)
2311

24-
@classmethod
25-
def create_speech_model(cls, dict) -> Speech:
26-
return cls.Speech.parse_obj(dict)
12+
class Speech(BaseModel):
13+
uuid: Optional[List[str]] = None
14+
endOnSilence: Optional[float] = Field(None, ge=0.4, le=10.0)
15+
language: Optional[str] = None
16+
context: Optional[List[str]] = None
17+
startTimeout: Optional[int] = Field(None, ge=1, le=60)
18+
maxDuration: Optional[int] = Field(None, ge=1, le=60)
19+
saveAudio: Optional[bool] = False
20+
sensitivity: Optional[int] = Field(None, ge=0, le=100)

0 commit comments

Comments
 (0)