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.
Files changed (182) hide show
  1. package/README.md +181 -0
  2. package/dist/bin.js +5755 -0
  3. package/dist/templates/monorepo/CLAUDE.md +164 -0
  4. package/dist/templates/monorepo/LICENSE +21 -0
  5. package/dist/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
  6. package/dist/templates/monorepo/README.md +74 -0
  7. package/dist/templates/monorepo/SYNC_VERIFICATION.md +1 -0
  8. package/dist/templates/monorepo/apps/example/package.json +19 -0
  9. package/dist/templates/monorepo/apps/example/src/index.ts +23 -0
  10. package/dist/templates/monorepo/apps/example/src/types/index.ts +7 -0
  11. package/dist/templates/monorepo/apps/example/src/utils/index.ts +7 -0
  12. package/dist/templates/monorepo/core/packages/main/package.json +41 -0
  13. package/dist/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
  14. package/dist/templates/monorepo/core/packages/main/src/index.ts +80 -0
  15. package/dist/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
  16. package/dist/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
  17. package/dist/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
  18. package/dist/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
  19. package/dist/templates/monorepo/core/packages/utils/package.json +43 -0
  20. package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
  21. package/dist/templates/monorepo/core/packages/utils/src/index.ts +2 -0
  22. package/dist/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
  23. package/dist/templates/monorepo/core/packages/utils/src/result.ts +146 -0
  24. package/dist/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
  25. package/dist/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
  26. package/dist/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
  27. package/dist/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
  28. package/dist/templates/monorepo/oxlint.json +14 -0
  29. package/dist/templates/monorepo/package.json +39 -0
  30. package/dist/templates/monorepo/tsconfig.json +35 -0
  31. package/dist/templates/telegram-bot/.oxlintrc.json +33 -0
  32. package/dist/templates/telegram-bot/.prettierignore +5 -0
  33. package/dist/templates/telegram-bot/.prettierrc +26 -0
  34. package/dist/templates/telegram-bot/CLAUDE.deploy.md +356 -0
  35. package/dist/templates/telegram-bot/CLAUDE.dev.md +266 -0
  36. package/dist/templates/telegram-bot/CLAUDE.md +280 -0
  37. package/dist/templates/telegram-bot/Dockerfile +46 -0
  38. package/dist/templates/telegram-bot/README.md +245 -0
  39. package/dist/templates/telegram-bot/apps/.gitkeep +0 -0
  40. package/dist/templates/telegram-bot/bun.lock +208 -0
  41. package/dist/templates/telegram-bot/core/.env.example +71 -0
  42. package/dist/templates/telegram-bot/core/README.md +1067 -0
  43. package/dist/templates/telegram-bot/core/package.json +15 -0
  44. package/dist/templates/telegram-bot/core/src/config/env.ts +131 -0
  45. package/dist/templates/telegram-bot/core/src/config/index.ts +97 -0
  46. package/dist/templates/telegram-bot/core/src/config/logging.ts +110 -0
  47. package/dist/templates/telegram-bot/core/src/handlers/control.ts +85 -0
  48. package/dist/templates/telegram-bot/core/src/handlers/health.ts +83 -0
  49. package/dist/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
  50. package/dist/templates/telegram-bot/core/src/index.ts +161 -0
  51. package/dist/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
  52. package/dist/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
  53. package/dist/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
  54. package/dist/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
  55. package/dist/templates/telegram-bot/core/src/types/bot.ts +92 -0
  56. package/dist/templates/telegram-bot/core/src/types/constants.ts +50 -0
  57. package/dist/templates/telegram-bot/core/src/types/result.ts +1 -0
  58. package/dist/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
  59. package/dist/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
  60. package/dist/templates/telegram-bot/core/src/utils/commands.ts +63 -0
  61. package/dist/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
  62. package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
  63. package/dist/templates/telegram-bot/core/src/utils/memory.ts +33 -0
  64. package/dist/templates/telegram-bot/core/src/utils/result.ts +26 -0
  65. package/dist/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
  66. package/dist/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
  67. package/dist/templates/telegram-bot/core/tsconfig.json +9 -0
  68. package/dist/templates/telegram-bot/docker-compose.yml +37 -0
  69. package/dist/templates/telegram-bot/docs/cli-commands.md +377 -0
  70. package/dist/templates/telegram-bot/docs/development.md +363 -0
  71. package/dist/templates/telegram-bot/docs/environment.md +460 -0
  72. package/dist/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
  73. package/dist/templates/telegram-bot/docs/examples/simple-command.md +207 -0
  74. package/dist/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
  75. package/dist/templates/telegram-bot/docs/getting-started.md +223 -0
  76. package/dist/templates/telegram-bot/docs/troubleshooting.md +489 -0
  77. package/dist/templates/telegram-bot/package.json +49 -0
  78. package/dist/templates/telegram-bot/packages/utils/package.json +12 -0
  79. package/dist/templates/telegram-bot/packages/utils/src/index.ts +2 -0
  80. package/dist/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
  81. package/dist/templates/telegram-bot/packages/utils/src/result.ts +80 -0
  82. package/dist/templates/telegram-bot/tools/README.md +47 -0
  83. package/dist/templates/telegram-bot/tools/commands/doctor.ts +460 -0
  84. package/dist/templates/telegram-bot/tools/commands/index.ts +35 -0
  85. package/dist/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
  86. package/dist/templates/telegram-bot/tools/commands/setup.ts +368 -0
  87. package/dist/templates/telegram-bot/tools/commands/status.ts +140 -0
  88. package/dist/templates/telegram-bot/tools/index.ts +16 -0
  89. package/dist/templates/telegram-bot/tools/package.json +12 -0
  90. package/dist/templates/telegram-bot/tools/utils/index.ts +13 -0
  91. package/dist/templates/telegram-bot/tsconfig.json +22 -0
  92. package/dist/templates/telegram-bot/vitest.config.ts +29 -0
  93. package/package.json +35 -0
  94. package/templates/monorepo/CLAUDE.md +164 -0
  95. package/templates/monorepo/LICENSE +21 -0
  96. package/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
  97. package/templates/monorepo/README.md +74 -0
  98. package/templates/monorepo/apps/example/package.json +19 -0
  99. package/templates/monorepo/apps/example/src/index.ts +23 -0
  100. package/templates/monorepo/apps/example/src/types/index.ts +7 -0
  101. package/templates/monorepo/apps/example/src/utils/index.ts +7 -0
  102. package/templates/monorepo/core/packages/main/package.json +41 -0
  103. package/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
  104. package/templates/monorepo/core/packages/main/src/index.ts +80 -0
  105. package/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
  106. package/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
  107. package/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
  108. package/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
  109. package/templates/monorepo/core/packages/utils/package.json +43 -0
  110. package/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
  111. package/templates/monorepo/core/packages/utils/src/index.ts +2 -0
  112. package/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
  113. package/templates/monorepo/core/packages/utils/src/result.ts +146 -0
  114. package/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
  115. package/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
  116. package/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
  117. package/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
  118. package/templates/monorepo/oxlint.json +14 -0
  119. package/templates/monorepo/package.json +39 -0
  120. package/templates/monorepo/tsconfig.json +35 -0
  121. package/templates/telegram-bot/.oxlintrc.json +33 -0
  122. package/templates/telegram-bot/.prettierignore +5 -0
  123. package/templates/telegram-bot/.prettierrc +26 -0
  124. package/templates/telegram-bot/CLAUDE.deploy.md +356 -0
  125. package/templates/telegram-bot/CLAUDE.dev.md +266 -0
  126. package/templates/telegram-bot/CLAUDE.md +280 -0
  127. package/templates/telegram-bot/Dockerfile +46 -0
  128. package/templates/telegram-bot/README.md +245 -0
  129. package/templates/telegram-bot/apps/.gitkeep +0 -0
  130. package/templates/telegram-bot/bun.lock +208 -0
  131. package/templates/telegram-bot/core/.env.example +71 -0
  132. package/templates/telegram-bot/core/README.md +1067 -0
  133. package/templates/telegram-bot/core/package.json +15 -0
  134. package/templates/telegram-bot/core/src/config/env.ts +131 -0
  135. package/templates/telegram-bot/core/src/config/index.ts +97 -0
  136. package/templates/telegram-bot/core/src/config/logging.ts +110 -0
  137. package/templates/telegram-bot/core/src/handlers/control.ts +85 -0
  138. package/templates/telegram-bot/core/src/handlers/health.ts +83 -0
  139. package/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
  140. package/templates/telegram-bot/core/src/index.ts +161 -0
  141. package/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
  142. package/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
  143. package/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
  144. package/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
  145. package/templates/telegram-bot/core/src/types/bot.ts +92 -0
  146. package/templates/telegram-bot/core/src/types/constants.ts +50 -0
  147. package/templates/telegram-bot/core/src/types/result.ts +1 -0
  148. package/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
  149. package/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
  150. package/templates/telegram-bot/core/src/utils/commands.ts +63 -0
  151. package/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
  152. package/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
  153. package/templates/telegram-bot/core/src/utils/memory.ts +33 -0
  154. package/templates/telegram-bot/core/src/utils/result.ts +26 -0
  155. package/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
  156. package/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
  157. package/templates/telegram-bot/core/tsconfig.json +9 -0
  158. package/templates/telegram-bot/docker-compose.yml +37 -0
  159. package/templates/telegram-bot/docs/cli-commands.md +377 -0
  160. package/templates/telegram-bot/docs/development.md +363 -0
  161. package/templates/telegram-bot/docs/environment.md +460 -0
  162. package/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
  163. package/templates/telegram-bot/docs/examples/simple-command.md +207 -0
  164. package/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
  165. package/templates/telegram-bot/docs/getting-started.md +223 -0
  166. package/templates/telegram-bot/docs/troubleshooting.md +489 -0
  167. package/templates/telegram-bot/package.json +49 -0
  168. package/templates/telegram-bot/packages/utils/package.json +12 -0
  169. package/templates/telegram-bot/packages/utils/src/index.ts +2 -0
  170. package/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
  171. package/templates/telegram-bot/packages/utils/src/result.ts +80 -0
  172. package/templates/telegram-bot/tools/README.md +47 -0
  173. package/templates/telegram-bot/tools/commands/doctor.ts +460 -0
  174. package/templates/telegram-bot/tools/commands/index.ts +35 -0
  175. package/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
  176. package/templates/telegram-bot/tools/commands/setup.ts +368 -0
  177. package/templates/telegram-bot/tools/commands/status.ts +140 -0
  178. package/templates/telegram-bot/tools/index.ts +16 -0
  179. package/templates/telegram-bot/tools/package.json +12 -0
  180. package/templates/telegram-bot/tools/utils/index.ts +13 -0
  181. package/templates/telegram-bot/tsconfig.json +22 -0
  182. package/templates/telegram-bot/vitest.config.ts +29 -0
