-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Bandwidth/SWI-2789
SWI-2789 Added Start/Stop Transcription
- Loading branch information
Showing
5 changed files
with
320 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* CustomParam.php | ||
* | ||
* Implementation of the BXML CustomParam tag. You may specify up to 12 <CustomParam/> elements nested within a <StartTranscription> tag. These elements define optional user specified parameters that will be sent to the destination URL when the real-time transcription is first started. | ||
* | ||
* * @copyright Bandwidth INC | ||
*/ | ||
|
||
namespace BandwidthLib\Voice\Bxml; | ||
|
||
use DOMDocument; | ||
|
||
require_once "Verb.php"; | ||
|
||
class CustomParam extends Verb { | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* Sets the name attribute for CustomParam | ||
* | ||
* @param string $name (required) The name of this parameter, up to 256 characters. | ||
*/ | ||
public function name(string $name) { | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* Sets the value attribute for CustomParam | ||
* | ||
* @param string $value (required) The value of this parameter, up to 2048 characters. | ||
*/ | ||
public function value(string $value) { | ||
$this->value = $value; | ||
} | ||
|
||
public function toBxml(DOMDocument $doc) { | ||
$element = $doc->createElement("CustomParam"); | ||
|
||
if(isset($this->name)) { | ||
$element->setAttribute("name", $this->name); | ||
} | ||
|
||
if(isset($this->value)) { | ||
$element->setAttribute("value", $this->value); | ||
} | ||
|
||
return $element; | ||
} | ||
} |
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,177 @@ | ||
<?php | ||
/** | ||
* StartTranscription.php | ||
* | ||
* Implementation of the BXML StartTranscription verb | ||
* | ||
* @copyright Bandwidth INC | ||
*/ | ||
|
||
namespace BandwidthLib\Voice\Bxml; | ||
|
||
use DOMDocument; | ||
|
||
require_once "Verb.php"; | ||
|
||
class StartTranscription extends Verb { | ||
private $customParams; | ||
/** | ||
* @var bool | ||
*/ | ||
private $transcriptionEventMethod; | ||
/** | ||
* @var string | ||
*/ | ||
private $transcriptionEventUrl; | ||
/** | ||
* @var string | ||
*/ | ||
private $password; | ||
/** | ||
* @var string | ||
*/ | ||
private $username; | ||
/** | ||
* @var string | ||
*/ | ||
private $tracks; | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
/** | ||
* @var string | ||
*/ | ||
private $destination; | ||
/** | ||
* @var bool | ||
*/ | ||
private $stability; | ||
|
||
/** | ||
* Sets the destination attribute for StartTranscription | ||
* | ||
* @param string $destination A websocket URI to send the real-time transcription to. The audio from the specified tracks will be sent via websocket to this URL encoded as base64 encoded PCMU/G711 audio. See below for more details on the websocket packet format. | ||
*/ | ||
public function destination(string $destination) { | ||
$this->destination = $destination; | ||
} | ||
|
||
/** | ||
* Sets the name attribute for StartTranscription | ||
* | ||
* @param string $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. | ||
*/ | ||
public function name(string $name) { | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* Sets the tracks attribute for StartTranscription | ||
* | ||
* @param string $tracks The part of the call to send a real-time transcription from. `inbound`, `outbound` or `both`. Default is `inbound`. | ||
* | ||
*/ | ||
public function tracks(string $tracks) { | ||
$this->tracks = $tracks; | ||
} | ||
|
||
/** | ||
* Sets the username attribute for StartTranscription | ||
* | ||
* @param string $username The username to send in the HTTP request to `transcriptionEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). | ||
*/ | ||
public function username(string $username) { | ||
$this->username = $username; | ||
} | ||
|
||
/** | ||
* Sets the password attribute for StartTranscription | ||
* | ||
* @param string $password The password to send in the HTTP request to `transcriptionEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). | ||
*/ | ||
public function password(string $password) { | ||
$this->password = $password; | ||
} | ||
|
||
/** | ||
* Sets the transcriptionEventUrl attribute for StartTranscription | ||
* | ||
* @param string $transcriptionEventUrl URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL. | ||
*/ | ||
public function transcriptionEventUrl(string $transcriptionEventUrl) { | ||
$this->transcriptionEventUrl = $transcriptionEventUrl; | ||
} | ||
|
||
/** | ||
* Sets the transcriptionEventMethod attribute for StartTranscription | ||
* | ||
* @param bool $transcriptionEventMethod The HTTP method to use for the request to `transcriptionEventUrl`. GET or POST. Default value is POST. | ||
*/ | ||
public function transcriptionEventMethod(string $transcriptionEventMethod) { | ||
$this->transcriptionEventMethod = $transcriptionEventMethod; | ||
} | ||
|
||
/** | ||
* Sets the stability attribute for StartTranscription | ||
* | ||
* @param bool Whether to send transcription update events to the specified destination only after they have become stable. Requires destination. Defaults to true. | ||
* | ||
*/ | ||
public function stability( bool $stability) { | ||
$this->stability = $stability; | ||
} | ||
|
||
/** | ||
* Sets the <CustomParam/> tag. You may specify up to 12 <CustomParam/> elements nested within a <StartTranscription> tag. These elements define optional user specified parameters that will be sent to the destination URL when the real-time transcription is first started. | ||
* | ||
* @param list<CustomParam> $customParams The list of CustomParam tags | ||
*/ | ||
public function customParams($customParams) { | ||
$this->customParams = $customParams; | ||
} | ||
|
||
public function toBxml(DOMDocument $doc) { | ||
$element = $doc->createElement("StartTranscription"); | ||
|
||
if(isset($this->destination)) { | ||
$element->setattribute("destination", $this->destination); | ||
} | ||
|
||
if(isset($this->name)) { | ||
$element->setattribute("name", $this->name); | ||
} | ||
|
||
if(isset($this->tracks)) { | ||
$element->setattribute("tracks", $this->tracks); | ||
} | ||
|
||
if(isset($this->username)) { | ||
$element->setattribute("username", $this->username); | ||
} | ||
|
||
if(isset($this->password)) { | ||
$element->setattribute("password", $this->password); | ||
} | ||
|
||
if(isset($this->transcriptionEventUrl)) { | ||
$element->setattribute("transcriptionEventUrl", $this->transcriptionEventUrl); | ||
} | ||
|
||
if(isset($this->transcriptionEventMethod)) { | ||
$element->setattribute("transcriptionEventMethod", $this->transcriptionEventMethod); | ||
} | ||
|
||
if(isset($this->stability)) { | ||
$element->setattribute("stablilty", $this->stability); | ||
} | ||
|
||
if(isset($this->customParams)) { | ||
foreach ($this->customParams as $customParam) { | ||
$element->appendChild($customParam->toBxml($doc)); | ||
} | ||
} | ||
|
||
return $element; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
/** | ||
* StopTranscription php | ||
* | ||
* Implementation of the BXML StopTranscription verb | ||
* | ||
* @copyright Bandwidth INC | ||
*/ | ||
|
||
namespace BandwidthLib\Voice\Bxml; | ||
|
||
use DOMDocument; | ||
|
||
require_once "Verb.php"; | ||
|
||
class StopTranscription extends Verb { | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* Sets the name attribute for StopTranscription | ||
* | ||
* @param string $name (required) The name of the real-time transcription to stop. This is either the user selected name when sending the [`<StartTranscription>`][1] verb, or the system generated name returned in the [Media Transcription Started][2] webhook if `<StartTranscription>` was sent with no `name` attribute. | ||
*/ | ||
public function name(string $name) { | ||
$this->name = $name; | ||
} | ||
|
||
public function toBxml(DOMDocument $doc) { | ||
$element = $doc->createElement("StopTranscription"); | ||
|
||
if(isset($this->name)) { | ||
$element->setAttribute("name", $this->name); | ||
} | ||
|
||
return $element; | ||
} | ||
} |
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