-
Notifications
You must be signed in to change notification settings - Fork 1
/
getPhoneNumbers.ts
32 lines (26 loc) · 985 Bytes
/
getPhoneNumbers.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
import { Sms, SmsService } from '@sinch/sdk-core';
import { getGroupIdFromConfig, getPrintFormat, printFullResponse } from '../../../config';
export const getPhoneNumbers = async(smsService: SmsService) => {
console.log('**************');
console.log('* GetMembers *');
console.log('**************');
const groupId = getGroupIdFromConfig();
const requestData: Sms.ListMembersRequestData = {
group_id: groupId,
};
let response;
try {
response = await smsService.groups.listMembers(requestData);
} catch (error) {
console.error(`ERROR: Impossible to get the numbers of the group ${requestData.group_id}`);
throw error;
}
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
console.log(response.length > 0
? 'List of phone numbers: ' + JSON.stringify(response, null, 2)
: `Sorry, no phone numbers in group ${requestData.group_id} were found.`);
} else {
printFullResponse(response);
}
};