create-bunspace 0.2.5 → 0.3.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.
Files changed (53) hide show
  1. package/dist/templates/telegram-bot/CLAUDE.deploy.md +2 -3
  2. package/dist/templates/telegram-bot/CLAUDE.dev.md +304 -5
  3. package/dist/templates/telegram-bot/CLAUDE.md +166 -89
  4. package/dist/templates/telegram-bot/README.md +252 -129
  5. package/dist/templates/telegram-bot/bun.lock +146 -3
  6. package/dist/templates/telegram-bot/core/.env.example +6 -0
  7. package/dist/templates/telegram-bot/core/src/config/env.ts +130 -1
  8. package/dist/templates/telegram-bot/core/src/config/logging.ts +3 -1
  9. package/dist/templates/telegram-bot/core/src/handlers/config-export.ts +122 -0
  10. package/dist/templates/telegram-bot/core/src/handlers/control.ts +37 -11
  11. package/dist/templates/telegram-bot/core/src/handlers/health.ts +21 -26
  12. package/dist/templates/telegram-bot/core/src/handlers/info.ts +191 -0
  13. package/dist/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
  14. package/dist/templates/telegram-bot/core/src/handlers/logs.ts +14 -7
  15. package/dist/templates/telegram-bot/core/src/index.ts +29 -0
  16. package/dist/templates/telegram-bot/core/src/utils/formatters.ts +55 -19
  17. package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
  18. package/dist/templates/telegram-bot/core/src/utils/message-builder.ts +180 -0
  19. package/dist/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
  20. package/dist/templates/telegram-bot/docs/cli-commands.md +514 -5
  21. package/dist/templates/telegram-bot/docs/environment.md +191 -3
  22. package/dist/templates/telegram-bot/docs/getting-started.md +202 -15
  23. package/dist/templates/telegram-bot/package.json +5 -2
  24. package/dist/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
  25. package/dist/templates/telegram-bot/tools/commands/doctor.ts +62 -0
  26. package/dist/templates/telegram-bot/tools/commands/setup.ts +984 -170
  27. package/package.json +1 -1
  28. package/templates/telegram-bot/CLAUDE.deploy.md +2 -3
  29. package/templates/telegram-bot/CLAUDE.dev.md +304 -5
  30. package/templates/telegram-bot/CLAUDE.md +166 -89
  31. package/templates/telegram-bot/README.md +252 -129
  32. package/templates/telegram-bot/bun.lock +146 -3
  33. package/templates/telegram-bot/core/.env.example +6 -0
  34. package/templates/telegram-bot/core/src/config/env.ts +130 -1
  35. package/templates/telegram-bot/core/src/config/logging.ts +3 -1
  36. package/templates/telegram-bot/core/src/handlers/config-export.ts +122 -0
  37. package/templates/telegram-bot/core/src/handlers/control.ts +37 -11
  38. package/templates/telegram-bot/core/src/handlers/health.ts +21 -26
  39. package/templates/telegram-bot/core/src/handlers/info.ts +191 -0
  40. package/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
  41. package/templates/telegram-bot/core/src/handlers/logs.ts +14 -7
  42. package/templates/telegram-bot/core/src/index.ts +29 -0
  43. package/templates/telegram-bot/core/src/utils/formatters.ts +55 -19
  44. package/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
  45. package/templates/telegram-bot/core/src/utils/message-builder.ts +180 -0
  46. package/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
  47. package/templates/telegram-bot/docs/cli-commands.md +514 -5
  48. package/templates/telegram-bot/docs/environment.md +191 -3
  49. package/templates/telegram-bot/docs/getting-started.md +202 -15
  50. package/templates/telegram-bot/package.json +5 -2
  51. package/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
  52. package/templates/telegram-bot/tools/commands/doctor.ts +62 -0
  53. package/templates/telegram-bot/tools/commands/setup.ts +984 -170
@@ -1,9 +1,9 @@
1
1
  # CLAUDE.md - mks-telegram-bot
2
2
 
3
3
  > **Template**: Monorepo para bots de Telegram con Bun, Telegraf y TypeScript
4
- > **Versión**: 0.1.0
4
+ > **Versión**: 0.3.0
5
5
 
6
- Template monorepo diseñado para ser usado como `bun create mks2508/mks-telegram-bot` o como GitHub template repository.
6
+ Template monorepo diseñado para ser usado como GitHub template repository o clonado directamente.
7
7
 
