-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrent.ts
51 lines (42 loc) · 1.57 KB
/
rent.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
import {
readApplicationKey,
getPhoneNumberFromConfig,
getPrintFormat,
readServicePlanId,
printFullResponse,
getNumberCallbackUrlFromConfig,
initNumbersService,
} from '../../config';
import { Numbers } from '@sinch/sdk-core';
(async () => {
console.log('****************************');
console.log('* NumberService_RentNumber *');
console.log('****************************');
const callbackUrl = getNumberCallbackUrlFromConfig();
const servicePlanId = readServicePlanId();
const appId = readApplicationKey();
let rentNumberRequest: Numbers.RentNumberRequest = {
smsConfiguration: servicePlanId ? { servicePlanId } : undefined,
voiceConfiguration: appId ? { appId } : undefined,
callbackUrl,
};
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 "SINCH_SERVICE_PLAN_ID" and "SINCH_APPLICATION_KEY" in the .env file');
}
const phoneNumber = getPhoneNumberFromConfig();
const requestData: Numbers.RentNumberRequestData = {
phoneNumber,
rentNumberRequestBody: rentNumberRequest,
};
const numbersService = initNumbersService();
const response = await numbersService.rent(requestData);
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
const prettyResponse = response.phoneNumber;
console.log(JSON.stringify(prettyResponse, null, 2));
} else {
printFullResponse(response);
}
})();