Skip to content

Commit 6a00b86

Browse files
Merge branch 'DX-2897' into DX-2895
2 parents 0ee65af + e8dd819 commit 6a00b86

16 files changed

+405
-5
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from .bridge import Bridge
2-
from .pause_recording import PauseRecording
2+
from .hangup import Hangup
33
from .gather import Gather
4+
from .pause import Pause
5+
from .pause_recording import PauseRecording
46
from .phone_number import PhoneNumber
57
from .play_audio import PlayAudio
68
from .record import Record
79
from .sip_uri import SipUri
810
from .speak_sentence import SpeakSentence
11+
from .start_recording import StartRecording
12+
from .stop_recording import StopRecording
913
from .tag import Tag
1014
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: 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", content=None)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
pause.py
3+
Bandwidth's Pause BXML verb
4+
@copyright Bandwidth INC
5+
"""
6+
from ..terminal_verb import TerminalVerb
7+
class Pause(TerminalVerb):
8+
def __init__(self, duration:str=None):
9+
"""Initialize a <Pause> verb
10+
Args:
11+
duration (str, optional): The time in seconds to pause. Default value is 1.
12+
"""
13+
self.duration = duration
14+
15+
super().__init__(tag="Pause", content=None)
16+
@property
17+
def _attributes(self):
18+
return {
19+
"duration": self.duration
20+
}

bandwidth/model/bxml/verbs/pause_recording.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class PauseRecording(TerminalVerb):
1313
def __init__(self):
1414
"""Initialize a <PauseRecording> verb
1515
"""
16-
super().__init__(tag="PauseRecording", content=None, attributes=None)
16+
super().__init__(tag="PauseRecording", content=None)
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: 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)