Add connector strategy and codex media replies

This commit is contained in:
Eduard Baturin 2026-04-20 22:57:13 +03:00
parent 840b3af2eb
commit b4d869bd0d
15 changed files with 799 additions and 22 deletions

View file

@ -19,6 +19,14 @@ npm install
```env
BOT_TOKEN=your_telegram_bot_token_here
BOT_API_ROOT=
BOT_CONNECTOR=local-codex
LOCAL_CODEX_COMMAND=codex
LOCAL_CODEX_WORKDIR=
LOCAL_CODEX_SANDBOX=workspace-write
LOCAL_CODEX_MODEL=
LOCAL_CODEX_PROFILE=
LOCAL_CODEX_SKIP_GIT_REPO_CHECK=
LOCAL_CODEX_ADD_DIRS=
```
3. Start the bot:
@ -31,7 +39,44 @@ npm start
- Saves text messages to `assets/request.txt` by appending new lines
- Saves photos, videos, voice messages, and documents to `assets/`
- Replies with `Ок` for supported message types
- Immediately replies with `Сообщение доставлено ИИ агенту, оно обрабатывается`
- Sends the saved request to the configured connector strategy
- Returns the connector result back to Telegram as a follow-up reply
## Connector Strategy
The bot uses a connector strategy selected by `BOT_CONNECTOR`.
### `local-codex`
Runs the local `codex` CLI with `codex exec` for every supported Telegram message.
The connector expects structured JSON output with:
- `message`: text reply for Telegram
- `attachments`: files to upload back to the user
- attachment fields: `path`, `kind`, `caption`
Supported attachment `kind` values:
- `photo`
- `video`
- `animation`
- `document`
If Codex generates an image, video, or any other file for the user, it should include that file path in `attachments`. Relative paths are resolved from `LOCAL_CODEX_WORKDIR`.
Relevant variables:
- `BOT_CONNECTOR=local-codex`
- `LOCAL_CODEX_COMMAND=codex`
- `LOCAL_CODEX_WORKDIR=`: working directory for Codex. Empty means this project root.
- `LOCAL_CODEX_SANDBOX=workspace-write`: sandbox mode passed to `codex exec`
- `LOCAL_CODEX_MODEL=`: optional model override
- `LOCAL_CODEX_PROFILE=`: optional Codex profile
- `LOCAL_CODEX_SKIP_GIT_REPO_CHECK=`: set to `true` if the Codex workdir is not a git repo
- `LOCAL_CODEX_ADD_DIRS=`: comma-separated extra directories for Codex access
The connector queue is sequential, so messages are processed one by one in arrival order.
## Optional: Local Bot API Server For Files Larger Than 20 MB
@ -111,6 +156,7 @@ Then set this in `.env`:
```env
BOT_TOKEN=your_telegram_bot_token_here
BOT_API_ROOT=http://127.0.0.1:8081
BOT_CONNECTOR=local-codex
```
Restart the bot after that:
@ -124,3 +170,4 @@ npm start
- `BOT_API_ROOT` is optional. Leave it empty to use the default Telegram hosted Bot API.
- The local Bot API server listens over HTTP by default.
- If both the bot and the local Bot API server run on the same machine, `127.0.0.1:8081` is enough.
- `BOT_CONNECTOR` defaults to `local-codex` in the current setup.