This utility is the successor of telegram-json-backup, written from the ground up in Ruby. It can create backups of your Telegram user and (super)group dialogs using telegram-cli's remote control feature.
Compared to the old project, telegram-history-dump:
The default configuration will backup all dialogs to a directory named output
,
in JSON format, without downloading any media.
ruby --version
config.yaml
telegram-cli --json -P 9009
ruby telegram-history-dump.rb
History will always be stored in JSON Lines compliant files. However, additional output formats can be produced by uncommenting a few lines in the configuration file.
You can enable one or more of the following formatter modules:
html
creates styled, paginated chat logs vieweable with a web browser.
plaintext
creates human-readable text files, organized as one file per day.
bare
outputs only the actual message texts without any context. It is meant
for linguistic / statistical analysis.
pisg
creates daily logs compatible with the EnergyMech IRC logging format as
input for the PISG chat statistics generator. Also see telegram-pisg.
You can also implement a custom formatter; see
formatters/lib/formatter_base.rb
for details.
Most of the backup configuration is done through the config file, but a few specific options are available as CLI options. None of them are mandatory.
Usage: telegram-history-dump.rb [options]
-c, --config=cfg.yaml Path to YAML configuration file
-k, --kill-tg Kill telegram-cli after backup
-h, --help Show help
-d, --dir=DIR Subdirectory for output files
(relative to backup_dir in YAML config)
-l, --limit=LIMIT Maximum number of messages to backup
for each target (overrides YAML config)
Usage notes:
--accept-any-tcp
to telegram-cli and
firewall the port appropriately to prevent unwanted exposure. Keep in mind
that some options regarding media files will not work in a remote setup.chunk_delay
or increasing chunk_size
. Telegram
seems to rate limit history requests. Going too fast may cause an operation
to time out and force the script to skip part of a dump.Telegram-cli issues known to affect telegram-history-dump: