Skip to Content
Telegram MCPComponentsConfig

src/config.ts — Env loader

Zod-parsed environment loader. Single point of failure: anything missing or malformed at boot raises one aggregated error listing every offending key, so operators fix the env file in one pass instead of one variable per restart.

Public surface

ExportShapePurpose
Configz.infer<typeof ConfigSchema>Strongly-typed env contract
loadConfig(env?)(NodeJS.ProcessEnv) => ConfigParse; throws on failure

Schema (current)

VarTypeDefaultNotes
NODE_ENV'production' | 'development' | 'test'developmentDrives logger format
PORTnumber (coerced)3000Loopback bind in src/index.ts
LOG_LEVELpino levelinfo
PUBLIC_BASE_URLURLUsed by npm run register-webhook
TELEGRAM_BOT_TOKENstringBotFather token
TELEGRAM_WEBHOOK_SECRETstringHeader echoed by Telegram on every webhook delivery
MCP_AUTH_TOKENstringPhase 2: bearer required on /mcp
INNGEST_EVENT_KEYstringPhase 5
INNGEST_SIGNING_KEYstringPhase 5
DATABASE_URLstringPostgres connection string
ADMIN_TELEGRAM_USER_IDnumber (coerced)Seeded as status=active, role=admin on boot

Behavior

  • loadConfig() runs once from src/index.ts before the logger is constructed — so a bad env file produces a clear stderr line
    • non-zero exit (systemd flags the unit as failed).
  • Numeric vars use z.coerce.number() so the env-file string is converted cleanly. Negative / non-integer values are rejected.
  • LOG_LEVEL is constrained to the known pino level set so a typo (e.g. verbose) fails at boot rather than silently falling through to info.

Tests

test/unit/config.test.ts — accepts a full env, applies defaults, coerces numerics, aggregates missing-field errors, rejects malformed PUBLIC_BASE_URL and unknown LOG_LEVEL.

See also