-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrentAny.ts
58 lines (48 loc) · 1.58 KB
/
rentAny.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
getNumberCallbackUrlFromConfig,
getPrintFormat,
initNumbersService,
printFullResponse,
readApplicationKey,
readServicePlanId,
} from '../../config';
import { Numbers } from '@sinch/sdk-core';
(async () => {
console.log('*******************************');
console.log('* NumberService_RentAnyNumber *');
console.log('*******************************');
const servicePlanId = readServicePlanId();
const appId = readApplicationKey();
const callbackUrl = getNumberCallbackUrlFromConfig();
if (!servicePlanId && !appId) {
console.error('Warning: no configuration has been provided for sms and voice configuration.'
+ 'You may want to check the value of "SINCH_SERVICE_PLAN_ID" and "SINCH_APPLICATION_KEY" in the .env file');
}
const rentAnyNumberRequest: Numbers.RentAnyNumberRequest = {
regionCode: 'US',
type: 'LOCAL',
numberPattern: {
searchPattern: 'START',
pattern: '+1781',
},
callbackUrl,
};
if (servicePlanId) {
rentAnyNumberRequest.smsConfiguration = { servicePlanId };
}
if (appId) {
rentAnyNumberRequest.voiceConfiguration = { appId };
}
const requestData: Numbers.RentAnyNumberRequestData = {
rentAnyNumberRequestBody: rentAnyNumberRequest,
};
const numbersService = initNumbersService();
const response = await numbersService.rentAny(requestData);
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
const prettyResponse = response.phoneNumber;
console.log(JSON.stringify(prettyResponse, null, 2));
} else {
printFullResponse(response);
}
})();