diff --git a/eslint.config.mjs b/eslint.config.mjs index 17fa817..14dd77d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -55,7 +55,6 @@ export default [...compat.extends('eslint:recommended', 'google', 'prettier'), { ignorePattern: '^import.+|test', }], - 'new-cap': 'off', - 'no-unused-vars': 'off' + 'new-cap': 'off' }, }]; diff --git a/snippets/voice/applications/assign-numbers.js b/snippets/voice/applications/assign-numbers.js new file mode 100644 index 0000000..9d83a51 --- /dev/null +++ b/snippets/voice/applications/assign-numbers.js @@ -0,0 +1,24 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const phoneNumber = 'YOUR_Sinch_phone_number_with_voice_capability'; + const applicationKey = 'YOUR_Voice_application_key_from_the_dashboard'; + + /** @type {Voice.AssignNumbersRequestData} */ + const requestData = { + assignNumbersRequestBody: { + numbers: [ + phoneNumber, + ], + applicationkey: applicationKey, + capability: 'voice', + }, + }; + + await voiceService.applications.assignNumbers(requestData); + + console.log('The phone numbers have been assigned to the application successfully.'); +}; diff --git a/snippets/voice/applications/get-callback-urls.js b/snippets/voice/applications/get-callback-urls.js new file mode 100644 index 0000000..1284fd1 --- /dev/null +++ b/snippets/voice/applications/get-callback-urls.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const applicationKey = 'YOUR_Voice_application_key_from_the_dashboard'; + + /** @type {Voice.GetCallbackURLsRequestData} */ + const requestData = { + applicationkey: applicationKey, + }; + + const response = await voiceService.applications.getCallbackURLs(requestData); + + console.log(`Callback URLs:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/applications/list-numbers.js b/snippets/voice/applications/list-numbers.js new file mode 100644 index 0000000..cf62023 --- /dev/null +++ b/snippets/voice/applications/list-numbers.js @@ -0,0 +1,13 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + /** @type {Voice.GetNumbersRequestData} */ + const requestData = {}; + + const response = await voiceService.applications.listNumbers(requestData); + + console.log(`Numbers list:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/applications/query-number.js b/snippets/voice/applications/query-number.js new file mode 100644 index 0000000..ceff50e --- /dev/null +++ b/snippets/voice/applications/query-number.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const phoneNumber = 'the_phone_number'; + + /** @type {Voice.QueryNumberRequestData} */ + const requestData = { + number: phoneNumber, + }; + + const response = await voiceService.applications.queryNumber(requestData); + + console.log(`Phone number information:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/applications/unassign-number.js b/snippets/voice/applications/unassign-number.js new file mode 100644 index 0000000..def66ff --- /dev/null +++ b/snippets/voice/applications/unassign-number.js @@ -0,0 +1,22 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const phoneNumber = 'YOUR_Sinch_phone_number_with_voice_capability'; + const applicationKey = 'YOUR_Voice_application_key_from_the_dashboard'; + + /** @type {Voice.UnassignNumberRequestData} */ + const requestData = { + unassignNumbersRequestBody: { + number: phoneNumber, + applicationkey: applicationKey, + capability: 'voice', + }, + }; + + await voiceService.applications.unassignNumber(requestData); + + console.log('The phone numbers have been unassigned from the application successfully.'); +}; diff --git a/snippets/voice/applications/update-callback-urls.js b/snippets/voice/applications/update-callback-urls.js new file mode 100644 index 0000000..55c5b25 --- /dev/null +++ b/snippets/voice/applications/update-callback-urls.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const applicationKey = 'YOUR_Voice_application_key_from_the_dashboard'; + + /** @type {Voice.UpdateCallbackURLsRequestData} */ + const requestData = { + applicationkey: applicationKey, + updateCallbacksRequestBody: { + url: { + primary: 'https://new-primary-callback-url.com', + fallback: 'https://new-fallback-callback-url.com', + }, + }, + }; + + await voiceService.applications.updateCallbackURLs(requestData); + + console.log('The callback URLs have been successfully updated.'); +}; diff --git a/snippets/voice/callouts/conference.js b/snippets/voice/callouts/conference.js new file mode 100644 index 0000000..0034f87 --- /dev/null +++ b/snippets/voice/callouts/conference.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const conferenceId = 'YOUR_conference_ID'; + const recipientPhoneNumber = 'the_phone_number_to_call'; + const callingNumber = 'the_calling_number'; + + /** @type {Voice.ConferenceCalloutRequestData} */ + const requestData = { + conferenceCalloutRequestBody: { + method: 'conferenceCallout', + conferenceCallout: { + conferenceId, + destination: { + type: 'number', + endpoint: recipientPhoneNumber, + }, + cli: callingNumber, + }, + }, + }; + + const response = await voiceService.callouts.conference(requestData); + + console.log(`Callout response: \n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/callouts/custom.js b/snippets/voice/callouts/custom.js new file mode 100644 index 0000000..9f330ee --- /dev/null +++ b/snippets/voice/callouts/custom.js @@ -0,0 +1,66 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const recipientPhoneNumber = 'the_phone_number_to_call'; + const callingNumber = 'the_calling_number'; + const callbackUrl= 'the_PIE_callback_URL'; + + /** @type {Voice.CustomCalloutRequestData} */ + const requestData = { + customCalloutRequestBody: { + method: 'customCallout', + customCallout: { + destination: { + type: 'number', + endpoint: recipientPhoneNumber, + }, + cli: callingNumber, + ice: Voice.customCalloutHelper.formatIceResponse( + Voice.iceActionHelper.connectPstn({ + number: recipientPhoneNumber, + cli: callingNumber, + }), + Voice.iceInstructionHelper.say('Welcome to Sinch', 'en-US/male'), + ), + 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 response = await voiceService.callouts.custom(requestData); + + console.log(`Callout response: \n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/callouts/tts.js b/snippets/voice/callouts/tts.js new file mode 100644 index 0000000..56a7b82 --- /dev/null +++ b/snippets/voice/callouts/tts.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const recipientPhoneNumber = 'the_phone_number_to_call'; + const callingNumber = 'the_calling_number'; + + /** @type {Voice.TtsCalloutRequestData} */ + const requestData = { + ttsCalloutRequestBody: { + method: 'ttsCallout', + ttsCallout: { + destination: { + type: 'number', + endpoint: recipientPhoneNumber, + }, + cli: callingNumber, + locale: 'en-US/male', + text: 'Hello, this is a call from Sinch.', + }, + }, + }; + + const response = await voiceService.callouts.tts(requestData); + + console.log(`Callout response: \n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/calls/get.js b/snippets/voice/calls/get.js new file mode 100644 index 0000000..4cb2eee --- /dev/null +++ b/snippets/voice/calls/get.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const callId = 'the_call_ID'; + + /** @type {Voice.GetCallResultRequestData} */ + const requestData = { + callId, + }; + + const response = await voiceService.calls.get(requestData); + + console.log(`Call information: \n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/calls/manage-with-call-leg.js b/snippets/voice/calls/manage-with-call-leg.js new file mode 100644 index 0000000..a65613e --- /dev/null +++ b/snippets/voice/calls/manage-with-call-leg.js @@ -0,0 +1,30 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const callId = 'the_call_ID'; + + /** @type {Voice.ManageWithCallLegRequestData} */ + const requestData = { + callId, + callLeg: 'callee', + manageWithCallLegRequestBody: { + action: { + name: 'hangup', + }, + instructions: [ + { + name: 'say', + locale: 'Matthew', + text: 'Hello, the call is over, hanging up now. Goodbye.', + }, + ], + }, + }; + + await voiceService.calls.manageWithCallLeg(requestData); + + console.log('Call managed with a call leg successfully.'); +}; diff --git a/snippets/voice/calls/update.js b/snippets/voice/calls/update.js new file mode 100644 index 0000000..e154697 --- /dev/null +++ b/snippets/voice/calls/update.js @@ -0,0 +1,36 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const callId = 'the_call_ID'; + + /** @type {Voice.UpdateCallRequestData} */ + const requestData = { + callId, + updateCallRequestBody: { + instructions: [ + { + name: 'startRecording', + options: { + destinationUrl: 's3://sinch-storage/voice-recordings/my-recording.mp3', + credentials: '(AwsAccessKey):(AwsSecretKey):(AwsRegion)', + notificationEvents: true, + transcriptionOptions: { + enabled: true, + locale: 'en-US', + }, + }, + }, + ], + action: { + name: 'hangup', + }, + }, + }; + + await voiceService.calls.update(requestData); + + console.log('Call updated successfully.'); +}; diff --git a/snippets/voice/conferences/get.js b/snippets/voice/conferences/get.js new file mode 100644 index 0000000..d620921 --- /dev/null +++ b/snippets/voice/conferences/get.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const conferenceId = 'the_conference_ID'; + + /** @type {Voice.GetConferenceInfoRequestData} */ + const requestData = { + conferenceId, + }; + + const response = await voiceService.conferences.get(requestData); + + console.log(`Conference information: \n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/voice/conferences/kick-all.js b/snippets/voice/conferences/kick-all.js new file mode 100644 index 0000000..6fbb359 --- /dev/null +++ b/snippets/voice/conferences/kick-all.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const conferenceId = 'the_conference_ID'; + + /** @type {Voice.KickAllRequestData} */ + const requestData = { + conferenceId, + }; + + await voiceService.conferences.kickAll(requestData); + + console.log('All the participants have been successfully kicked from the conference'); +}; diff --git a/snippets/voice/conferences/kick-participant.js b/snippets/voice/conferences/kick-participant.js new file mode 100644 index 0000000..fd5eccd --- /dev/null +++ b/snippets/voice/conferences/kick-participant.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const conferenceId = 'the_conference_ID'; + const callId = 'the_call_ID_identifying_a_participant'; + + /** @type {Voice.KickParticipantRequestData} */ + const requestData = { + conferenceId, + callId, + }; + + await voiceService.conferences.kickParticipant(requestData); + + console.log('The participant has been successfully kicked from the conference'); +}; diff --git a/snippets/voice/conferences/manage-participant.js b/snippets/voice/conferences/manage-participant.js new file mode 100644 index 0000000..9975e23 --- /dev/null +++ b/snippets/voice/conferences/manage-participant.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line no-unused-vars +import { Voice, VoiceService } from '@sinch/sdk-core'; + +/** @param {VoiceService} voiceService */ +export const execute = async (voiceService) => { + + const conferenceId = 'the_conference_ID'; + const callId = 'the_call_ID_identifying_a_participant'; + + /** @type {Voice.ManageParticipantRequestData} */ + const requestData = { + conferenceId, + callId, + manageParticipantRequestBody: { + command: 'mute', + moh: 'music1', + }, + }; + + await voiceService.conferences.manageParticipant(requestData); + + console.log('The participant has been managed successfully.'); +};