# Verifying Docker Multi-Bot Setup

## ✅ Configuration Check

### 1. Environment Files

**`.env.shared`** - Contains:
- ✅ Provider settings (custom/Ollama)
- ✅ Agent defaults (model, workspace, temperature, etc.)
- ✅ Tool settings
- ✅ Gateway settings
- ✅ Email IMAP/SMTP settings (shared)

**`.env.user1`** - Contains:
- ✅ Telegram token (bot-specific)
- ✅ Email credentials (bot-specific override)
- ⚠️ **Issue**: `ALLOW_FROM` should NOT be in env files (arrays don't work in env vars)

### 2. Config Files

**`~/.nanobot-user1/config.json`** - Contains:
- ✅ Telegram `allowFrom` array (correct location)
- ✅ Email `allowFrom` array (correct location)

### 3. Docker Compose

**`docker-compose.multi.env.yml`** - Correctly configured:
- ✅ Loads `.env.shared` first
- ✅ Loads `.env.user1` second (overrides shared)
- ✅ Mounts `~/.nanobot-user1:/root/.nanobot` (maps host config to container)

## 🔍 How Nanobot Loads Config in Docker

1. **Environment Variables** (from `.env.shared` and `.env.user1`):
   - Loaded by Docker Compose into container environment
   - Nanobot's Pydantic `BaseSettings` reads them automatically
   - Format: `NANOBOT_CHANNELS__TELEGRAM__TOKEN=...`

2. **Config File** (`config.json`):
   - Path inside container: `/root/.nanobot/config.json`
   - Maps to host: `~/.nanobot-user1/config.json`
   - Loaded by `load_config()` which calls `get_config_path()`
   - `get_config_path()` returns `Path.home() / ".nanobot" / "config.json"`
   - In Docker, `Path.home()` = `/root`, so it reads `/root/.nanobot/config.json`
   - This is mounted from `~/.nanobot-user1/config.json` on host ✅

## ⚠️ Issues Found

### Issue 1: ALLOW_FROM in env file
**Problem**: `.env.user1` has:
```bash
NANOBOT_CHANNELS__TELEGRAM__ALLOW_FROM=["TADec2023"]
NANOBOT_CHANNELS__EMAIL__ALLOW_FROM=["adayear2025@gmail.com"]
```

**Why it's wrong**: Environment variables can't handle JSON arrays. These will be treated as strings, not arrays.

**Fix**: Remove these from `.env.user1` - they're already correctly in `config.json`:
```json
{
  "channels": {
    "telegram": {
      "allowFrom": ["TADec2023"]
    },
    "email": {
      "allowFrom": ["adayear2025@gmail.com"]
    }
  }
}
```

### Issue 2: Duplicate email settings
**Problem**: Email IMAP/SMTP settings are in both `.env.shared` and `.env.user1`

**Recommendation**: 
- If all bots use same email account → Keep only in `.env.shared`
- If each bot uses different email → Keep only in `.env.userX` files

## ✅ Verification Steps

1. **Check env files don't have ALLOW_FROM**:
   ```bash
   grep ALLOW_FROM .env.user1
   # Should return nothing or be removed
   ```

2. **Check config files have allowFrom**:
   ```bash
   cat ~/.nanobot-user1/config.json | jq '.channels.telegram.allowFrom'
   # Should show: ["TADec2023"]
   ```

3. **Verify Docker mounts**:
   ```bash
   docker compose -f docker-compose.multi.env.yml config | grep -A 5 "nanobot-user1"
   # Should show volume mount: ~/.nanobot-user1:/root/.nanobot
   ```

4. **Test config loading in container**:
   ```bash
   docker run --rm -v ~/.nanobot-user1:/root/.nanobot \
     -e NANOBOT_CHANNELS__TELEGRAM__TOKEN=test \
     nanobot gateway --help
   ```

## 🎯 Summary

**What's Correct:**
- ✅ Docker Compose loads env files correctly
- ✅ Config files are in correct locations
- ✅ Volume mounts map host configs to container paths
- ✅ Nanobot will read from `/root/.nanobot/config.json` inside container

**What Needs Fixing:**
- ⚠️ Remove `ALLOW_FROM` from `.env.user1` (keep only in config.json)
- ⚠️ Decide: Email settings in `.env.shared` OR `.env.userX` (not both)

**How It Works:**
1. Docker Compose loads `.env.shared` → sets environment variables
2. Docker Compose loads `.env.user1` → overrides with bot-specific vars
3. Container starts → mounts `~/.nanobot-user1` to `/root/.nanobot`
4. Nanobot starts → reads env vars (from Docker) + config.json (from mount)
5. Result: Bot uses combined settings from env vars + config.json ✅


