add_contact()

Client.add_contact()

Add an existing Telegram user as contact, even without a phone number.

Usable by Users Bots
Parameters:
  • user_id (int | str) – Unique identifier (int) or username (str) of the target user. You can also use user profile link in form of t.me/<username> (str).

  • first_name (str) – User’s first name.

  • last_name (str, optional) – User’s last name.

  • phone_number (str, optional) – User’s phone number.

  • share_phone_number (bool, optional) – Whether or not to share the phone number with the user. Defaults to False.

Returns:

User – On success the user is returned.

Example

# Add contact by id
await app.add_contact(12345678, "Foo")

# Add contact by username
await app.add_contact("username", "Bar")