commit 064543f4150a805cc620ca3994b0aae7a49f9ab8 Author: Dmitry <124861781+ada-dmitry@users.noreply.github.com> Date: Thu Nov 27 15:17:11 2025 +0300 Добавлен Dockerfile и основной скрипт для интеграции с Trilium через Telegram бота diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b400ac2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11-slim + +ENV PYTHONUNBUFFERED=1 + +# Устанавливаем системные зависимости +RUN apt-get update && apt-get install -y --no-install-recommends \ + libmagic1 file \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY main.py . +RUN pip install --no-cache-dir trilium-py dotenv aiogram + +CMD ["python", "main.py"] diff --git a/main.py b/main.py new file mode 100644 index 0000000..86cf83a --- /dev/null +++ b/main.py @@ -0,0 +1,53 @@ +import os +from dotenv import load_dotenv +from aiogram import Bot, Dispatcher +from aiogram.client.default import DefaultBotProperties +from aiogram.enums import ParseMode +from aiogram.filters import CommandStart +from aiogram.types import Message +from trilium_py.client import ETAPI + +load_dotenv() + +TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN") +TRILIUM_URL = os.getenv("TRILIUM_URL") +TRILIUM_TOKEN = os.getenv("TRILIUM_TOKEN") +INBOX_NOTE_ID = os.getenv("INBOX_NOTE_ID") + +# создаем Trilium API клиент +ea = ETAPI(server_url=TRILIUM_URL, token=TRILIUM_TOKEN) + +bot = Bot(token=TELEGRAM_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) + +dp = Dispatcher() + + +@dp.message(CommandStart()) +async def start(msg: Message): + await msg.answer("Отправь мне текст — я создам заметку в Trilium.") + + +@dp.message() +async def handler(msg: Message): + text = msg.text.strip() + + # разделяем на заголовок и тело + lines = text.split("\n", 1) + title = lines[0][:100] # заголовок = первая строка + content = lines[1] if len(lines) > 1 else "" # остальное — тело заметки + + ea.create_note( + parentNoteId=INBOX_NOTE_ID, title=title, content=content, type="text" + ) + + await msg.answer("Заметка сохранена в Trilium.") + + +async def main(): + await dp.start_polling(bot) + + +if __name__ == "__main__": + import asyncio + + asyncio.run(main())