8
8
  **Objetivo**: Template reutilizable para crear bots de Telegram con las mejores prácticas, tipado estricto y arquitectura modular.
9
9
 
@@ -13,13 +13,13 @@ Template monorepo diseñado para ser usado como `bun create mks2508/mks-telegram
13
13
 
14
14
  ```bash
15
15
  # Clonar o usar como template
16
- bun create mks2508/mks-telegram-bot my-bot
16
+ gh repo create my-bot --template MKS2508/mks-telegram-bot
17
17
 
18
18
  # Instalar dependencias
19
19
  bun install
20
20
 
21
- # Configurar variables de entorno
22
- cp core/.env.example core/.env
21
+ # Bootstrap interactivo (crea bot, grupo, topics)
22
+ bunx @mks2508/telegram-bot-manager bootstrap
23
23
 
24
24
  # Desarrollo
25
25
  bun run dev
@@ -35,25 +35,7 @@ Este template tiene contextos separados por dominio:
35
35
  | ------- | --------- |
36
36
  | [CLAUDE.dev.md](./CLAUDE.dev.md) | Desarrollo, patterns, testing |
37
37
  | [CLAUDE.deploy.md](./CLAUDE.deploy.md) | Deployment, Docker, entornos |
38
- | [docs/](./docs/) | Documentación web (MDX, futuro) |
39
-
40
- ### CLAUDE.dev.md
41
-
42
- Ver [CLAUDE.dev.md](./CLAUDE.dev.md) para:
43
- - Development standards y code style
44
- - Cómo agregar commands y middleware
45
- - Testing patterns
46
- - Result type pattern y Singleton pattern
47
- - Better Logger usage
48
-
49
- ### CLAUDE.deploy.md
50
-
51
- Ver [CLAUDE.deploy.md](./CLAUDE.deploy.md) para:
52
- - Multi-environment (local, staging, production)
53
- - Multi-instance management
54
- - Docker deployment
55
- - ngrok integration
56
- - VPS deployment guide
38
+ | [docs/](./docs/) | Documentación detallada |
57
39
 
58
40
  ---
59
41
 
@@ -61,76 +43,163 @@ Ver [CLAUDE.deploy.md](./CLAUDE.deploy.md) para:
61
43
 
62
44
  When modifying this codebase, prioritize understanding:
63
45
 
46
+ ### Core Bot (`core/`)
64
47
  - `core/src/index.ts` - Bot entry point, command registration
65
- - `core/src/config/env.ts` - Environment schema validation
48
+ - `core/src/config/env.ts` - Environment schema validation, multibot loading
49
+ - `core/src/handlers/` - Command handlers (health, control, logs, etc.)
50
+ - `core/src/middleware/` - Telegraf middleware (auth, error, topics)
66
51
  - `core/src/utils/instance-manager.ts` - Multi-instance locking
67
- - `packages/utils/src/` - Shared utilities (logger, result)
68
52
 
69
- ---
53
+ ### Local CLI Tools (`tools/`)
54
+ - `tools/commands/setup.ts` - Setup manual de entorno
55
+ - `tools/commands/doctor.ts` - Diagnóstico de configuración
56
+ - `tools/commands/status.ts` - Estado de instancias
57
+ - `tools/commands/ngrok.ts` - Túnel ngrok para webhooks
70
58
 
71
- ## Session Context Template
59
+ ### Bot Management (External Package)
72
60
 
73
- When starting a new session, include:
74
- - **User's goal**: developing vs deploying vs extending
75
- - **Current environment**: local/staging/production
76
- - **Any errors or issues encountered**: Paste error messages
61
+ Para gestión de bots (bootstrap, configuración BotFather, multibot), usar **@mks2508/telegram-bot-manager**:
62
+
63
+ ```bash
64
+ # Bootstrap completo (bot + grupo + topics)
65
+ bunx @mks2508/telegram-bot-manager bootstrap
66
+
67
+ # Listar bots desde BotFather e importar
68
+ bunx @mks2508/telegram-bot-manager bootstrap --list
69
+
70
+ # Gestión de bots configurados
71
+ bunx @mks2508/telegram-bot-manager bot list
72
+ bunx @mks2508/telegram-bot-manager bot use mybot123bot
73
+ bunx @mks2508/telegram-bot-manager bot info mybot123bot
74
+ bunx @mks2508/telegram-bot-manager bot delete mybot123bot
75
+
76
+ # Configurar bot via BotFather
77
+ bunx @mks2508/telegram-bot-manager configure commands mybot123bot
78
+ bunx @mks2508/telegram-bot-manager configure description mybot123bot
79
+ bunx @mks2508/telegram-bot-manager configure about mybot123bot
80
+ bunx @mks2508/telegram-bot-manager configure name mybot123bot
81
+
82
+ # Crear topics en grupo forum
83
+ bunx @mks2508/telegram-bot-manager topics
84
+ ```
77
85
 
