Skip to content

Commit

Permalink
SWI-2792 Add Transcription BXML (#78)
Browse files Browse the repository at this point in the history
* SWI-2792 Add Transcription BXML

* update stream verbs

* add tests and update to use arrow functions

* update get call logic

* remove instanceof check

* remove big jest timeout
  • Loading branch information
ckoegel authored Jun 20, 2023
1 parent c24a0d0 commit 8bd8392
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 111 deletions.
30 changes: 30 additions & 0 deletions src/bxml/customParam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { XMLElement } from 'xmlbuilder'
import { Verb } from './Verb'

export interface CustomParamOptions {
name: string

value: string
}

export class CustomParam implements CustomParamOptions, Verb {
name: string

value: string

constructor(options: CustomParamOptions) {
this.name = options.name
this.value = options.value
}

addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}

attributes['name'] = this.name

attributes['value'] = this.value

xml.ele('CustomParam', attributes)
}

}
3 changes: 3 additions & 0 deletions src/bxml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ export * from './forward'
export * from './startStream'
export * from './streamParam'
export * from './stopStream'
export * from './startTranscription'
export * from './customParam'
export * from './stopTranscription'
8 changes: 3 additions & 5 deletions src/bxml/startStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class StartStream implements StartStreamOptions, Verb {
this.name = options.name
this.tracks = options.tracks
this.streamEventUrl = options.streamEventUrl
this.streamParams = options?.streamParams || []
this.streamParams = options.streamParams || []
this.streamEventMethod = options.streamEventMethod
this.username = options.username
this.password = options.password
Expand All @@ -50,9 +50,7 @@ export class StartStream implements StartStreamOptions, Verb {
addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}

if (this.destination !== undefined) {
attributes['destination'] = this.destination
}
attributes['destination'] = this.destination

if (this.name !== undefined) {
attributes['name'] = this.name
Expand Down Expand Up @@ -86,4 +84,4 @@ export class StartStream implements StartStreamOptions, Verb {
}
}

}
}
99 changes: 99 additions & 0 deletions src/bxml/startTranscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { XMLElement } from 'xmlbuilder'
import { Verb } from './Verb'

export interface StartTranscriptionOptions {
name?: string

tracks?: string

transcriptionEventUrl?: string

transcriptionEventMethod?: string

username?: string

password?: string

destination?: string

stabilized?: boolean

customParams?: Verb[]
}

export class StartTranscription implements StartTranscriptionOptions, Verb {

name?: string

tracks?: string

transcriptionEventUrl?: string

transcriptionEventMethod?: string

username?: string

password?: string

destination?: string

stabilized?: boolean

customParams?: Verb[]

constructor(options: StartTranscriptionOptions) {
this.name = options.name
this.tracks = options.tracks
this.transcriptionEventUrl = options.transcriptionEventUrl
this.customParams = options.customParams || []
this.transcriptionEventMethod = options.transcriptionEventMethod
this.username = options.username
this.password = options.password
this.destination = options.destination
this.stabilized = options.stabilized
}

addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}

if (this.name !== undefined) {
attributes['name'] = this.name
}

if (this.tracks !== undefined) {
attributes['tracks'] = this.tracks
}
if (this.transcriptionEventUrl !== undefined) {
attributes['transcriptionEventUrl'] = this.transcriptionEventUrl
}

if (this.transcriptionEventMethod !== undefined) {
attributes['transcriptionEventMethod'] = this.transcriptionEventMethod
}

if (this.username !== undefined) {
attributes['username'] = this.username
}

if (this.password !== undefined) {
attributes['password'] = this.password
}

if (this.destination !== undefined) {
attributes['destination'] = this.destination
}

if (this.stabilized !== undefined) {
attributes['stabilized'] = `${this.stabilized}`
}

var StartTranscription = xml.ele('StartTranscription', attributes)

if (Array.isArray(this.customParams)) {
this.customParams.forEach( (verb) => {
verb.addXml(StartTranscription)
})
}
}

}
7 changes: 2 additions & 5 deletions src/bxml/stopStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ export class StopStream implements StopStreamOptions, Verb {
addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}


if (this.name !== null) {
attributes['name'] = `${this.name}`
}
attributes['name'] = this.name

