Skip to content

pakeko78/telegram-document-utility-bo

Repository files navigation

This is a Telegram bot that converts documents and merges PDFs.

What it does

  1. PDF to Word (DOCX)
  2. Word (DOCX) to PDF
  3. Merge multiple PDFs into one

How it works (architecture) The project is a single Node.js service.

  1. src/index.js boots the process and starts grammY long polling via @grammyjs/runner.
  2. src/bot.js wires session state, commands, and message handlers.
  3. src/services/telegramFiles.js downloads Telegram file bytes safely.
  4. src/services/conversion/* runs conversions (LibreOffice-based where possible) and merging (pdf-lib).
  5. src/lib/memory.js stores an audit trail of user and bot messages in MongoDB when MONGODB_URI is set, otherwise an in-memory fallback.

Setup

  1. Install npm run install:root

  2. Configure env Copy .env.sample to .env and set at least TELEGRAM_BOT_TOKEN.

Environment variables TELEGRAM_BOT_TOKEN (required) Telegram bot token.

MONGODB_URI (optional) If set, the bot stores conversation audit messages in MongoDB (collection: memory_messages). If not set, it uses an in-memory fallback.

MAX_FILE_BYTES (optional, default 20000000) Max allowed size per uploaded file.

MAX_MERGE_FILES (optional, default 10) Maximum number of PDFs allowed in a merge session.

JOB_TIMEOUT_MS (optional, default 180000) Timeout for conversion/merge work (milliseconds).

CONCURRENCY (optional, default 2) Global in-process concurrency limit for conversion/merge work.

Run Development: npm run dev

Production: npm run start

Commands /start Shows the main menu and usage.

/help Explains supported formats and merge usage.

/status Shows your current mode and merge queue size.

/reset Clears your memory audit history (if DB enabled) and clears any in-progress merge queue/mode.

Using the bot without buttons You can just upload a file.

  1. If you upload a PDF while not merging, it defaults to PDF to Word.
  2. If you upload a DOCX while not merging, it defaults to Word to PDF.
  3. If you are in merge mode, PDFs are appended to the queue.

Deployment notes (Render) This bot is designed for long polling. It always deletes any webhook on boot to avoid conflicts. If you deploy a new version while the old one is still running, the bot handles Telegram 409 conflicts by backing off and retrying.

Troubleshooting

  1. Bot not responding Check TELEGRAM_BOT_TOKEN is set.

  2. Conversions fail immediately LibreOffice may not be available in your runtime. DOCX to PDF generally works best with LibreOffice installed. PDF to DOCX is best-effort and may be limited; the bot will return a clear message.

  3. Merges fail Make sure you only upload PDF files. The bot rejects non-PDFs during merge mode.

Extending Add new commands in src/commands/*.js and they will auto-register via src/commands/loader.js. Shared utilities live in src/lib and src/services.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors