This utility is the successor of telegram-json-backup, written from the ground up in Ruby. It can create backups of your Telegram conversations using telegram-cli's remote control feature.
Compared to the old project, telegram-history-dump:
- Has better support for media downloads
- Supports output formats other than JSON and is extensible with custom dumpers
- Does not depend on unstable Python/Lua bindings within telegram-cli
- Has a separate JSON5 formatted configuration file
The default configuration will backup all dialogs to a directory named output
,
in JSON format, without downloading any media.
- Compile telegram-cli, start it once to link your Telegram account
- Make sure Ruby 2+ is installed on your system:
ruby --version
- Install gem dependencies with Bundler, or manually with
gem
:
gem install json5
- Configure your backup routine by editing
config.json5
- Start telegram-cli with at least the following options:
telegram-cli --json -P 9009
- Run the backup:
ruby telegram-history-dump.rb
You can select one of the following dumper modules in the configuration file.
json
creates JSON Lines compliant files with one event object per line,
ordered from newest to oldest.
plaintext
creates human-readable logs, 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.
You can also implement a custom dumper; see dumpers/dumper_interface.rb
for
details.
Most of the backup configuration is done through the config file, but a few specific options are available exclusively as CLI options.
Usage: telegram-history-dump.rb [options]
-c, --config=cfgfile.json5 Path to configuration file
-k, --kill-tg Kill telegram-cli after backup
-h, --help Show help
- Backing up channels is possible but it requires a test build of telegram-cli until they merge this functionality into master.
- It is possible to run telegram-cli on a different machine, e.g. as a daemon
on a server. In this case you must pass
--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. - Be careful with decreasing
chunk_delay
or increasingchunk_size
. Telegram seems to rate limit history requests and going too fast may cause an operation to time out and force the script to skip part of a dump.