Skip to content

Commit 674d96e

Browse files
committed
DX-2903 Add <Record> BXML
1 parent 6f9c47d commit 674d96e

File tree

4 files changed

+129
-3
lines changed

4 files changed

+129
-3
lines changed

bandwidth/model/bxml/verb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ def __init__(self, tag: str, content: str = None, attributes: dict = None, neste
2424
"""
2525
self._tag = tag
2626
self._content = content
27-
self._attributes = attributes
2827
self._nested_verbs = nested_verbs
2928
if not self._nested_verbs:
3029
self._nested_verbs = []
3130

31+
@property
32+
def attributes():
33+
return {}
34+
3235
def __len__(self) -> int:
3336
"""Override default len method. Returns length of _nested_verbs array
3437
@@ -54,8 +57,8 @@ def _set_attributes(self, root: ET.Element):
5457
Args:
5558
root (ET.Element): XML Element to add attributes to
5659
"""
57-
if self._attributes:
58-
for key, value in self._attributes.items():
60+
if self.attributes:
61+
for key, value in self.attributes.items():
5962
if value is not None:
6063
root.set(key, value)
6164

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .bridge import Bridge
22
from .phone_number import PhoneNumber
3+
from .record import Record
34
from .sip_uri import SipUri
45
from .tag import Tag
56
from .transfer import Transfer
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""
2+
record.py
3+
4+
Bandwidth's Record BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Record(TerminalVerb):
12+
13+
def __init__(
14+
self, record_complete_url: str = None,
15+
record_complete_method: str = None,
16+
record_complete_fallback_url: str = None,
17+
record_complete_fallback_method: str = None,
18+
recording_available_url: str = None,
19+
recording_available_method: str = None,
20+
transcribe: str = None, transcription_available_url: str = None,
21+
transcription_available_method: str = None, username: str=None,
22+
password: str=None, fallback_username: str=None,
23+
fallback_password: str=None, tag: str=None,
24+
terminating_digits: str = None, max_duration: str = None,
25+
silence_timeout: str = None, file_format: str = None
26+
):
27+
"""Initialize a <Record> verb
28+
29+
Args:
30+
record_complete_url (str, optional): URL to send the Record Complete event to once the recording has ended. Accepts BXML, and may be a relative URL. This callback will not be sent if the recording ended due to the call hanging up. Defaults to None.
31+
record_complete_method (str, optional): The HTTP method to use for the request to recordCompleteUrl. GET or POST. Default value is POST. Defaults to None.
32+
record_complete_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Record Complete callback delivery in case recordCompleteUrl fails to respond. Defaults to None.
33+
record_complete_fallback_method (str, optional): The HTTP method to use to deliver the Record Complete callback to recordCompleteFallbackUrl. GET or POST. Default value is POST. Defaults to None.
34+
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.
35+
recording_available_method (str, optional): The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default value is POST. Defaults to None.
36+
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.
37+
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.
38+
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.
39+
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.
40+
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.
41+
fallback_username (str, optional): The username to send in the HTTP request to recordCompleteFallbackUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
42+
fallback_password (str, optional): The password to send in the HTTP request to recordCompleteFallbackUrl. If specified, the URLs must be TLS-encrypted (i.e., https). Defaults to None.
43+
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.
44+
terminating_digits (str, optional): When pressed, this digit will terminate the recording. Default value is “#”. This feature can be disabled with "". Defaults to None.
45+
max_duration (str, optional): Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. Defaults to None.
46+
silence_timeout (str, optional): Length of silence after which to end the recording (in seconds). Max is equivalent to the maximum maxDuration value. Default value is 0, which means no timeout. Defaults to None.
47+
file_format (str, optional): The audio format that the recording will be saved as: mp3 or wav. Default value is wav. Defaults to None.
48+
"""
49+
self.record_complete_url = record_complete_url
50+
self.record_complete_method = record_complete_method
51+
self.record_complete_fallback_url = record_complete_fallback_url
52+
self.record_complete_fallback_method = record_complete_fallback_method
53+
self.recording_available_url = recording_available_url
54+
self.recording_available_method = recording_available_method
55+
self.transcribe = transcribe
56+
self.transcription_available_url = transcription_available_url
57+
self.transcription_available_method = transcription_available_method
58+
self.username = username
59+
self.password = password
60+
self.fallback_username = fallback_username
61+
self.fallback_password = fallback_password
62+
self.tag = tag
63+
self.terminating_digits = terminating_digits
64+
self.max_duration = max_duration
65+
self.silence_timeout = silence_timeout
66+
self.file_format = file_format
67+
super().__init__(tag="Record", content=None, attributes=self.attributes)
68+
69+
@property
70+
def attributes(self):
71+
return {
72+
"recordCompleteUrl": self.record_complete_url,
73+
"recordCompleteMethod": self.record_complete_method,
74+
"recordCompleteFallback_url": self.record_complete_fallback_url,
75+
"recordCompleteFallback_method": self.record_complete_fallback_method,
76+
"recordingAvailableUrl": self.recording_available_url,
77+
"recordingAvailableMethod": self.recording_available_method,
78+
"transcribe": self.transcribe,
79+
"transcriptionAvailableUrl": self.transcription_available_url,
80+
"transcriptionAvailableMethod": self.transcription_available_method,
81+
"username": self.username,
82+
"password": self.password,
83+
"fallbackUsername": self.fallback_username,
84+
"fallbackPassword": self.fallback_password,
85+
"tag": self.tag,
86+
"terminatingDigits": self.terminating_digits,
87+
"maxDuration": self.max_duration,
88+
"silenceTimeout": self.silence_timeout,
89+
"fileFormat": self.file_format
90+
}

test/unit/bxml/test_record.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
test_record.py
3+
4+
Unit tests for the <Record> BXML verb
5+
6+
@copyright Bandwidth Inc.
7+
"""
8+
from rich import inspect
9+
import pytest
10+
import unittest
11+
12+
from bandwidth.model.bxml.verb import Verb
13+
from bandwidth.model.bxml.verbs.record import Record
14+
15+
16+
class TestRecord(unittest.TestCase):
17+
18+
def setUp(self):
19+
self.record = Record()
20+
inspect(self.record)
21+
self.record.max_duration = "10"
22+
inspect(self.record)
23+
self.test_verb = Verb(tag="test")
24+
25+
def test_to_bxml(self):
26+
expected = '<Record maxDuration="10" />'
27+
assert(expected == self.record.to_bxml())
28+
29+
def test_add_verb(self):
30+
with pytest.raises(AttributeError):
31+
self.record.add_verb(self.test_verb)
32+

0 commit comments

Comments
 (0)