-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#154) * SWI-2787 Add Support for `StartTranscription` and `StopTranscription` BXML * Ignore 404s from GET Call in tests due to API Bug * Update bandwidth/tests/test_api.py Co-authored-by: Cameron Koegel <[email protected]> --------- Co-authored-by: Cameron Koegel <[email protected]>
- Loading branch information
1 parent
7652465
commit 2872359
Showing
6 changed files
with
212 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
custom_param.py | ||
Representation of Bandwidth's StartTranscription BXML verb | ||
@license MIT | ||
""" | ||
|
||
from lxml import etree | ||
|
||
from .base_verb import AbstractBxmlVerb | ||
|
||
CUSTOM_PARAM_TAG = "CustomParam" | ||
|
||
|
||
class CustomParam(AbstractBxmlVerb): | ||
def __init__( | ||
self, | ||
name: str, | ||
value: str, | ||
): | ||
""" | ||
Initializes the CustomParam class | ||
:param name: The name of this parameter, up to 256 characters. | ||
:param value: The value of this parameter, up to 2048 characters. | ||
""" | ||
self.name = name | ||
self.value = value | ||
|
||
def to_etree_element(self): | ||
root = etree.Element(CUSTOM_PARAM_TAG) | ||
root.set("name", self.name) | ||
root.set("value", self.value) | ||
return root | ||
|
||
def to_bxml(self): | ||
root = etree.Element(CUSTOM_PARAM_TAG) | ||
return etree.tostring(root).decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
start_transcription.py | ||
Representation of Bandwidth's StartTranscription BXML verb | ||
@license MIT | ||
""" | ||
|
||
from typing import List | ||
|
||
from lxml import etree | ||
|
||
from .base_verb import AbstractBxmlVerb | ||
from .custom_param import CustomParam | ||
|
||
START_TRANSCRIPTION_TAG = "StartTranscription" | ||
|
||
|
||
class StartTranscription(AbstractBxmlVerb): | ||
|
||
def __init__( | ||
self, | ||
name: str = None, | ||
tracks: str = None, | ||
transcription_event_url: str = None, | ||
transcription_event_method: str = None, | ||
username: str = None, | ||
password: str = None, | ||
destination: str = None, | ||
stabilized: bool = None, | ||
custom_params: List[CustomParam] = None, | ||
): | ||
""" | ||
Initializes the StartTranscription class | ||
:param name: A name to refer to this transcription by. Used when sending <StopTranscription>. If not provided, it will default to the generated transcription id as sent in the Real-Time Transcription Started webhook. | ||
:param tracks: The part of the call to send a transcription from. inbound, outbound or both. Default is inbound. | ||
:param transcription_event_url: URL to send the associated Webhook events to during this real-time transcription's lifetime. Does not accept BXML. May be a relative URL. | ||
:param transcription_event_method: The HTTP method to use for the request to transcriptionEventUrl. GET or POST. Default value is POST. | ||
:param username: The username to send in the HTTP request to transcriptionEventUrl. If specified, the transcriptionEventUrl must be TLS-encrypted (i.e., https). | ||
:param password: The password to send in the HTTP request to transcriptionEventUrl. If specified, the transcriptionEventUrl must be TLS-encrypted (i.e., https). | ||
:param destination: A websocket URI to send the transcription to. A transcription of the specified tracks will be sent via websocket to this URL as a series of JSON messages. See below for more details on the websocket packet format. | ||
:param stabilized: Whether to send transcription update events to the specified destination only after they have become stable. Requires destination. Defaults to true. | ||
:param custom_params: These elements define optional user specified parameters that will be sent to the destination URL when the real-time transcription is first started. | ||
""" | ||
self.name = name | ||
self.tracks = tracks | ||
self.transcription_event_url = transcription_event_url | ||
self.transcription_event_method = transcription_event_method | ||
self.username = username | ||
self.password = password | ||
self.destination = destination | ||
self.stabilized = stabilized | ||
self.custom_params = custom_params | ||
|
||
def to_bxml(self): | ||
root = etree.Element(START_TRANSCRIPTION_TAG) | ||
if self.name is not None: | ||
root.set("name", self.name) | ||
if self.tracks is not None: | ||
root.set("tracks", self.tracks) | ||
if self.transcription_event_url is not None: | ||
root.set("transcriptionEventUrl", self.transcription_event_url) | ||
if self.transcription_event_method is not None: | ||
root.set("transcriptionEventMethod", self.transcription_event_method) | ||
if self.username is not None: | ||
root.set("username", self.username) | ||
if self.password is not None: | ||
root.set("password", self.password) | ||
if self.destination is not None: | ||
root.set("destination", self.destination) | ||
if self.stabilized is not None: | ||
root.set("stabilized", str(self.stabilized).lower()) | ||
if self.custom_params is not None: | ||
for custom_param in self.custom_params: | ||
root.append(custom_param.to_etree_element()) | ||
return etree.tostring(root).decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
stop_transcription.py | ||
Representation of Bandwidth's StartTranscription BXML verb | ||
@license MIT | ||
""" | ||
|
||
from lxml import etree | ||
|
||
from .base_verb import AbstractBxmlVerb | ||
|
||
STOP_TRANSCRIPTION_TAG = "StopTranscription" | ||
|
||
|
||
class StopTranscription(AbstractBxmlVerb): | ||
|
||
def __init__( | ||
self, | ||
name: str = None | ||
): | ||
""" | ||
Initializes the StopTranscription class | ||
:param name: The name of the real-time transcription to stop. This is either the user selected name when sending the <StartTranscription> verb, or the system generated name returned in the Real-Time Transcription Started webhook if <StartTranscription> was sent with no name attribute. If no name is specified, then all active call transcriptions will be stopped. | ||
""" | ||
self.name = name | ||
|
||
def to_bxml(self): | ||
root = etree.Element(STOP_TRANSCRIPTION_TAG) | ||
if self.name is not None: | ||
root.set("name", self.name) | ||
return etree.tostring(root).decode() |