Contacts

Working with contacts.

Importing phone contacts

Schema:

inputPhoneContact#f392b7f4 client_id:long phone:string first_name:string last_name:string = InputContact;

importedContact#c13e3c50 user_id:long client_id:long = ImportedContact;
popularContact#5ce14175 client_id:long importers:int = PopularContact;

contacts.importedContacts#77d01c3b imported:Vector<ImportedContact> popular_invites:Vector<PopularContact> retry_contacts:Vector<long> users:Vector<User> = contacts.ImportedContacts;

---functions---

contacts.importContacts#2c800be5 contacts:Vector<InputContact> = contacts.ImportedContacts;

To upload the local contact list to Telegram and see which contacts are already signed up on telegram, use contacts.importContacts, passing an array of inputPhoneContact constructors, containing:

  • phone - The phone number in international format
  • first_name - First name
  • last_name - Last name, can be empty
  • client_id - An arbitrary 64-bit integer (not the contact's Telegram user ID, since we do not have it yet); make sure there are no collisions between the client_ids passed to a single contacts.importContacts call (for example, use a simple incremental ID starting from 0)

The method will return a contacts.importedContacts constructor, containing the following fields:

  • imported - A list of successfully imported contacts that have an associated Telegram account as importedContact constructors.
    user_id is the Telegram user ID, client_id is the client_id associated to the contact, passed during the method call. Note that according to the user's privacy settings, not all contacts which have an associated Telegram account may be returned here.
  • users - Contains info about the Telegram users mentioned in imported
  • popular_invites - Contains info about popular contacts: each popularContact constructor indicates that the contact with the specified client_id was imported imported times by that many Telegram users.
  • retry_contacts - List of contact ids that could not be imported due to a server-side system limitation and have to be reimported with another call to contacts.importedContacts.

Adding Telegram users as contacts

Schema:

users.userFull#3b6d152e full_user:UserFull chats:Vector<Chat> users:Vector<User> = users.UserFull;

inputUser#f21158c6 user_id:long access_hash:long = InputUser;

user#83314fca flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true close_friend:flags2.2?true stories_hidden:flags2.3?true stories_unavailable:flags2.4?true contact_require_premium:flags2.10?true bot_business:flags2.11?true bot_has_main_app:flags2.13?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector<RestrictionReason> bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector<Username> stories_max_id:flags2.5?int color:flags2.8?PeerColor profile_color:flags2.9?PeerColor bot_active_users:flags2.12?int = User;

peerSettings#acd66c5e flags:# report_spam:flags.0?true add_contact:flags.1?true block_contact:flags.2?true share_contact:flags.3?true need_contacts_exception:flags.4?true report_geo:flags.5?true autoarchived:flags.7?true invite_members:flags.8?true request_chat_broadcast:flags.10?true business_bot_paused:flags.11?true business_bot_can_reply:flags.12?true geo_distance:flags.6?int request_chat_title:flags.9?string request_chat_date:flags.9?int business_bot_id:flags.13?long business_bot_manage_url:flags.13?string = PeerSettings;

userFull#979d2376 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true stories_pinned_available:flags.26?true blocked_my_stories_from:flags.27?true wallpaper_overridden:flags.28?true contact_require_premium:flags.29?true read_dates_private:flags.30?true flags2:# sponsored_enabled:flags2.7?true can_view_revenue:flags2.9?true bot_can_manage_emoji_status:flags2.10?true id:long about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector<PremiumGiftOption> wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?long personal_channel_message:flags2.6?int stargifts_count:flags2.8?int starref_program:flags2.11?StarRefProgram = UserFull;

updatePeerSettings#6a7e7366 peer:Peer settings:PeerSettings = Update;

---functions---

users.getFullUser#b60f5918 id:InputUser = users.UserFull;

contacts.addContact#e8f463d0 flags:# add_phone_privacy_exception:flags.0?true id:InputUser first_name:string last_name:string phone:string = Updates;

Telegram users may also be added to the contact list (even if we do not have access to their phone number!) using contacts.addContact.

Set the add_phone_privacy_exception flag if we wish to allow the other user to see our phone number: this flag must be set if the need_contacts_exception flag of peerSettings is set (see the action bar documentation for more info »).

The other user will be offered to also add us to the contact list via the add contact action bar: if they accept, their phone number will be automatically added to our contact.

Share our phone number

---functions---

contacts.acceptContact#f831a20f id:InputUser = Updates;

This method is invoked if the user clicks on the add contact button in the add contact chat bar.

The bar is activated only if the other user has added us as a contact using contacts.addContact without using a phone number, and none of the add_contact, report_spam, block_contact bar flags are set, the share_contact flag are be set, indicating we can invoke contacts.acceptContact to share our phone number with the other user.

Fetching the contact list

Schema:

contact#145ade0b user_id:long mutual:Bool = Contact;

user#83314fca flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true close_friend:flags2.2?true stories_hidden:flags2.3?true stories_unavailable:flags2.4?true contact_require_premium:flags2.10?true bot_business:flags2.11?true bot_has_main_app:flags2.13?true id:long access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector<RestrictionReason> bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector<Username> stories_max_id:flags2.5?int color:flags2.8?PeerColor profile_color:flags2.9?PeerColor bot_active_users:flags2.12?int = User;

contacts.contacts#eae87e42 contacts:Vector<Contact> saved_count:int users:Vector<User> = contacts.Contacts;
contacts.contactsNotModified#b74ba9d2 = contacts.Contacts;

savedPhoneContact#1142bd56 phone:string first_name:string last_name:string date:int = SavedContact;

---functions---

contacts.getContacts#5dd69e12 hash:long = contacts.Contacts;

contacts.getSaved#82f1e39f = Vector<SavedContact>;

contacts.getContactIDs#7adc669d hash:long = Vector<int>;

Use contacts.getContacts to obtain all members of the contact list that have an associated Telegram account.

Use contacts.getContactIDs to obtain an array of Telegram user IDs for all contacts (0 is returned for contacts do not have an associated Telegram account or have hidden their account using privacy settings).

To obtain the full contact list, including contacts which do not have an associated Telegram account, use contacts.getSaved in combination with a takeout session ».

Getting contact statuses

Schema:

userStatusEmpty#9d05049 = UserStatus;
userStatusOnline#edb93949 expires:int = UserStatus;
userStatusOffline#8c703f was_online:int = UserStatus;
userStatusRecently#7b197dc8 flags:# by_me:flags.0?true = UserStatus;
userStatusLastWeek#541a1d1a flags:# by_me:flags.0?true = UserStatus;
userStatusLastMonth#65899777 flags:# by_me:flags.0?true = UserStatus;

contactStatus#16d9703b user_id:long status:UserStatus = ContactStatus;

---functions---

contacts.getStatuses#c4a353ee = Vector<ContactStatus>;

Use contacts.getStatuses to obtain the online statuses of all contacts with an accessible Telegram account.

Searching for contacts

Schema:

contacts.found#b3134d9d my_results:Vector<Peer> results:Vector<Peer> chats:Vector<Chat> users:Vector<User> = contacts.Found;

---functions---

contacts.search#11f812d8 q:string limit:int = contacts.Found;

Use contacts.search to search within the contact list.

Deleting contacts

Schema:

---functions---

contacts.deleteContacts#96a0e00 id:Vector<InputUser> = Updates;

contacts.deleteByPhones#1013fd9e phones:Vector<string> = Bool;

contacts.resetSaved#879537f1 = Bool;

Use contacts.deleteContacts to delete contacts with an associated Telegram account; the returned Updates will contain updated user information.

Use contacts.deleteByPhones to delete contacts by their phone number, even if they don't have an associated Telegram account.

Use contacts.resetSaved to remove all contacts without an associated Telegram account.