create-bunspace 0.2.5 → 0.3.1

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.
Files changed (80) hide show
  1. package/dist/templates/monorepo/apps/example/package.json +1 -1
  2. package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +30 -0
  3. package/dist/templates/monorepo/tsconfig.json +3 -1
  4. package/dist/templates/telegram-bot/CLAUDE.deploy.md +2 -3
  5. package/dist/templates/telegram-bot/CLAUDE.dev.md +304 -5
  6. package/dist/templates/telegram-bot/CLAUDE.md +166 -89
  7. package/dist/templates/telegram-bot/README.md +252 -129
  8. package/dist/templates/telegram-bot/bun.lock +132 -3
  9. package/dist/templates/telegram-bot/core/.env.example +6 -0
  10. package/dist/templates/telegram-bot/core/package.json +11 -0
  11. package/dist/templates/telegram-bot/core/rolldown.config.ts +11 -0
  12. package/dist/templates/telegram-bot/core/src/config/env.ts +130 -1
  13. package/dist/templates/telegram-bot/core/src/config/logging.ts +4 -4
  14. package/dist/templates/telegram-bot/core/src/handlers/config-export.ts +123 -0
  15. package/dist/templates/telegram-bot/core/src/handlers/control.ts +46 -11
  16. package/dist/templates/telegram-bot/core/src/handlers/demo-full.ts +58 -0
  17. package/dist/templates/telegram-bot/core/src/handlers/demo-keyboard.ts +49 -0
  18. package/dist/templates/telegram-bot/core/src/handlers/demo-media.ts +163 -0
  19. package/dist/templates/telegram-bot/core/src/handlers/demo-text.ts +27 -0
  20. package/dist/templates/telegram-bot/core/src/handlers/health.ts +40 -37
  21. package/dist/templates/telegram-bot/core/src/handlers/info.ts +189 -0
  22. package/dist/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
  23. package/dist/templates/telegram-bot/core/src/handlers/logs.ts +16 -7
  24. package/dist/templates/telegram-bot/core/src/index.ts +49 -1
  25. package/dist/templates/telegram-bot/core/src/utils/formatters.ts +14 -33
  26. package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
  27. package/dist/templates/telegram-bot/core/src/utils/message-builder.ts +180 -0
  28. package/dist/templates/telegram-bot/core/tsconfig.json +2 -0
  29. package/dist/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
  30. package/dist/templates/telegram-bot/docs/cli-commands.md +514 -5
  31. package/dist/templates/telegram-bot/docs/environment.md +191 -3
  32. package/dist/templates/telegram-bot/docs/getting-started.md +202 -15
  33. package/dist/templates/telegram-bot/package.json +7 -3
  34. package/dist/templates/telegram-bot/packages/utils/package.json +12 -1
  35. package/dist/templates/telegram-bot/packages/utils/rolldown.config.ts +11 -0
  36. package/dist/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
  37. package/dist/templates/telegram-bot/packages/utils/tsconfig.json +10 -0
  38. package/dist/templates/telegram-bot/tools/commands/doctor.ts +62 -0
  39. package/dist/templates/telegram-bot/tools/commands/setup.ts +984 -170
  40. package/dist/templates/telegram-bot/tsconfig.json +7 -2
  41. package/package.json +1 -1
  42. package/templates/monorepo/apps/example/package.json +1 -1
  43. package/templates/monorepo/core/packages/utils/rolldown.config.ts +30 -0
  44. package/templates/monorepo/tsconfig.json +3 -1
  45. package/templates/telegram-bot/CLAUDE.deploy.md +2 -3
  46. package/templates/telegram-bot/CLAUDE.dev.md +304 -5
  47. package/templates/telegram-bot/CLAUDE.md +166 -89
  48. package/templates/telegram-bot/README.md +252 -129
  49. package/templates/telegram-bot/bun.lock +132 -3
  50. package/templates/telegram-bot/core/.env.example +6 -0
  51. package/templates/telegram-bot/core/package.json +11 -0
  52. package/templates/telegram-bot/core/rolldown.config.ts +11 -0
  53. package/templates/telegram-bot/core/src/config/env.ts +130 -1
  54. package/templates/telegram-bot/core/src/config/logging.ts +4 -4
  55. package/templates/telegram-bot/core/src/handlers/config-export.ts +123 -0
  56. package/templates/telegram-bot/core/src/handlers/control.ts +46 -11
  57. package/templates/telegram-bot/core/src/handlers/demo-full.ts +58 -0
  58. package/templates/telegram-bot/core/src/handlers/demo-keyboard.ts +49 -0
  59. package/templates/telegram-bot/core/src/handlers/demo-media.ts +163 -0
  60. package/templates/telegram-bot/core/src/handlers/demo-text.ts +27 -0
  61. package/templates/telegram-bot/core/src/handlers/health.ts +40 -37
  62. package/templates/telegram-bot/core/src/handlers/info.ts +189 -0
  63. package/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
  64. package/templates/telegram-bot/core/src/handlers/logs.ts +16 -7
  65. package/templates/telegram-bot/core/src/index.ts +49 -1
  66. package/templates/telegram-bot/core/src/utils/formatters.ts +14 -33
  67. package/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
  68. package/templates/telegram-bot/core/tsconfig.json +2 -0
  69. package/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
  70. package/templates/telegram-bot/docs/cli-commands.md +514 -5
  71. package/templates/telegram-bot/docs/environment.md +191 -3
  72. package/templates/telegram-bot/docs/getting-started.md +202 -15
  73. package/templates/telegram-bot/package.json +7 -3
  74. package/templates/telegram-bot/packages/utils/package.json +12 -1
  75. package/templates/telegram-bot/packages/utils/rolldown.config.ts +11 -0
  76. package/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
  77. package/templates/telegram-bot/packages/utils/tsconfig.json +10 -0
  78. package/templates/telegram-bot/tools/commands/doctor.ts +62 -0
  79. package/templates/telegram-bot/tools/commands/setup.ts +984 -170
  80. package/templates/telegram-bot/tsconfig.json +7 -2
