Skip to content

Commit

Permalink
fix: missing dtmfAnswer and onAnswer properties (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck authored Jan 21, 2025
1 parent f786add commit 4c582a2
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 1 deletion.
60 changes: 60 additions & 0 deletions packages/voice/__tests__/__dataSets__/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,64 @@ export default [
conversationUUID: callPhone.conversationUUID,
} as CallResult,
},
{
label: 'create a call with DTFM and answer endpoint',
requests: [
[
'/v1/calls?',
'POST',
{
to: [
{
type: 'phone',
number: '19162255887',
dtmfAnswer: '1234',
},
],
from: {
type: 'phone',
number: '14152739164',
},
answer_url: ['https://example.com/answer'],
},
],
],
responses: [
[
201,
{
uuid: callPhone.uuid,
status: CallStatus.STARTED,
direction: CallDirection.OUTBOUND,
conversation_uuid: callPhone.conversationUUID,
} as CreateCallResponse,
],
],
clientMethod: 'createOutboundCall',
parameters: [
{
answerUrl: ['https://example.com/answer'],
to: [
{
type: 'phone',
number: '19162255887',
dtmfAnswer: '1234',
},
],
from: {
type: 'phone',
number: '14152739164',
},
} as CallWithAnswerURL,
],
generator: false,
error: false,
expected: {
uuid: callPhone.uuid,
status: CallStatus.STARTED,
direction: CallDirection.OUTBOUND,
conversation_uuid: callPhone.conversationUUID,
conversationUUID: callPhone.conversationUUID,
} as CallResult,
},
];
59 changes: 59 additions & 0 deletions packages/voice/__tests__/__dataSets__/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TTSLanguages,
CallUpdateResult,
TalkAction,
PhoneEndpoint,
} from '../../lib';
import { callPhone } from '../common';

Expand Down Expand Up @@ -374,6 +375,64 @@ export default [
error: false,
expected: undefined,
},
{
label: 'transfer call with NCCO and onAnswer',
requests: [
[
`/v1/calls/${callPhone.uuid}`,
'PUT',
{
action: 'transfer',
destination: {
type: 'ncco',
ncco: [
{
action: NCCOActions.CONNECT,
from: '19172255887',
endpoint: [
{
type: 'phone',
number: '19172255887',
dtmfAnswer: '1234',
onAnswer: {
url: 'https://example.com/answer',
ringbackTone: 'http://example.com/ringbackTone.wav',
},
},
],
},
],
},
},
],
],
responses: [[204]],
clientMethod: 'transferCallWithNCCO',
parameters: [
callPhone.uuid,
[
{
action: NCCOActions.CONNECT,
from: '19172255887',
endpoint: [
{
type: 'phone',
number: '19172255887',
dtmfAnswer: '1234',
onAnswer: {
url: 'https://example.com/answer',
ringbackTone: 'http://example.com/ringbackTone.wav',
},
} as PhoneEndpoint,
],
}
,
],
],
generator: false,
error: false,
expected: undefined,
},
{
label: 'hangup call',
requests: [
Expand Down
5 changes: 5 additions & 0 deletions packages/voice/lib/types/CallWithAnswerURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export type CallWithAnswerURL = CommonOutboundCall & {
* The HTTP method used to send events to the answer URL(s), typically "GET" or "POST."
*/
answerMethod?: HttpMethod;

/**
* Provide DTMF digits to send when the call is answerMethod
*/
dtmfAnswer?: string;
};
19 changes: 19 additions & 0 deletions packages/voice/lib/types/Endpoint/AppEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

/**
* Connect the call to a RTC capable application
*/
export type AppEndpoint = {
/**
* Specifies the type of endpoint, which is 'app' for RTC capable
* applications.
*/
type: 'app';

/**
* The username of ther user to connect too.
*
* The username must have been added using
* {@link https://developer.nexmo.com/api/conversation#createUser}
*/
user: string;
} & Record<string, unknown>;
2 changes: 2 additions & 0 deletions packages/voice/lib/types/Endpoint/CallEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PhoneEndpoint } from './PhoneEndpoint';
import { SIPEndpoint } from './SIPEndpoint';
import { VBCEndpoint } from './VBCEndpoint';
import { WebsocketEndpoint } from './WebsocketEndpoint';
import { AppEndpoint } from './AppEndpoint';

/**
* Represents a call endpoint, which can be of different types such as Phone, SIP, VBC, or Websocket.
Expand All @@ -11,4 +12,5 @@ export type CallEndpoint =
| WebsocketEndpoint
| PhoneEndpoint
| SIPEndpoint
| AppEndpoint
| VBCEndpoint;
28 changes: 27 additions & 1 deletion packages/voice/lib/types/Endpoint/PhoneEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,30 @@ export type PhoneEndpoint = {
* The phone number associated with the endpoint.
*/
number: string;
};

/**
* Provide DTMF digits to send when the call is answered
*/
dtmfAnswer?: string;

// onAnswer?: {
// /**
// * The URL serves an NCCO to execute in the number being connected to,
// * before that call is joined to your existing conversation
// */
// url: string;
//
// /**
// * The ringbackTone key can be specified with a URL value that points to a
// * ringbackTone to be played back on repeat to the caller, so they do not
// * hear just silence.
// */
// ringbackTone?: string;
//
// /**
// * @deprecated Use `ringbackTone` instead.
// */
// ringback?: string;
//
// };
} & Record<string, unknown>;
1 change: 1 addition & 0 deletions packages/voice/lib/types/Endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './PhoneEndpoint';
export * from './SIPEndpoint';
export * from './VBCEndpoint';
export * from './WebsocketEndpoint';
export * from './AppEndpoint';

0 comments on commit 4c582a2

Please sign in to comment.