KitDevguides

KitDev / Guides / Saved contacts

Saved contacts

KitDev stores in the database the people who write to you privately or who start your assistant bot, with everything Telegram lets it see about them. You don't have to enable anything: it is automatic.

What is stored

The contacts table of data/kitdev.sqlite3 has one row per person:

Column What it contains
user_id, first_name, last_name, username Identifier, name and username
language_code, dc_id, is_premium, is_bot Language, data center, whether they have Premium and whether they are a bot
phone_number Phone number, only if the person lets it be seen
bio, birthday Biography and birthday (YYYY-MM-DD, or ----MM-DD without a year)
data Everything else Telegram delivers, in JSON: connection status, extra usernames, photo, emoji status, verification, personal channel, business data, restrictions...
first_seen, updated_at When you first saw them and the last update (Unix time)
pm_count, pm_first, pm_last Private messages they wrote to you, and when the first and the last were
start_count, start_first, start_last Times they started the assistant, and when the first and the last were
  • What the person hides with their privacy settings (phone, last seen, birthday...) doesn't arrive, so it stays empty.
  • The content of messages or stories is not stored, only the profile data.
  • Bots and Telegram's official accounts that write to you are not stored.
  • When the assistant is started, only the person the assistant serves is stored (not someone you have blocked in the PM Bot).

When it is updated

  • Every private message or every start of the assistant updates the name, the username and other basic data, and adds to the counter.
  • The full profile (bio, birthday, personal channel...) is requested in the background, at most once a week per person. If Telegram doesn't deliver it, it is retried after an hour. With the assistant it may not be available: this is something I couldn't check on real Telegram.
  • New data replaces the previous data; no change history is kept.

Querying them

With the sqlite3 tool from the project folder:

sqlite3 data/kitdev.sqlite3 "SELECT user_id, first_name, username, pm_count, start_count FROM contacts ORDER BY updated_at DESC LIMIT 20;"
sqlite3 data/kitdev.sqlite3 "SELECT data FROM contacts WHERE user_id = 123456789;"

Notes

  • They are included in .backup because they live in the same database as the rest, and they are not uploaded to Git.
  • It is third-party information: take care of access to data/ and to the backups.