@@ -6,12 +6,68 @@ Guía completa de configuración de variables de entorno para el bot.
6
6
 
7
7
  El template soporta múltiples entornos con archivos `.env` separados:
8
8
 
9
+ ### Estructura Multibot (Nueva)
10
+
11
+ > **Sistema Multibot**: Gestiona múltiples bots desde un mismo proyecto con configuraciones independientes.
12
+
13
+ El template ahora usa una estructura `.envs/` para soportar múltiples bots:
14
+
15
+ ```
16
+ core/.envs/
17
+ ├── {botUsername}/
18
+ │ ├── local.env # Configuración local del bot
19
+ │ ├── staging.env # Configuración staging del bot
20
+ │ ├── production.env # Configuración production del bot
21
+ │ └── metadata.json # Metadatos del bot
22
+ └── .active -> {botUsername} # Symlink al bot activo
23
+ ```
24
+
25
+ ### Estructura Legada (Antigua)
26
+
27
+ Para backwards compatibility, el template todavía soporta la estructura antigua:
28
+
9
29
  | Archivo | Uso | Modo | Bot Token |
10
30
  | ------- | --- | ---- | --------- |
11
31
  | `core/.env.local` | Desarrollo local | Polling | Local dev token |
12
32
  | `core/.env.staging` | Testing/Staging | Webhook | Test bot token |
13
33
  | `core/.env.production` | Producción | Webhook | Real bot token |
14
34
 
35
+ ### Selección de Bot Activo
36
+
37
+ En la estructura multibot, hay tres formas de seleccionar el bot activo:
38
+
39
+ #### 1. Vía Symlink .active (Automático)
40
+
41
+ ```bash
42
+ bun run bot use mybot123bot
43
+ ```
44
+
45
+ Esto crea/actualiza el symlink `.active` para apuntar al bot seleccionado.
46
+
47
+ #### 2. Vía Variable de Entorno TG_BOT
48
+
49
+ ```bash
50
+ TG_BOT=mybot123bot bun run dev
51
+ ```
52
+
53
+ #### 3. Automático
54
+
55
+ El bot configurado más recientemente se activa automáticamente.
56
+
57
+ ### Migración desde Estructura Antigua
58
+
59
+ Si tienes archivos `.env.{env}` antiguos, puedes migrarlos a la nueva estructura:
60
+
61
+ ```bash
62
+ bun run bot migrate
63
+ ```
64
+
65
+ Este comando:
66
+ - Detecta archivos `.env.local`, `.env.staging`, `.env.production`
67
+ - Crea la estructura `.envs/{bot}/{env}.env`
68
+ - Hace backup de archivos antiguos como `.env.{env}.backup`
69
+ - Actualiza el symlink `.active`
70
+
15
71
  ### Selección de Entorno
