create-bunspace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -0
- package/dist/bin.js +5755 -0
- package/dist/templates/monorepo/CLAUDE.md +164 -0
- package/dist/templates/monorepo/LICENSE +21 -0
- package/dist/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/dist/templates/monorepo/README.md +74 -0
- package/dist/templates/monorepo/SYNC_VERIFICATION.md +1 -0
- package/dist/templates/monorepo/apps/example/package.json +19 -0
- package/dist/templates/monorepo/apps/example/src/index.ts +23 -0
- package/dist/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/dist/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/dist/templates/monorepo/core/packages/main/package.json +41 -0
- package/dist/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/dist/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/dist/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/dist/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/core/packages/utils/package.json +43 -0
- package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/dist/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/dist/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/dist/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/dist/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/oxlint.json +14 -0
- package/dist/templates/monorepo/package.json +39 -0
- package/dist/templates/monorepo/tsconfig.json +35 -0
- package/dist/templates/telegram-bot/.oxlintrc.json +33 -0
- package/dist/templates/telegram-bot/.prettierignore +5 -0
- package/dist/templates/telegram-bot/.prettierrc +26 -0
- package/dist/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/dist/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/dist/templates/telegram-bot/CLAUDE.md +280 -0
- package/dist/templates/telegram-bot/Dockerfile +46 -0
- package/dist/templates/telegram-bot/README.md +245 -0
- package/dist/templates/telegram-bot/apps/.gitkeep +0 -0
- package/dist/templates/telegram-bot/bun.lock +208 -0
- package/dist/templates/telegram-bot/core/.env.example +71 -0
- package/dist/templates/telegram-bot/core/README.md +1067 -0
- package/dist/templates/telegram-bot/core/package.json +15 -0
- package/dist/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/dist/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/dist/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/dist/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/dist/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/dist/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/dist/templates/telegram-bot/core/src/index.ts +161 -0
- package/dist/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/dist/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/dist/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/dist/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/dist/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/dist/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/dist/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/dist/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/dist/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/dist/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/dist/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/dist/templates/telegram-bot/core/tsconfig.json +9 -0
- package/dist/templates/telegram-bot/docker-compose.yml +37 -0
- package/dist/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/dist/templates/telegram-bot/docs/development.md +363 -0
- package/dist/templates/telegram-bot/docs/environment.md +460 -0
- package/dist/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/dist/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/dist/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/dist/templates/telegram-bot/docs/getting-started.md +223 -0
- package/dist/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/dist/templates/telegram-bot/package.json +49 -0
- package/dist/templates/telegram-bot/packages/utils/package.json +12 -0
- package/dist/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/dist/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/dist/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/dist/templates/telegram-bot/tools/README.md +47 -0
- package/dist/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/dist/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/dist/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/dist/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/dist/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/dist/templates/telegram-bot/tools/index.ts +16 -0
- package/dist/templates/telegram-bot/tools/package.json +12 -0
- package/dist/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/dist/templates/telegram-bot/tsconfig.json +22 -0
- package/dist/templates/telegram-bot/vitest.config.ts +29 -0
- package/package.json +35 -0
- package/templates/monorepo/CLAUDE.md +164 -0
- package/templates/monorepo/LICENSE +21 -0
- package/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/templates/monorepo/README.md +74 -0
- package/templates/monorepo/apps/example/package.json +19 -0
- package/templates/monorepo/apps/example/src/index.ts +23 -0
- package/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/templates/monorepo/core/packages/main/package.json +41 -0
- package/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/templates/monorepo/core/packages/utils/package.json +43 -0
- package/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/templates/monorepo/oxlint.json +14 -0
- package/templates/monorepo/package.json +39 -0
- package/templates/monorepo/tsconfig.json +35 -0
- package/templates/telegram-bot/.oxlintrc.json +33 -0
- package/templates/telegram-bot/.prettierignore +5 -0
- package/templates/telegram-bot/.prettierrc +26 -0
- package/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/templates/telegram-bot/CLAUDE.md +280 -0
- package/templates/telegram-bot/Dockerfile +46 -0
- package/templates/telegram-bot/README.md +245 -0
- package/templates/telegram-bot/apps/.gitkeep +0 -0
- package/templates/telegram-bot/bun.lock +208 -0
- package/templates/telegram-bot/core/.env.example +71 -0
- package/templates/telegram-bot/core/README.md +1067 -0
- package/templates/telegram-bot/core/package.json +15 -0
- package/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/templates/telegram-bot/core/src/index.ts +161 -0
- package/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/templates/telegram-bot/core/tsconfig.json +9 -0
- package/templates/telegram-bot/docker-compose.yml +37 -0
- package/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/templates/telegram-bot/docs/development.md +363 -0
- package/templates/telegram-bot/docs/environment.md +460 -0
- package/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/templates/telegram-bot/docs/getting-started.md +223 -0
- package/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/templates/telegram-bot/package.json +49 -0
- package/templates/telegram-bot/packages/utils/package.json +12 -0
- package/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/templates/telegram-bot/tools/README.md +47 -0
- package/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/templates/telegram-bot/tools/index.ts +16 -0
- package/templates/telegram-bot/tools/package.json +12 -0
- package/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/templates/telegram-bot/tsconfig.json +22 -0
- package/templates/telegram-bot/vitest.config.ts +29 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitAny": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"strictFunctionTypes": true,
|
|
13
|
+
"strictBindCallApply": true,
|
|
14
|
+
"strictPropertyInitialization": true,
|
|
15
|
+
"noImplicitThis": true,
|
|
16
|
+
"alwaysStrict": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"noImplicitReturns": false,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": false,
|
|
22
|
+
"exactOptionalPropertyTypes": false,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"esModuleInterop": true,
|
|
25
|
+
"allowSyntheticDefaultImports": true,
|
|
26
|
+
"forceConsistentCasingInFileNames": true,
|
|
27
|
+
"isolatedModules": true,
|
|
28
|
+
"verbatimModuleSyntax": true,
|
|
29
|
+
"declaration": true,
|
|
30
|
+
"declarationMap": true,
|
|
31
|
+
"sourceMap": true,
|
|
32
|
+
"removeComments": false
|
|
33
|
+
},
|
|
34
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"plugins": ["typescript", "import"],
|
|
4
|
+
"env": {
|
|
5
|
+
"browser": false,
|
|
6
|
+
"node": true
|
|
7
|
+
},
|
|
8
|
+
"categories": {
|
|
9
|
+
"correctness": "error",
|
|
10
|
+
"suspicious": "warn",
|
|
11
|
+
"style": "off",
|
|
12
|
+
"pedantic": "off",
|
|
13
|
+
"perf": "warn"
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"no-unused-vars": "warn",
|
|
17
|
+
"no-console": "off",
|
|
18
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
19
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
20
|
+
"@typescript-eslint/prefer-as-const": "error",
|
|
21
|
+
"import/no-cycle": "error",
|
|
22
|
+
"import/no-duplicates": "warn"
|
|
23
|
+
},
|
|
24
|
+
"overrides": [
|
|
25
|
+
{
|
|
26
|
+
"files": ["*.test.ts", "*.spec.ts", "**/__tests__/**"],
|
|
27
|
+
"rules": {
|
|
28
|
+
"@typescript-eslint/no-explicit-any": "off"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"ignorePatterns": ["node_modules", "dist", "*.lock"]
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"semi": false,
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"tabWidth": 2,
|
|
5
|
+
"useTabs": false,
|
|
6
|
+
"trailingComma": "es5",
|
|
7
|
+
"bracketSpacing": true,
|
|
8
|
+
"arrowParens": "always",
|
|
9
|
+
"printWidth": 100,
|
|
10
|
+
"endOfLine": "lf",
|
|
11
|
+
"overrides": [
|
|
12
|
+
{
|
|
13
|
+
"files": "*.json",
|
|
14
|
+
"options": {
|
|
15
|
+
"tabWidth": 2
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"files": ["*.md", "*.mdx"],
|
|
20
|
+
"options": {
|
|
21
|
+
"proseWrap": "always",
|
|
22
|
+
"printWidth": 80
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# CLAUDE.deploy.md - Guía de Deployment
|
|
2
|
+
|
|
3
|
+
> **Parte de**: [CLAUDE.md](./CLAUDE.md) | Ver también: [CLAUDE.dev.md](./CLAUDE.dev.md)
|
|
4
|
+
|
|
5
|
+
Guía de deployment para multi-entorno y multi-instancia.
|
|
6
|
+
|
|
7
|
+
**Documentación relacionada**:
|
|
8
|
+
- [docs/deployment/docker.mdx](./docs/deployment/docker.mdx)
|
|
9
|
+
- [docs/deployment/vps.mdx](./docs/deployment/vps.mdx)
|
|
10
|
+
- [docs/deployment/environments.mdx](./docs/deployment/environments.mdx)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Multi-Environment Architecture
|
|
15
|
+
|
|
16
|
+
El template soporta múltiples entornos con archivos `.env` separados:
|
|
17
|
+
|
|
18
|
+
### Archivos de Entorno
|
|
19
|
+
|
|
20
|
+
| Archivo | Uso | Modo | Bot Token |
|
|
21
|
+
| ------- | --- | ---- | --------- |
|
|
22
|
+
| `core/.env.local` | Desarrollo local | Polling | Local dev token |
|
|
23
|
+
| `core/.env.staging` | Testing/Staging | Webhook | Test bot token |
|
|
24
|
+
| `core/.env.production` | Producción | Webhook | Real bot token |
|
|
25
|
+
|
|
26
|
+
### Selección de Entorno
|
|
27
|
+
|
|
28
|
+
La variable `TG_ENV` determina cuál archivo cargar:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Default: local (carga .env.local)
|
|
32
|
+
bun run start
|
|
33
|
+
|
|
34
|
+
# Staging
|
|
35
|
+
TG_ENV=staging bun run start
|
|
36
|
+
|
|
37
|
+
# Production
|
|
38
|
+
TG_ENV=production bun run start
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Multi-Instance Management
|
|
44
|
+
|
|
45
|
+
### Sistema de Lock
|
|
46
|
+
|
|
47
|
+
El `InstanceManager` previene conflictos usando archivos PID/LOCK en `core/tmp/`:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
core/tmp/
|
|
51
|
+
├── mks-bot-local.pid # Process ID
|
|
52
|
+
├── mks-bot-local.lock # Lock data (JSON)
|
|
53
|
+
├── mks-bot-staging.pid
|
|
54
|
+
└── mks-bot-staging.lock
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Contenido del Lock File
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"pid": 12345,
|
|
62
|
+
"instanceId": "1734567890-abc123",
|
|
63
|
+
"environment": "production",
|
|
64
|
+
"instanceName": "mks-bot-prod",
|
|
65
|
+
"startTime": "2025-01-06T10:30:00.000Z",
|
|
66
|
+
"nodeVersion": "v1.3.0",
|
|
67
|
+
"cwd": "/app"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Detección de Conflictos
|
|
72
|
+
|
|
73
|
+
Al iniciar, el bot verifica si otra instancia está corriendo:
|
|
74
|
+
|
|
75
|
+
- **Si está corriendo**: Error `INSTANCE_CONFLICT` con detalles
|
|
76
|
+
- **Si no está corriendo**: Remueve lock stale y continua
|
|
77
|
+
- **Si está deshabilitado**: `TG_INSTANCE_CHECK=false` salta verificación
|
|
78
|
+
|
|
79
|
+
### Ver Instancias Corriendo
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Ver todas las instancias
|
|
83
|
+
bun run status
|
|
84
|
+
|
|
85
|
+
# Output como JSON
|
|
86
|
+
bun run cli status --json
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Output**:
|
|
90
|
+
```
|
|
91
|
+
┌─────────┬───────────────┬───────────────────┬─────────────┬────────┐
|
|
92
|
+
│ (index) │ PID │ Environment │ Name │ Status │
|
|
93
|
+
├─────────┼───────────────┼───────────────────┼─────────────┼────────┤
|
|
94
|
+
│ 0 │ 12345 │ 'production' │ 'mks-bot...' │'✓ Run' │
|
|
95
|
+
│ 1 │ 12346 │ 'staging' │ 'mks-bot...' │'✓ Run' │
|
|
96
|
+
└─────────┴───────────────┴───────────────────┴─────────────┴────────┘
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Docker Deployment
|
|
102
|
+
|
|
103
|
+
### Dockerfile Multi-Stage
|
|
104
|
+
|
|
105
|
+
El template incluye un Dockerfile multi-stage:
|
|
106
|
+
|
|
107
|
+
```dockerfile
|
|
108
|
+
# Build stage
|
|
109
|
+
FROM oven/bun:1.3 AS builder
|
|
110
|
+
WORKDIR /app
|
|
111
|
+
COPY package.json bun.lock ./
|
|
112
|
+
COPY core/package.json core/
|
|
113
|
+
RUN bun install --frozen-lockfile
|
|
114
|
+
COPY core/src core/src
|
|
115
|
+
|
|
116
|
+
# Production stage
|
|
117
|
+
FROM oven/bun:1.3 AS production
|
|
118
|
+
WORKDIR /app
|
|
119
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
120
|
+
COPY --from=builder /app/core/node_modules ./core/node_modules
|
|
121
|
+
COPY --from=builder /app/core/src ./core/src
|
|
122
|
+
RUN mkdir -p /app/core/tmp /app/core/logs
|
|
123
|
+
ENV TG_ENV=production
|
|
124
|
+
ENV NODE_ENV=production
|
|
125
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
126
|
+
CMD bun run cli status || exit 1
|
|
127
|
+
EXPOSE 3000
|
|
128
|
+
CMD ["bun", "run", "start"]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Docker Compose
|
|
132
|
+
|
|
133
|
+
```yaml
|
|
134
|
+
version: '3.8'
|
|
135
|
+
|
|
136
|
+
services:
|
|
137
|
+
bot-local:
|
|
138
|
+
build: .
|
|
139
|
+
container_name: mks-bot-local
|
|
140
|
+
environment:
|
|
141
|
+
- TG_ENV=local
|
|
142
|
+
env_file:
|
|
143
|
+
- core/.env.local
|
|
144
|
+
volumes:
|
|
145
|
+
- ./core/src:/app/core/src:ro
|
|
146
|
+
- ./core/logs:/app/core/logs
|
|
147
|
+
command: bun run --watch src/index.ts
|
|
148
|
+
|
|
149
|
+
bot-staging:
|
|
150
|
+
build: .
|
|
151
|
+
container_name: mks-bot-staging
|
|
152
|
+
environment:
|
|
153
|
+
- TG_ENV=staging
|
|
154
|
+
env_file:
|
|
155
|
+
- core/.env.staging
|
|
156
|
+
ports:
|
|
157
|
+
- "3001:3000"
|
|
158
|
+
|
|
159
|
+
bot-production:
|
|
160
|
+
build: .
|
|
161
|
+
container_name: mks-bot-prod
|
|
162
|
+
environment:
|
|
163
|
+
- TG_ENV=production
|
|
164
|
+
env_file:
|
|
165
|
+
- core/.env.production
|
|
166
|
+
ports:
|
|
167
|
+
- "3000:3000"
|
|
168
|
+
restart: unless-stopped
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Build y Run
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Build imagen
|
|
175
|
+
docker build -t mks-telegram-bot .
|
|
176
|
+
|
|
177
|
+
# Run con docker-compose
|
|
178
|
+
docker-compose up bot-production
|
|
179
|
+
|
|
180
|
+
# Ver logs
|
|
181
|
+
docker-compose logs -f bot-production
|
|
182
|
+
|
|
183
|
+
# Ver healthcheck
|
|
184
|
+
docker inspect mks-bot-prod | jq '.[0].State.Health'
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## ngrok Integration
|
|
190
|
+
|
|
191
|
+
### ngrock para Testing Local
|
|
192
|
+
|
|
193
|
+
El comando `ngrok` tiene soporte multi-entorno:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Development con ngrok (local environment)
|
|
197
|
+
bun run ngrok --environment local --start-bot
|
|
198
|
+
|
|
199
|
+
# Staging con ngrok (test bot)
|
|
200
|
+
bun run ngrok --environment staging --webhook-url
|
|
201
|
+
|
|
202
|
+
# Force start aunque haya conflicto
|
|
203
|
+
bun run ngrok --environment production --force
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Opciones Disponibles
|
|
207
|
+
|
|
208
|
+
| Opción | Default | Descripción |
|
|
209
|
+
| ------ | ------- | ----------- |
|
|
210
|
+
| `-p, --port <port>` | `3000` | Puerto a forward |
|
|
211
|
+
| `-e, --environment <env>` | `local` | Entorno: local/staging/production |
|
|
212
|
+
| `-w, --webhook-url` | `false` | Auto-update webhook URL en .env |
|
|
213
|
+
| `-s, --start-bot` | `false` | Auto-start bot después de ngrok |
|
|
214
|
+
| `-f, --force` | `false` | Force start aún si hay conflicto |
|
|
215
|
+
|
|
216
|
+
### Flujo con --environment
|
|
217
|
+
|
|
218
|
+
1. Carga el archivo `.env.{environment}` correspondiente
|
|
219
|
+
2. Detecta conflictos con instancias existentes
|
|
220
|
+
3. Inicia ngrok tunnel
|
|
221
|
+
4. Opcionalmente actualiza `TG_WEBHOOK_URL` en el .env
|
|
222
|
+
5. Opcionalmente inicia el bot con `TG_ENV` configurado
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## VPS Deployment
|
|
227
|
+
|
|
228
|
+
### Preparar VPS
|
|
229
|
+
|
|
230
|
+
1. **Instalar dependencias**:
|
|
231
|
+
```bash
|
|
232
|
+
curl -fsSL https://bun.sh/install | bash
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
2. **Clonar repositorio**:
|
|
236
|
+
```bash
|
|
237
|
+
git clone <repo-url>
|
|
238
|
+
cd mks-telegram-bot
|
|
239
|
+
bun install
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
3. **Configurar entorno**:
|
|
243
|
+
```bash
|
|
244
|
+
cp core/.env.example core/.env.production
|
|
245
|
+
nano core/.env.production
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
4. **Crear servicio systemd** (opcional):
|
|
249
|
+
```ini
|
|
250
|
+
[Unit]
|
|
251
|
+
Description=mks-telegram-bot
|
|
252
|
+
After=network.target
|
|
253
|
+
|
|
254
|
+
[Service]
|
|
255
|
+
Type=simple
|
|
256
|
+
User=botuser
|
|
257
|
+
WorkingDirectory=/app/mks-telegram-bot
|
|
258
|
+
Environment="TG_ENV=production"
|
|
259
|
+
ExecStart=/usr/local/bin/bun run start
|
|
260
|
+
Restart=always
|
|
261
|
+
|
|
262
|
+
[Install]
|
|
263
|
+
WantedBy=multi-user.target
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Deployment con Docker (Recomendado)
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Build y taggear imagen
|
|
270
|
+
docker build -t mks-telegram-bot:latest .
|
|
271
|
+
docker tag mks-telegram-bot:latest registry.example.com/mks-bot:latest
|
|
272
|
+
|
|
273
|
+
# Push a registry (opcional)
|
|
274
|
+
docker push registry.example.com/mks-bot:latest
|
|
275
|
+
|
|
276
|
+
# En VPS
|
|
277
|
+
docker pull registry.example.com/mks-bot:latest
|
|
278
|
+
docker run -d \
|
|
279
|
+
--name mks-bot-prod \
|
|
280
|
+
--restart unless-stopped \
|
|
281
|
+
-p 3000:3000 \
|
|
282
|
+
--env-file core/.env.production \
|
|
283
|
+
registry.example.com/mks-bot:latest
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Troubleshooting Deployment
|
|
289
|
+
|
|
290
|
+
### Bot Doesn't Respond
|
|
291
|
+
|
|
292
|
+
1. Check `TG_BOT_TOKEN` is valid
|
|
293
|
+
2. Verify bot is running (`bun run status`)
|
|
294
|
+
3. Check `TG_AUTHORIZED_USER_IDS` for control commands
|
|
295
|
+
|
|
296
|
+
### Webhook Not Working
|
|
297
|
+
|
|
298
|
+
1. Verify `TG_WEBHOOK_URL` is HTTPS and publicly accessible
|
|
299
|
+
2. Check `TG_WEBHOOK_SECRET` matches (min 16 chars)
|
|
300
|
+
3. Verify firewall allows incoming connections
|
|
301
|
+
|
|
302
|
+
### Instance Conflict
|
|
303
|
+
|
|
304
|
+
**Error**: `INSTANCE_CONFLICT - Another instance is already running`
|
|
305
|
+
|
|
306
|
+
**Solutions**:
|
|
307
|
+
1. Stop the existing instance: `bun run cli kill <instance_name>`
|
|
308
|
+
2. Use a different instance name in your `.env` file
|
|
309
|
+
3. Disable instance check: `TG_INSTANCE_CHECK=false` (not recommended)
|
|
310
|
+
4. Remove stale lock files: `rm -f core/tmp/*.lock core/tmp/*.pid`
|
|
311
|
+
|
|
312
|
+
### Docker Issues
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# Ver logs del container
|
|
316
|
+
docker logs mks-bot-prod
|
|
317
|
+
|
|
318
|
+
# Entrar al container
|
|
319
|
+
docker exec -it mks-bot-prod /bin/sh
|
|
320
|
+
|
|
321
|
+
# Ver healthcheck
|
|
322
|
+
docker inspect mks-bot-prod | jq '.[0].State.Health'
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### ngrok Tunnel Not Working
|
|
326
|
+
|
|
327
|
+
1. Verify ngrok is installed: `ngrok version`
|
|
328
|
+
2. Check ngrok is not already running on port 4040
|
|
329
|
+
3. Use `--force` flag if conflict detected
|
|
330
|
+
4. Check port is available: `lsof -i :3000`
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Environment Variables Reference
|
|
335
|
+
|
|
336
|
+
### Variables de Entorno
|
|
337
|
+
|
|
338
|
+
| Variable | Default | Descripción |
|
|
339
|
+
| -------- | ------- | ----------- |
|
|
340
|
+
| `TG_ENV` | `local` | Environment: local/staging/production |
|
|
341
|
+
| `TG_BOT_TOKEN` | required | Bot token from @BotFather |
|
|
342
|
+
| `TG_MODE` | `polling` | `polling` or `webhook` |
|
|
343
|
+
| `TG_WEBHOOK_URL` | - | Public HTTPS webhook URL |
|
|
344
|
+
| `TG_WEBHOOK_SECRET` | - | Secret token for validation |
|
|
345
|
+
| `TG_INSTANCE_NAME` | `mks-bot` | Unique instance name for locking |
|
|
346
|
+
| `TG_INSTANCE_CHECK` | `true` | Enable instance conflict detection |
|
|
347
|
+
| `LOG_LEVEL` | `info` | Log verbosity |
|
|
348
|
+
| `TG_DEBUG` | `false` | Enable debug mode |
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Ver También
|
|
353
|
+
|
|
354
|
+
- [CLAUDE.md](./CLAUDE.md) - Entry point principal
|
|
355
|
+
- [CLAUDE.dev.md](./CLAUDE.dev.md) - Desarrollo y patterns
|
|
356
|
+
- [README.md](./README.md) - Quick start del proyecto
|