-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcontact-list.ts
More file actions
34 lines (27 loc) · 1006 Bytes
/
Copy pathcontact-list.ts
File metadata and controls
34 lines (27 loc) · 1006 Bytes
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
import { createSDK, handleError } from "./utils";
async function main() {
const sdk = createSDK();
sdk.on("ready", async () => {
try {
const contacts = await sdk.contacts.getContacts();
console.log(`${contacts.length} contacts\n`);
contacts.slice(0, 10).forEach((contact, i) => {
const name = contact.displayName || contact.firstName || "unknown";
console.log(`${i + 1}. ${name}`);
contact.phoneNumbers?.forEach((phone: any) => {
console.log(` ${phone.address}`);
});
contact.emails?.forEach((email: any) => {
console.log(` ${email.address}`);
});
console.log();
});
} catch (error) {
handleError(error, "Failed to fetch contacts");
}
await sdk.close();
process.exit(0);
});
await sdk.connect();
}
main().catch(console.error);