Skip to content

Commit 72100ab

Browse files
Merge branch 'DX-2897' into DX-2910
2 parents f14d158 + 2b48892 commit 72100ab

31 files changed

+1055
-2
lines changed

bandwidth/model/bxml/terminal_verb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def add_verb(self, verb: Verb):
2828
verb (Verb): BXML verb
2929
3030
Raises:
31-
AttributeError: This method is not allowed for <SipUri>
31+
AttributeError: This method is not allowed for this verb
3232
"""
3333
raise AttributeError('Adding verbs is not supported by this verb')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
from .bridge import Bridge
2+
from .hangup import Hangup
3+
from .gather import Gather
4+
from .pause import Pause
25
from .pause_recording import PauseRecording
36
from .phone_number import PhoneNumber
7+
from .play_audio import PlayAudio
48
from .record import Record
9+
from .send_dtmf import SendDtmf
510
from .sip_uri import SipUri
11+
from .speak_sentence import SpeakSentence
612
from .start_gather import StartGather
13+
from .start_recording import StartRecording
14+
from .start_stream import StartStream
15+
from .stop_gather import StopGather
16+
from .stop_stream import StopStream
17+
from .stop_recording import StopRecording
18+
from .stream_param import StreamParam
719
from .tag import Tag
820
from .transfer import Transfer
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
forward.py
3+
4+
Bandwidth's Forward BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Forward(TerminalVerb):
12+
13+
def __init__(
14+
self, to: str=None, _from: str=None,
15+
call_timeout: str=None, diversion_treatment: str=None,
16+
diversion_reason: str=None, uui: str=None
17+
):
18+
"""Initialize a <Forward> verb
19+
20+
Args:
21+
to (str): The phone number destination of the call.
22+
from_ (str, optional): The phone number that the recipient will receive the call from.
23+
call_timeout (str, optional): The number of seconds to wait before timing out the call.
24+
diversion_treatment (str, optional): Can be any of the following:
25+
none: No diversion headers are sent on the outbound leg of the transferred call.
26+
propagate: Copy the Diversion header from the inbound leg to the outbound leg. Ignored if there is no Diversion header present on the inbound leg.
27+
stack: After propagating any Diversion header from the inbound leg to the outbound leg, stack on top another Diversion header based on the Request-URI of the inbound call.
28+
29+
Defaults to none. If diversionTreatment is not specified, no diversion header will be included for the transfer even if one came with the inbound call. Defaults to None.
30+
diversion_reason (str, optional): Can be any of the following values:
31+
unknown
32+
user-busy
33+
no-answer
34+
unavailable
35+
unconditional
36+
time-of-day
37+
do-not-disturb
38+
deflection
39+
follow-me
40+
out-of-service
41+
away
42+
43+
This parameter is considered only when diversionTreatment is set to stack. Defaults is unknown.
44+
Defaults to None.
45+
uui (str, optional): The value of the User-To-User header to send within the outbound INVITE when forwarding to a SIP URI.
46+
Must include the encoding parameter as specified in RFC 7433. Only base64 and jwt encoding are currently allowed.
47+
This value, including the encoding specifier, may not exceed 256 characters.
48+
"""
49+
self.to = to
50+
self._from = _from
51+
self.call_timeout = call_timeout
52+
self.diversion_treatment = diversion_treatment
53+
self.diversion_reason = diversion_reason
54+
self.uui = uui
55+
56+
super().__init__(tag="Forward")
57+
"""
58+
Don't need to define this since default for the parent class is `None`
59+
@property
60+
def _attributes(self):
61+
return {
62+
"to": self.to,
63+
"_from": self._from,
64+
"callTimeout": self.call_timeout,
65+
"diversionTreatment": self.diversion_treatment,
66+
"diversionReason": self.diversion_reason,
67+
"uui": self.uui,
68+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
gather.py
3+
4+
Bandwidth's Gather BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from typing import Union, List
9+
from ..verb import Verb
10+
from .play_audio import PlayAudio
11+
from .speak_sentence import SpeakSentence
12+
13+
14+
class Gather(Verb):
15+
16+
def __init__(
17+
self, audio_verbs: List[Union[PlayAudio, SpeakSentence]] = [],
18+
gather_url: str=None, gather_method: str=None,
19+
gather_fallback_url: str=None, gather_fallback_method: str=None,
20+
username: str=None, password: str=None,
21+
fallback_username: str=None, fallback_password: str=None,
22+
tag: str=None, terminating_digits: str=None,
23+
max_digits: str=None, inter_digit_timeout: str=None,
24+
first_digit_timeout: str=None, repeat_count: str=None
25+
):
26+
"""Initialize a <Gather> verb
27+
28+
Args:
29+
gather_url (str, optional): URL to send Gather event to and request new BXML. May be a relative URL.
30+
gather_method (str, optional): The HTTP method to use for the request to gather_url. GET or POST. Default value is POST.
31+
gather_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Gather event callback delivery in case gather_url fails to respond.
32+
gather_fallback_method (str, optional): The HTTP method to use to deliver the Gather event callback to gather_fallback_url. GET or POST. Default value is POST.
33+
username (str, optional): The username to send in the HTTP request to gather_url.
34+
password (str, optional): The password to send in the HTTP request to gather_url.
35+
fallback_username (str, optional): The username to send in the HTTP request to gather_fallback_url.
36+
fallback_password (str, optional): The password to send in the HTTP request to gather_fallback_url.
37+
tag (str, optional): A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or <Tag> verb, or cleared.
38+
May be cleared by setting tag="". Max length 256 characters.
39+
terminating_digits (str, optional): When any of these digits are pressed, it will terminate the Gather. Default value is "", which disables this feature.
40+
max_digits (str, optional): Max number of digits to collect. Default value is 50. Range: decimal values between 1 - 50.
41+
inter_digit_timeout (str, optional): Time (in seconds) allowed between digit presses before automatically terminating the Gather. Default value is 5. Range: decimal values between 1 - 60.
42+
first_digit_timeout (str, optional): Time (in seconds) to pause after any audio from nested <SpeakSentence> or <PlayAudio> verb is played (in seconds) before terminating the Gather.
43+
Default value is 5. Range: decimal values between 0 - 60.
44+
repeat_count (str, optional): The number of times the audio prompt should be played if no digits are pressed. For example, if this value is 3, the nested audio clip will be played a maximum of three times.
45+
The delay between repetitions will be equal to first_digit_timeout. Default value is 1. repeat_count * number of verbs must not be greater than 20.
46+
47+
Nested Verbs:
48+
PlayAudio: (optional) Using the PlayAudio inside the Gather verb will play the media until a digit is received.
49+
SpeakSentence: (optional) Using the SpeakSentence inside the Gather verb will speak the text until a digit is received.
50+
"""
51+
self.gather_url = gather_url
52+
self.gather_method = gather_method
53+
self.gather_fallback_url = gather_fallback_url
54+
self.gather_fallback_method = gather_fallback_method
55+
self.username = username
56+
self.password = password
57+
self.fallback_username = fallback_username
58+
self.fallback_password = fallback_password
59+
self.tag = tag
60+
self.terminating_digits = terminating_digits
61+
self.max_digits = max_digits
62+
self.inter_digit_timeout = inter_digit_timeout
63+
self.first_digit_timeout = first_digit_timeout
64+
self.repeat_count = repeat_count
65+
self.audio_verbs = audio_verbs
66+
super().__init__(
67+
tag="Gather",
68+
nested_verbs=self.audio_verbs)
69+
70+
@property
71+
def _attributes(self):
72+
return {
73+
"gatherUrl": self.gather_url,
74+
"gatherMethod": self.gather_method,
75+
"gatherFallbackUrl": self.gather_fallback_url,
76+
"gatherFallbackMethod": self.gather_fallback_method,
77+
"username": self.username,
78+
"password": self.password,
79+
"fallbackUsername": self.fallback_username,
80+
"fallbackPassword": self.fallback_password,
81+
"tag": self.tag,
82+
"terminatingDigits": self.terminating_digits,
83+
"maxDigits": self.max_digits,
84+
"interDigitTimeout": self.inter_digit_timeout,
85+
"firstDigitTimeout": self.first_digit_timeout,
86+
"repeatCount": self.repeat_count,
87+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
hangup.py
3+
4+
Bandwidth's Hangup BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Hangup(TerminalVerb):
12+
13+
def __init__(self):
14+
"""Initialize a <Hangup> verb
15+
16+
Args:
17+
None
18+
"""
19+
super().__init__(tag="Hangup")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
pause.py
3+
4+
Bandwidth's Pause BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
class Pause(TerminalVerb):
10+
def __init__(self, duration:str=None):
11+
"""Initialize a <Pause> verb
12+
Args:
13+
duration (str, optional): The time in seconds to pause. Default value is 1.
14+
"""
15+
self.duration = duration
16+
17+
super().__init__(tag="Pause")
18+
19+
@property
20+
def _attributes(self):
21+
return {
22+
"duration": self.duration
23+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
play_audio.py
3+
4+
Bandwidth's PlayAudio BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class PlayAudio(TerminalVerb):
12+
13+
def __init__(
14+
self, audio_uri: str,
15+
username: str=None, password: str=None
16+
):
17+
"""Initialize a <PlayAudio> verb
18+
19+
Args:
20+
audio_uri (str): The URL of the audio file to play. May be a relative URL.
21+
username (str, optional): The username to send in the HTTP request to audio_uri.
22+
password (str, optional): The password to send in the HTTP request to audio_uri.
23+
"""
24+
self.audio_uri = audio_uri
25+
self.username = username
26+
self.password = password
27+
super().__init__(
28+
tag="PlayAudio",
29+
content=self.audio_uri,
30+
)
31+
32+
@property
33+
def _attributes(self):
34+
return {
35+
"username": self.username,
36+
"password": self.password,
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
record.py
3+
4+
Bandwidth's ResumeRecording BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class ResumeRecording(TerminalVerb):
12+
13+
def __init__(
14+
self
15+
):
16+
"""Initialize a <ResumeRecording> verb
17+
18+
Args: There are no args or text content for ResumeRecording
19+
"""
20+
21+
super().__init__(tag="ResumeRecording", content=None)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
send_dtmf.py
3+
4+
Bandwidth's SendDtmf BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class SendDtmf(TerminalVerb):
12+
13+
def __init__(
14+
self, digits: str,
15+
tone_duration: str=None,
16+
tone_interval: str=None,
17+
):
18+
"""Initialize a <SendDtmf> verb
19+
20+
Args:
21+
digits (str): String containing the DTMF characters to be sent in a call. Allows a maximum of 50 characters. The digits will be sent one-by-one with a marginal delay.
22+
tone_duration (str, optional): The length (in milliseconds) of each DTMF tone. Default value is 200. Range: decimal values between 50 - 5000.
23+
tone_interval (str, optional): The duration of silence (in milliseconds) following each DTMF tone. Default value is 400. Range: decimal values between 50 - 5000.
24+
"""
25+
self.digits = digits
26+
self.tone_duration = tone_duration
27+
self.tone_interval = tone_interval
28+
super().__init__(
29+
tag="SendDtmf",
30+
content=self.digits
31+
)
32+
33+
@property
34+
def _attributes(self):
35+
return {
36+
"toneDuration": self.tone_duration,
37+
"toneInterval": self.tone_interval
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
speak_sentence.py
3+
4+
Bandwidth's SpeakSentence BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class SpeakSentence(TerminalVerb):
12+
13+
def __init__(
14+
self, text: str, voice: str=None,
15+
gender: str=None, locale: str=None
16+
):
17+
"""Initialize a <SpeakSentence> verb
18+
19+
Args:
20+
text (str): The text to speak. Cannot be blank. Can be a mixture of plain text and SSML tags.
21+
You can find a list of supported SSML tags here: https://dev.bandwidth.com/docs/voice/bxml/speakSentence/#supported-ssml-tags
22+
voice (str, optional): Selects the voice of the speaker. Consult the voice column in the below table for valid values.
23+
If the voice attribute is present, gender and locale are ignored. You can find a list of supported voices here: https://dev.bandwidth.com/docs/voice/bxml/speakSentence/#supported-voices
24+
gender (str, optional): Selects the gender of the speaker. Valid values are "male" or "female". Default "female".
25+
locale (str, optional): Selects the locale of the speaker. Consult the locale column in the below table for valid values. Default "en_US"
26+
"""
27+
self.text = text
28+
self.voice = voice
29+
self.gender = gender
30+
self.locale = locale
31+
super().__init__(
32+
tag="SpeakSentence",
33+
content=self.text,
34+
)
35+
36+
@property
37+
def _attributes(self):
38+
return {
39+
"voice": self.voice,
40+
"gender": self.gender,
41+
"locale": self.locale,
42+
}

0 commit comments

Comments
 (0)