All Projects → Kosat → Telegram Messages Dump

Kosat / Telegram Messages Dump

Licence: mit
Command-line tool to dump message history of a Telegram chat.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Telegram Messages Dump

Telegram backup
Java app to download all your telegram data.
Stars: ✭ 409 (+326.04%)
Mutual labels:  cli, telegram
Backslide
💦 CLI tool for making HTML presentations with Remark.js using Markdown
Stars: ✭ 679 (+607.29%)
Mutual labels:  utility, cli
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+338.54%)
Mutual labels:  utility, cli
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+21391.67%)
Mutual labels:  cli, telegram
Start Server And Test
Starts server, waits for URL, then runs test command; when the tests end, shuts down server
Stars: ✭ 879 (+815.63%)
Mutual labels:  utility, cli
Pytg
Python package that wraps around Telegram messenger CLI. Send and receive messages, and more.
Stars: ✭ 365 (+280.21%)
Mutual labels:  cli, telegram
Saws
A supercharged AWS command line interface (CLI).
Stars: ✭ 4,886 (+4989.58%)
Mutual labels:  utility, cli
Gitlab Cli
Create a merge request from command line in gitlab
Stars: ✭ 224 (+133.33%)
Mutual labels:  utility, cli
Executor
Watch for file changes and then execute command. Very nice for test driven development.
Stars: ✭ 14 (-85.42%)
Mutual labels:  utility, cli
Git Repo
Git-Repo: CLI utility to manage git services from your workspace
Stars: ✭ 818 (+752.08%)
Mutual labels:  utility, cli
Haxor News
Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Stars: ✭ 3,342 (+3381.25%)
Mutual labels:  utility, cli
Unidump
hexdump(1) for Unicode data
Stars: ✭ 31 (-67.71%)
Mutual labels:  utility, cli
Musoq
Use SQL on various data sources
Stars: ✭ 252 (+162.5%)
Mutual labels:  utility, cli
Jql
A JSON Query Language CLI tool
Stars: ✭ 368 (+283.33%)
Mutual labels:  utility, cli
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+2838.54%)
Mutual labels:  utility, cli
Things.sh
Simple read-only comand-line interface to your Things 3 database
Stars: ✭ 492 (+412.5%)
Mutual labels:  cli, travis-ci
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+3132.29%)
Mutual labels:  utility, cli
Fwd
🚂 The little forwarder that could
Stars: ✭ 203 (+111.46%)
Mutual labels:  utility, cli
Awesome bot
✅ Validate links in awesome projects
Stars: ✭ 697 (+626.04%)
Mutual labels:  cli, travis-ci
Hint
重构到 ---> https://github.com/hustcc/lint-md
Stars: ✭ 30 (-68.75%)
Mutual labels:  cli, travis-ci

Telegram Messages Dump

GitHub version Build Status

This is a simple console tool for dumping message history from a Telegram chat into a jsonl, csv or plain text file.

Installation

From PyPI:

pip install telegram-messages-dump

From sources: Fetch the latest sources with git:

git clone https://github.com/Kosat/telegram-messages-dump.git

Then run directly from sources

cd telegram-messages-dump
python -m telegram_messages_dump

Or run after installing locally

python setup.py install
telegram-messages-dump

Binaries:

Binaries for Linux, Windows and MacOS are available in Releases section.

Usage

Mandatory parameters are <chat_name> e.g. @Python, @CSharp or a title of a dialogue, as seen in the UI, and <phone_num> - a telephone number. A phone number is needed for authentication and will not be stored anywhere. After the first successful authorization it will create telegram_chat_dump.session file containing auth token. The information from this file is being reused in next runs. If this is not a desirable behaviour, use -cl flag to delete session file on exit.

Note1: You can use telegram dialogue multi-word title like so: --chat="Telegram Geeks" with double quotes. However, when using multi-word title (rather than @channel_name), you need to join the channel first. Only then you will be able to dump it. This way you can dump private dialogues which doesn't have @channel_name.

Note2: For private channels you can also pass an invitation link as chat name. E.g. --chat="https://t.me/joinchat/XXXXXYYYYZZZZZ". IMPORTANT: It only works when you (the logged-in user) has already joined the private chat that the invitation link corresponds to.

telegram-messages-dump -c <chat_name> -p <phone_num> [-l <count>] [-o <file>] [-cl]

Where:
    -c,  --chat     Unique name of a channel/chat. E.g. @python.
    -p,  --phone    Phone number. E.g. +380503211234.
    -o,  --out      Output file name or full path. (Default: telegram_<chatName>.log)
    -e,  --exp      Exporter name. text | jsonl | csv (Default: 'text')
      ,  --continue Continue previous dump. Supports optional integer param <message_id>.
    -l,  --limit    Number of the latest messages to dump, 0 means no limit. (Default: 100)
    -cl, --clean    Clean session sensitive data (e.g. auth token) on exit. (Default: False)
    -v,  --verbose  Verbose mode. (Default: False)
      ,  --addbom   Add BOM to the beginning of the output file. (Default: False)
    -h,  --help     Show this help message and exit.

telegram-dump-gif

Increamental/Continuous mode

After dumping messages into an output file, telegram-messages-dump also creates a meta file with the latest (biggest) message id that was successfully saved into an output file. For instance, if messages with ids 10..100 were saved in output file, the metafile will contain the "latest_message_id": 100 record in it.

  • If you want to update an existing dump file use --continue option without a parameter value. In this case telegram-messages-dump will read the latest message id from a meta file. In the sample below it will be C:\temp\xyz.txt.meta:
    telegram-messages-dump -p... -oC:\temp\xyz.txt  --continue
    
    In this case telegram-messages-dump will look for C:\temp\xyz.txt.meta file and try to incrimentally update the contents of C:\temp\xyz.txt with new messages.

Note: In incremental mode when metafile exists --exp and --chat will be taken from the meta file and must NOT be specified explicitely as parameters. --limit setting has to be omitted.

  • Otherwise, if you DON'T have a metafile or want to ignore it, you can still open your dump file and find the last message's id at the bottom of the file and then specify it explicitly as --continue=<LAST_MSG_ID> command, along with the correct --exp and --chat that were used to generate the existing dump file.
    telegram-messages-dump -p... -oC:\temp\xyz.txt --continue=100500 --exp=jsonl [email protected]
    

In both aforementioned cases, telegram-messages-dump will open the existing C:\temp\xyz.txt file and append the newer messages that were posted in the telegram chat since the message with the message with id 100500 was created.

Note1: There must be = sign between the --continue command name and integer message id.

Note2: In incremental mode without metafile, --out, --exp and --chat must be specified explicitely as parameters. --limit setting has to be omitted.

Notes

  • This tool relies on Telethon - a Telegram client implementation in Python.

Plugins

Output format is managed by exporter plugins. Currently there are two exporters available: text, jsonl and csv. Exporters reside in ./exporters subfolder. Basically an exporter is a class that implements three methods:

  • format(...) that extracts all necessary data from a message and stringifies it.
  • begin_final_file(...) that allows an exporter to write a preamble to a resulting output file.

To use a custom exporter. Place you .py file with a class implementing those 3 methods into ./exporters subfolder and specify its name in --exp <exporter_name> setting.

Note1: the class name MUST exactly match the file name of its .py file. This very same name is used as an argument for the --exp setting.

Note2: in .vscode subfolder you can find the default settings that I use for debugging this project.

License

This project is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].