Skip to content

Commit d146552

Browse files
authored
SWI-2788 Add Transcription BXML (#99)
* SWI-2788 Add Transcription BXML * remove huge sleeps and add new error handling logic * remove unnecessary tests job from pr workflow
1 parent 4002ddc commit d146552

File tree

6 files changed

+167
-36
lines changed

6 files changed

+167
-36
lines changed

.github/workflows/test-pr.yml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ env:
2525

2626
jobs:
2727
test_pr_main:
28-
name: Test PR to Main Branch
28+
name: Test PR
2929
runs-on: ${{ matrix.os }}
30-
if: github.base_ref == 'main'
3130
strategy:
3231
matrix:
3332
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-22.04]
@@ -45,28 +44,3 @@ jobs:
4544
run: |
4645
bundle install
4746
rake
48-
49-
test_pr_feature:
50-
name: Test PR to Feature Branch
51-
runs-on: ${{ matrix.os }}
52-
if: github.base_ref == 'feature/openapi-generator-sdk'
53-
strategy:
54-
matrix:
55-
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-22.04]
56-
ruby-version: [2.7, 3.0, 3.1, 3.2]
57-
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v3
60-
61-
- name: Set up Ruby
62-
uses: ruby/setup-ruby@v1
63-
with:
64-
ruby-version: ${{ matrix.ruby-version }}
65-
66-
- name: Install Packages and Test
67-
env:
68-
RUBY_VERSION: ${{ matrix.ruby-version }}
69-
OPERATING_SYSTEM: ${{ matrix.os }}
70-
run: |
71-
bundle install
72-
rake
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative 'xml_verb'
2+
3+
module Bandwidth
4+
module Voice
5+
# These elements define optional user specified parameters that will be sent to the destination URL when the real-time transcription is first started
6+
class CustomParam
7+
include XmlVerb
8+
9+
def to_bxml(xml)
10+
xml.CustomParam(compact_hash({
11+
'name' => name,
12+
'value' => value
13+
}))
14+
end
15+
end
16+
end
17+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require_relative 'xml_verb'
2+
3+
module Bandwidth
4+
module Voice
5+
# The StartTranscription verb allows a segment of a call to be transcribed and optionally for the live transcription to be sent off to another destination for additional processing
6+
class StartTranscription
7+
include XmlVerb
8+
9+
def to_bxml(xml)
10+
xml.StartTranscription(compact_hash({
11+
'name' => name,
12+
'tracks' => tracks,
13+
'transcriptionEventUrl' => transcriptionEventUrl,
14+
'transcriptionEventMethod' => transcriptionEventMethod,
15+
'username' => username,
16+
'password' => password,
17+
'destination' => destination,
18+
'stabilized' => stabilized
19+
})) do
20+
def embedded_xml(xml, property, type)
21+
if property
22+
s = if property.is_a?(type)
23+
then property
24+
else type.new(property)
25+
end
26+
s.to_bxml(xml)
27+
end
28+
end
29+
def nest_verbs_list(xml, property)
30+
if property
31+
property.each do |verb|
32+
verb.to_bxml(xml)
33+
end
34+
end
35+
end
36+
embedded_xml(xml, custom_params, CustomParam)
37+
nest_verbs_list(xml, nested_verbs)
38+
end
39+
end
40+
end
41+
end
42+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative 'xml_verb'
2+
3+
module Bandwidth
4+
module Voice
5+
# The StopTranscription verb is used to stop a real-time transcription that was started with a previous `<StartTranscription>` verb
6+
class StopTranscription
7+
include XmlVerb
8+
9+
def to_bxml(xml)
10+
xml.StopTranscription(compact_hash({
11+
'name' => name
12+
}))
13+
end
14+
end
15+
end
16+
end

lib/bandwidth/voice_lib/bxml/verbs/stream_param.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Bandwidth
44
module Voice
5-
# The StartStream verb allows a segment of a call to be sent off to another destination for additional processing
5+
# These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started
66
class StreamParam
77
include XmlVerb
88

test/integration/test_integration.rb

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,18 @@ def test_create_call_and_get_call_state
122122
assert(response.data.enqueued_time.is_a?(DateTime), "enqueued time is not a DateTime object")
123123

