ContactsUSER-ONLY
User clients can manage the account’s Telegram contacts.
Listing Contacts
Use getContacts to get the account’s contacts as User objects.
const contacts = await client.getContacts();
for (const contact of contacts) {
console.log(contact.id, contact.firstName, contact.phoneNumber);
}
Adding a Contact
Use addContact with the user’s identifier and first name.
await client.addContact(userId, "Ada", {
lastName: "Lovelace",
});
The options can also include phoneNumber and isPhoneNumberShared.
Setting a Contact Note
Use setContactNote to add or update a note.
await client.setContactNote(userId, {
note: "Met at the conference.",
});
Call it without a note to remove the current note.
await client.setContactNote(userId);
Removing Contacts
Use deleteContact to remove one contact.
await client.deleteContact(userId);
Use deleteContacts to remove several contacts at once.
await client.deleteContacts([firstUserId, secondUserId]);