# DigiDala Bot

`bot/bot.cjs` is the standalone CommonJS Telegram bot for DigiDala. The
repository uses ESM (`"type": "module"`), so the bot remains a separate `.cjs`
entry point.

## Mini App

Stable test Mini App entry URL:

```text
https://im-test.bktis.ru/apps/miniapp/
```

## Source and service

Git source:

```text
bot/bot.cjs
```

Systemd unit:

```text
infra/systemd/pixdala-bot.service
```

Runtime path in the active release:

```text
/opt/pixdala/current/bot/bot.cjs
```

## Bot flow

`/start` sends the DigiDala welcome message and an `🪷 Открыть DigiDala` button
that opens the Mini App.

`/help` points the user to the DigiDala menu button or `/start`.

The bot uses long polling and configures the Telegram Menu Button as a
`web_app` pointing to the stable Mini App URL.

## Configuration

The Telegram bot token is not stored in Git. It is provided through:

```text
/opt/pixdala/.env
TELEGRAM_BOT_TOKEN
```

## Administration

Administrative commands are intentionally private-only and are not published in the bot help/command menu. Authorization is based on Telegram numeric user ID plus role. Roles are `content_admin` and `superadmin`.

Initial superadmin bootstrap is supplied outside Git through:

```text
/opt/pixdala/.env
TELEGRAM_SUPERADMIN_IDS
```

The bot administration can edit the main welcome message and `О нас` message, manage the competitive campaign queue, edit queued/active competitive campaign content, and manage admin roles (superadmin only).

New Competitive Mandalas are created through the bot from two PNG files (each 1024×2048, RGB/RGBA 8-bit), a Pix price per cell and a description. The price is entered by the administrator during creation rather than hard-coded. Queued/active competitive campaigns can be edited with `/competitive_edit <slug>`; the price may be changed only before the first cell is occupied, while the description remains editable after occupation. New queued content does not require a new source release. Campaign assets are stored under `PIXDALA_CAMPAIGN_ASSETS_DIR` (default `/opt/pixdala/data/campaign-assets`).

## Deployment

The bot is released together with the web/API release through:

```text
scripts/deploy-test.sh <tag>
```

The deployment installs `infra/systemd/pixdala-bot.service` and runs the bot
from `/opt/pixdala/current/bot/bot.cjs`.

Source files are not edited manually on the VPS.

## Legacy migration note

The old `pixdala-test-bot.service` name is retained only for historical
rollback compatibility with pre-migration releases. It must not be started
alongside `pixdala-bot.service`, because both services use the same Telegram
bot token.
