-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVEXP-559: Add snippets for Voice API
- Loading branch information
1 parent
1591a88
commit c57348d
Showing
17 changed files
with
400 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}; |
Oops, something went wrong.