16
72
 
17
73
  La variable `TG_ENV` determina cuál archivo cargar:
@@ -58,6 +114,62 @@ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
58
114
  TG_MODE=polling
59
115
  ```
60
116
 
117
+ ## Variables MTProto (para Bootstrap)
118
+
119
+ ### `TG_API_ID`
120
+
121
+ **Descripción**: API ID de Telegram para MTProto (obtenido de my.telegram.org)
122
+
123
+ **Requerido para**: `bun run bootstrap` (comando de creación automática de bots)
124
+
125
+ **Obtenerlo**:
126
+ 1. Ve a [https://my.telegram.org](https://my.telegram.org)
127
+ 2. Log in con tu número de teléfono
128
+ 3. Click en "API development tools"
129
+ 4. Llena el formulario (App title, Short name, Platform)
130
+ 5. Click "Create application"
131
+ 6. Copia el `api_id` (número entero)
132
+
133
+ **Formato**: Número entero positivo
134
+
135
+ **Ejemplo**:
136
+ ```bash
137
+ TG_API_ID=12345678
138
+ ```
139
+
140
+ ### `TG_API_HASH`
141
+
142
+ **Descripción**: API Hash de Telegram para MTProto (obtenido de my.telegram.org)
143
+
144
+ **Requerido para**: `bun run bootstrap` (comando de creación automática de bots)
145
+
146
+ **Formato**: String de 32+ caracteres
147
+
148
+ **Ejemplo**:
149
+ ```bash
150
+ TG_API_HASH=abc123def456789abc123def456789ab
151
+ ```
152
+
153
+ > **IMPORTANTE**: Estas credenciales son diferentes del bot token.
154
+ > - **Bot Token** (TG_BOT_TOKEN): Para Bot API, usado en runtime
155
+ > - **MTProto Credentials** (TG_API_ID/TG_API_HASH): Para crear bots automáticamente vía @BotFather
156
+
157
+ **Uso en Bootstrap**:
158
+ ```bash
159
+ # Con credenciales en .env, bootstrap no te las pedirá
160
+ bun run bootstrap
161
+
162
+ # Sin credenciales, bootstrap te pedirá que las ingreses
163
+ bun run bootstrap
164
+ # → Enter your API ID: ********
165
+ # → Enter your API Hash: ************************************
166
+ ```
167
+
168
+ **Seguridad**:
169
+ - Guarda estas credenciales en tu `.env` (nunca en el repo)
170
+ - Son menos sensibles que el bot token, pero aún así privadas
171
+ - Permiten que el bootstrainer automatice la creación de bots
172
+
61
173
  ## Variables Webhook (si TG_MODE=webhook)
62
174
 
63
175
  ### `TG_WEBHOOK_URL`
@@ -88,6 +200,30 @@ TG_WEBHOOK_SECRET=my_secret_token_min_16_chars
88
200
 
89
201
  ## Variables de Identificación
90
202
 
203
+ ### `TG_BOT`
204
+
205
+ **Descripción**: Username del bot a activar (sistema multibot)
206
+
207
+ **Formato**: Bot username sin el `@`
208
+
209
+ **Ejemplo**:
210
+ ```bash
211
+ TG_BOT=mybot123bot
212
+ ```
213
+
214
+ **Uso**:
215
+ ```bash
216
+ # Arrancar bot específico
217
+ TG_BOT=mybot123bot bun run dev
218
+
219
+ # Arrancar otro bot
220
+ TG_BOT=anotherbot456bot bun run dev
221
+ ```
222
+
223
+ **Alternativas**:
224
+ - Usar `bun run bot use <username>` para establecer bot activo permanentemente
225
+ - El symlink `.active` se usa automáticamente si `TG_BOT` no está seteado
226
+
91
227
  ### `TG_ENV`
92
228
 
93
229
  **Descripción**: Entorno actual del bot
@@ -364,7 +500,7 @@ TG_MAX_RETRIES=5
364
500
 
365
501
  ### Nunca Commitear .env Files
366
502
 
367
- Los archivos `.env.*` contienen secrets y no deben estar en git.
503
+ Los archivos `.env.*` y el directorio `.envs/` contienen secrets y no deben estar en git.
368
504
 
369
505
  ```gitignore
