Skip to content

Commit 131db56

Browse files
Merge branch 'DX-2897' into DX-2898
2 parents f773456 + 18a50a9 commit 131db56

15 files changed

+601
-1
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from .bridge import Bridge
22
from .hangup import Hangup
3-
from .pause_recording import PauseRecording
3+
from .gather import Gather
44
from .phone_number import PhoneNumber
5+
from .play_audio import PlayAudio
56
from .record import Record
7+
from .start_recording import StartRecording
68
from .sip_uri import SipUri
9+
from .stop_recording import StopRecording
10+
from .speak_sentence import SpeakSentence
711
from .tag import Tag
812
from .transfer import Transfer
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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", content=None)
57+
@property
58+
def _attributes(self):
59+
return {
60+
"to": self.to,
61+
"from_": self.from_,
62+
"callTimeout": self.call_timeout,
63+
"diversionTreatment": self.diversion_treatment,
64+
"diversionReason": self.diversion_reason,
65+
"uui": self.uui,
66+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
content=None,
69+
nested_verbs=self.audio_verbs)
70+
71+
@property
72+
def _attributes(self):
73+
return {
74+
"gatherUrl": self.gather_url,
75+
"gatherMethod": self.gather_method,
76+
"gatherFallbackUrl": self.gather_fallback_url,
77+
"gatherFallbackMethod": self.gather_fallback_method,
78+
"username": self.username,
79+
"password": self.password,
80+
"fallbackUsername": self.fallback_username,
81+
"fallbackPassword": self.fallback_password,
82+
"tag": self.tag,
83+
"terminatingDigits": self.terminating_digits,
84+
"maxDigits": self.max_digits,
85+
"interDigitTimeout": self.inter_digit_timeout,
86+
"firstDigitTimeout": self.first_digit_timeout,
87+
"repeatCount": self.repeat_count,
88+
}
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: 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+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
start_recording.py
3+
4+
Bandwidth's StartRecording BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class StartRecording(TerminalVerb):
12+
13+
def __init__(
14+
self, recording_available_url: str = None,
15+
recording_available_method: str = None,
16+
transcribe: str = None, transcription_available_url: str = None,
17+
transcription_available_method: str = None, username: str=None,
18+
password: str=None, tag: str=None,
19+
file_format: str = None, multi_channel: str = None
20+
):
21+
"""Initialize a <StartRecording> verb
22+
23+
Args:
24+
recording_available_url (str, optional): URL to send the Recording Available event to once it has been processed. Does not accept BXML. May be a relative URL. Defaults to None.
25+
recording_available_method (str, optional): The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default value is POST.
26+
transcribe (str, optional): A boolean value to indicate that recording should be transcribed. Transcription can succeed only for recordings of length greater than 500 milliseconds and less than 4 hours. Default is false. Defaults to None.
27+
transcription_available_url (str, optional): URL to send the Transcription Available event to once it has been processed. Does not accept BXML. May be a relative URL. Defaults to None.
28+
transcription_available_method (str, optional): The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default value is POST. Defaults to None.
29+
username (str, optional): The username to send in the HTTP request to recordCompleteUrl, recordingAvailableUrl or transcriptionAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
30+
password (str, optional): The password to send in the HTTP request to recordCompleteUrl, recordingAvailableUrl or transcriptionAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
31+
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. May be cleared by setting tag="". Max length 256 characters. Defaults to None.
32+
file_format (str, optional): The audio format that the recording will be saved as: mp3 or wav. Default value is wav. Defaults to None. max_duration (str, optional): Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. Defaults to None.
33+
multi_channel (str, optional): A boolean value indicating whether or not the recording file should separate each side of the call into its own audio channel. Default value is false.
34+
35+
"""
36+
self.recording_available_url = recording_available_url
37+
self.recording_available_method = recording_available_method
38+
self.transcribe = transcribe
39+
self.transcription_available_url = transcription_available_url
40+
self.transcription_available_method = transcription_available_method
41+
self.username = username
42+
self.password = password
43+
self.tag = tag
44+
self.file_format = file_format
45+
self.multi_channel = multi_channel
46+
super().__init__(tag="StartRecording", content=None)
47+
48+
@property
49+
def _attributes(self):
50+
return {
51+
"recordingAvailableUrl": self.recording_available_url,
52+
"recordingAvailableMethod": self.recording_available_method,
53+
"transcribe": self.transcribe,
54+
"transcriptionAvailableUrl": self.transcription_available_url,
55+
"transcriptionAvailableMethod": self.transcription_available_method,
56+
"username": self.username,
57+
"password": self.password,
58+
"tag": self.tag,
59+
"fileFormat": self.file_format,
60+
"multiChannel": self.multi_channel
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
record.py
3+
4+
Bandwidth's StopRecording BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class StopRecording(TerminalVerb):
12+
13+
def __init__(self):
14+
"""Initialize a <StopRecording> verb
15+
16+
Args: There are no args or text content for StopRecording
17+
"""
18+
19+
super().__init__(tag="StopRecording", content=None)

test/unit/bxml/test_forward.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
test_forward.py
3+
4+
Unit tests for the <Forward> BXML verb
5+
6+
@copyright Bandwidth Inc.
7+
"""
8+
import os
9+
import pytest
10+
import unittest
11+
12+
from bandwidth.model.bxml.verb import Verb
13+
from bandwidth.model.bxml.verbs.forward import Forward
14+
15+
class TestForward(unittest.TestCase):
16+
17+
def setUp(self):
18+
self.forward = Forward(
19+
to="19195554321",
20+
from_="19195554322",
21+
call_timeout = "15",
22+
diversion_treatment="propagate",
23+
diversion_reason="away",
24+
uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt"
25+
)
26+
self.test_verb = Verb(tag="test")
27+
28+
29+
def test_to_bxml(self):
30+
if os.environ['PYTHON_VERSION'] == '3.7':
31+
expected = '<Forward callTimeout="15" diversionReason="away" diversionTreatment="propagate" from_="19195554322" to="19195554321" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
32+
else:
33+
expected = '<Forward to="19195554321" from_="19195554322" callTimeout="15" diversionTreatment="propagate" diversionReason="away" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
34+
assert(expected == self.forward.to_bxml())
35+
36+
def test_add_verb(self):
37+
with pytest.raises(AttributeError):
38+
self.forward.add_verb(self.test_verb)

0 commit comments

Comments
 (0)