diff --git a/packages/voice/__tests__/__dataSets__/update.ts b/packages/voice/__tests__/__dataSets__/update.ts index b6428e32..ac475ddf 100644 --- a/packages/voice/__tests__/__dataSets__/update.ts +++ b/packages/voice/__tests__/__dataSets__/update.ts @@ -184,6 +184,108 @@ export default [ error: false, expected: undefined, }, + { + label: 'transfer call with NCCO with userToUser', + requests: [ + [ + `/v1/calls/${callPhone.uuid}`, + 'PUT', + { + action: 'transfer', + destination: { + type: 'ncco', + ncco: [ + { + action: NCCOActions.CONNECT, + endpoint: [ + { + type: 'sip', + uri: 'xxx', + standardHeaders: { + 'User-to-User': 'yyy' + } + }, + ] + }, + ], + }, + }, + ], + ], + responses: [[204]], + clientMethod: 'transferCallWithNCCO', + parameters: [ + callPhone.uuid, + [ + { + action: NCCOActions.CONNECT, + endpoint: [ + { + type: 'sip', + uri: 'xxx', + standardHeaders: { + 'userToUser': 'yyy' + } + }, + ], + }, + ], + ], + generator: false, + error: false, + expected: undefined, + }, + { + label: 'transfer call with NCCO with User-To-User', + requests: [ + [ + `/v1/calls/${callPhone.uuid}`, + 'PUT', + { + action: 'transfer', + destination: { + type: 'ncco', + ncco: [ + { + action: NCCOActions.CONNECT, + endpoint: [ + { + type: 'sip', + uri: 'xxx', + standardHeaders: { + 'User-to-User': 'yyy' + } + }, + ] + }, + ], + }, + }, + ], + ], + responses: [[204]], + clientMethod: 'transferCallWithNCCO', + parameters: [ + callPhone.uuid, + [ + { + action: NCCOActions.CONNECT, + endpoint: [ + { + type: 'sip', + uri: 'xxx', + standardHeaders: { + 'User-to-User': 'yyy' + } + }, + ], + }, + ], + ], + generator: false, + error: false, + expected: undefined, + }, { label: 'transfer call with NCCO', requests: [ diff --git a/packages/voice/lib/types/Endpoint/SIPEndpoint.ts b/packages/voice/lib/types/Endpoint/SIPEndpoint.ts index 1bc11069..fc8e673d 100644 --- a/packages/voice/lib/types/Endpoint/SIPEndpoint.ts +++ b/packages/voice/lib/types/Endpoint/SIPEndpoint.ts @@ -28,7 +28,12 @@ export type SIPEndpoint = { * * @link https://tools.ietf.org/html/rfc7433 */ - userToUser: string; + userToUser?: string; + + /** + * Allows using the pure header that is expected in the API call. + */ + 'User-to-User'?: string; } }; diff --git a/packages/voice/lib/voice.ts b/packages/voice/lib/voice.ts index 63b8e514..0a7bf809 100644 --- a/packages/voice/lib/voice.ts +++ b/packages/voice/lib/voice.ts @@ -12,9 +12,11 @@ import { TalkAction, OutboundCall, CallWithNCCO, + SIPEndpoint, } from './types'; import { ResponseTypes } from '@vonage/vetch'; +import { NCCOActions } from './enums'; const apiCallsToCalls = (call: CallDetailResponse): CallDetail => { delete call._links; @@ -30,6 +32,34 @@ const apiCallsToCalls = (call: CallDetailResponse): CallDetail => { } as CallDetail; }; +const NCCOToApiCalls = (ncco: Action[]): Array => ncco.map((action) => { + switch (action.action) { + case NCCOActions.CONNECT: + return { + ...action, + endpoint: action.endpoint.map((endpoint) => { + switch (endpoint.type) { + case 'sip': + return { + type: 'sip', + uri: endpoint.uri, + headers: endpoint.headers, + standardHeaders: { + 'User-to-User': Object.hasOwn(endpoint.standardHeaders || {} ,'User-to-User') + ? {...endpoint.standardHeaders}['User-to-User'] + : endpoint.standardHeaders?.userToUser, + } + } as SIPEndpoint; + default: + return endpoint; + } + }) + }; + default: + return action; + } +}); + type NCCODestination = { type: 'ncco'; url?: Array; @@ -443,10 +473,14 @@ export class Voice extends Client { * ``` */ async transferCallWithNCCO(uuid: string, ncco: Action[]): Promise { - return this.callAction(uuid, 'transfer', { - type: 'ncco', - ncco: ncco, - }); + return this.callAction( + uuid, + 'transfer', + { + type: 'ncco', + ncco: NCCOToApiCalls(ncco), + }, + ); } /**