|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * StartTranscription.php |
| 4 | + * |
| 5 | + * Implementation of the BXML StartTranscription verb |
| 6 | + * |
| 7 | + * @copyright Bandwidth INC |
| 8 | + */ |
| 9 | + |
| 10 | +namespace BandwidthLib\Voice\Bxml; |
| 11 | + |
| 12 | +use DOMDocument; |
| 13 | + |
| 14 | +require_once "Verb.php"; |
| 15 | + |
| 16 | +class StartTranscription extends Verb { |
| 17 | + private $customParams; |
| 18 | + /** |
| 19 | + * @var bool |
| 20 | + */ |
| 21 | + private $transcriptionEventMethod; |
| 22 | + /** |
| 23 | + * @var string |
| 24 | + */ |
| 25 | + private $transcriptionEventUrl; |
| 26 | + /** |
| 27 | + * @var string |
| 28 | + */ |
| 29 | + private $password; |
| 30 | + /** |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + private $username; |
| 34 | + /** |
| 35 | + * @var string |
| 36 | + */ |
| 37 | + private $tracks; |
| 38 | + /** |
| 39 | + * @var string |
| 40 | + */ |
| 41 | + private $name; |
| 42 | + /** |
| 43 | + * @var string |
| 44 | + */ |
| 45 | + private $destination; |
| 46 | + /** |
| 47 | + * @var bool |
| 48 | + */ |
| 49 | + private $stability; |
| 50 | + |
| 51 | + /** |
| 52 | + * Sets the destination attribute for StartTranscription |
| 53 | + * |
| 54 | + * @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. |
| 55 | + */ |
| 56 | + public function destination(string $destination) { |
| 57 | + $this->destination = $destination; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Sets the name attribute for StartTranscription |
| 62 | + * |
| 63 | + * @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. |
| 64 | + */ |
| 65 | + public function name(string $name) { |
| 66 | + $this->name = $name; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Sets the tracks attribute for StartTranscription |
| 71 | + * |
| 72 | + * @param string $tracks The part of the call to send a real-time transcription from. `inbound`, `outbound` or `both`. Default is `inbound`. |
| 73 | + * |
| 74 | + */ |
| 75 | + public function tracks(string $tracks) { |
| 76 | + $this->tracks = $tracks; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Sets the username attribute for StartTranscription |
| 81 | + * |
| 82 | + * @param string $username The username to send in the HTTP request to `transcriptionEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). |
| 83 | + */ |
| 84 | + public function username(string $username) { |
| 85 | + $this->username = $username; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Sets the password attribute for StartTranscription |
| 90 | + * |
| 91 | + * @param string $password The password to send in the HTTP request to `transcriptionEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). |
| 92 | + */ |
| 93 | + public function password(string $password) { |
| 94 | + $this->password = $password; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Sets the transcriptionEventUrl attribute for StartTranscription |
| 99 | + * |
| 100 | + * @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. |
| 101 | + */ |
| 102 | + public function transcriptionEventUrl(string $transcriptionEventUrl) { |
| 103 | + $this->transcriptionEventUrl = $transcriptionEventUrl; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Sets the transcriptionEventMethod attribute for StartTranscription |
| 108 | + * |
| 109 | + * @param bool $transcriptionEventMethod The HTTP method to use for the request to `transcriptionEventUrl`. GET or POST. Default value is POST. |
| 110 | + */ |
| 111 | + public function transcriptionEventMethod(string $transcriptionEventMethod) { |
| 112 | + $this->transcriptionEventMethod = $transcriptionEventMethod; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Sets the stability attribute for StartTranscription |
| 117 | + * |
| 118 | + * @param bool Whether to send transcription update events to the specified destination only after they have become stable. Requires destination. Defaults to true. |
| 119 | + * |
| 120 | + */ |
| 121 | + public function stability( bool $stability) { |
| 122 | + $this->stability = $stability; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * 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. |
| 127 | + * |
| 128 | + * @param list<CustomParam> $customParams The list of CustomParam tags |
| 129 | + */ |
| 130 | + public function customParams($customParams) { |
| 131 | + $this->customParams = $customParams; |
| 132 | + } |
| 133 | + |
| 134 | + public function toBxml(DOMDocument $doc) { |
| 135 | + $element = $doc->createElement("StartTranscription"); |
| 136 | + |
| 137 | + if(isset($this->destination)) { |
| 138 | + $element->setattribute("destination", $this->destination); |
| 139 | + } |
| 140 | + |
| 141 | + if(isset($this->name)) { |
| 142 | + $element->setattribute("name", $this->name); |
| 143 | + } |
| 144 | + |
| 145 | + if(isset($this->tracks)) { |
| 146 | + $element->setattribute("tracks", $this->tracks); |
| 147 | + } |
| 148 | + |
| 149 | + if(isset($this->username)) { |
| 150 | + $element->setattribute("username", $this->username); |
| 151 | + } |
| 152 | + |
| 153 | + if(isset($this->password)) { |
| 154 | + $element->setattribute("password", $this->password); |
| 155 | + } |
| 156 | + |
| 157 | + if(isset($this->transcriptionEventUrl)) { |
| 158 | + $element->setattribute("transcriptionEventUrl", $this->transcriptionEventUrl); |
| 159 | + } |
| 160 | + |
| 161 | + if(isset($this->transcriptionEventMethod)) { |
| 162 | + $element->setattribute("transcriptionEventMethod", $this->transcriptionEventMethod); |
| 163 | + } |
| 164 | + |
| 165 | + if(isset($this->stability)) { |
| 166 | + $element->setattribute("stablilty", $this->stability); |
| 167 | + } |
| 168 | + |
| 169 | + if(isset($this->customParams)) { |
| 170 | + foreach ($this->customParams as $customParam) { |
| 171 | + $element->appendChild($customParam->toBxml($doc)); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + return $element; |
| 176 | + } |
| 177 | +} |
0 commit comments