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

Feature/Elastic SIP Trunking #73

Merged
merged 5 commits into from
May 14, 2024
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
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {

const sinch = new SinchClient(sinchClientParameters);
const conversationService = sinch.conversation;
const elasticSipTrunkingService = sinch.elasticSipTrunking;
const faxService = sinch.fax;
const numbersService = sinch.numbers;
const smsService = sinch.sms;
Expand Down Expand Up @@ -135,14 +136,15 @@ console.log(`The SMS has been sent successfully. Here is the batch id: ${respons

Here is the list of the Sinch products and their level of support by the Node.js SDK:

| API Category | API Name | Status |
|------------------------|------------------|:------:|
| Messaging | SMS API | ✅ |
| | Conversation API | ✅ |
| | Fax API | ✅ |
| Voice and Video | Voice API | ✅ |
| Numbers & Connectivity | Numbers API | ✅ |
| Verification | Verification API | ✅ |
| API Category | API Name | Status |
|------------------------|---------------------------------|:------:|
| Messaging | SMS API | ✅ |
| | Conversation API | ✅ |
| | Fax API | ✅ |
| Voice and Video | Voice API | ✅ |
| | Elastic SIP Trunking API (beta) | ✅ |
| Numbers & Connectivity | Numbers API | ✅ |
| Verification | Verification API | ✅ |

### Packages

Expand All @@ -153,7 +155,8 @@ The Sinch Node.js SDK is packaged in the following way:
- [`@sinch/voice`](./packages/voice): package that contains the Voice services: Callouts, Calls, Conferences, Applications management and Webhooks callbacks.
- [`@sinch/numbers`](./packages/numbers): package that contains the Numbers services: Available number, Active number, Available regions, Callbacks management and Webhooks callbacks.
- [`@sinch/verification`](./packages/verification): package that contains the Verification services: Verification start and report, Verification status and Webhooks callbacks.
- [`@sinch/fax`](./packages/fax): package that contains the Fax services: Services, Faxes and Faxes-on-emails
- [`@sinch/fax`](./packages/fax): package that contains the Fax services: Services, Faxes and Faxes-on-emails.
- [`@sinch/elastic-sip-trunking`](./packages/elastic-sip-trunking): package that contains the Elastic SIP Trunking services: SIP Trunks, Access Control List, SIP Endpoints, Country Permissions, Phones Numbers and Calls.
- [`@sinch/sdk-client`](./packages/sdk-client): package included by all the other ones that contains the API client classes and helpers.

## Examples
Expand Down
37 changes: 37 additions & 0 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ FAX_SERVICE_ID=serviceId to fill with one the fax services created with the Fax
FAX_ID=id from a sendFax response
FAX_CALLBACK_URL=callback url to override the one defined in the default service or specified service
FAX_EMAIL=email to associate with a phone number to use the fax-to-email functionality
## Elastic SIP Trunking API
SIP_TRUNK_ID=sipTrunkId to fill with one of the SIP trunks created with the Elastic SIP Trunking API
SIP_ENDPOINT_ID=sipEndpointId to fill with one of the SIP endpoints created with the Elastic SIP Trunking API
ACL_ID=accessControlListId to fill with one of the access control lists created with the Elastic SIP Trunking API
IP_RANGE_ID=ipRangeId to fill with one of the IP ranges added to an ACL with the Elastic SIP Trunking API
```

**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 @@ -270,3 +275,35 @@ yarn run numbers:regions:list
| | [./src/fax/emails/update.ts](./src/fax/emails/update.ts) | `FAX_EMAIL` + `PHONE_NUMBER` |
| | [./src/fax/emails/delete.ts](./src/fax/emails/delete.ts) | `FAX_EMAIL` |

### Elastic SIP Trunk

| Service | Sample application name and location | Required parameters |
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| SIP Trunks | [./src/elastic-sip-trunking/sip-trunks/create.ts](./src/elastic-sip-trunking/sip-trunks/create.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/get.ts](./src/elastic-sip-trunking/sip-trunks/get.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/list.ts](./src/elastic-sip-trunking/sip-trunks/list.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/update.ts](./src/elastic-sip-trunking/sip-trunks/update.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/delete.ts](./src/elastic-sip-trunking/sip-trunks/delete.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/addACL.ts](./src/elastic-sip-trunking/sip-trunks/addACL.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/sip-trunks/listACLs.ts](./src/elastic-sip-trunking/sip-trunks/listACLs.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/deleteACL.ts](./src/elastic-sip-trunking/sip-trunks/deleteACL.ts) | SIP_TRUNK_ID, ACL_ID |
| SIP Endpoints | [./src/elastic-sip-trunking/sip-endpoints/create.ts](./src/elastic-sip-trunking/sip-endpoints/create.ts) | |
| | [./src/elastic-sip-trunking/sip-endpoints/get.ts](./src/elastic-sip-trunking/sip-endpoints/get.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| | [./src/elastic-sip-trunking/sip-endpoints/list.ts](./src/elastic-sip-trunking/sip-endpoints/list.ts) | |
| | [./src/elastic-sip-trunking/sip-endpoints/update.ts](./src/elastic-sip-trunking/sip-endpoints/update.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| | [./src/elastic-sip-trunking/sip-endpoints/delete.ts](./src/elastic-sip-trunking/sip-endpoints/delete.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| Access Control List | [./src/elastic-sip-trunking/access-control-list/create.ts](./src/elastic-sip-trunking/access-control-list/create.ts) | |
| | [./src/elastic-sip-trunking/access-control-list/list.ts](./src/elastic-sip-trunking/access-control-list/list.ts) | |
| | [./src/elastic-sip-trunking/access-control-list/update.ts](./src/elastic-sip-trunking/access-control-list/update.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/delete.ts](./src/elastic-sip-trunking/access-control-list/delete.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/addIpRange.ts](./src/elastic-sip-trunking/access-control-list/addIpRange.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/listIpRanges.ts](./src/elastic-sip-trunking/access-control-list/listIpRanges.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/updateIpRange.ts](./src/elastic-sip-trunking/access-control-list/updateIpRange.ts) | ACL_ID, IP_RANGE_ID |
| | [./src/elastic-sip-trunking/access-control-list/deleteIpRange.ts](./src/elastic-sip-trunking/access-control-list/deleteIpRange.ts) | ACL_ID, IP_RANGE_ID |
| | [./src/elastic-sip-trunking/access-control-list/addToTrunk.ts](./src/elastic-sip-trunking/access-control-list/addToTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/listForTrunk.ts](./src/elastic-sip-trunking/access-control-list/listForTrunk.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts](./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| Country Permissions | [./src/elastic-sip-trunking/country-permissions/get.ts](./src/elastic-sip-trunking/country-permissions/get.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/list.ts](./src/elastic-sip-trunking/country-permissions/list.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/update.ts](./src/elastic-sip-trunking/country-permissions/update.ts) | |
| Calls | [./src/elastic-sip-trunking/calls-history/find.ts](./src/elastic-sip-trunking/calls-history/find.ts) | SIP_TRUNK_ID |
28 changes: 28 additions & 0 deletions examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@
"conversation:templatev2:listTranslations": "ts-node src/conversation/templates-v2/list-translations.ts",
"conversation:templatev2:update": "ts-node src/conversation/templates-v2/update.ts",
"conversation:templatev2:delete": "ts-node src/conversation/templates-v2/delete.ts",
"elasticSipTrunks:sipTrunk:create": "ts-node src/elastic-sip-trunking/sip-trunks/create.ts",
"elasticSipTrunks:sipTrunk:get": "ts-node src/elastic-sip-trunking/sip-trunks/get.ts",
"elasticSipTrunks:sipTrunk:list": "ts-node src/elastic-sip-trunking/sip-trunks/list.ts",
"elasticSipTrunks:sipTrunk:update": "ts-node src/elastic-sip-trunking/sip-trunks/update.ts",
"elasticSipTrunks:sipTrunk:delete": "ts-node src/elastic-sip-trunking/sip-trunks/delete.ts",
"elasticSipTrunks:sipTrunk:addACL": "ts-node src/elastic-sip-trunking/sip-trunks/addACL.ts",
"elasticSipTrunks:sipTrunk:listACLs": "ts-node src/elastic-sip-trunking/sip-trunks/listACLs.ts",
"elasticSipTrunks:sipTrunk:deleteACL": "ts-node src/elastic-sip-trunking/sip-trunks/deleteACL.ts",
"elasticSipTrunks:sipEndpoint:create": "ts-node src/elastic-sip-trunking/sip-endpoints/create.ts",
"elasticSipTrunks:sipEndpoint:get": "ts-node src/elastic-sip-trunking/sip-endpoints/get.ts",
"elasticSipTrunks:sipEndpoint:list": "ts-node src/elastic-sip-trunking/sip-endpoints/list.ts",
"elasticSipTrunks:sipEndpoint:update": "ts-node src/elastic-sip-trunking/sip-endpoints/update.ts",
"elasticSipTrunks:sipEndpoint:delete": "ts-node src/elastic-sip-trunking/sip-endpoints/delete.ts",
"elasticSipTrunks:accessControlList:create": "ts-node src/elastic-sip-trunking/access-control-list/create.ts",
"elasticSipTrunks:accessControlList:list": "ts-node src/elastic-sip-trunking/access-control-list/list.ts",
"elasticSipTrunks:accessControlList:update": "ts-node src/elastic-sip-trunking/access-control-list/update.ts",
"elasticSipTrunks:accessControlList:delete": "ts-node src/elastic-sip-trunking/access-control-list/delete.ts",
"elasticSipTrunks:accessControlList:addIpRange": "ts-node src/elastic-sip-trunking/access-control-list/addIpRange.ts",
"elasticSipTrunks:accessControlList:listIpRanges": "ts-node src/elastic-sip-trunking/access-control-list/listIpRanges.ts",
"elasticSipTrunks:accessControlList:updateIpRange": "ts-node src/elastic-sip-trunking/access-control-list/updateIpRange.ts",
"elasticSipTrunks:accessControlList:deleteIpRange": "ts-node src/elastic-sip-trunking/access-control-list/deleteIpRange.ts",
"elasticSipTrunks:accessControlList:addToTrunk": "ts-node src/elastic-sip-trunking/access-control-list/addToTrunk.ts",
"elasticSipTrunks:accessControlList:listForTrunk": "ts-node src/elastic-sip-trunking/access-control-list/listForTrunk.ts",
"elasticSipTrunks:accessControlList:deleteFromTrunk": "ts-node src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts",
"elasticSipTrunks:countryPermissions:get": "ts-node src/elastic-sip-trunking/country-permissions/get.ts",
"elasticSipTrunks:countryPermissions:list": "ts-node src/elastic-sip-trunking/country-permissions/list.ts",
"elasticSipTrunks:countryPermissions:update": "ts-node src/elastic-sip-trunking/country-permissions/update.ts",
"elasticSipTrunks:calls:find": "ts-node src/elastic-sip-trunking/calls-history/find.ts",
"fax:services:create": "ts-node src/fax/services/create.ts",
"fax:services:get": "ts-node src/fax/services/get.ts",
"fax:services:list": "ts-node src/fax/services/list.ts",
Expand Down
23 changes: 22 additions & 1 deletion examples/simple-examples/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
SmsService,
VerificationService,
VoiceService,
ElasticSipTrunkingService,
} from '@sinch/sdk-core';
require('dotenv').config();

const initClient = (): Pick<SinchClient, 'conversation' | 'fax' | 'numbers' | 'sms'> => {
const initClient = (): Pick<SinchClient, 'conversation' | 'elasticSipTrunking' | 'fax' | 'numbers' | 'sms'> => {
const keyId = process.env.SINCH_KEY_ID || '';
const keySecret = process.env.SINCH_KEY_SECRET || '';
const projectId = process.env.SINCH_PROJECT_ID || '';
Expand All @@ -21,6 +22,10 @@ export const initConversationService = (): ConversationService => {
return initClient().conversation;
};

export const initElasticSipTrunkingService = (): ElasticSipTrunkingService => {
return initClient().elasticSipTrunking;
};

export const initFaxService = (): FaxService => {
return initClient().fax;
};
Expand Down Expand Up @@ -198,6 +203,22 @@ export const getFaxEmailFromConfig = () => {
return readVariable('FAX_EMAIL');
};

export const getSipTrunkIdFromConfig = () => {
return readVariable('SIP_TRUNK_ID');
};

export const getSipEndpointIdFromConfig = () => {
return readVariable('SIP_ENDPOINT_ID');
};

export const getAccessControlListIdFromConfig = () => {
return readVariable('ACL_ID');
};

export const getIpRangeIdFromConfig = () => {
return readVariable('IP_RANGE_ID');
};

const readVariable = ( name: string): string => {
const value = process.env[name];
if (!value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getPrintFormat,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('*******************************');
console.log('* addAccessControlListToTrunk *');
console.log('*******************************');

const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.AddIpRangeToAccessControlListRequestData = {
accessControlListId: aclId,
addIpRangeRequestBody: {
description: 'IP range to add with the Node.js SDK',
ipAddress: '11.12.13.14',
range: 27,
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.addIpRange(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The IP range with the ID ${response.id} associated to the ACL '${response.accessControlListId}' has been created at ${response.createTime?.toISOString()}`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getPrintFormat,
getSipTrunkIdFromConfig,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('*******************************');
console.log('* addAccessControlListToTrunk *');
console.log('*******************************');

const sipTrunkId = getSipTrunkIdFromConfig();
const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.AddAccessControlListToTrunkRequestData = {
trunkId: sipTrunkId,
addAccessControlListToTrunkRequestBody: {
accessControlListIds: [
aclId,
],
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.addToTrunk(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The SIP trunk with the id '${requestData.trunkId}' contains the following ACL IDs:\n - ${response.accessControlListIds?.join('\n - ')}`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config';

(async () => {
console.log('***************************');
console.log('* createAccessControlList *');
console.log('***************************');

const requestData: ElasticSipTrunking.CreateAccessControlListRequestData = {
createAccessControlListBody: {
name: 'New ACL created with the Node.js SDK',
enabled: true,
ipRanges: [
{
description: 'Location 1',
ipAddress: '15.15.15.15',
range: 20,
},
],
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.create(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`New access control list created with the id '${response.id}' at '${response.createTime?.toISOString()}'`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import { getAccessControlListIdFromConfig, initElasticSipTrunkingService } from '../../config';

(async () => {
console.log('***************************');
console.log('* deleteAccessControlList *');
console.log('***************************');

const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.DeleteAccessControlListRequestData = {
id: aclId,
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
await elasticSipTrunkingService.accessControlList.delete(requestData);

console.log(`The SIP trunk with the id '${requestData.id}' has been deleted.`);

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getSipTrunkIdFromConfig,
initElasticSipTrunkingService,
} from '../../config';

(async () => {
console.log('************************************');
console.log('* deleteAccessControlListFromTrunk *');
console.log('************************************');

const sipTrunkId = getSipTrunkIdFromConfig();
const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.DeleteAccessControlListFromTrunkRequestData = {
trunkId: sipTrunkId,
accessControlListId: aclId,
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
await elasticSipTrunkingService.accessControlList.deleteFromTrunk(requestData);

console.log(`The ACL '${requestData.accessControlListId}' has been removed fromm the SIP trunk '${requestData.trunkId}'`);

})();
Loading
Loading