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-248: Voice API - Generate models #3

Merged
merged 5 commits into from
Dec 29, 2023
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
19 changes: 19 additions & 0 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ VERIFICATION_IDENTITY=verification-identity to fill with the identity of the use
VERIFICATION_REFERENCE=verification-reference to add when starting a verification or getting its status
VERIFICATION_CODE=verification-code received for a verification via SMS or callout
VERIFICATION_CLI=verification-cli received for a verification via flashCall
CALL_ID=call_id to fill with one of the callouts created with the Voice API
CONFERENCE_ID=unique identifier of the conference you want to interact with
```

**Note**: If you prefer using environment variables, the sample app is also supporting them: they take precedence over the value from the `.env` file.
Expand Down Expand Up @@ -113,3 +115,20 @@ yarn run numbers:regions:list
| | Verification-status | [./src/verification/verification-status/verification-by-id.ts](./src/verification/verification-status/verification-by-id.ts) | `VERIFICATION_ID` |
| | | [./src/verification/verification-status/verification-by-identity.ts](./src/verification/verification-status/verification-by-identity.ts) | `VERIFICATION_IDENTITY` |
| | | [./src/verification/verification-status/verification-by-reference.ts](./src/verification/verification-status/verification-by-reference.ts) | `VERIFICATION_REFERENCE` |
| Voice | Applications | [./src/voice/applications/assignNumbers.ts](./src/voice/applications/assignNumbers.ts) | `PHONE_NUMBER` + `SINCH_APPLICATION_KEY` |
| | | [./src/voice/applications/getCallbackURLs.ts](./src/voice/applications/getCallbackURLs.ts) | `SINCH_APPLICATION_KEY` |
| | | [./src/voice/applications/getNumbers.ts](./src/voice/applications/getNumbers.ts) | |
| | | [./src/voice/applications/queryNumber.ts](./src/voice/applications/queryNumber.ts) | `PHONE_NUMBER` |
| | | [./src/voice/applications/unassignNumber.ts](./src/voice/applications/unassignNumber.ts) | `PHONE_NUMBER` + `SINCH_APPLICATION_KEY` |
| | | [./src/voice/applications/updateCallbackURLs.ts](./src/voice/applications/updateCallbackURLs.ts) | `SINCH_APPLICATION_KEY` |
| | Callouts | [./src/voice/callouts/conference.ts](./src/voice/callouts/conference.ts) | `PHONE_NUMBER` + `RECIPIENT_PHONE_NUMBER` + `CONFERENCE_ID` |
| | | [./src/voice/callouts/custom.ts](./src/voice/callouts/custom.ts) | `PHONE_NUMBER` + `RECIPIENT_PHONE_NUMBER` |
| | | [./src/voice/callouts/tts.ts](./src/voice/callouts/tts.ts) | `PHONE_NUMBER` + `RECIPIENT_PHONE_NUMBER` |
| | Calls | [./src/voice/calls/get.ts](./src/voice/calls/get.ts) | `CALL_ID` |
| | | [./src/voice/calls/manageWithCallLeg.ts](./src/voice/calls/manageWithCallLeg.ts) | `CALL_ID` |
| | | [./src/voice/calls/update.ts](./src/voice/calls/update.ts) | `CALL_ID` |
| | Conferences | [./src/voice/conferences/get.ts](./src/voice/conferences/get.ts) | `CONFERENCE_ID` |
| | | [./src/voice/conferences/kickAll.ts](./src/voice/conferences/kickAll.ts) | `CONFERENCE_ID` |
| | | [./src/voice/conferences/kickParticipant.ts](./src/voice/conferences/kickParticipant.ts) | `CONFERENCE_ID` + `CALL_ID` |
| | | [./src/voice/conferences/manageParticipant.ts](./src/voice/conferences/manageParticipant.ts) | `CONFERENCE_ID` + `CALL_ID` |

18 changes: 17 additions & 1 deletion examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,23 @@
"verification:verifications:report-with-identity": "ts-node src/verification/verifications/report-with-identity.ts",
"verification:verification-status:verification-by-id": "ts-node src/verification/verification-status/verification-by-id.ts",
"verification:verification-status:verification-by-identity": "ts-node src/verification/verification-status/verification-by-identity.ts",
"verification:verification-status:verification-by-reference": "ts-node src/verification/verification-status/verification-by-reference.ts"
"verification:verification-status:verification-by-reference": "ts-node src/verification/verification-status/verification-by-reference.ts",
"voice:applications:getNumbers": "ts-node src/voice/applications/getNumbers.ts",
"voice:applications:queryNumber": "ts-node src/voice/applications/queryNumber.ts",
"voice:applications:assignNumbers": "ts-node src/voice/applications/assignNumbers.ts",
"voice:applications:unassignNumber": "ts-node src/voice/applications/unassignNumber.ts",
"voice:applications:getCallbackURLs": "ts-node src/voice/applications/getCallbackURLs.ts",
"voice:applications:updateCallbackURLs": "ts-node src/voice/applications/updateCallbackURLs.ts",
"voice:callouts:tts": "ts-node src/voice/callouts/tts.ts",
"voice:callouts:conference": "ts-node src/voice/callouts/conference.ts",
"voice:callouts:custom": "ts-node src/voice/callouts/custom.ts",
"voice:calls:get": "ts-node src/voice/calls/get.ts",
"voice:calls:update": "ts-node src/voice/calls/update.ts",
"voice:calls:manageWithCallLeg": "ts-node src/voice/calls/manageWithCallLeg.ts",
"voice:conferences:get": "ts-node src/voice/conferences/get.ts",
"voice:conferences:manageParticipant": "ts-node src/voice/conferences/manageParticipant.ts",
"voice:conferences:kickParticipant": "ts-node src/voice/conferences/kickParticipant.ts",
"voice:conferences:kickAll": "ts-node src/voice/conferences/kickAll.ts"
},
"dependencies": {
"@sinch/sdk-core": "^0.0.0",
Expand Down
78 changes: 51 additions & 27 deletions examples/simple-examples/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const initSmsClient = () => {
return new SinchClient({ servicePlanId, apiToken, region });
};

export const initVerificationClient = () => {
export const initApplicationClient = () => {
const applicationKey = process.env.SINCH_APPLICATION_KEY || '';
const applicationSecret = process.env.SINCH_APPLICATION_SECRET || '';
return new SinchClient({ applicationKey, applicationSecret });
Expand All @@ -29,56 +29,80 @@ export const getPrintFormat = (args: string[]): 'pretty' | 'full' => {
return 'full';
};

export const getPhoneNumberFromConfig = (): string | undefined => {
return process.env.PHONE_NUMBER;
export const getPhoneNumberFromConfig = (): string => {
return readVariable('PHONE_NUMBER');
};

export const getServicePlanIdFromConfig = (): string | undefined => {
return process.env.SINCH_SERVICE_PLAN_ID;
export const readServicePlanId = (): string | undefined => {
return process.env.SERVICE_PLAN_ID;
};

export const getApplicationKeyFromConfig = (): string | undefined => {
return process.env.APPLICATION_KEY;
export const readApplicationKey = (): string | undefined => {
return process.env.SINCH_APPLICATION_KEY;
};

export const getGroupIdFromConfig = (): string | undefined => {
return process.env.GROUP_ID;
export const getServicePlanIdFromConfig = (): string => {
return readVariable('SERVICE_PLAN_ID');
};

export const getRecipientPhoneNumberFromConfig = (): string | undefined => {
return process.env.RECIPIENT_PHONE_NUMBER;
export const getApplicationKeyFromConfig = (): string => {
return readVariable('SINCH_APPLICATION_KEY');
};

export const getBatchIdFromConfig = (): string | undefined => {
return process.env.BATCH_ID;
export const getGroupIdFromConfig = (): string => {
return readVariable('GROUP_ID');
};

export const getInboundIdFromConfig = (): string | undefined => {
return process.env.INBOUND_ID;
export const getRecipientPhoneNumberFromConfig = (): string => {
return readVariable('RECIPIENT_PHONE_NUMBER');
};

export const getHmacSecretFromConfig = (): string | undefined => {
return process.env.HMAC_SECRET;
export const getBatchIdFromConfig = (): string => {
return readVariable('BATCH_ID');
};

export const getVerificationIdFromConfig = (): string | undefined => {
return process.env.VERIFICATION_ID;
export const getInboundIdFromConfig = (): string => {
return readVariable('INBOUND_ID');
};

export const getVerificationIdentityFromConfig = (): string | undefined => {
return process.env.VERIFICATION_IDENTITY;
export const getHmacSecretFromConfig = (): string => {
return readVariable('HMAC_SECRET');
};

export const getVerificationReferenceFromConfig = (): string | undefined => {
return process.env.VERIFICATION_REFERENCE;
export const getVerificationIdFromConfig = (): string => {
return readVariable('VERIFICATION_ID');
};

export const getVerificationCodeFromConfig = (): string | undefined => {
return process.env.VERIFICATION_CODE;
export const getVerificationIdentityFromConfig = (): string => {
return readVariable('VERIFICATION_IDENTITY');
};

export const getVerificationCliFromConfig = (): string | undefined => {
return process.env.VERIFICATION_CLI;
export const getVerificationReferenceFromConfig = (): string => {
return readVariable('VERIFICATION_REFERENCE');
};

export const getVerificationCodeFromConfig = (): string => {
return readVariable('VERIFICATION_CODE');
};

export const getVerificationCliFromConfig = (): string => {
return readVariable('VERIFICATION_CLI');
};

export const getCallIdFromConfig = (): string => {
return readVariable('CALL_ID');
};

export const getConferenceIdFromConfig = (): string => {
return readVariable('CONFERENCE_ID');
};

const readVariable = ( name: string): string => {
const value = process.env[name];
if (!value) {
throw new Error(`No "${name}" has been provided. Please update your .env file.`);
}
return value;
};

export const printFullResponse = (response: any) => {
Expand Down
4 changes: 0 additions & 4 deletions examples/simple-examples/src/numbers/active/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { GetActiveNumberRequestData } from '@sinch/sdk-core';
console.log('*********************************');

const phoneNumber = getPhoneNumberFromConfig();
if (!phoneNumber) {
throw new Error('No phone number has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/active/get.ts file');
}

const requestData: GetActiveNumberRequestData= {
phoneNumber,
Expand Down
4 changes: 0 additions & 4 deletions examples/simple-examples/src/numbers/active/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { ReleaseNumberRequestData } from '@sinch/sdk-core';
console.log('*******************************');

const phoneNumber = getPhoneNumberFromConfig();
if (!phoneNumber) {
throw new Error('No phone number has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/active/release.ts file');
}

const requestData: ReleaseNumberRequestData= {
phoneNumber,
Expand Down
9 changes: 0 additions & 9 deletions examples/simple-examples/src/numbers/active/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import { UpdateActiveNumberRequestData } from '@sinch/sdk-core';
console.log('************************************');

const phoneNumber = getPhoneNumberFromConfig();
if (!phoneNumber) {
throw new Error('No phone number has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/active/update.ts file');
}

const servicePlanId = getServicePlanIdFromConfig();
if (!servicePlanId) {
throw new Error('No servicePlanId has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/active/update.ts file');
}

const requestData: UpdateActiveNumberRequestData= {
phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { GetAvailableNumberRequestData } from '@sinch/sdk-core';

// Use the phone number from the .env file
const phoneNumber = getPhoneNumberFromConfig();
if (!phoneNumber) {
throw new Error('No phone number has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/available/checkAvailability.ts file');
}

const requestData: GetAvailableNumberRequestData= {
phoneNumber,
Expand Down
19 changes: 7 additions & 12 deletions examples/simple-examples/src/numbers/available/rent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
getApplicationKeyFromConfig,
readApplicationKey,
getPhoneNumberFromConfig,
getPrintFormat,
getServicePlanIdFromConfig,
readServicePlanId,
initClient,
printFullResponse,
} from '../../config';
Expand All @@ -16,15 +16,8 @@ import {
console.log('* NumberService_RentNumber *');
console.log('****************************');

// Use the phone number from the .env file
const phoneNumber = getPhoneNumberFromConfig();
if (!phoneNumber) {
throw new Error('No phone number has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/available/rent.ts file');
}

const servicePlanId = getServicePlanIdFromConfig();
const appId = getApplicationKeyFromConfig();
const servicePlanId = readServicePlanId();
const appId = readApplicationKey();

let rentNumberRequest: RentNumberRequest = {
smsConfiguration: servicePlanId ? { servicePlanId } : undefined,
Expand All @@ -34,9 +27,11 @@ import {
if (!rentNumberRequest.smsConfiguration && !rentNumberRequest.voiceConfiguration) {
rentNumberRequest = {};
console.error('Warning: no configuration has been provided for sms and voice configuration.'
+ 'You may want to check the value of "SERVICE_PLAN_ID" and "APPLICATION_KEY" in the .env file');
+ 'You may want to check the value of "SINCH_SERVICE_PLAN_ID" and "SINCH_APPLICATION_KEY" in the .env file');
}

const phoneNumber = getPhoneNumberFromConfig();

const requestData: RentNumberRequestData = {
phoneNumber,
rentNumberRequestBody: rentNumberRequest,
Expand Down
10 changes: 5 additions & 5 deletions examples/simple-examples/src/numbers/available/rentAny.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
getApplicationKeyFromConfig,
getPrintFormat,
getServicePlanIdFromConfig,
initClient,
printFullResponse,
readApplicationKey,
readServicePlanId,
} from '../../config';
import {
RentAnyNumberRequest,
Expand All @@ -15,12 +15,12 @@ import {
console.log('* NumberService_RentAnyNumber *');
console.log('*******************************');

const servicePlanId = getServicePlanIdFromConfig();
const appId = getApplicationKeyFromConfig();
const servicePlanId = readServicePlanId();
const appId = readApplicationKey();

if (!servicePlanId && !appId) {
console.error('Warning: no configuration has been provided for sms and voice configuration.'
+ 'You may want to check the value of "SERVICE_PLAN_ID" and "APPLICATION_KEY" in the .env file');
+ 'You may want to check the value of "SINCH_SERVICE_PLAN_ID" and "SINCH_APPLICATION_KEY" in the .env file');
}

const rentAnyNumberRequest: RentAnyNumberRequest = {
Expand Down
4 changes: 0 additions & 4 deletions examples/simple-examples/src/numbers/callbacks/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import * as process from 'process';
console.log('*******************************');

const hmacSecret = getHmacSecretFromConfig();
if (!hmacSecret) {
console.log('No HMAC secret has been provided. '
+ 'Please update your .env file or edit the ./src/numbers/callback/update.ts file');
}

const requestData: UpdateCallbackConfigurationRequestData = {
callbackConfigurationUpdateRequestBody: {
Expand Down
4 changes: 0 additions & 4 deletions examples/simple-examples/src/sms/batches/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { CancelBatchMessageRequestData } from '@sinch/sdk-core';
console.log('**********************');

const batchIdInTheFuture = getBatchIdFromConfig();
if (!batchIdInTheFuture) {
throw new Error('No batch id has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/cancel.ts file');
}

const requestData: CancelBatchMessageRequestData= {
batch_id: batchIdInTheFuture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ import { DeliveryFeedbackRequestData } from '@sinch/sdk-core';
console.log('********************');

const batchIdInTheFuture = getBatchIdFromConfig();
if (!batchIdInTheFuture) {
throw new Error('No batch id has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/delivery-feedback.ts file');
}

const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
if (!recipientPhoneNumber) {
throw new Error('No recipient phone number has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/delivery-feedback.ts file');
}

const requestData: DeliveryFeedbackRequestData= {
batch_id: batchIdInTheFuture,
Expand Down
9 changes: 0 additions & 9 deletions examples/simple-examples/src/sms/batches/dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import { DryRunRequestData, TextRequest } from '@sinch/sdk-core';
console.log('***********');

const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
if (!recipientPhoneNumber) {
throw new Error('No recipient phone number has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/dry-run.ts file');
}

const senderPhoneNumber = getPhoneNumberFromConfig();
if (!senderPhoneNumber) {
throw new Error('No sender phone number has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/dry-run.ts file');
}

const requestData: DryRunRequestData= {
dryRunRequestBody: {
Expand Down
4 changes: 0 additions & 4 deletions examples/simple-examples/src/sms/batches/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { GetBatchMessageRequestData } from '@sinch/sdk-core';
console.log('*******************');

const batchId = getBatchIdFromConfig();
if (!batchId) {
throw new Error('No batch id has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/get.ts file');
}

const requestData: GetBatchMessageRequestData= {
batch_id: batchId,
Expand Down
14 changes: 0 additions & 14 deletions examples/simple-examples/src/sms/batches/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ import { BinaryRequest, ReplaceBatchMessageRequestData, textToHex } from '@sinch
console.log('****************');

const batchIdInTheFuture = getBatchIdFromConfig();
if (!batchIdInTheFuture) {
throw new Error('No batch id has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/replace.ts file');
}

const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
if (!recipientPhoneNumber) {
throw new Error('No recipient phone number has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/replace.ts file');
}

const senderPhoneNumber = getPhoneNumberFromConfig();
if (!senderPhoneNumber) {
throw new Error('No sender phone number has been provided. '
+ 'Please update your .env file or edit the ./src/sms/batches/replace.ts file');
}

const requestData: ReplaceBatchMessageRequestData= {
batch_id: batchIdInTheFuture,
Expand Down
Loading