@@ -0,0 +1,460 @@
1
+ # Environment Configuration
2
+
3
+ Guía completa de configuración de variables de entorno para el bot.
4
+
5
+ ## Archivos de Entorno
6
+
7
+ El template soporta múltiples entornos con archivos `.env` separados:
8
+
9
+ | Archivo | Uso | Modo | Bot Token |
10
+ | ------- | --- | ---- | --------- |
11
+ | `core/.env.local` | Desarrollo local | Polling | Local dev token |
12
+ | `core/.env.staging` | Testing/Staging | Webhook | Test bot token |
13
+ | `core/.env.production` | Producción | Webhook | Real bot token |
14
+
15
+ ### Selección de Entorno
16
+
17
+ La variable `TG_ENV` determina cuál archivo cargar:
18
+
19
+ ```bash
20
+ # Default: local (carga .env.local)
21
+ bun run start
22
+
23
+ # Staging
24
+ TG_ENV=staging bun run start
25
+
26
+ # Production
27
+ TG_ENV=production bun run start
28
+ ```
29
+
30
+ ## Variables Requeridas
31
+
32
+ ### `TG_BOT_TOKEN`
33
+
34
+ **Descripción**: Token de acceso al bot desde @BotFather
35
+
36
+ **Formato**: `123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11`
37
+
38
+ **Obtenerlo**:
39
+ 1. Habla con [@BotFather](https://t.me/BotFather)
40
+ 2. `/newbot`
41
+ 3. Copia el token proporcionado
42
+
43
+ **Ejemplo**:
44
+ ```bash
45
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
46
+ ```
47
+
48
+ ### `TG_MODE`
49
+
50
+ **Descripción**: Modo de operación del bot
51
+
52
+ **Opciones**:
53
+ - `polling` - El bot pregunta por updates (recomendado para desarrollo)
54
+ - `webhook` - Telegram envía updates a una URL (recomendado para producción)
55
+
56
+ **Ejemplo**:
57
+ ```bash
58
+ TG_MODE=polling
59
+ ```
60
+
61
+ ## Variables Webhook (si TG_MODE=webhook)
62
+
63
+ ### `TG_WEBHOOK_URL`
64
+
65
+ **Descripción**: URL pública HTTPS donde Telegram enviará updates
66
+
67
+ **Requerido**: Solo si `TG_MODE=webhook`
68
+
69
+ **Validación**: Debe ser HTTPS y públicamente accesible
70
+
71
+ **Ejemplo**:
72
+ ```bash
73
+ TG_WEBHOOK_URL=https://mybot.example.com/webhook
74
+ ```
75
+
76
+ ### `TG_WEBHOOK_SECRET`
77
+
78
+ **Descripción**: Token secreto para validar webhooks
79
+
80
+ **Requerido**: Solo si `TG_MODE=webhook`
81
+
82
+ **Restricción**: Mínimo 16 caracteres
83
+
84
+ **Ejemplo**:
85
+ ```bash
86
+ TG_WEBHOOK_SECRET=my_secret_token_min_16_chars
87
+ ```
88
+
89
+ ## Variables de Identificación
90
+
91
+ ### `TG_ENV`
92
+
93
+ **Descripción**: Entorno actual del bot
94
+
95
+ **Opciones**: `local`, `staging`, `production`
96
+
97
+ **Default**: `local`
98
+
99
+ **Ejemplo**:
100
+ ```bash
101
+ TG_ENV=local
102
+ ```
103
+
104
+ ### `TG_INSTANCE_NAME`
105
+
106
+ **Descripción**: Nombre único de la instancia (para multi-instancia)
107
+
108
+ **Default**: `mks-bot`
109
+
110
+ **Ejemplo**:
111
+ ```bash
112
+ TG_INSTANCE_NAME=my-awesome-bot
113
+ ```
114
+
115
+ ## Variables de Control (Opcional)
116
+
117
+ ### `TG_LOG_CHAT_ID` / `TG_LOG_TOPIC_ID`
118
+
119
+ **Descripción**: Chat y topic para streaming de logs
120
+
121
+ **Uso**: Los logs del bot se envían a este chat/topic
122
+
123
+ **Obtener chat ID**:
124
+ 1. Añade el bot a un grupo
125
+ 2. Envía un mensaje
126
+ 3. Usa `bun run cli status` para ver updates
127
+ 4. O usa [@GetTelegraphBot](https://t.me/GetTelegraphBot)
128
+
129
+ **Ejemplo**:
130
+ ```bash
131
+ TG_LOG_CHAT_ID=-1001234567890
132
+ TG_LOG_TOPIC_ID=123
133
+ ```
134
+
135
+ ### `TG_CONTROL_CHAT_ID` / `TG_CONTROL_TOPIC_ID`
136
+
137
+ **Descripción**: Chat y topic para comandos de control
138
+
139
+ **Uso**: Comandos como `/stop`, `/restart`, `/mode`
140
+
141
+ **Ejemplo**:
142
+ ```bash
143
+ TG_CONTROL_CHAT_ID=-1001234567890
144
+ TG_CONTROL_TOPIC_ID=124
145
+ ```
146
+
147
+ ### `TG_AUTHORIZED_USER_IDS`
148
+
149
+ **Descripción**: IDs de usuarios autorizados para comandos de control
150
+
151
+ **Formato**: Comma-separated list
152
+
153
+ **Obtener user ID**:
154
+ 1. Envía un mensaje al bot
155
+ 2. Usa `bun run cli status --json`
156
+ 3. Busca `from.id` en el update
157
+
158
+ **Ejemplo**:
159
+ ```bash
160
+ TG_AUTHORIZED_USER_IDS=123456789,987654321
161
+ ```
162
+
163
+ ## Variables de Logging
164
+
165
+ ### `LOG_LEVEL`
166
+
167
+ **Descripción**: Nivel de verbose del logging
168
+
169
+ **Opciones**:
170
+ - `debug` - Muy detallado (desarrollo)
171
+ - `info` - Información general (default)
172
+ - `warn` - Solo warnings
173
+ - `error` - Solo errores
174
+
175
+ **Ejemplo**:
176
+ ```bash
177
+ LOG_LEVEL=info
178
+ ```
179
+
180
+ ### `TG_DEBUG`
181
+
182
+ **Descripción**: Habilita modo debug
183
+
184
+ **Default**: `false`
185
+
186
+ **Ejemplo**:
187
+ ```bash
188
+ TG_DEBUG=true
189
+ ```
190
+
191
+ ## Variables de Multi-Instancia
192
+
193
+ ### `TG_INSTANCE_CHECK`
194
+
195
+ **Descripción**: Habilita detección de conflictos de instancia
196
+
197
+ **Default**: `true`
198
+
199
+ **Ejemplo**:
200
+ ```bash
201
+ TG_INSTANCE_CHECK=true
202
+ ```
203
+
204
+ ### `TG_LOCK_BACKEND`
205
+
206
+ **Descripción**: Backend para lock de instancias
207
+
208
+ **Opciones**:
209
+ - `pid` - Archivos PID (default)
210
+ - `redis` - Redis para multi-servidor
211
+
212
+ **Ejemplo**:
213
+ ```bash
214
+ TG_LOCK_BACKEND=pid
215
+ ```
216
+
217
+ ### `TG_REDIS_URL`
218
+
219
+ **Descripción**: URL de Redis (si `TG_LOCK_BACKEND=redis`)
220
+
221
+ **Ejemplo**:
222
+ ```bash
223
+ TG_REDIS_URL=redis://localhost:6379
224
+ ```
225
+
226
+ ## Variables de ngrok
227
+
228
+ ### `TG_NGROK_ENABLED`
229
+
230
+ **Descripción**: Habilita integración con ngrok
231
+
232
+ **Default**: `false`
233
+
234
+ **Ejemplo**:
235
+ ```bash
236
+ TG_NGROK_ENABLED=true
237
+ ```
238
+
239
+ ### `TG_NGROK_PORT`
240
+
241
+ **Descripción**: Puerto a forward con ngrok
242
+
243
+ **Default**: `3000`
244
+
245
+ **Ejemplo**:
246
+ ```bash
247
+ TG_NGROK_PORT=3000
248
+ ```
249
+
250
+ ### `TG_NGROK_REGION`
251
+
252
+ **Descripción**: Región de ngrok
253
+
254
+ **Opciones**: `us`, `eu`, `ap`, `au`, `sa`, `jp`, `in`
255
+
256
+ **Default**: `us`
257
+
258
+ **Ejemplo**:
259
+ ```bash
260
+ TG_NGROK_REGION=eu
261
+ ```
262
+
263
+ ## Variables de File Logging
264
+
265
+ ### `TG_LOG_FILE_ENABLED`
266
+
267
+ **Descripción**: Habilita logging a archivos
268
+
269
+ **Default**: `true`
270
+
271
+ **Ejemplo**:
272
+ ```bash
273
+ TG_LOG_FILE_ENABLED=true
274
+ ```
275
+
276
+ ### `TG_LOG_DIR`
277
+
278
+ **Descripción**: Directorio para archivos de log
279
+
280
+ **Default**: `./logs`
281
+
282
+ **Ejemplo**:
283
+ ```bash
284
+ TG_LOG_DIR=./var/log
285
+ ```
286
+
287
+ ### `TG_LOG_MAX_SIZE`
288
+
289
+ **Descripción**: Tamaño máximo de archivo de log (bytes)
290
+
291
+ **Default**: `1048576` (1MB)
292
+
293
+ **Ejemplo**:
294
+ ```bash
295
+ TG_LOG_MAX_SIZE=5242880
296
+ ```
297
+
298
+ ### `TG_LOG_MAX_FILES`
299
+
300
+ **Descripción**: Número máximo de archivos a mantener
301
+
302
+ **Default**: `5`
303
+
304
+ **Ejemplo**:
305
+ ```bash
306
+ TG_LOG_MAX_FILES=10
307
+ ```
308
+
309
+ ### `TG_LOG_LEVELS`
310
+
311
+ **Descripción**: Niveles a loggear en archivos
312
+
313
+ **Default**: `info,warn,error,critical`
314
+
315
+ **Ejemplo**:
316
+ ```bash
317
+ TG_LOG_LEVELS=debug,info,warn,error,critical
318
+ ```
319
+
320
+ ## Variables de Rate Limiting
321
+
322
+ ### `TG_RATE_LIMIT`
323
+
324
+ **Descripción**: Máximo de mensajes por minuto
325
+
326
+ **Default**: `60`
327
+
328
+ **Rango**: 1-120
329
+
330
+ **Ejemplo**:
331
+ ```bash
332
+ TG_RATE_LIMIT=30
333
+ ```
334
+
335
+ ## Variables de Timeout
336
+
337
+ ### `TG_TIMEOUT`
338
+
339
+ **Descripción**: Timeout de respuesta de comandos (ms)
340
+
341
+ **Default**: `5000`
342
+
343
+ **Mínimo**: `1000`
344
+
345
+ **Ejemplo**:
346
+ ```bash
347
+ TG_TIMEOUT=10000
348
+ ```
349
+
350
+ ### `TG_MAX_RETRIES`
351
+
352
+ **Descripción**: Máximo de reintentos para operaciones
353
+
354
+ **Default**: `3`
355
+
356
+ **Rango**: 1-10
357
+
358
+ **Ejemplo**:
359
+ ```bash
360
+ TG_MAX_RETRIES=5
361
+ ```
362
+
363
+ ## Seguridad
364
+
365
+ ### Nunca Commitear .env Files
366
+
367
+ Los archivos `.env.*` contienen secrets y no deben estar en git.
368
+
369
+ ```gitignore
370
+ # En .gitignore
371
+ core/.env.local
372
+ core/.env.staging
373
+ core/.env.production
374
+ core/.env.*
375
+ ```
376
+
377
+ ### Usar .env.example
378
+
379
+ El archivo `.env.example` tiene placeholders seguros:
380
+
381
+ ```bash
382
+ # Ejemplo seguro
383
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
384
+
385
+ # NUNCA comitear un token real
386
+ # TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 # ❌ MAL
387
+ ```
388
+
389
+ ### Variables de Entorno en Producción
390
+
391
+ En producción, usa secretos de tu plataforma:
392
+
393
+ - **Vercel**: Environment Variables
394
+ - **Railway**: Variables
395
+ - **Docker**: `--env-file` o `-e`
396
+ - **Kubernetes**: Secrets
397
+
398
+ ```bash
399
+ # Docker
400
+ docker run -e TG_BOT_TOKEN=xxx -e TG_MODE=webhook ...
401
+
402
+ # Kubernetes
403
+ kubectl create secret generic bot-secrets --from-literal=TG_BOT_TOKEN=xxx
404
+ ```
405
+
406
+ ## Plantillas de Entorno
407
+
408
+ ### Desarrollo (.env.local)
409
+
410
+ ```bash
411
+ # Required
412
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
413
+ TG_MODE=polling
414
+ TG_ENV=local
415
+
416
+ # Logging
417
+ LOG_LEVEL=debug
418
+ TG_DEBUG=true
419
+ ```
420
+
421
+ ### Staging (.env.staging)
422
+
423
+ ```bash
424
+ # Required
425
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
426
+ TG_MODE=webhook
427
+ TG_WEBHOOK_URL=https://staging.example.com/webhook
428
+ TG_WEBHOOK_SECRET=staging_secret_min_16_chars
429
+ TG_ENV=staging
430
+
431
+ # Logging
432
+ LOG_LEVEL=info
433
+ TG_LOG_CHAT_ID=-1001234567890
434
+ TG_LOG_TOPIC_ID=123
435
+ ```
436
+
437
+ ### Producción (.env.production)
438
+
439
+ ```bash
440
+ # Required
441
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
442
+ TG_MODE=webhook
443
+ TG_WEBHOOK_URL=https://bot.example.com/webhook
444
+ TG_WEBHOOK_SECRET=super_secure_secret_min_16_chars
445
+ TG_ENV=production
446
+
447
+ # Logging (minimal in production)
448
+ LOG_LEVEL=warn
449
+ TG_LOG_CHAT_ID=-1001234567890
450
+ TG_LOG_TOPIC_ID=456
451
+
452
+ # Rate limiting
453
+ TG_RATE_LIMIT=30
454
+ ```
455
+
456
+ ## Referencias
457
+
458
+ - [Getting Started](./getting-started.md) - Guía de inicio
459
+ - [CLI Commands](./cli-commands.md) - Comandos disponibles
460
+ - [Deployment Guide](../CLAUDE.deploy.md) - Deployment completo