A Telegram bot that generates professional LaTeX reports using OpenAI, compiles them into PDF, and returns both the .tex and .pdf files to the user fully automatically.
- ✔ Accepts a title and description from the user
- ✔ Generates LaTeX code via OpenAI (with up to 3 retry attempts)
- ✔ Compiles the LaTeX into PDF using
pdflatex - ✔ Returns both .tex and .pdf to the Telegram user
- ✔ Uses a safe temporary directory and cleans up
- ✔ Docker-ready
- ✔ Self-contained and production-ready
-
User sends:
/report <Title> <Description> -
Bot builds a LaTeX-focused prompt (from
prompt.js) -
OpenAI generates a full
.texfile → If LaTeX is invalid, bot retries up to 3 times -
Bot saves the
.texin/tmp -
Bot compiles it using:
pdflatex -interaction=batchmode -
Bot sends back:
report-xxxx.pdfreport-xxxx.tex
-
Bot removes temporary files
telegram-proposal-me/
│
├── bot.js # Main Telegram bot logic
├── prompt.js # LaTeX generation prompt
├── docker-compose.yml # Container orchestration
├── Dockerfile-telegrambot # Node + TeXLive environment
├── package.json
├── .env.example
├── LICENSE
├── README.md
└── tmp/ # Runtime generated LaTeX/PDF files
npm installCreate a .env:
PROJECT_PREFIX=telegram-proposal-me
TELEGRAM_BOT_TOKEN=your_telegram_token_here
OPENAI_API_KEY=your_openai_api_key_here
node bot.jsservices:
telegram-bot:
container_name: ${PROJECT_PREFIX}_telegram_bot
build:
context: ./
dockerfile: Dockerfile-telegrambot
restart: always
volumes:
- ./:/app
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY}
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}docker compose up --build -dIncludes:
- Node 20
- TeXLive full LaTeX toolchain
- Minimal editor tools
FROM node:20-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
bash \
nano \
htop \
git \
curl \
texlive-latex-base \
texlive-latex-recommended \
texlive-latex-extra \
texlive-fonts-recommended \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY package*.json ./
RUN npm install --production
COPY . .
CMD ["node", "bot.js"]/report طراحی پلتفرم رزرو غذا برای سازمان نفت
در حال حاضر سیستم رزرو غذا سنتی است و ...
The bot replies with:
- PDF report
- LaTeX source file
- Any error logs if LaTeX fails
The bot automatically retries up to 3 times:
generateLatexWithRetry(title, description, 3)If after 3 attempts OpenAI still fails → bot returns an error to the user.
prompt.js ensures OpenAI produces raw, clean LaTeX (no markdown, no backticks):
Return ONLY the raw LaTeX code.
Start with \documentclass.
Produce a single .tex file.
MIT License
Copyright © 2025 Seyyed Ali Mohammadiyeh (Max Base)