|
| 1 | +// eslint-disable-next-line no-unused-vars |
| 2 | +import { Voice, VoiceService } from '@sinch/sdk-core'; |
| 3 | + |
| 4 | +/** @param {VoiceService} voiceService */ |
| 5 | +export const execute = async (voiceService) => { |
| 6 | + |
| 7 | + const recipientPhoneNumber = 'the_phone_number_to_call'; |
| 8 | + const callingNumber = 'the_calling_number'; |
| 9 | + const callbackUrl= 'the_PIE_callback_URL'; |
| 10 | + |
| 11 | + /** @type {Voice.CustomCalloutRequestData} */ |
| 12 | + const requestData = { |
| 13 | + customCalloutRequestBody: { |
| 14 | + method: 'customCallout', |
| 15 | + customCallout: { |
| 16 | + destination: { |
| 17 | + type: 'number', |
| 18 | + endpoint: recipientPhoneNumber, |
| 19 | + }, |
| 20 | + cli: callingNumber, |
| 21 | + ice: Voice.customCalloutHelper.formatIceResponse( |
| 22 | + Voice.iceActionHelper.connectPstn({ |
| 23 | + number: recipientPhoneNumber, |
| 24 | + cli: callingNumber, |
| 25 | + }), |
| 26 | + Voice.iceInstructionHelper.say('Welcome to Sinch', 'en-US/male'), |
| 27 | + ), |
| 28 | + ace: Voice.customCalloutHelper.formatAceResponse( |
| 29 | + Voice.aceActionHelper.runMenu({ |
| 30 | + locale: 'Kimberly', |
| 31 | + enableVoice: true, |
| 32 | + barge: true, |
| 33 | + menus: [ |
| 34 | + { |
| 35 | + id: 'main', |
| 36 | + mainPrompt: '#tts[Welcome to the main menu. Press 1 to confirm order or 2 to cancel.', |
| 37 | + repeatPrompt: '#tts[We didn\'t get your input, please try again.]', |
| 38 | + timeoutMills: 5000, |
| 39 | + options: [ |
| 40 | + { |
| 41 | + dtmf: '1', |
| 42 | + action: 'menu(confirm)', |
| 43 | + }, |
| 44 | + { |
| 45 | + dtmf: '2', |
| 46 | + action: 'return(cancel)', |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + { |
| 51 | + id: 'confirm', |
| 52 | + mainPrompt: '#tts[Thank you for confirming your order. Enter your 4-digit PIN.]', |
| 53 | + maxDigits: 4, |
| 54 | + }, |
| 55 | + ], |
| 56 | + }), |
| 57 | + ), |
| 58 | + pie: callbackUrl, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }; |
| 62 | + |
| 63 | + const response = await voiceService.callouts.custom(requestData); |
| 64 | + |
| 65 | + console.log(`Callout response: \n${JSON.stringify(response, null, 2)}`); |
| 66 | +}; |
0 commit comments