Skip to content

Commit 488e7a7

Browse files
Merge pull request #93 from Bandwidth/SWI-2789
SWI-2789 Added Start/Stop Transcription
2 parents 4297481 + f29b3e2 commit 488e7a7

File tree

7 files changed

+401
-150
lines changed

7 files changed

+401
-150
lines changed

src/main/java/com/bandwidth/voice/bxml/verbs/Bxml.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public class Bxml {
4848
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class),
4949
@XmlElement(name = StartStream.TYPE_NAME, type = StartStream.class),
5050
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class),
51-
@XmlElement(name = StreamParam.TYPE_NAME, type = StreamParam.class)
51+
@XmlElement(name = StreamParam.TYPE_NAME, type = StreamParam.class),
52+
@XmlElement(name = StartTranscription.TYPE_NAME, type = StartTranscription.class),
53+
@XmlElement(name = StopTranscription.TYPE_NAME, type = StopTranscription.class),
54+
@XmlElement(name = CustomParam.TYPE_NAME, type = CustomParam.class),
55+
5256
})
5357
private final List<Verb> verbs = new ArrayList<>();
5458

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import javax.xml.bind.annotation.XmlType;
5+
import javax.xml.bind.annotation.XmlAttribute;
6+
import lombok.Builder;
7+
8+
/**
9+
* 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.
10+
*/
11+
@Builder
12+
@XmlType(name = CustomParam.TYPE_NAME)
13+
public class CustomParam implements Verb {
14+
public static final String TYPE_NAME = "CustomParam";
15+
16+
/**
17+
* <b>(required)</b> The name of this parameter, up to 256 characters.
18+
*/
19+
@XmlAttribute
20+
private String name;
21+
22+
/**
23+
* <b>(required)</b> The value of this parameter, up to 2048 characters.
24+
*/
25+
@XmlAttribute
26+
private String value;
27+
}