78
86
  ---
79
87
 
80
- ## Monorepo Structure
88
+ ## Project Structure
81
89
 
82
90
  ```
83
91
  mks-telegram-bot/
84
- ├── core/ # @mks2508/telegram-bot-core
85
- │ ├── .env.local # Local development
86
- │ ├── .env.staging # Staging environment
87
- │ ├── .env.production # Production environment
88
- │ ├── tmp/ # Instance lock files
89
- └── src/ # Bot source code
90
- ├── packages/ # Shared code
91
- │ └── utils/ # @mks2508/telegram-bot-utils
92
- ├── tools/ # CLI tools
93
- └── commands/ # ngrok, status
94
- ├── apps/ # Future: examples, docs
95
- ├── docs/ # Future MDX site
96
- ├── Dockerfile # Multi-stage build
97
- └── docker-compose.yml # Local dev containers
92
+ ├── core/ # @mks2508/telegram-bot-core (Bot principal)
93
+ │ ├── .envs/ # Configuraciones multibot
94
+ ├── {botUsername}/
95
+ │ │ ├── local.env
96
+ │ │ ├── staging.env
97
+ │ │ ├── production.env
98
+ │ │ │ └── metadata.json
99
+ └── .active -> {botUsername}
100
+ ├── src/
101
+ │ ├── index.ts # Entry point
102
+ │ │ ├── config/ # Configuration & env validation (Zod)
103
+ │ │ ├── handlers/ # Command handlers
104
+ │ │ ├── middleware/ # Telegraf middleware
105
+ │ │ ├── types/ # TypeScript types
106
+ │ │ └── utils/ # Utilities (instance-manager, etc.)
107
+ │ ├── logs/ # Log files (rotated)
108
+ │ ├── tmp/ # Instance lock files (.pid, .lock)
109
+ │ └── .env.example # Template de variables
110
+ ├── tools/ # CLI tools locales
111
+ │ ├── index.ts # CLI entry point
112
+ │ └── commands/
113
+ │ ├── setup.ts # Setup manual interactivo
114
+ │ ├── doctor.ts # Diagnóstico de configuración
115
+ │ ├── status.ts # Estado de instancias
116
+ │ └── ngrok.ts # Integración ngrok
117
+ ├── docs/ # Documentación
118
+ │ ├── getting-started.md
119
+ │ ├── environment.md
120
+ │ ├── cli-commands.md
121
+ │ ├── development.md
122
+ │ └── troubleshooting.md
123
+ ├── apps/ # Apps adicionales (futuro)
124
+ ├── Dockerfile # Multi-stage build
125
+ ├── docker-compose.yml # Containers locales
126
+ └── package.json # Root workspace config
98
127
  ```
99
128
 
100
129
  ---
101
130
 
102
- ## Commands
131
+ ## Commands Reference
132
+
133
+ ### Local Development Commands
103
134
 
