# Telegram bot bridge

This project contains a dependency-free Python Telegram Bot API bridge for `@kjn3bot`.

It supports:

- Receiving messages with long polling.
- Receiving and downloading incoming files.
- Sending text messages.
- Sending files/documents.
- Persisting the polling offset so processed updates are not repeated.

## Setup

1. Copy `.env.example` to `.env`.
2. Put the token from BotFather into `TELEGRAM_BOT_TOKEN`.
3. Send any message to `@kjn3bot` in Telegram so the bot is allowed to reply and the chat ID becomes visible in the logs.

Telegram bot usernames are public identifiers; the Bot API token is still required for API access.

## Commands

Check token and bot identity:

```bash
python3 telegram_bot.py get-me
```

Run incoming message/file polling:

```bash
python3 telegram_bot.py run
```

Send a text message:

```bash
python3 telegram_bot.py send-message <chat_id> "Hello"
```

Send a file:

```bash
python3 telegram_bot.py send-file <chat_id> ./path/to/file.pdf --caption "Report"
```

If `TELEGRAM_DEFAULT_CHAT_ID` is set, `chat_id` can be omitted:

```bash
python3 telegram_bot.py send-message "Hello"
python3 telegram_bot.py send-file ./path/to/file.pdf
```

## Local data

- Incoming update log: `data/inbox.jsonl`
- Polling state: `data/state.json`
- Downloaded incoming files: `downloads/`

## Предкомпиляция JSX макета (20.09) — против белого экрана на телефоне

Экспорт Claude Design компилирует 28 JSX-файлов прямо в браузере (@babel/standalone вшит в бандл): на сервере это ~11 с
занятого главного потока при каждом открытии, на телефоне в разы дольше — пользователь видит белый экран и перезагружает.
`precompile.py` прогоняет те же файлы через тот же Babel (тот же пресет `react, env`, те же плагины, что применяет
`Babel.transformScriptTags`) один раз при сборке, заменяет `<script type="text/babel">` на обычные скрипты и убирает тег Babel
(файл худеет на ~750 КБ). Текст экранов и поведение прототипов совпадают со старой сборкой (сравнение `dbg-compare.js`),
самая длинная задача при запуске — 0,27 с вместо 10,8 с.

    cd /home/dev2f/FasX-test-version && P=/home/dev2f/fastx-v2/work/assist-proto
    python3 $P/precompile.py FastX_publish.html FastX_publish_fast.html          # нужен node; Babel берётся из бандла
    FX_BASE=FastX_publish_fast.html python3 $P/build-inject.py FastX_publish_proto.html \
        $P/fx-assist.js $P/fx-tags.js $P/fx-seed.js $P/fx-pair.js $P/fx-offer.js $P/fx-chat.js
    sudo cp FastX_publish_proto.html /var/www/fastx-miniapp/proto.html

То же самое стоит делать для публикуемого макета бота (`index.html`) — он собран так же и грузится так же долго.