370
506
  # En .gitignore
@@ -372,6 +508,11 @@ core/.env.local
372
508
  core/.env.staging
373
509
  core/.env.production
374
510
  core/.env.*
511
+
512
+ # Multibot environment directory
513
+ core/.envs/
514
+ core/.envs/*/
515
+ !core/.envs/.gitkeep
375
516
  ```
376
517
 
377
518
  ### Usar .env.example
@@ -405,7 +546,50 @@ kubectl create secret generic bot-secrets --from-literal=TG_BOT_TOKEN=xxx
405
546
 
406
547
  ## Plantillas de Entorno
407
548
 
408
- ### Desarrollo (.env.local)
549
+ ### Estructura Multibot
550
+
551
+ Para sistemas multibot, cada bot tiene su propio directorio con archivos de entorno:
552
+
553
+ ```bash
554
+ # core/.envs/mybot123bot/local.env
555
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
556
+ TG_MODE=polling
557
+ TG_ENV=local
558
+ LOG_LEVEL=debug
559
+ TG_DEBUG=true
560
+
561
+ # core/.envs/mybot123bot/staging.env
562
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
563
+ TG_MODE=webhook
564
+ TG_WEBHOOK_URL=https://staging.example.com/webhook
565
+ TG_WEBHOOK_SECRET=staging_secret_min_16_chars
566
+ TG_ENV=staging
567
+ LOG_LEVEL=info
568
+
569
+ # core/.envs/mybot123bot/production.env
570
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
571
+ TG_MODE=webhook
572
+ TG_WEBHOOK_URL=https://bot.example.com/webhook
573
+ TG_WEBHOOK_SECRET=super_secure_secret_min_16_chars
574
+ TG_ENV=production
575
+ LOG_LEVEL=warn
576
+ TG_RATE_LIMIT=30
577
+
578
+ # core/.envs/mybot123bot/metadata.json
579
+ {
580
+ "name": "My Bot",
581
+ "description": "My awesome Telegram bot",
582
+ "createdAt": "2025-01-07T14:30:45.000Z",
583
+ "updatedAt": "2025-01-07T15:15:22.000Z",
584
+ "tags": ["test", "demo"]
585
+ }
586
+ ```
587
+
588
+ ### Estructura Legada (Archivos Únicos)
589
+
590
+ Para proyectos con un solo bot, puedes usar archivos de entorno únicos:
591
+
592
+ #### Desarrollo (.env.local)
409
593
 
410
594
  ```bash
411
595
  # Required
@@ -413,12 +597,16 @@ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
413
597
  TG_MODE=polling
414
598
  TG_ENV=local
415
599
 
600
+ # MTProto (opcional - para comando bootstrap)
601
+ # TG_API_ID=12345678
602
+ # TG_API_HASH=abc123def456789...
603
+
416
604
  # Logging
417
605
  LOG_LEVEL=debug
418
606
  TG_DEBUG=true
419
607
  ```
420
608
 
421
- ### Staging (.env.staging)
609
+ #### Staging (.env.staging)
422
610
 
423
611
  ```bash
424
612
  # Required
@@ -18,7 +18,11 @@ bun --version
18
18
 
19
19
  ## Paso 1: Crear el Bot en Telegram
20
20
 
21
- ### Hablar con @BotFather
21
+ > **OPCIÓN RECOMENDADA: Bootstrap Automático**
22
+ >
23
+ > Si quieres automatizar TODO el proceso (crear bot, grupo, topics), salta a [Paso 4: Bootstrap Automático](#paso-4-bootstrap-automtico).
24
+
25
+ ### Hablar con @BotFather (Método Manual)
22
26
 
23
27
  1. Abre Telegram y busca **@BotFather**
24
28
  2. Inicia el chat con el comando `/newbot`
@@ -61,7 +65,33 @@ Esto instala todas las dependencias del workspace:
61
65
 
62
66
  ## Paso 4: Configurar el Entorno
63
67
 
64
- ### Opción Recomendada: Setup Interactivo
68
+ ### 🌟 Opción Recomendada: Bootstrap Multibot
69
+
70
+ El template ahora soporta **múltiples bots** desde un mismo proyecto. Usa el comando `bootstrap` para configurar todo automáticamente:
71
+
72
+ ```bash
73
+ # Bootstrap interactivo completo (recomendado)
74
+ bun run bootstrap
75
+
76
+ # Listar bots disponibles desde BotFather
77
+ bun run bootstrap --list
78
+
79
+ # Usar bot específico
80
+ bun run bootstrap --bot mybot123bot
81
+
82
+ # Reutilizar configuración existente sin prompts
83
+ bun run bootstrap --reuse
84
+ ```
85
+
86
+ El bootstrap te guiará paso a paso:
87
+
88
+ 1. **Credenciales API** (si no las tienes): Tu API ID y Hash de https://my.telegram.org
89
+ 2. **Bot Selection**: Crear nuevo bot o reutilizar uno existente
90
+ 3. **Group Selection**: Crear nuevo grupo/forum o reutilizar existente
91
+ 4. **Topics Selection**: Crear topics para organización (Control, Logs, Config, Bugs)
92
+ 5. **Listo!**: Tu bot está configurado y listo para usar
93
+
94
+ ### Opción Manual: Setup Interactivo
65
95
 
66
96
  ```bash
67
97
  bun run setup
@@ -75,34 +105,156 @@ El comando te preguntará:
75
105
  4. **Streaming de logs** - Opcional, para ver logs en Telegram
76
106
  5. **Comandos de control** - Opcional, para comandos admin
77
107
 
78
- ### Opción Manual: Editar Archivo .env
108
+ ### Opción Manual Avanzada: Editar Archivo .env
79
109
 
80
- ```bash
81
- cp core/.env.example core/.env.local
82
- nano core/.env.local
83
- ```
84
-
85
- Edita las variables mínimas:
110
+ > **NOTA**: El sistema ahora usa la estructura `.envs/{bot}/{environment}.env` para multibot.
86
111
 
87
112
  ```bash
113
+ # Crear directorio para tu bot
114
+ mkdir -p core/.envs/mybot123bot
115
+
116
+ # Crear archivo de entorno local
117
+ cat > core/.envs/mybot123bot/local.env << 'EOF'
88
118
  # Required
89
119
  TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
90
120
  TG_MODE=polling
91
121
  TG_ENV=local
122
+ EOF
123
+ ```
124
+
125
+ ### Sistema Multibot
126
+
127
+ El template soporta gestión de **múltiples bots** desde un mismo proyecto:
128
+
129
+ #### Estructura de Directorios
130
+
131
+ ```
132
+ core/.envs/
133
+ ├── mybot123bot/
134
+ │ ├── local.env # Configuración local
135
+ │ ├── staging.env # Configuración staging
136
+ │ ├── production.env # Configuración production
137
+ │ └── metadata.json # Metadatos del bot
138
+ ├── anotherbot456bot/
139
+ │ ├── local.env
140
+ │ ├── staging.env
141
+ │ └── production.env
142
+ └── .active -> mybot123bot # Symlink al bot activo
143
+ ```
144
+
145
+ #### Comandos de Gestión de Bots
146
+
147
+ ```bash
148
+ # Listar todos los bots configurados
149
+ bun run bot list
150
+
151
+ # Establecer bot activo
152
+ bun run bot use mybot123bot
153
+
154
+ # Ver información detallada de un bot
155
+ bun run bot info mybot123bot
156
+
157
+ # Eliminar configuración de un bot
158
+ bun run bot delete mybot123bot
159
+
160
+ # Migrar .envs antiguos a nueva estructura
161
+ bun run bot migrate
162
+ ```
163
+
164
+ #### Selección de Bot Activo
165
+
166
+ Hay tres formas de seleccionar el bot activo:
167
+
168
+ 1. **Vía symlink .active** (automático con `bot use`):
169
+ ```bash
170
+ bun run bot use mybot123bot
171
+ ```
172
+
173
+ 2. **Vía variable de entorno**:
174
+ ```bash
175
+ TG_BOT=mybot123bot bun run dev
176
+ ```
177
+
178
+ 3. **Automático**: El bot configurado más recientemente se activa automáticamente
179
+
180
+ ### Opción Automática: Bootstrap Completo (Método Anterior)
181
+
182
+ > **"BotFather Personal"** - Automatiza TODO el proceso de creación
183
+
184
+ Si no has creado el bot todavía, puedes usar `bootstrap` para:
185
+
186
+ 1. **Crear el bot automáticamente** vía @BotFather
187
+ 2. **Crear un grupo/forum** para el bot
188
+ 3. **Añadir el bot como admin** del grupo
189
+ 4. **Crear topics** automáticamente (General, Control, Logs, Config, Bugs)
190
+ 5. **Configurar todos los IDs** en el `.env`
191
+
192
+ ```bash
193
+ # Requiere credenciales MTProto API (ver abajo)
194
+ bun run bootstrap
92
195
  ```
93
196
 
197
+ <details>
198
+ <summary>💡 ¿Cómo obtener credenciales MTProto API?</summary>
199
+
200
+ 1. Ve a [https://my.telegram.org](https://my.telegram.org)
201
+ 2. Log in con tu número de teléfono
202
+ 3. Click en "API development tools"
203
+ 4. Llena el formulario:
204
+ - **App title**: My Bot App
205
+ - **Short name**: mybotapp
206
+ - **Platform**: Desktop o Web
207
+ 5. Click "Create application"
208
+ 6. Copia el `api_id` y `api_hash`
209
+
210
+ > Puedes guardar estas credenciales en tu `.env` para evitar re-pedirlas:
211
+ > ```bash
212
+ > # MTProto API Credentials (for bootstrap command)
213
+ > TG_API_ID=12345678
214
+ > TG_API_HASH=abc123def456789...
215
+ > ```
216
+
217
+ </details>
218
+
219
+ **Ventajas del Bootstrap:**
220
+
221
+ | Feature | Bootstrap | Manual |
222
+ |---------|-----------|--------|
223
+ | Tiempo total | ~3-5 minutos | ~10-15 minutos |
224
+ | Creación de bot | Automático | Hablar con @BotFather |
225
+ | Creación de grupo | Automático | Manual en Telegram |
226
+ | Creación de topics | Automática | Manual o comando separado |
227
+ | IDs detection | Automático | Requiere auto-configure |
228
+
229
+ > **Ver documentación completa**: [CLI Commands - Bootstrap](./cli-commands.md#bootstrap-command)
230
+
94
231
  ## Paso 5: Verificar Configuración
95
232
 
233
+ > **ALTAMENTE RECOMENDADO** después de setup
234
+
96
235
  ```bash
97
236
  bun run doctor
98
237
  ```
99
238
 
100
- Este comando diagnostica tu configuración:
239
+ Este comando diagnostica tu configuración y valida que todo esté correcto:
101
240
 
102
- - Dependencias instaladas
103
- - ✓ Archivos .env configurados
104
- - Token de bot válido
105
- - Puertos disponibles
241
+ ### Checks que Realiza
242
+
243
+ | Check | Descripción |
244
+ | ----- | ----------- |
245
+ | ✓ Node.js version | Versión >= 20 |
246
+ | ✓ Bun installation | Bun está instalado |
247
+ | ✓ Dependencies | Todas las dependencias instaladas |
248
+ | ✓ Environment files | Archivos .env existen |
249
+ | ✓ Environment variables | Variables requeridas seteadas |
250
+ | ✓ Bot token validation | Token válido contra Telegram API |
251
+ | ✓ Control commands | Configuración de comandos de control |
252
+ | ✓ Temp directory | core/tmp es writable |
253
+ | ✓ Logs directory | core/logs existe |
254
+ | ✓ Port availability | Puerto 3000 disponible |
255
+ | ✓ Git ignore | .env files excluidos de git |
256
+
257
+ ### Output Esperado
106
258
 
107
259
  Deberías ver:
108
260
 
@@ -195,6 +347,8 @@ Ver [Troubleshooting](./troubleshooting.mdx) para más detalles.
195
347
 
196
348
  ## Resumen Rápido
197
349
 
350
+ ### Flujo Manual (con bot ya creado)
351
+
198
352
  ```bash
199
353
  # 1. Clonar el template
200
354
  git clone <repo>
@@ -206,7 +360,7 @@ bun install
206
360
  # 3. Configurar entorno (setup interactivo)
207
361
  bun run setup
208
362
 
209
- # 4. Verificar configuración
363
+ # 4. Verificar configuración (recomendado)
210
364
  bun run doctor
211
365
 
212
366
  # 5. Arrancar en desarrollo
@@ -216,6 +370,39 @@ bun run dev
216
370
  # Envía /start a tu bot
217
371
  ```
218
372
 
373
+ ### Flujo Automático (Bootstrap)
374
+
375
+ ```bash
376
+ # 1. Clonar el template
377
+ git clone <repo>
378
+ cd mks-telegram-bot
379
+
380
+ # 2. Instalar dependencias
381
+ bun install
382
+
383
+ # 3. Obtener credenciales MTProto (my.telegram.org)
384
+ # TG_API_ID=12345678
385
+ # TG_API_HASH=abc123def456789...
386
+
387
+ # 4. Bootstrap automático (crea bot, grupo, topics)
388
+ bun run bootstrap
389
+
390
+ # 5. Verificar configuración (recomendado)
391
+ bun run doctor
392
+
393
+ # 6. Arrancar en desarrollo
394
+ bun run dev
395
+
396
+ # 7. Probar en Telegram
397
+ # Envía /start a tu bot
398
+ ```
399
+
400
+ > **¿Cuál usar?**
401
+ > - **Bootstrap** - Si no has creado el bot todavía (~3-5 min total)
402
+ > - **Manual** - Si ya tienes el token de @BotFather (~10-15 min total)
403
+ > - **Siempre** ejecuta `bun run doctor` después del setup para verificar
404
+
405
+
219
406
  ## Referencias
220
407
 
221
408
  - **@BotFather** - [@BotFather en Telegram](https://t.me/BotFather)
@@ -5,8 +5,7 @@
5
5
  "type": "module",
6
6
  "workspaces": [
7
7
  "core",
8
- "packages/*",
9
- "apps/*"
8
+ "packages/*"
10
9
  ],
11
10
  "scripts": {
12
11
  "dev": "bun run --filter @mks2508/telegram-bot-core dev",
@@ -40,10 +39,15 @@
40
39
  "typescript": "^5"
41
40
  },
42
41
  "dependencies": {
42
+ "@mks2508/telegram-message-builder": "0.3.1",
43
+ "@mks2508/telegram-bot-utils": "workspace:*",
43
44
  "@inquirer/prompts": "^8.1.0",
44
45
  "chalk": "^5.6.2",
45
46
  "commander": "^14.0.2",
46
47
  "dotenv": "^17.2.3",
47
- "glob": "^13.0.0"
48
+ "glob": "^13.0.0",
49
+ "ora": "^9.0.0",
50
+ "telegraf": "^4.16.3",
51
+ "telegram": "^2.26.22"
48
52
  }
49
53
  }
@@ -2,11 +2,22 @@
2
2
  "name": "@mks2508/telegram-bot-utils",
3
3
  "version": "0.1.0",
4
4
  "type": "module",
5
+ "scripts": {
6
+ "build": "rolldown --config rolldown.config.ts && tsgo --emitDeclarationOnly",
7
+ "dev": "bun run --watch src/index.ts",
8
+ "typecheck": "tsgo --noEmit"
9
+ },
5
10
  "exports": {
6
- ".": "./src/index.ts"
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
7
15
  },
8
16
  "dependencies": {
9
17
  "@mks2508/better-logger": "^4.0.0",
10
18
  "@mks2508/no-throw": "^0.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "rolldown": "^1.0.0-beta.58"
11
22
  }
12
23
  }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'rolldown';
2
+
3
+ export default defineConfig({
4
+ input: './src/index.ts',
5
+ output: {
6
+ file: './dist/index.js',
7
+ format: 'esm',
8
+ sourcemap: true,
9
+ },
10
+ external: ['@mks2508/better-logger', '@mks2508/no-throw'],
11
+ });
@@ -30,6 +30,7 @@ export const botLogger = component('Bot')
30
30
  export const configLogger = component('Config')
31
31
  export const commandLogger = component('Command')
32
32
  export const healthLogger = component('Health')
33
+ export const infoLogger = component('Info')
33
34
  export const controlLogger = component('Control')
34
35
  export const streamLogger = component('LogStream')
35
36
  export const errorLogger = component('Error')
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist",
6
+ "declarationDir": "./dist"
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["node_modules", "dist"]
10
+ }
@@ -55,6 +55,7 @@ async function handleDoctor(): Promise<void> {
55
55
  checks.push(await checkEnvFile())
56
56
  checks.push(await checkRequiredEnvVars())
57
57
  checks.push(await checkBotToken())
58
+ checks.push(await checkControlCommands())
58
59
  checks.push(await checkTmpDirectory())
59
60
  checks.push(await checkLogsDirectory())
60
61
  checks.push(await checkPorts())
@@ -302,6 +303,67 @@ async function checkBotToken(): Promise<CheckResult> {
302
303
  }
303
304
  }
304
305
 
306
+ async function checkControlCommands(): Promise<CheckResult> {
307
+ const envPath = join(process.cwd(), 'core', '.env.local')
308
+
309
+ if (!existsSync(envPath)) {
310
+ return {
311
+ name: 'Control commands',
312
+ status: 'warn',
313
+ message: 'No .env.local file found',
314
+ }
315
+ }
316
+
317
+ try {
318
+ const content = await readFile(envPath, 'utf-8')
319
+ const hasControlChatId = content.includes('TG_CONTROL_CHAT_ID=') && !content.includes('TG_CONTROL_CHAT_ID=#')
320
+
321
+ if (hasControlChatId) {
322
+ const match = content.match(/TG_CONTROL_CHAT_ID=([^\n]+)/)
323
+ const chatId = match?.[1]?.trim()
324
+
325
+ if (!chatId || chatId === 'your_control_chat_id_here' || chatId.startsWith('#')) {
326
+ return {
327
+ name: 'Control commands',
328
+ status: 'warn',
329
+ message: 'Control chat ID not configured',
330
+ details: 'Control commands (/stop, /restart) are disabled. Run: bun run setup',
331
+ }
332
+ }
333
+
334
+ const hasAuthorizedUsers = content.includes('TG_AUTHORIZED_USER_IDS=')
335
+
336
+ if (!hasAuthorizedUsers) {
337
+ return {
338
+ name: 'Control commands',
339
+ status: 'warn',
340
+ message: 'Control enabled but no authorized users',
341
+ details: 'Add TG_AUTHORIZED_USER_IDS to .env.local',
342
+ }
343
+ }
344
+
345
+ return {
346
+ name: 'Control commands',
347
+ status: 'pass',
348
+ message: 'Control commands enabled',
349
+ }
350
+ }
351
+
352
+ return {
353
+ name: 'Control commands',
354
+ status: 'warn',
355
+ message: 'Control commands disabled',
356
+ details: 'Enable with TG_CONTROL_CHAT_ID. Run: bun run setup',
357
+ }
358
+ } catch {
359
+ return {
360
+ name: 'Control commands',
361
+ status: 'warn',
362
+ message: 'Could not read .env.local',
363
+ }
364
+ }
365
+ }
366
+
305
367
  async function checkTmpDirectory(): Promise<CheckResult> {
306
368
  const tmpPath = join(process.cwd(), 'core', 'tmp')
307
369