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

DEVEXP-269 (Part 1/2): Refactor Voice models #24

Merged
merged 5 commits into from
Feb 22, 2024
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
2 changes: 1 addition & 1 deletion examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"conversation:templatev1:delete": "ts-node src/conversation/templates-v1/delete.ts",
"conversation:templatev2:create": "ts-node src/conversation/templates-v2/create.ts",
"conversation:templatev2:get": "ts-node src/conversation/templates-v2/get.ts",
"conversation:templatev2:list": "ts-node src/conversation/templates-v2/list.ts pretty",
"conversation:templatev2:list": "ts-node src/conversation/templates-v2/list.ts",
"conversation:templatev2:listTranslations": "ts-node src/conversation/templates-v2/list-translations.ts pretty",
"conversation:templatev2:update": "ts-node src/conversation/templates-v2/update.ts",
"conversation:templatev2:delete": "ts-node src/conversation/templates-v2/delete.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GetNumbersRequestData } from '@sinch/sdk-core';
const sinchClient = initApplicationClient();
let response;
try {
response = await sinchClient.voice.applications.getNumbers(requestData);
response = await sinchClient.voice.applications.listNumbers(requestData);
} catch (error) {
console.log(`Impossible to get information about your numbers`);
throw error;
Expand Down
41 changes: 26 additions & 15 deletions examples/simple-examples/src/voice/callouts/custom.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import {
getPhoneNumberFromConfig,
getPrintFormat,
getRecipientPhoneNumberFromConfig, getVoiceCallBackUrl,
getRecipientPhoneNumberFromConfig,
getVoiceCallBackUrl,
initApplicationClient,
printFullResponse,
} from '../../config';
import { AceResponse, CustomCalloutRequestData, IceResponse } from '@sinch/sdk-core';
import {
aceActionHelper,
customCalloutHelper,
CustomCalloutRequestData,
iceActionHelper,
iceInstructionHelper,
} from '@sinch/sdk-core';

(async () => {
console.log('*********************');
Expand All @@ -26,31 +33,35 @@ import { AceResponse, CustomCalloutRequestData, IceResponse } from '@sinch/sdk-c
endpoint: recipientPhoneNumber,
},
custom: 'Custom text',
ice: JSON.stringify({
action: {
name: 'connectPstn',
ice: customCalloutHelper.formatIceResponse(
iceActionHelper.connectPstn({
number: recipientPhoneNumber,
cli: callingNumber,
},
} as IceResponse),
ace: JSON.stringify({
action: {
name: 'runMenu',
}),
iceInstructionHelper.say('Welcome to Sinch.', 'en-US/male'),
iceInstructionHelper.startRecording({
destinationUrl: 'To specify',
credentials: 'To specify',
}),
),
ace: customCalloutHelper.formatAceResponse(
aceActionHelper.runMenu({
locale: 'Kimberly',
enableVoice: true,
barge: true,
menus: [
{
id: 'main',
mainPrompt: '#tts[Welcome to the main menu. Press 1 to confirm order or 4 to cancel]',
repeatPrompt: '#tts[Incorrect value, please try again]',
mainPrompt: '#tts[Welcome to the main menu. Press 1 to confirm order or 2 to cancel]',
repeatPrompt: '#tts[We didn\'t get your input, please try again]',
timeoutMills: 5000,
options: [
{
dtmf: '1',
action: 'menu(confirm)',
},
{
dtmf: '4',
dtmf: '2',
action: 'return(cancel)',
},
],
Expand All @@ -61,8 +72,8 @@ import { AceResponse, CustomCalloutRequestData, IceResponse } from '@sinch/sdk-c
maxDigits: 4,
},
],
},
} as AceResponse),
}),
),
pie: callbackUrl,
},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/voice/callouts/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TtsCalloutRequestData, VoiceRegion } from '@sinch/sdk-core';
type: 'number',
endpoint: recipientPhoneNumber,
},
locale: 'en-US',
locale: 'en-US/male',
text: 'Hello, this is a call from Sinch',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ManageWithCallLegRequestData, VoiceRegion } from '@sinch/sdk-core';
const requestData: ManageWithCallLegRequestData = {
callId,
callLeg: 'callee',
svamlRequestBody: {
manageWithCallLegRequestBody: {
instructions: [
{
name: 'say',
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/voice/calls/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { UpdateCallRequestData, VoiceRegion } from '@sinch/sdk-core';

const requestData: UpdateCallRequestData = {
callId,
svamlRequestBody: {
updateCallRequestBody: {
instructions: [
{
name: 'sendDtmf',
Expand Down
62 changes: 27 additions & 35 deletions examples/webhooks/src/services/voice.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Injectable } from '@nestjs/common';
import { Response } from 'express';
import {
aceActionHelper,
aceInstructionHelper,
AceRequest,
AceResponse,
AceSvamletBuilder,
DiceRequest,
iceActionHelper,
iceInstructionHelper,
IceRequest,
IceResponse,
IceSvamletBuilder,
NotifyRequest,
pieActionHelper,
pieInstructionHelper,
PieRequest,
PieResponse,
PieSvamletBuilder,
VoiceCallback,
} from '@sinch/sdk-core';

Expand Down Expand Up @@ -40,25 +46,17 @@ export class VoiceService {

private handleIceRequest(event: IceRequest, res: Response) {
console.log(`ICE request: CLI = ${event.cli} - To = ${event.to.endpoint} (${event.to.type})`)
const iceResponse: IceResponse = {
action: {
name: 'hangup'
},
instructions: [
{
name: 'say',
text: 'Thank you for calling Sinch! This call will now end.'
}
]
};
const iceResponse = new IceSvamletBuilder()
.setAction(iceActionHelper.hangup())
.addInstruction(iceInstructionHelper.say('Thank you for calling Sinch! This call will now end.', 'en-US'))
.build();
res.status(200).json(iceResponse);
}

private handleAceRequest(event: AceRequest, res: Response) {
console.log(`ACE request: Call answered at '${event.timestamp}'`);
const aceResponse: AceResponse = {
action: {
name: 'runMenu',
console.log(`ACE request: Call answered at '${event.timestamp.toISOString()}'`);
const aceResponse = new AceSvamletBuilder()
.setAction(aceActionHelper.runMenu({
barge: true,
menus: [
{
Expand All @@ -81,36 +79,30 @@ export class VoiceService {
repeatPrompt: '#tts[Please enter your 4-digit pin.]',
repeats: 3,
maxDigits: 4
}
]
}
};
},
],
}))
.build();
res.status(200).json(aceResponse);
}

private handleDiceRequest(event: DiceRequest, res: Response) {
console.log(`DICE request: Call disconnected at '${event.timestamp}' with the reason '${event.reason}'.`);
console.log(`DICE request: Call disconnected at '${event.timestamp.toISOString()}' with the reason '${event.reason}'.`);
res.status(200).send();
}

private handlePieRequest(event: PieRequest, res: Response) {
console.log(`PIE request: IVR menu choice: '${event.menuResult?.value}'`);
const pieResponse: PieResponse = {
action: {
name: 'hangup'
},
instructions: [
{
name: 'say',
text: 'Thanks for your input. The call will now end.'
}
]
}
const pieResponse = new PieSvamletBuilder()
.setAction(pieActionHelper.hangup())
.addInstruction(pieInstructionHelper.say('Thanks for your input. The call will end after some music.'))
.addInstruction(pieInstructionHelper.playFiles(['https://samples-files.com/samples/Audio/mp3/sample-file-4.mp3']))
.build();
res.status(200).send(pieResponse);
}

private handleNotifyRequest(event: NotifyRequest, res: Response) {
console.log(`Notification received: "${event.type}"`)
console.log(`Notification received: "${event.type}"`);
res.status(200).send();
}
}
22 changes: 0 additions & 22 deletions packages/voice/src/models/v1/ace-request-amd/ace-request-amd.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/voice/src/models/v1/ace-request-amd/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/voice/src/models/v1/ace-request/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions packages/voice/src/models/v1/ace-response/ace-response.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/voice/src/models/v1/ace-response/index.ts

This file was deleted.

13 changes: 1 addition & 12 deletions packages/voice/src/models/v1/assign-numbers/assign-numbers.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
/**
* Model: AssignNumbers
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


export interface AssignNumbers {

/** The phone number or list of numbers in E.164 format. */
numbers?: string[];
/** indicates the application where the number(s) will be assigned. If empty, the application key that is used to sign the request will be used. */
applicationkey?: string;
/** indicates the DID capability that needs to be assigned to the chosen application. Valid values are 'voice' and 'sms'. Please note that the DID needs to support the selected capability. */
capability?: CapabilityEnum;
capability?: 'voice' | 'sms';
}

export type CapabilityEnum = 'voice' | 'sms';

10 changes: 0 additions & 10 deletions packages/voice/src/models/v1/call-header/call-header.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/**
* Model: CallHeader
*
* THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
*
*/


/**
* Call Headers can be used to pass custom data from a Sinch SDK client to another, or specified in an ICE response to be made available to the receiving client. Further, if Call Headers is specified they will be available in ICE and DICE events.
*/
Expand All @@ -16,5 +8,3 @@ export interface CallHeader {
/** The call header value of the key value pair. */
value?: string;
}


28 changes: 0 additions & 28 deletions packages/voice/src/models/v1/callout-request/callout-request.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/voice/src/models/v1/callout-request/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* The returned call ID.
*/
export interface CalloutResponse {

/** The returned call identifier. */
callId?: string;
}


1 change: 1 addition & 0 deletions packages/voice/src/models/v1/callout-response/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CalloutResponse } from './callout-response';

This file was deleted.

This file was deleted.

Loading
Loading