104
135
  ```bash
105
136
  # Development
106
137
  bun run dev # Hot reload (watch mode)
107
138
  bun run start # Production mode
108
139
 
109
- # CLI tools
110
- bun run status # Show running instances
111
- bun run ngrok # Start ngrok tunnel
112
-
113
140
  # Quality
114
- bun run typecheck # Type check (tsgo ~10x faster)
141
+ bun run typecheck # Type check (tsgo - ~10x faster)
115
142
  bun run lint # Lint (oxlint)
116
143
  bun run format # Format (prettier)
144
+ bun run test # Run tests
145
+
146
+ # Local CLI tools
147
+ bun run setup # Setup manual de entorno
148
+ bun run setup:staging # Setup staging
149
+ bun run setup:production # Setup production
150
+ bun run doctor # Diagnóstico de configuración
151
+ bun run ngrok # Start ngrok tunnel
152
+ bun run cli status # Ver instancias corriendo
153
+
154
+ # Maintenance
155
+ bun run clean:logs # Limpiar logs y locks
156
+ bun run clean:all # Limpiar todo
157
+ ```
158
+
159
+ ### Bot Management Commands (External)
160
+
161
+ ```bash
162
+ # Usar @mks2508/telegram-bot-manager via bunx/npx:
163
+
164
+ # Bootstrap
165
+ bunx @mks2508/telegram-bot-manager bootstrap # Interactivo completo
166
+ bunx @mks2508/telegram-bot-manager bootstrap --list # Listar e importar bots
167
+ bunx @mks2508/telegram-bot-manager bootstrap --auto # Auto-generado sin prompts
168
+
169
+ # Bot management
170
+ bunx @mks2508/telegram-bot-manager bot list # Listar bots configurados
171
+ bunx @mks2508/telegram-bot-manager bot use <username> # Cambiar bot activo
172
+ bunx @mks2508/telegram-bot-manager bot info <username># Info de bot
173
+ bunx @mks2508/telegram-bot-manager bot delete <user> # Eliminar bot
174
+ bunx @mks2508/telegram-bot-manager bot migrate # Migrar .env antiguos
175
+
176
+ # Configure via BotFather
177
+ bunx @mks2508/telegram-bot-manager configure commands <user>
178
+ bunx @mks2508/telegram-bot-manager configure description <user>
179
+ bunx @mks2508/telegram-bot-manager configure about <user>
180
+ bunx @mks2508/telegram-bot-manager configure name <user>
181
+
182
+ # Topics
183
+ bunx @mks2508/telegram-bot-manager topics
117
184
  ```
118
185
 
119
186
  ---
120
187
 
121
188
  ## Environment Variables
122
189
 
123
- ### Multi-Environment Support
190
+ ### Multibot Structure
124
191
 
125
- El proyecto soporta múltiples entornos con archivos `.env` separados:
192
+ El proyecto soporta **gestión multibot** con estructura `.envs/`:
126
193
 
127
- | Archivo | Uso |
128
- | ------- | --- |
129
- | `core/.env.local` | Desarrollo local (polling mode) |
130
- | `core/.env.staging` | Testing con bot de test |
131
- | `core/.env.production` | Producción con bot real |
132
-
133
- La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
194
+ ```
195
+ core/.envs/
196
+ ├── {botUsername}/
197
+ │ ├── local.env # Configuración local del bot
198
+ │ ├── staging.env # Configuración staging del bot
199
+ │ ├── production.env # Configuración production del bot
200
+ │ └── metadata.json # Metadatos del bot
201
+ └── .active -> {botUsername} # Symlink al bot activo
202
+ ```
134
203
 
135
204
  ### Required Variables
136
205
 
@@ -139,13 +208,18 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
139
208
  | `TG_BOT_TOKEN` | string | Bot token from @BotFather |
140
209
  | `TG_MODE` | enum | `polling` or `webhook` |
141
210
 
142
- ### Instance Detection Variables
211
+ ### Optional Variables
143
212
 
144
213
  | Variable | Default | Description |
145
214
  | -------- | ------- | ----------- |
146
215
  | `TG_ENV` | `local` | Environment: local/staging/production |
147
216
  | `TG_INSTANCE_NAME` | `mks-bot` | Unique instance name for locking |
148
217
  | `TG_INSTANCE_CHECK` | `true` | Enable instance conflict detection |
218
+ | `TG_AUTHORIZED_USER_IDS` | - | Comma-separated user IDs for control commands |
219
+ | `TG_CONTROL_CHAT_ID` | - | Chat ID for control commands |
220
+ | `TG_CONTROL_TOPIC_ID` | - | Topic ID for control commands |
221
+ | `TG_LOG_CHAT_ID` | - | Chat ID for log streaming |
222
+ | `TG_LOG_TOPIC_ID` | - | Topic ID for log streaming |
149
223
 
150
224
  ---
151
225
 
@@ -158,11 +232,9 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
158
232
  | **TypeScript** | Language | 5.9+ |
159
233
  | **tsgo** | Type-checking | native-preview |
160
234
  | **Zod** | Schema validation | 3.24+ |
161
- | **Better Logger** | Logging | 4.0.0 |
162
- | **@mks2508/no-throw** | Result type | 0.1.0 |
163
235
  | **oxlint** | Linting | latest |
164
236
  | **prettier** | Formatting | 3.4+ |