124124
#Get phone call information
125-
sleep(15)
126-
response = @bandwidth_client.voice_client.client.get_call(BW_ACCOUNT_ID, response.data.call_id)
127-
assert(response.data.state.length > 0, "state value not set")
128-
assert_not_nil(response.data.enqueued_time, "enqueued time is nil")
129-
assert(response.data.enqueued_time.is_a?(DateTime), "enqueued time is not a DateTime object")
125+
sleep(2)
126+
begin
127+
response = @bandwidth_client.voice_client.client.get_call(BW_ACCOUNT_ID, response.data.call_id)
128+
assert(response.data.state.length > 0, "state value not set")
129+
assert_not_nil(response.data.enqueued_time, "enqueued time is nil")
130+
assert(response.data.enqueued_time.is_a?(DateTime), "enqueued time is not a DateTime object")
131+
rescue ApiErrorException => e
132+
if e.response_code != 404
133+
raise StandardError, "Unexpected HTTP Response: " + e.message
134+
end
135+
end
136+
130137
end
131138

132139
def test_create_call_with_amd_and_get_call_state
@@ -151,9 +158,15 @@ def test_create_call_with_amd_and_get_call_state
151158
assert(response.data.call_id.length > 0, "call_id value not set")
152159

153160
#Get phone call information
154-
sleep(15)
155-
response = @bandwidth_client.voice_client.client.get_call(BW_ACCOUNT_ID, response.data.call_id)
156-
assert(response.data.state.length > 0, "state value not set")
161+
sleep(2)
162+
begin
163+
response = @bandwidth_client.voice_client.client.get_call(BW_ACCOUNT_ID, response.data.call_id)
164+
assert(response.data.state.length > 0, "state value not set")
165+
rescue ApiErrorException => e
166+
if e.response_code != 404
167+
raise StandardError, "Unexpected HTTP Response: " + e.message
168+
end
169+
end
157170
end
158171

159172
def test_create_call_with_priority
@@ -766,4 +779,73 @@ def test_stop_stream_bxml_verb
766779

767780
assert_equal(expected, actual)
768781
end
782+
783+
def test_start_transcription_bxml_verb
784+
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartTranscription name="test_transcription" tracks="inbound" transcriptionEventUrl="https://www.test.com/event" transcriptionEventMethod="POST" username="username" password="password" destination="https://www.test.com/transcription"><CustomParam name="name1" value="value1"/></StartTranscription></Response>'
785+
response = Bandwidth::Voice::Response.new()
786+
787+
custom_param1 = Bandwidth::Voice::CustomParam.new({
788+
:name => "name1",
789+
:value => "value1"
790+
})
791+
792+
start_transcription = Bandwidth::Voice::StartTranscription.new({
793+
:name => "test_transcription",
794+
:tracks => "inbound",
795+
:transcriptionEventUrl => "https://www.test.com/event",
796+
:transcriptionEventMethod => "POST",
797+
:username => "username",
798+
:password => "password",
799+
:destination => "https://www.test.com/transcription",
800+
:custom_params => custom_param1
801+
})
802+
803+
response.push(start_transcription)
804+
actual = response.to_bxml()
805+
806+
assert_equal(expected, actual)
807+
end
808+
809+
def test_start_transcription_multiple_nested_custom_params
810+
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartTranscription name="test_transcription" tracks="inbound" transcriptionEventUrl="https://www.test.com/event" transcriptionEventMethod="POST" username="username" password="password" destination="https://www.test.com/transcription"><CustomParam name="name1" value="value1"/><CustomParam name="name2" value="value2"/></StartTranscription></Response>'
811+
response = Bandwidth::Voice::Response.new()
812+
813+
custom_param1 = Bandwidth::Voice::CustomParam.new({
814+
:name => "name1",
815+
:value => "value1"
816+
})
817+
818+
custom_param2 = Bandwidth::Voice::CustomParam.new({
819+
:name => "name2",
820+
:value => "value2"
821+
})
822+
823+
start_transcription = Bandwidth::Voice::StartTranscription.new({
824+
:destination => "https://www.test.com/transcription",
825+
:name => "test_transcription",
826+
:tracks => "inbound",
827+
:transcriptionEventUrl => "https://www.test.com/event",
828+
:transcriptionEventMethod => "POST",
829+
:username => "username",
830+
:password => "password",
831+
:nested_verbs => [custom_param1, custom_param2]
832+
})
833+
834+
response.push(start_transcription)
835+
actual = response.to_bxml()
836+
837+
assert_equal(expected, actual)
838+
end
839+
840+
def test_stop_transcription_bxml_verb
841+
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopTranscription name="test_transcription"/></Response>'
842+
response = Bandwidth::Voice::Response.new()
843+
stop_transcription = Bandwidth::Voice::StopTranscription.new({
844+
:name => "test_transcription"
845+
})
846+
response.push(stop_transcription)
847+
actual = response.to_bxml()
848+
849+
assert_equal(expected, actual)
850+
end
769851
end

0 commit comments

Comments
 (0)