Package: telegram-messages-dump
Telegram Messages DumpThis is a simple console tool for dumping message history from a Telegram chat into ajsonl,csvor plaintextfile.InstallationFrom sources:Fetch the latest sources with git:git clone https://github.com/Kosat/telegram-messages-dump.gitThen run directly from sourcescd telegram-messages-dump
python -m telegram_messages_dumpOr run after installing locallypython setup.py install
telegram-messages-dumpBinaries:Binaries for Linux, Windowsand MacOSare available inReleasessection.UsageMandatory 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 dumpprivatedialogues 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.Increamental/Continuous modeAfter dumping messages into an output file,telegram-messages-dumpalso creates ameta filewith 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": 100record in it.If you want to update an existing dump file use--continueoption without a parameter value. In this casetelegram-messages-dumpwill read the latest message id from a meta file. In the sample below it will beC:\temp\xyz.txt.meta:telegram-messages-dump -p... -oC:\temp\xyz.txt  --continueIn this casetelegram-messages-dumpwill look forC:\temp\xyz.txt.metafile and try to incrimentally update the contents ofC:\temp\xyz.txtwith new messages.Note: In incremental mode when metafile exists--expand--chatwill be taken from the meta file and must NOT be specified explicitely as parameters.--limitsetting 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--expand--chatthat were used to generate the existing dump file.telegram-messages-dump -p... -oC:\temp\xyz.txt --continue=100500 --exp=jsonl --chat=@geekschatIn both aforementioned cases,telegram-messages-dumpwill open the existingC:\temp\xyz.txtfile 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--continuecommand name and integer message id.Note2: In incremental mode without metafile,--out,--expand--chatmust be specified explicitely as parameters.--limitsetting has to be omitted.NotesThis tool relies onTelethon- a Telegram client implementation in Python.PluginsOutput format is managed byexporterplugins. Currently there are two exporters available:text,jsonlandcsv.
Exporters reside in./exporterssubfolder.
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.pyfile with a class implementing those 3 methods into./exporterssubfolder and specify its name in--exp <exporter_name>setting.Note1: the class nameMUSTexactly match the file name of its.pyfile. This very same name is used as an argument for the--expsetting.Note2: in.vscodesubfolder you can find the default settings that I use for debugging this project.LicenseThis project is licensed under theMIT license.