Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions bandwidth/model/bxml/verbs/conference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@

@copyright Bandwidth INC
"""
from typing import Union, List
from ..verb import Verb
from .play_audio import PlayAudio
from .speak_sentence import SpeakSentence
from .start_recording import StartRecording
from .stop_recording import StopRecording
from .pause_recording import PauseRecording
from .resume_recording import ResumeRecording
from ..terminal_verb import TerminalVerb


class Conference(Verb):
class Conference(TerminalVerb):

def __init__(
self, name: str,
audio_and_recording_verbs: List[Union[PlayAudio, SpeakSentence, StartRecording, StopRecording, PauseRecording, ResumeRecording]] = [], mute: str=None,
hold: str=None, call_ids_to_coach: str=None,
conference_event_url: str=None, conference_event_method: str=None,
conference_event_fallback_url: str=None, conference_event_fallback_method: str=None,
self, name: str, mute: str=None,
hold: str=None, call_ids_to_coach: str=None,
conference_event_url: str=None, conference_event_method: str=None,
conference_event_fallback_url: str=None, conference_event_fallback_method: str=None,
username: str=None, password: str=None,
fallback_username: str=None, fallback_password: str=None,
fallback_username: str=None, fallback_password: str=None,
tag: str=None, callback_timeout: str=None,
):
"""Initialize a <Conference> verb
Expand All @@ -33,10 +25,10 @@ def __init__(
name (str): The name of the conference. Can contain up to 100 characters of letters, numbers, and the symbols -, _, and .
mute (str, optional): A boolean value to indicate whether the member should be on mute in the conference. When muted, a member can hear others speak, but others cannot hear them speak. Defaults to false.
hold (str, optional): A boolean value to indicate whether the member should be on hold in the conference. When on hold, a member cannot hear others, and they cannot be heard. Defaults to false.
call_ids_to_coach (str, optional): A comma-separated list of call ids to coach. When a call joins a conference with this attribute set, it will coach the listed calls.
call_ids_to_coach (str, optional): A comma-separated list of call ids to coach. When a call joins a conference with this attribute set, it will coach the listed calls.
Those calls will be able to hear and be heard by the coach, but other calls in the conference will not hear the coach.
conference_event_url (str, optional): URL to send Conference events to. The URL, method, username, and password are set by the BXML document that creates the conference,
and all events related to that conference will be delivered to that same endpoint. If more calls join afterwards and also have this property (or any other webhook related properties like username and password),
conference_event_url (str, optional): URL to send Conference events to. The URL, method, username, and password are set by the BXML document that creates the conference,
and all events related to that conference will be delivered to that same endpoint. If more calls join afterwards and also have this property (or any other webhook related properties like username and password),
they will be ignored and the original webhook information will be used. This URL may be a relative endpoint.
conference_event_method (str, optional): The HTTP method to use for the request to conferenceEventUrl. GET or POST. Default value is POST.
conference_event_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the conference webhook deliveries in case conferenceEventUrl fails to respond.
Expand All @@ -45,17 +37,17 @@ def __init__(
password (str, optional): The password to send in the HTTP request to conferenceEventUrl.
fallback_username (str, optional): The username to send in the HTTP request to conferenceEventFallbackUrl.
fallback_password (str, optional): The password to send in the HTTP request to conferenceEventFallbackUrl.
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="".
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.
callback_timeout (str, optional): This is the timeout (in seconds) to use when delivering webhooks for the conference.
callback_timeout (str, optional): This is the timeout (in seconds) to use when delivering webhooks for the conference.
If not set, it will inherit the webhook timeout from the call that creates the conference. Can be any numeric value (including decimals) between 1 and 25.

Nested Verbs:
PlayAudio: (optional)
SpeakSentence: (optional)
StartRecording: (optional)
PlayAudio: (optional)
SpeakSentence: (optional)
StartRecording: (optional)
StopRecording: (optional)
PauseRecording: (optional)
PauseRecording: (optional)
ResumeRecording: (optional)
"""
self.name = name
Expand All @@ -72,11 +64,10 @@ def __init__(
self.fallback_password = fallback_password
self.tag = tag
self.callback_timeout = callback_timeout
self.audio_and_recording_verbs = audio_and_recording_verbs
super().__init__(
tag="Conference",
content=self.name,
nested_verbs=self.audio_and_recording_verbs)
tag="Conference",
content=self.name
)

@property
def _attributes(self):
Expand Down
30 changes: 15 additions & 15 deletions bandwidth/model/bxml/verbs/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Gather(Verb):

def __init__(
self, audio_verbs: List[Union[PlayAudio, SpeakSentence]] = [],
gather_url: str=None, gather_method: str=None,
gather_fallback_url: str=None, gather_fallback_method: str=None,
gather_url: str=None, gather_method: str=None,
gather_fallback_url: str=None, gather_fallback_method: str=None,
username: str=None, password: str=None,
fallback_username: str=None, fallback_password: str=None,
fallback_username: str=None, fallback_password: str=None,
tag: str=None, terminating_digits: str=None,
max_digits: str=None, inter_digit_timeout: str=None,
first_digit_timeout: str=None, repeat_count: str=None
max_digits: int=None, inter_digit_timeout: int=None,
first_digit_timeout: int=None, repeat_count: int=None
):
"""Initialize a <Gather> verb

Expand All @@ -34,14 +34,14 @@ def __init__(
password (str, optional): The password to send in the HTTP request to gather_url.
fallback_username (str, optional): The username to send in the HTTP request to gather_fallback_url.
fallback_password (str, optional): The password to send in the HTTP request to gather_fallback_url.
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.
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.
terminating_digits (str, optional): When any of these digits are pressed, it will terminate the Gather. Default value is "", which disables this feature.
max_digits (str, optional): Max number of digits to collect. Default value is 50. Range: decimal values between 1 - 50.
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.
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.
max_digits (int, optional): Max number of digits to collect. Default value is 50. Range: decimal values between 1 - 50.
inter_digit_timeout (int, optional): Time (in seconds) allowed between digit presses before automatically terminating the Gather. Default value is 5. Range: decimal values between 1 - 60.
first_digit_timeout (int, optional): Time (in seconds) to pause after any audio from nested <SpeakSentence> or <PlayAudio> verb is played (in seconds) before terminating the Gather.
Default value is 5. Range: decimal values between 0 - 60.
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.
repeat_count (int, 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.
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.

Nested Verbs:
Expand All @@ -64,7 +64,7 @@ def __init__(
self.repeat_count = repeat_count
self.audio_verbs = audio_verbs
super().__init__(
tag="Gather",
tag="Gather",
nested_verbs=self.audio_verbs)

@property
Expand All @@ -80,8 +80,8 @@ def _attributes(self):
"fallbackPassword": self.fallback_password,
"tag": self.tag,
"terminatingDigits": self.terminating_digits,
"maxDigits": self.max_digits,
"interDigitTimeout": self.inter_digit_timeout,
"firstDigitTimeout": self.first_digit_timeout,
"repeatCount": self.repeat_count,
"maxDigits": str(self.max_digits),
"interDigitTimeout": str(self.inter_digit_timeout),
"firstDigitTimeout": str(self.first_digit_timeout),
"repeatCount": str(self.repeat_count),
}
10 changes: 6 additions & 4 deletions bandwidth/model/bxml/verbs/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
@copyright Bandwidth INC
"""
from ..terminal_verb import TerminalVerb


class Pause(TerminalVerb):
def __init__(self, duration:str=None):
def __init__(self, duration:int=1):
"""Initialize a <Pause> verb
Args:
duration (str, optional): The time in seconds to pause. Default value is 1.
"""
self.duration = duration
self.duration = str(duration)

super().__init__(tag="Pause")

@property
def _attributes(self):
return {
"duration": self.duration
}
}
25 changes: 13 additions & 12 deletions bandwidth/model/bxml/verbs/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
class Record(TerminalVerb):

def __init__(
self, record_complete_url: str = None,
record_complete_method: str = None,
record_complete_fallback_url: str = None,
record_complete_fallback_method: str = None,
recording_available_url: str = None,
recording_available_method: str = None,
transcribe: str = None, transcription_available_url: str = None,
transcription_available_method: str = None, username: str=None,
self, record_complete_url: str=None,
record_complete_method: str=None,
record_complete_fallback_url: str=None,
record_complete_fallback_method: str=None,
recording_available_url: str=None,
recording_available_method: str=None,
transcribe: str=None, transcription_available_url: str=None,
transcription_available_method: str=None, username: str=None,
password: str=None, fallback_username: str=None,
fallback_password: str=None, tag: str=None,
terminating_digits: str = None, max_duration: str = None,
silence_timeout: str = None, file_format: str = None
terminating_digits: str=None, max_duration: int=None,
silence_timeout: str=None, file_format: str=None
):
"""Initialize a <Record> verb

Expand All @@ -42,7 +42,7 @@ def __init__(
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.
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.
terminating_digits (str, optional): When pressed, this digit will terminate the recording. Default value is “#”. This feature can be disabled with "". Defaults to None.
max_duration (str, optional): Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. Defaults to None.
max_duration (int, optional): Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. Defaults to None.
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.
file_format (str, optional): The audio format that the recording will be saved as: mp3 or wav. Default value is wav. Defaults to None.
"""
Expand All @@ -64,6 +64,7 @@ def __init__(
self.max_duration = max_duration
self.silence_timeout = silence_timeout
self.file_format = file_format

super().__init__(tag="Record", content=None)

@property
Expand All @@ -84,7 +85,7 @@ def _attributes(self):
"fallbackPassword": self.fallback_password,
"tag": self.tag,
"terminatingDigits": self.terminating_digits,
"maxDuration": self.max_duration,
"maxDuration": str(self.max_duration),
"silenceTimeout": self.silence_timeout,
"fileFormat": self.file_format
}
12 changes: 6 additions & 6 deletions bandwidth/model/bxml/verbs/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
class Ring(TerminalVerb):

def __init__(
self, duration: str = None,
answer_call: str = None,
self, duration: int=None,
answer_call: bool=None,
):
"""Initialize a <Ring> verb

Args:
duration (str, optional): How many seconds to play ringing on the call. Default value is 5. Range: decimal values between 0.1 - 86400.
answer_call (str, optional): A boolean indicating whether or not to answer the call when Ring is executed on an unanswered incoming call. Default value is 'true'.
duration (int, optional): How many seconds to play ringing on the call. Default value is 5. Range: decimal values between 0.1 - 86400.
answer_call (bool, optional): A boolean indicating whether or not to answer the call when Ring is executed on an unanswered incoming call. Default value is 'true'.
"""
self.duration = duration
self.answer_call = answer_call
Expand All @@ -27,6 +27,6 @@ def __init__(
@property
def _attributes(self):
return {
"duration": self.duration,
"answerCall": self.answer_call,
"duration": str(self.duration),
"answerCall": str(self.answer_call),
}
12 changes: 6 additions & 6 deletions bandwidth/model/bxml/verbs/send_dtmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class SendDtmf(TerminalVerb):

def __init__(
self, digits: str,
tone_duration: str=None,
tone_interval: str=None,
tone_duration: int=None,
tone_interval: int=None,
):
"""Initialize a <SendDtmf> verb

Args:
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.
tone_duration (str, optional): The length (in milliseconds) of each DTMF tone. Default value is 200. Range: decimal values between 50 - 5000.
tone_interval (str, optional): The duration of silence (in milliseconds) following each DTMF tone. Default value is 400. Range: decimal values between 50 - 5000.
tone_duration (int, optional): The length (in milliseconds) of each DTMF tone. Default value is 200. Range: decimal values between 50 - 5000.
tone_interval (int, optional): The duration of silence (in milliseconds) following each DTMF tone. Default value is 400. Range: decimal values between 50 - 5000.
"""
self.digits = digits
self.tone_duration = tone_duration
Expand All @@ -33,6 +33,6 @@ def __init__(
@property
def _attributes(self):
return {
"toneDuration": self.tone_duration,
"toneInterval": self.tone_interval
"toneDuration": str(self.tone_duration),
"toneInterval": str(self.tone_interval)
}
8 changes: 4 additions & 4 deletions bandwidth/model/bxml/verbs/start_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class StartRecording(TerminalVerb):
def __init__(
self, recording_available_url: str = None,
recording_available_method: str = None,
transcribe: str = None, transcription_available_url: str = None,
transcribe: bool = None, transcription_available_url: str = None,
transcription_available_method: str = None, username: str=None,
password: str=None, tag: str=None,
file_format: str = None, multi_channel: str = None
file_format: str = None, multi_channel: bool = None
):
"""Initialize a <StartRecording> verb

Expand Down Expand Up @@ -50,12 +50,12 @@ def _attributes(self):
return {
"recordingAvailableUrl": self.recording_available_url,
"recordingAvailableMethod": self.recording_available_method,
"transcribe": self.transcribe,
"transcribe": str(self.transcribe),
"transcriptionAvailableUrl": self.transcription_available_url,
"transcriptionAvailableMethod": self.transcription_available_method,
"username": self.username,
"password": self.password,
"tag": self.tag,
"fileFormat": self.file_format,
"multiChannel": self.multi_channel
"multiChannel": str(self.multi_channel)
}
18 changes: 12 additions & 6 deletions test/unit/bxml/test_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,45 @@

@copyright Bandwidth Inc.
"""
import pytest
import unittest

from bandwidth.model.bxml.root import Root
from bandwidth.model.bxml.verb import Verb
from bandwidth.model.bxml.terminal_verb import TerminalVerb


class TestBaseClasses(unittest.TestCase):
def setUp(self):

def setUp(self):
self.root = Root(tag="TestRoot")
self.verb1 = Verb(tag="TestVerb1", content="test")
self.verb2 = Verb(tag="TestVerb2")
self.verb3 = Verb(tag="TestVerb3")

self.terminal_verb = TerminalVerb(tag="TestTerminalVerb")

def test_root(self):
self.root.add_verb(self.verb1)
self.root.add_verb(self.verb2)

expected_bxml = "<?xml version='1.0' encoding='utf8'?>\n<TestRoot><TestVerb1>test</TestVerb1><TestVerb2 /></TestRoot>"
assert(type(self.root[0]) == Verb)
assert(len(self.root) == 2)
assert(expected_bxml == self.root.to_bxml())

def test_verb(self):
self.verb3.add_verb(self.verb1)

expected_bxml = "<TestVerb3><TestVerb1>test</TestVerb1></TestVerb3>"
assert(type(self.verb3[0]) == Verb)
assert(len(self.verb3) == 1)
assert(expected_bxml == self.verb3.to_bxml())

def test_adding_verbs_to_root_during_creation(self):
self.root2 = Root(tag="TestRoot2", nested_verbs=[self.verb1, self.verb2])

assert(len(self.root2) == 2)

def test_adding_verbs_to_terminal_verb(self):
with pytest.raises(AttributeError):
self.terminal_verb.add_verb(self.verb1)
Loading