From 8e3554be958e89fa3877866183e52938a8ddd103 Mon Sep 17 00:00:00 2001 From: Lonami Date: Sat, 7 Oct 2017 12:15:45 +0200 Subject: [PATCH] Updated Session Files (markdown) --- Session-Files.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Session-Files.md b/Session-Files.md index 7440c14..1f9964a 100644 --- a/Session-Files.md +++ b/Session-Files.md @@ -1,5 +1,19 @@ The first parameter you pass the the constructor of the `TelegramClient` is the `session`, and defaults to be the session name (or full path). That is, if you create a `TelegramClient('anon')` instance and connect, an `anon.session` file will be created on the working directory. -These sessions contain the required information to talk to the Telegram servers, such as to which IP the client should connect, port, authorization key so that messages can be encrypted, and so on. +These JSON session files contain the required information to talk to the Telegram servers, such as to which IP the client should connect, port, authorization key so that messages can be encrypted, and so on. -These files will by default also save all the input entities that you've seen (**WIP**). \ No newline at end of file +These files will by default also save all the input entities that you've seen, so that you can get information about an user or channel by just their ID. Telegram will **not** send their `access_hash` required to retrieve more information about them, if it thinks you have already seem them. For this reason, the library needs to store this information offline. + +If you're not going to work without updates, or don't need to cache the `access_hash` associated with the entities' ID, you can disable this by setting `client.session.save_entities = False`. + +If you don't want to save the files as JSON, you can also create your custom `Session` subclass and override the `.save()` and `.load()` methods. For example, you could save it on a database: +```python +class DatabaseSession(Session): + def save(): + # serialize relevant data to the database + + def load(): + # load relevant data to the database +``` + +You should read the `session.py` source file to know what "relevant data" you need to keep track of. \ No newline at end of file