Files

77 lines
2.3 KiB
Markdown

# Development
## Prerequisites
- Node.js ≥ 20 (LTS)
- Docker + Docker Compose
- Access to the DSM `mem0_net` network (for `mem0-postgres` and `litellm`)
## Environment setup
```bash
cd bot
cp .env.example .env
```
Fill in at minimum:
| Var | Value | Source |
|---|---|---|
| `BOT_TOKEN` | Telegram bot token | `@BotFather` |
| `LLM_API_KEY` | LiteLLM master key | `../SECRETS.md` (mem0 LiteLLM) |
| `POSTGRES_PASSWORD` | mem0 postgres password | `../SECRETS.md` |
| `N8N_API_KEY` | n8n API key (Phase 2 tools) | `../SECRETS.md` |
## Local development (long-polling, no public URL)
```bash
npm install
npm run dev
```
With no `TELEGRAM_WEBHOOK_URL` set, the bot falls back to **long-polling** — you can
chat with it immediately without any public endpoint or tunnel.
## Docker development mode (bind mount + hot reload)
```bash
docker compose -f docker-compose.dev.yml up -d --build
```
`./src`, `./package.json`, `./tsconfig.json` are bind-mounted; `npm run dev` runs
`tsx watch`, so editing a source file restarts the Node process **without**
rebuilding the image.
## Webhook (production-style)
1. Set `TELEGRAM_WEBHOOK_URL=https://bot.digikedai.com/<secret>/webhook` and `TELEGRAM_WEBHOOK_SECRET=<secret>`.
2. Ensure the public route reaches the container (Traefik label or reverse proxy).
3. On startup the bot calls `setWebhook` automatically.
For **local webhook testing** without a public DNS, use a temporary tunnel (e.g.
Cloudflare `cloudflared tunnel --url http://localhost:8080`) and set the URL to the
tunnel's `https://…` address. Document the tunnel choice and its security scope
before relying on it in production.
## Tests
```bash
npm test # vitest run
npm run test:watch # watch mode
npm run typecheck # tsc --noEmit
```
Test coverage:
- `tests/normalize.test.ts` — Telegram → normalized message contract
- `tests/config.test.ts` — env validation and user allowlist
- `tests/prompt.test.ts` — system/business prompt assembly + no-info-leak
- `tests/agent.test.ts` — agent orchestration with a mock LLM
- `tests/commands.test.ts` — /start & /help tri-lingual routing
## Manual smoke test
1. Start the bot (dev or docker dev).
2. Open the bot in Telegram, send `/start` → expect the tri-lingual greeting.
3. Send a normal question → expect an AI reply.
4. `curl http://localhost:8080/health``{"status":"ok"}`.