Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user-to-user header was not being transformed to lisp case #976

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions packages/voice/__tests__/__dataSets__/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
7 changes: 6 additions & 1 deletion packages/voice/lib/types/Endpoint/SIPEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

42 changes: 38 additions & 4 deletions packages/voice/lib/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +32,34 @@ const apiCallsToCalls = (call: CallDetailResponse): CallDetail => {
} as CallDetail;
};

const NCCOToApiCalls = (ncco: Action[]): Array<Action> => 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<string>;
Expand Down Expand Up @@ -443,10 +473,14 @@ export class Voice extends Client {
* ```
*/
async transferCallWithNCCO(uuid: string, ncco: Action[]): Promise<void> {
return this.callAction(uuid, 'transfer', {
type: 'ncco',
ncco: ncco,
});
return this.callAction(
uuid,
'transfer',
{
type: 'ncco',
ncco: NCCOToApiCalls(ncco),
},
);
}

/**
Expand Down
Loading