Guides

ContactsUSER-ONLY

User Walkthrough 1 of 50

Users can manage the account’s Telegram contacts.

Listing Contacts

With getContacts, you can 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

addContact accepts the user’s identifier and first name.

await client.addContact(userId, "Ada", {
  lastName: "Lovelace",
});

The options can also include phoneNumber and isPhoneNumberShared.

Resolving a Phone Number

resolvePhoneNumber resolves a Telegram user by phone number.

const user = await client.resolvePhoneNumber("+12025550123");

Setting a Contact Note

setContactNote lets you add or update a note.

await client.setContactNote(userId, {
  note: "Met at the conference.",
});

Omitting the note removes the current one.

await client.setContactNote(userId);

Removing Contacts

To remove one contact, call deleteContact.

await client.deleteContact(userId);

With deleteContacts, you can remove several contacts at once.

await client.deleteContacts([firstUserId, secondUserId]);