2.3 KiB
2.3 KiB
Development
Prerequisites
- Node.js ≥ 20 (LTS)
- Docker + Docker Compose
- Access to the DSM
mem0_netnetwork (formem0-postgresandlitellm)
Environment setup
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)
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)
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)
- Set
TELEGRAM_WEBHOOK_URL=https://bot.digikedai.com/<secret>/webhookandTELEGRAM_WEBHOOK_SECRET=<secret>. - Ensure the public route reaches the container (Traefik label or reverse proxy).
- On startup the bot calls
setWebhookautomatically.
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
npm test # vitest run
npm run test:watch # watch mode
npm run typecheck # tsc --noEmit
Test coverage:
tests/normalize.test.ts— Telegram → normalized message contracttests/config.test.ts— env validation and user allowlisttests/prompt.test.ts— system/business prompt assembly + no-info-leaktests/agent.test.ts— agent orchestration with a mock LLMtests/commands.test.ts— /start & /help tri-lingual routing
Manual smoke test
- Start the bot (dev or docker dev).
- Open the bot in Telegram, send
/start→ expect the tri-lingual greeting. - Send a normal question → expect an AI reply.
curl http://localhost:8080/health→{"status":"ok"}.