-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start adding voice api and ncco builder
- Loading branch information
Showing
38 changed files
with
901 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
resource(name='pyproject', source='pyproject.toml') | ||
file(name='readme', source='README.md') | ||
|
||
files(sources=['tests/data/*']) | ||
|
||
python_distribution( | ||
name='vonage-voice', | ||
dependencies=[ | ||
':pyproject', | ||
':readme', | ||
'voice/src/vonage_voice', | ||
], | ||
provides=python_artifact(), | ||
generate_setup=False, | ||
repositories=['@pypi'], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 1.0.1 | ||
- Initial upload | ||
|
||
# 1.0.0 | ||
- This version was skipped due to a technical issue with the package distribution. Please use version 1.0.1 or later. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Vonage Voice Package | ||
|
||
This package contains the code to use [Vonage's Voice API](https://developer.vonage.com/en/voice/voice-api/overview) in Python. This package includes methods for working with the Voice API. It also contains an NCCO (Call Control Object) builder to help you to control call flow. | ||
|
||
## Usage | ||
|
||
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`. | ||
|
||
### Create a Call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[project] | ||
name = 'vonage-voice' | ||
version = '1.0.0' | ||
description = 'Vonage voice package' | ||
readme = "README.md" | ||
authors = [{ name = "Vonage", email = "devrel@vonage.com" }] | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
"vonage-http-client>=1.2.1", | ||
"vonage-utils>=1.0.1", | ||
"pydantic>=2.6.1", | ||
] | ||
classifiers = [ | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"License :: OSI Approved :: Apache Software License", | ||
] | ||
|
||
[project.urls] | ||
homepage = "https://github.com/Vonage/vonage-python-sdk" | ||
|
||
[build-system] | ||
requires = ["setuptools>=61.0", "wheel"] | ||
build-backend = "setuptools.build_meta" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .voice import Voice | ||
|
||
__all__ = ['Voice'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from vonage_utils.errors import VonageError | ||
|
||
|
||
class VoiceError(VonageError): | ||
"""Indicates an error when using the Vonage Voice API.""" | ||
|
||
|
||
class NccoActionError(VoiceError): | ||
"""Indicates an error when using an NCCO action.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import Literal, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class AdvancedMachineDetection(BaseModel): | ||
behavior: Optional[Literal['continue', 'hangup']] = None | ||
mode: Optional[Literal['default', 'detect', 'detect_beep']] = 'detect' | ||
beep_timeout: Optional[int] = Field(None, ge=45, le=120) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pydantic import BaseModel, AnyUrl, Field | ||
from typing import Optional | ||
from typing_extensions import Literal | ||
|
||
from .enums import ConnectEndpointType | ||
|
||
from vonage_utils.types import Dtmf, PhoneNumber, SipUri | ||
|
||
|
||
class BaseEndpoint(BaseModel): | ||
"""Base Endpoint model for use with the NCCO Connect action.""" | ||
|
||
|
||
class OnAnswer(BaseModel): | ||
url: AnyUrl | ||
ringbackTone: Optional[AnyUrl] = None | ||
|
||
|
||
class PhoneEndpoint(BaseEndpoint): | ||
number: PhoneNumber | ||
dtmfAnswer: Optional[Dtmf] = None | ||
onAnswer: Optional[OnAnswer] = None | ||
type: ConnectEndpointType = ConnectEndpointType.PHONE | ||
|
||
|
||
class AppEndpoint(BaseEndpoint): | ||
user: str | ||
type: ConnectEndpointType = ConnectEndpointType.APP | ||
|
||
|
||
class WebsocketEndpoint(BaseEndpoint): | ||
uri: AnyUrl | ||
contentType: Literal['audio/l16;rate=16000', 'audio/l16;rate=8000'] = Field( | ||
'audio/l16;rate=16000', serialization_alias='content-type' | ||
) | ||
headers: Optional[dict] = {} | ||
type: ConnectEndpointType = ConnectEndpointType.WEBSOCKET | ||
|
||
|
||
class SipEndpoint(BaseEndpoint): | ||
uri: SipUri | ||
headers: Optional[dict] = {} | ||
type: ConnectEndpointType = ConnectEndpointType.SIP | ||
|
||
|
||
class VbcEndpoint(BaseEndpoint): | ||
extension: str | ||
type: ConnectEndpointType = ConnectEndpointType.VBC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from enum import Enum | ||
|
||
|
||
class Channel(Enum, str): | ||
PHONE = 'phone' | ||
SIP = 'sip' | ||
WEBSOCKET = 'websocket' | ||
VBC = 'vbc' | ||
|
||
|
||
class NccoActionType(Enum, str): | ||
RECORD = 'record' | ||
CONVERSATION = 'conversation' | ||
CONNECT = 'connect' | ||
TALK = 'talk' | ||
STREAM = 'stream' | ||
INPUT = 'input' | ||
NOTIFY = 'notify' | ||
|
||
|
||
class ConnectEndpointType(Enum, str): | ||
PHONE = 'phone' | ||
APP = 'app' | ||
WEBSOCKET = 'websocket' | ||
SIP = 'sip' | ||
VBC = 'vbc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from pydantic import BaseModel, confloat, conint | ||
from typing import Optional, List | ||
|
||
|
||
class InputTypes: | ||
class Dtmf(BaseModel): | ||
timeOut: Optional[conint(ge=0, le=10)] | ||
maxDigits: Optional[conint(ge=1, le=20)] | ||
submitOnHash: Optional[bool] | ||
|
||
class Speech(BaseModel): | ||
uuid: Optional[str] | ||
endOnSilence: Optional[confloat(ge=0.4, le=10.0)] | ||
language: Optional[str] | ||
context: Optional[List[str]] | ||
startTimeout: Optional[conint(ge=1, le=60)] | ||
maxDuration: Optional[conint(ge=1, le=60)] | ||
saveAudio: Optional[bool] | ||
|
||
@classmethod | ||
def create_dtmf_model(cls, dict) -> Dtmf: | ||
return cls.Dtmf.parse_obj(dict) | ||
|
||
@classmethod | ||
def create_speech_model(cls, dict) -> Speech: | ||
return cls.Speech.parse_obj(dict) |
Oops, something went wrong.