The short answer
- 1Users and channels need ID + access_hash; basic groups need only the ID.
- 2access_hash differs per account and only comes from API results.
- 3Keep a peer store, and never overwrite full info with min info.
In this article
Peers: whoever you exchange messages with
In the Telegram API, anything you send messages to or ask about, whether a user, a group or a channel, is called a peer. In the Bot API a numeric chat_id was enough (see reading chat IDs), but in the user-account API, pointing at a user or a channel needs a second value along with the ID: the access_hash.
| Peer | What you need to refer to it |
|---|---|
| User | ID + access_hash |
| Channel or supergroup | ID + access_hash |
| Basic group | ID only |
Why access_hash exists
If a numeric ID were enough to message any user, someone could count upwards through the numbers and spam everyone. The access_hash is proof that this account has legitimately come across this peer. That gives it two properties:
- It differs per account (session). An access_hash your account received cannot be used from another account, so a list of IDs and hashes obtained from someone else cannot be used to send messages.
- You only get it from what the API returns. It comes with user and channel information included in results such as received messages, the chat list, contacts and username lookups (
contacts.resolveUsername).
Keep a peer store
The official documentation recommends storing peer information (ID, access_hash, name and so on) persistently on the device. Update it every time a response includes users or channels, and take values from it when you send. That way you do not waste requests looking peers up again after every restart, and you avoid rate limits; see reading API errors.
min: partially filled information
Some user information comes only partly filled, such as users attached to a message in a large group. It is marked min, and its access_hash cannot be used as is in requests.
- If you already have full information stored, do not overwrite it with the min version.
- If you must refer to that peer, you can point at it as "the user seen in this message", using
inputPeerUserFromMessageorinputPeerChannelFromMessage.
TDLib manages the peer store for you; see building TDLib. How group and channel types differ is in channels, supergroups and basic groups.
FAQ
What is access_hash in the Telegram API?
A value that must accompany a user or channel ID. It proves your account has legitimately seen that peer.
Can I use an access_hash from another account?
No. Each account receives its own access_hash values.
What does min mean on a Telegram user object?
The information is only partly filled and its access_hash cannot be used directly; don't overwrite full stored data with it.
Sources
At a glance
- 1Peers
User, channel or group you talk to.
- 2access_hash
Proof your account has seen the peer; not shareable.
- 3Store
Update from every response; use FromMessage peers for min info.
Updated