knopki / tg2obsidian

This script pulls new messages from a Telegram group and puts them into Obsidian vault on a local machine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tg2obsidian

This program ("Bot") uses Telegram's free bot functionality in order to save messages from a Telegram group to the Obsidian vault on your local computer.

The Markdown markup used will also work for most other programs that work with local Markdown files.

The Bot is designed to run locally on the computer where the Obsidian files are located.

This readme is also available in Russian.

Use case

  • You type, record, or forward messages to your personal Telegram group on the go
  • Bot receives new messages from Telegram and saves them as Inbox notes in your PKM vault
  • Afterwards, in a quiet environment, you process those notes, moving the information from them to appropriate places in your vault

Features

  • All messages are grouped by date — one note per day — or stored in a single note.
  • Each message in a note has a header with a date and time stamp.
  • Formatting of messages and captions is preserved or ignored depending on settings.
  • For forwarded messages, information about the origin is added.
  • Photos, animations, videos, and documents are saved to the vault and embedded in the note.
  • For contacts, YAML front matter and vcard are saved.
  • For locations, relevant links to Google and Yandex maps are created.
  • It is possible to convert notes with certain keywords into a task.
  • It is possible to tag notes with certain keywords.
  • It is possible to recognize speech from the notes. In this case, the Bot sends the recognized text as a response to the original voice message.

Set up

  1. Install Python 3.10+
  2. install script dependencies:
pip install aiogram
pip install beautifulsoup4
pip install lxml
  1. Install Whisper module if you need voice messages get recognized to text:
pip install -U openai-whisper
  1. Install compiled FFMPEG and add the path to the executable (in Windows — ffmpeg.exe) to the path environment variable. Go to the folder containing this script and make sure that ffmpeg.exe could be started there.
  2. Create your own bot using https://t.me/BotFather
  3. Paste the token received from @botfather into the appropriate parameter in config.py and change the rest of the parameters in config.py as desired.
  4. (Optional) Add the bot created above to a private Telegram group and make it administrator so it can read messages.

Usage

  1. Send or forward messages that should go to your Obsidian vault to the private Telegram group or directly to your Telegram bot.

  2. Run Bot:

python tg2obsidian_bot.py
  • You can keep Bot running indefinitely on a computer or server that is permanently turned on. In this case, it will recognize speech and create/update notes in Obsidian in real time.
  • If you only turn your computer on when you're using it, run Bot directly when you need to get Obsidian messages, and close the program when you've received all the messages.

Important! Bot can only retrieve messages for the last 24 hours. Messages sent earlier and not retrieved in a timely manner will not be received by Bot and saved in the vault.

Known issues

Check in the Issues section.

Support author

If you would like to thank the author of this project, your donations will be gratefully accepted here: https://pay.cloudtips.ru/p/1f9bf82f

About

This script pulls new messages from a Telegram group and puts them into Obsidian vault on a local machine

License:MIT License


Languages

Language:Python 100.0%