xml.ele('StopStream', attributes)

}

}
}
26 changes: 26 additions & 0 deletions src/bxml/stopTranscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { XMLElement } from 'xmlbuilder'
import { Verb } from './Verb'

export interface StopTranscriptionOptions {
name?: string
}

export class StopTranscription implements StopTranscriptionOptions, Verb {
name?: string

constructor(options: StopTranscriptionOptions) {
this.name = options.name
}

addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}

if (this.name !== undefined) {
attributes['name'] = this.name
}

xml.ele('StopTranscription', attributes)

}

}
8 changes: 2 additions & 6 deletions src/bxml/streamParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ export class StreamParam implements StreamParamOptions, Verb {
addXml(xml: XMLElement) {
const attributes: {[key: string]: string} = {}

if (this.name !== undefined) {
attributes['name'] = this.name
}
attributes['name'] = this.name

if (this.value !== undefined) {
attributes['value'] = this.value
}
attributes['value'] = this.value

xml.ele('StreamParam', attributes)
}
Expand Down
43 changes: 26 additions & 17 deletions tests/api.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiError, ApiController, Client, ModeEnum, CallbackMethodEnum, MachineDetectionConfiguration, Environment } from '../src';
import { ApiError, ApiController, Client, ModeEnum, CallbackMethodEnum, MachineDetectionConfiguration, Environment, ExternalApiError } from '../src';
import { HttpClient } from '../src/http/httpClient';

const sleepMs = ms => new Promise(r => setTimeout(r, ms));
Expand Down Expand Up @@ -48,7 +48,6 @@ describe('http client', () => {

describe('api', () => {
it('should create call and get call state', async () => {
jest.setTimeout(11000);
// create call
const accountId = process.env.BW_ACCOUNT_ID;
const from = process.env.BW_NUMBER;
Expand All @@ -68,16 +67,21 @@ describe('api', () => {
expect(Date.parse(createCallResponse.result.enqueuedTime)).toBeTruthy();

// get call state
await sleepMs(10000);
await sleepMs(2000);
const callId = createCallResponse.result.callId;
const getCallStateResponse = await controller.getCall(accountId, callId);

expect(getCallStateResponse.result.applicationId).toEqual(applicationId);
expect(getCallStateResponse.result.to).toEqual(to);
expect(getCallStateResponse.result.from).toEqual(from);
expect(getCallStateResponse.result.callId).toEqual(callId);
expect(Date.parse(getCallStateResponse.result.enqueuedTime)).toBeTruthy();
expect(getCallStateResponse.result.enqueuedTime).toEqual(createCallResponse.result.enqueuedTime);

try {
const getCallStateResponse = await controller.getCall(accountId, callId);

expect(getCallStateResponse.result.applicationId).toEqual(applicationId);
expect(getCallStateResponse.result.to).toEqual(to);
expect(getCallStateResponse.result.from).toEqual(from);
expect(getCallStateResponse.result.callId).toEqual(callId);
expect(Date.parse(getCallStateResponse.result.enqueuedTime)).toBeTruthy();
expect(getCallStateResponse.result.enqueuedTime).toEqual(createCallResponse.result.enqueuedTime);
} catch (e) {
if (e.statusCode != 404) { throw e; }
}
});

it('should create call with AMD and get call state', async () => {
Expand Down Expand Up @@ -113,14 +117,19 @@ describe('api', () => {
expect(createCallResponse.result.from).toEqual(from);

// get call state
await sleepMs(10000);
await sleepMs(2000);
const callId = createCallResponse.result.callId;
const getCallStateResponse = await controller.getCall(accountId, callId);

expect(getCallStateResponse.result.applicationId).toEqual(applicationId);
expect(getCallStateResponse.result.to).toEqual(to);
expect(getCallStateResponse.result.from).toEqual(from);
expect(getCallStateResponse.result.callId).toEqual(callId);
try {
const getCallStateResponse = await controller.getCall(accountId, callId);

expect(getCallStateResponse.result.applicationId).toEqual(applicationId);
expect(getCallStateResponse.result.to).toEqual(to);
expect(getCallStateResponse.result.from).toEqual(from);
expect(getCallStateResponse.result.callId).toEqual(callId);
} catch (e) {
if (e.statusCode != 404) { throw e; }
}
});

it('should create call with priority', async () => {
Expand Down
Loading

0 comments on commit 8bd8392

Please sign in to comment.