src/main/java/com/bandwidth/voice/bxml/verbs/Response.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ public class Response {
4747
@XmlElement(name = Tag.TYPE_NAME, type = Tag.class),
4848
@XmlElement(name = SipUri.TYPE_NAME, type = SipUri.class),
4949
@XmlElement(name = StartStream.TYPE_NAME, type = StartStream.class),
50-
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class)
50+
@XmlElement(name = StopStream.TYPE_NAME, type = StopStream.class),
51+
@XmlElement(name = StartTranscription.TYPE_NAME, type = StartTranscription.class),
52+
@XmlElement(name = StopTranscription.TYPE_NAME, type = StopTranscription.class),
53+
@XmlElement(name = CustomParam.TYPE_NAME, type = CustomParam.class),
54+
55+
5156
})
5257
private final List<Verb> verbs = new ArrayList<>();
5358

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import lombok.Builder;
5+
6+
import java.net.URI;
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
import javax.xml.bind.annotation.XmlAttribute;
12+
import javax.xml.bind.annotation.XmlType;
13+
import javax.xml.bind.annotation.XmlElement;
14+
15+
16+
/**
17+
* 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.
18+
*/
19+
@Builder
20+
@XmlType(name = StartTranscription.TYPE_NAME)
21+
public class StartTranscription implements Verb {
22+
public static final String TYPE_NAME = "StartTranscription";
23+
24+
@XmlElement(name = CustomParam.TYPE_NAME)
25+
private final List<CustomParam> customParams;
26+
27+
/**
28+
* <i>(optional)</i> 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.
29+
*/
30+
@XmlAttribute
31+
private String name;
32+
33+
/**
34+
* <i>(optional)</i> the part of the call to send a transcription from. `inbound`, `outbound` or `both`. default is `inbound`.
35+
*/
36+
@XmlAttribute
37+
private String tracks;
38+
39+
/**
40+
* <i>(optional)</i> 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.
41+
*/
42+
@XmlAttribute
43+
private URI destination;
44+
45+
/**
46+
* <i>(optional)</i> Whether to send transcription update events to the specified destination only after they have become stable. Requires destination. Defaults to true.
47+
*/
48+
@XmlAttribute
49+
private Boolean stabilized;
50+
51+
/**
52+
* <i>(optional)</i> url to send the associated webhook events to during this real-time transcription's lifetime. Does not accept bxml. May be a relative URL.
53+
*/
54+
@XmlAttribute
55+
private URI transcriptionEventUrl;
56+
57+
/**
58+
* <i>(optional)</i> the http method to use for the request to `transcriptioneventurl`. get or post. default value is post.
59+
*/
60+
@XmlAttribute
61+
private Method transcriptionEventMethod;
62+
63+
/**
64+
* <i>(optional)</i> the username to send in the http request to `transcriptioneventurl`. if specified, the urls must be tls-encrypted (i.e., `https`).
65+
*/
66+
@XmlAttribute
67+
protected String username;
68+
69+
/**
70+
* <i>(optional)</i> the password to send in the http request to `transcriptioneventurl`. if specified, the urls must be tls-encrypted (i.e., `https`).
71+
*/
72+
@XmlAttribute
73+
protected String password;
74+
75+
76+
public static class StartTranscriptionBuilder {
77+
78+
/**
79+
* <b>(optional)</b> url to send the associated webhook events to during this real-time transcription's lifetime. does not accept bxml. may be a relative url.
80+
*/
81+
public StartTranscriptionBuilder transcriptionEventUrl(URI uri ){
82+
this.transcriptionEventUrl = uri;
83+
return this;
84+
}
85+
86+
/**
87+
* <b>(optional)</b> url to send the associated webhook events to during this real-time transcription's lifetime. does not accept bxml. may be a relative url.
88+
*/
89+
public StartTranscriptionBuilder transcriptionEventUrl(String uri ){
90+
return transcriptionEventUrl(URI.create(uri));
91+
}
92+
93+
/**
94+
* <b>(required)</b> 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.
95+
*/
96+
public StartTranscriptionBuilder destination(URI uri ){
97+
this.destination = uri;
98+
return this;
99+
}
100+
101+
/**
102+
* <b>(optional)</b> 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.
103+
*/
104+
public StartTranscriptionBuilder destination(String uri ){
105+
return destination(URI.create(uri));
106+
}
107+
108+
/**
109+
* <i>(optional)</i> the http method to use for the request to `transcriptioneventurl`. get or post. default value is post.
110+
*/
111+
public StartTranscriptionBuilder transcriptionEventMethod(Method method){
112+
this.transcriptionEventMethod = method;
113+
return this;
114+
}
115+
116+
/**
117+
* <i>(optional)</i> the http method to use for the request to `transcriptionEventUrl`. GET or POST. Default value is POST.
118+
*/
119+
public StartTranscriptionBuilder transcriptionEventMethod(String method){
120+
return transcriptionEventMethod(Method.fromValue(method));
121+
}
122+
123+
/**
124+
* <i>(optional)</i> 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.
125+
*/
126+
public StartTranscriptionBuilder customParams(CustomParam ... customParams){
127+
this.customParams = Arrays.asList(customParams);
128+
return this;
129+
}
130+
131+
/**
132+
* <i>(optional)</i> 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.
133+
*/
134+
public StartTranscriptionBuilder customParams(List<CustomParam> customParams){
135+
this.customParams = customParams;
136+
return this;
137+
}
138+
}
139+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
package com.bandwidth.voice.bxml.verbs;
3+
4+
import lombok.Builder;
5+
import javax.xml.bind.annotation.XmlAttribute;
6+
import javax.xml.bind.annotation.XmlType;
7+
8+
9+
/**
10+
* The Stoptranscription verb is used to stop the real-time transcription previously started by a `<StartTranscriptionm>` verb.
11+
*/
12+
@Builder
13+
@XmlType(name = StopTranscription.TYPE_NAME)
14+
public class StopTranscription implements Verb {
15+
public static final String TYPE_NAME = "StopTranscription";
16+
17+
/**
18+
* <i>(required)</i> 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.
19+
*/
20+
@XmlAttribute
21+
private String name;
22+
}

src/test/java/com/bandwidth/BxmlTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,4 +583,51 @@ public void testGenerateBxmlVerb() {
583583
+ "</Transfer>";
584584
assertEquals("BXML strings are equal", expected, response);
585585
}
586+
587+
@Test
588+
public void testStartTranscriptionBxmlVerb() {
589+
CustomParam customParam1 = CustomParam.builder()
590+
.name("name1")
591+
.value("value1")
592+
.build();
593+
CustomParam customParam2 = CustomParam.builder()
594+
.name("name2")
595+
.value("value2")
596+
.build();
597+
ArrayList<CustomParam> customParams = new ArrayList<CustomParam>();
598+
customParams.add(customParam1);
599+
customParams.add(customParam2);
600+
StartTranscription startTranscription = StartTranscription.builder()
601+
.destination("https://url.com")
602+
.transcriptionEventMethod("POST")
603+
.username("user")
604+
.password("pass")
605+
.name("test_transcription")
606+
.tracks("inbound")
607+
.transcriptionEventUrl("https://url.com")
608+
.customParams(customParams)
609+
.build();
610+
611+
String response = new Response()
612+
.add(startTranscription)
613+
.toBXML();
614+
615+
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartTranscription name=\"test_transcription\" tracks=\"inbound\" destination=\"https://url.com\" transcriptionEventUrl=\"https://url.com\" transcriptionEventMethod=\"POST\" username=\"user\" password=\"pass\"><CustomParam name=\"name1\" value=\"value1\"/><CustomParam name=\"name2\" value=\"value2\"/></StartTranscription></Response>";
616+
assertEquals("BXML strings are equal", expected, response);
617+
}
618+
619+
@Test
620+
public void testStopTranscription() {
621+
StopTranscription stopTranscription = StopTranscription.builder()
622+
.name("test")
623+
.build();
624+
625+
String response = new Response()
626+
.add(stopTranscription)
627+
.toBXML();
628+
629+
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopTranscription name=\"test\"/></Response>";
630+
631+
assertEquals("BXML strings not equal", expected, response);
632+
}
586633
}

0 commit comments

Comments
 (0)