-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom.ts
92 lines (86 loc) · 2.77 KB
/
custom.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
getPhoneNumberFromConfig,
getPrintFormat,
getRecipientPhoneNumberFromConfig,
getVoiceCallBackUrl,
initVoiceService,
printFullResponse,
} from '../../config';
import { Voice } from '@sinch/sdk-core';
(async () => {
console.log('*********************');
console.log('* Callouts - Custom *');
console.log('*********************');
const callingNumber = getPhoneNumberFromConfig();
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
const callbackUrl = getVoiceCallBackUrl();
const requestData: Voice.CustomCalloutRequestData = {
customCalloutRequestBody: {
method: 'customCallout',
customCallout: {
cli: callingNumber,
destination: {
type: 'number',
endpoint: recipientPhoneNumber,
},
custom: 'Custom text',
ice: Voice.customCalloutHelper.formatIceResponse(
Voice.iceActionHelper.connectPstn({
number: recipientPhoneNumber,
cli: callingNumber,
}),
Voice.iceInstructionHelper.say('Welcome to Sinch.', 'en-US/male'),
Voice.iceInstructionHelper.startRecording({
destinationUrl: 'To specify',
credentials: 'To specify',
}),
),
ace: Voice.customCalloutHelper.formatAceResponse(
Voice.aceActionHelper.runMenu({
locale: 'Kimberly',
enableVoice: true,
barge: true,
menus: [
{
id: 'main',
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: '2',
action: 'return(cancel)',
},
],
},
{
id: 'confirm',
mainPrompt: '#tts[Thank you for confirming your order. Enter your 4-digit PIN.]',
maxDigits: 4,
},
],
}),
),
pie: callbackUrl,
},
},
};
const voiceService = initVoiceService();
let response;
try {
response = await voiceService.callouts.custom(requestData);
} catch (error) {
console.log(`Impossible to make a Custom callout to '${requestData.customCalloutRequestBody?.customCallout.destination?.endpoint}'`);
throw error;
}
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
console.log(`The Custom callout was successful. Id = ${response.callId}`);
} else {
printFullResponse(response);
}
})();