165
- | **commander** | CLI framework | 14.0+ |
237
+ | **@mks2508/telegram-bot-manager** | Bot management (external) | 0.1.1+ |
166
238
 
167
239
  ---
168
240
 
@@ -176,10 +248,10 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
176
248
  ┌─────────────────┼─────────────────┐
177
249
  │ │ │
178
250
  ┌────▼────┐ ┌───────▼───────┐ ┌──────▼──────┐
179
- │Middleware│ │ Handlers │ │ BotManager
180
- │ • auth │ │ • health │ │ InstanceMgr
181
- │ • error │ │ • control │ │ • stats
182
- │ • topics │ │ • logs │ │ • lifecycle
251
+ │Middleware│ │ Handlers │ │ Config
252
+ │ • auth │ │ • health │ │ env.ts
253
+ │ • error │ │ • control │ │ • Zod
254
+ │ • topics │ │ • logs │ │ validation
183
255
  └──────────┘ └──────────────┘ └─────────────┘
184
256
  │ │
185
257
  └────────────┬───────────────────┘
@@ -188,6 +260,7 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
188
260
  │ InstanceManager │
189
261
  │ • acquireLock │
190
262
  │ • releaseLock │
263
+ │ • PID files │
191
264
  └─────────────────┘
192
265
  ```
193
266
 
@@ -203,6 +276,7 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
203
276
  | `/health` | handleHealth | Bot health status |
204
277
  | `/uptime` | handleUptime | Uptime information |
205
278
  | `/stats` | handleStats | Bot statistics |
279
+ | `/getinfo` | inline | Get User ID, Chat ID, Topic ID |
206
280
  | `/logs` | handleLogs | Log streaming status |
207
281
 
208
282
  ### Control Commands (requires auth)
@@ -220,32 +294,16 @@ La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
220
294
 
221
295
  ### Before Commit
222
296
 
223
- - [ ] `bun run typecheck` → 0 errores
297
+ - [ ] `bun run typecheck` → 0 errors
224
298
  - [ ] `bun run lint` → 0 warnings, 0 errors
225
299
  - [ ] `bun test` → all tests pass (if tests exist)
226
- - [ ] No `console.*` (use Better Logger)
227
300
 
228
301
  ### Code Style
229
302
 
230
303
  - TypeScript strict mode enabled
231
304
  - `noUncheckedIndexedAccess: true` - arrays need undefined checks
232
305
  - Semi: false, singleQuote: true
233
- - Result type pattern para error handling
234
-
235
- ---
236
-
237
- ## Documentation Web
238
-
239
- Ver [docs/](./docs/) para documentación completa (futuro MDX site con Astro/Starlight).
240
-
241
- ---
242
-
243
- ## Future Apps
244
-
245
- El directorio `apps/` está preparado para:
246
- - `apps/example/` - Ejemplo de bot completo
247
- - `apps/docs/` - Documentación interactiva
248
- - `apps/cli/` - CLI extendida para gestión
306
+ - No console.* - use structured logger
249
307
 
250
308
  ---
251
309
 
@@ -267,7 +325,7 @@ El template soporta múltiples instancias simultáneas con detección de conflic
267
325
 
268
326
  ```bash
269
327
  # Ver instancias corriendo
270
- bun run status
328
+ bun run cli status
271
329
 
272
330
  # Iniciar en entorno específico
273
331
  TG_ENV=staging bun run start
@@ -275,6 +333,25 @@ TG_ENV=staging bun run start
275
333
 
276
334
  ---
277
335
 
336
+ ## Relationship with @mks2508/telegram-bot-manager
337
+
338
+ Este template usa **@mks2508/telegram-bot-manager** como paquete externo para:
339
+
340
+ - **Bootstrap**: Crear bots via BotFather automáticamente
341
+ - **Group Management**: Crear grupos/forums con topics
342
+ - **Multibot Management**: Gestionar múltiples bots configurados
343
+ - **BotFather Configuration**: Configurar commands, description, about, name
344
+
345
+ El paquete se usa via `bunx` (no se instala como dependencia):
346
+
347
+ ```bash
348
+ bunx @mks2508/telegram-bot-manager <command>
349
+ ```
350
+
351
+ **Documentación del paquete**: https://github.com/MKS2508/telegram-bot-manager
352
+
353
+ ---
354
+
278
355
  ## License
279
356
 
280
357
  MIT