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,362 @@
1
+ # Example: Webhook Setup
2
+
3
+ Ejemplo completo de cómo configurar el bot en modo webhook.
4
+
5
+ ## Paso 1: Configurar Variables de Entorno
6
+
7
+ **Archivo**: `core/.env.production` (o `.env.staging`)
8
+
9
+ ```bash
10
+ # Required para webhook
11
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
12
+ TG_MODE=webhook
13
+ TG_WEBHOOK_URL=https://mybot.example.com/webhook
14
+ TG_WEBHOOK_SECRET=super_secret_token_min_16_chars
15
+
16
+ # Environment
17
+ TG_ENV=production
18
+
19
+ # Instance
20
+ TG_INSTANCE_NAME=my-bot-prod
21
+ ```
22
+
23
+ ### Generar Webhook Secret
24
+
25
+ ```bash
26
+ # Generar secret aleatorio (32 chars)
27
+ openssl rand -hex 16
28
+
29
+ # O usar Node/Bun
30
+ bun -e "console.log(require('crypto').randomBytes(16).toString('hex'))"
31
+ ```
32
+
33
+ ## Paso 2: Configurar Endpoint del Webhook
34
+
35
+ El endpoint ya está configurado en Telegraf, pero aquí está cómo funciona:
36
+
37
+ **En `core/src/index.ts`**:
38
+
39
+ ```typescript
40
+ import { Bot } from 'telegraf'
41
+
42
+ const bot = new Bot(process.env.TG_BOT_TOKEN!)
43
+
44
+ // Webhook configuration
45
+ const webhookUrl = process.env.TG_WEBHOOK_URL
46
+ const webhookSecret = process.env.TG_WEBHOOK_SECRET
47
+
48
+ if (process.env.TG_MODE === 'webhook' && webhookUrl) {
49
+ bot.telegram.setWebhook(webhookUrl, {
50
+ secret_token: webhookSecret,
51
+ })
52
+ }
53
+
54
+ // ... rest of bot setup
55
+
56
+ // Start webhook server
57
+ if (process.env.TG_MODE === 'webhook') {
58
+ const port = Number.parseInt(process.env.PORT ?? '3000', 10)
59
+ await bot.startWebhook({
60
+ hookPath: '/webhook',
61
+ port,
62
+ secretToken: webhookSecret,
63
+ })
64
+ } else {
65
+ bot.start()
66
+ }
67
+ ```
68
+
69
+ ## Paso 3: Deploy con ngrok (Testing)
70
+
71
+ ### ngrock para Desarrollo Local
72
+
73
+ ```bash
74
+ # Iniciar ngrok
75
+ bun run ngrok --webhook-url --start-bot
76
+ ```
77
+
78
+ Esto:
79
+ 1. Inicia ngrok tunnel
80
+ 2. Actualiza `TG_WEBHOOK_URL` en `.env.local`
81
+ 3. Arranca el bot automáticamente
82
+
83
+ ### Manual ngrok
84
+
85
+ ```bash
86
+ # Terminal 1: ngrok
87
+ ngrok http 3000
88
+
89
+ # Copia la URL (ej: https://abc123.ngrok.io)
90
+
91
+ # Terminal 2: setup
92
+ bun run setup --mode webhook --token "YOUR_TOKEN"
93
+
94
+ # Editar core/.env.local:
95
+ # TG_WEBHOOK_URL=https://abc123.ngrok.io/webhook
96
+ # TG_WEBHOOK_SECRET=mi_secret_min_16_chars
97
+
98
+ # Terminal 3: arrancar bot
99
+ bun run dev
100
+ ```
101
+
102
+ ## Paso 4: Deploy a VPS/Cloud
103
+
104
+ ### Opción A: VPS con systemd
105
+
106
+ **1. Subir código al VPS**:
107
+ ```bash
108
+ git clone <repo>
109
+ cd mks-telegram-bot
110
+ bun install
111
+ ```
112
+
113
+ **2. Configurar entorno**:
114
+ ```bash
115
+ cp core/.env.example core/.env.production
116
+ nano core/.env.production
117
+ ```
118
+
119
+ **3. Crear servicio systemd**:
120
+
121
+ ```bash
122
+ sudo nano /etc/systemd/system/mks-bot.service
123
+ ```
124
+
125
+ ```ini
126
+ [Unit]
127
+ Description=mks-telegram-bot
128
+ After=network.target
129
+
130
+ [Service]
131
+ Type=simple
132
+ User=botuser
133
+ WorkingDirectory=/app/mks-telegram-bot
134
+ Environment="TG_ENV=production"
135
+ ExecStart=/usr/local/bin/bun run start
136
+ Restart=always
137
+ RestartSec=10
138
+
139
+ [Install]
140
+ WantedBy=multi-user.target
141
+ ```
142
+
143
+ **4. Habilitar e iniciar**:
144
+ ```bash
145
+ sudo systemctl daemon-reload
146
+ sudo systemctl enable mks-bot
147
+ sudo systemctl start mks-bot
148
+ sudo systemctl status mks-bot
149
+ ```
150
+
151
+ **5. Ver logs**:
152
+ ```bash
153
+ sudo journalctl -u mks-bot -f
154
+ ```
155
+
156
+ ### Opción B: Docker
157
+
158
+ **1. Crear Dockerfile** (ya incluido):
159
+
160
+ ```dockerfile
161
+ FROM oven/bun:1.3 AS production
162
+ WORKDIR /app
163
+ COPY package.json bun.lock ./
164
+ COPY core/package.json core/
165
+ RUN bun install --frozen-lockfile
166
+ COPY core/src core/src
167
+ RUN mkdir -p /app/core/tmp /app/core/logs
168
+ ENV TG_ENV=production
169
+ ENV NODE_ENV=production
170
+ EXPOSE 3000
171
+ CMD ["bun", "run", "start"]
172
+ ```
173
+
174
+ **2. Build y run**:
175
+ ```bash
176
+ docker build -t mks-telegram-bot .
177
+ docker run -d \
178
+ --name mks-bot-prod \
179
+ --restart unless-stopped \
180
+ -p 3000:3000 \
181
+ --env-file core/.env.production \
182
+ mks-telegram-bot
183
+ ```
184
+
185
+ **3. Ver logs**:
186
+ ```bash
187
+ docker logs -f mks-bot-prod
188
+ ```
189
+
190
+ ### Opción C: Railway
191
+
192
+ **1. Crear archivo `railway.json`**:
193
+ ```json
194
+ {
195
+ "$schema": "https://railway.app/railway.schema.json",
196
+ "build": {
197
+ "builder": "NIXPACKS"
198
+ },
199
+ "deploy": {
200
+ "startCommand": "bun run start",
201
+ "healthcheckPath": "/health"
202
+ }
203
+ }
204
+ ```
205
+
206
+ **2. Subir a Railway**:
207
+ - Connect repo en Railway
208
+ - Add variables en el dashboard:
209
+ - `TG_BOT_TOKEN`
210
+ - `TG_MODE=webhook`
211
+ - `TG_WEBHOOK_URL` (Railway lo provee)
212
+ - `TG_WEBHOOK_SECRET`
213
+
214
+ **3. Deploy automático** al hacer push.
215
+
216
+ ## Paso 5: Configurar Dominio y SSL
217
+
218
+ ### Usar Nginx como Reverse Proxy
219
+
220
+ ```nginx
221
+ server {
222
+ listen 443 ssl http2;
223
+ server_name mybot.example.com;
224
+
225
+ ssl_certificate /etc/letsencrypt/live/mybot.example.com/fullchain.pem;
226
+ ssl_certificate_key /etc/letsencrypt/live/mybot.example.com/privkey.pem;
227
+
228
+ location /webhook {
229
+ proxy_pass http://localhost:3000;
230
+ proxy_http_version 1.1;
231
+ proxy_set_header Upgrade $http_upgrade;
232
+ proxy_set_header Connection 'upgrade';
233
+ proxy_set_header Host $host;
234
+ proxy_cache_bypass $http_upgrade;
235
+ proxy_set_header X-Real-IP $remote_addr;
236
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
237
+ proxy_set_header X-Forwarded-Proto $scheme;
238
+ }
239
+ }
240
+ ```
241
+
242
+ ### Obtener Certificado SSL Gratis (Let's Encrypt)
243
+
244
+ ```bash
245
+ sudo certbot --nginx -d mybot.example.com
246
+ ```
247
+
248
+ ## Paso 6: Verificar Webhook
249
+
250
+ ### Chequear Info del Webhook
251
+
252
+ ```bash
253
+ curl "https://api.telegram.org/bot<TG_BOT_TOKEN>/getWebhookInfo"
254
+ ```
255
+
256
+ Response esperado:
257
+ ```json
258
+ {
259
+ "ok": true,
260
+ "result": {
261
+ "url": "https://mybot.example.com/webhook",
262
+ "has_custom_certificate": false,
263
+ "pending_update_count": 0,
264
+ "last_error_date": 0,
265
+ "last_error_message": "",
266
+ "max_connections": 40
267
+ }
268
+ }
269
+ ```
270
+
271
+ ### Testear Webhook
272
+
273
+ Enviar mensaje al bot y verificar logs:
274
+
275
+ ```bash
276
+ # Ver logs del bot
277
+ tail -f core/logs/info.log
278
+
279
+ # O en Docker
280
+ docker logs -f mks-bot-prod
281
+
282
+ # O en systemd
283
+ journalctl -u mks-bot -f
284
+ ```
285
+
286
+ ### Borrar Webhook (Volver a Polling)
287
+
288
+ ```bash
289
+ curl "https://api.telegram.org/bot<TG_BOT_TOKEN>/deleteWebhook"
290
+ ```
291
+
292
+ ## Troubleshooting Webhook
293
+
294
+ ### Webhook No Recibe Updates
295
+
296
+ **1. Verificar URL es accesible**:
297
+ ```bash
298
+ curl https://mybot.example.com/webhook
299
+ ```
300
+
301
+ **2. Verificar firewall**:
302
+ ```bash
303
+ # Abrir puertos
304
+ sudo ufw allow 443/tcp
305
+ sudo ufw allow 80/tcp
306
+ ```
307
+
308
+ **3. Verificar nginx está corriendo**:
309
+ ```bash
310
+ sudo systemctl status nginx
311
+ ```
312
+
313
+ **4. Verificar bot está corriendo**:
314
+ ```bash
315
+ sudo systemctl status mks-bot
316
+ ```
317
+
318
+ ### Error: Webhook Secret No Coincide
319
+
320
+ **Verificar secret coincide**:
321
+ ```bash
322
+ grep TG_WEBHOOK_SECRET core/.env.production
323
+ ```
324
+
325
+ **Regenerar si es necesario**:
326
+ ```bash
327
+ # Generar nuevo secret
328
+ openssl rand -hex 16
329
+
330
+ # Actualizar .env
331
+ nano core/.env.production
332
+
333
+ # Reiniciar bot
334
+ sudo systemctl restart mks-bot
335
+ ```
336
+
337
+ ### Error: SSL Certificate
338
+
339
+ **Verificar certificado**:
340
+ ```bash
341
+ curl https://mybot.example.com/webhook -v
342
+ ```
343
+
344
+ **Renovar certificado**:
345
+ ```bash
346
+ sudo certbot renew
347
+ sudo systemctl reload nginx
348
+ ```
349
+
350
+ ## Resumen
351
+
352
+ 1. **Configurar variables** en `.env.production`
353
+ 2. **Deploy** (VPS/Docker/Railway)
354
+ 3. **Configurar dominio** con SSL
355
+ 4. **Verificar webhook** con getWebhookInfo
356
+ 5. **Testear** enviando mensaje al bot
357
+
358
+ ## Próximos Pasos
359
+
360
+ - [Simple Command Example](./simple-command.md) - Crear comandos
361
+ - [Auth Middleware Example](./middleware-auth.md) - Agregar auth
362
+ - [Deployment Guide](../CLAUDE.deploy.md) - Deployment completo
@@ -0,0 +1,223 @@
1
+ # Getting Started
2
+
3
+ Guía paso a paso para configurar y ejecutar tu bot de Telegram.
4
+
5
+ ## Prerrequisitos
6
+
7
+ Antes de comenzar, asegúrate de tener:
8
+
9
+ - **Bun** v1.3+ - Instalar desde [bun.sh](https://bun.sh)
10
+ - **Cuenta de Telegram** - Para crear el bot
11
+ - **Editor de código** - VS Code recomendado
12
+
13
+ Verifica tu instalación:
14
+
15
+ ```bash
16
+ bun --version
17
+ ```
18
+
19
+ ## Paso 1: Crear el Bot en Telegram
20
+
21
+ ### Hablar con @BotFather
22
+
23
+ 1. Abre Telegram y busca **@BotFather**
24
+ 2. Inicia el chat con el comando `/newbot`
25
+ 3. Sigue las instrucciones:
26
+ - **Nombre del bot**: `Mi Bot Increíble`
27
+ - **Username**: `mi_increible_bot` (debe terminar en "bot")
28
+
29
+ 4. **Copia el token** que te da @BotFather:
30
+ ```
31
+ 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
32
+ ```
33
+
34
+ > **Guarda el token en un lugar seguro**. Es la llave de acceso a tu bot.
35
+
36
+ ## Paso 2: Instalar el Template
37
+
38
+ ### Opción A: Clonar desde GitHub
39
+
40
+ ```bash
41
+ git clone <tu-repo-url>
42
+ cd mks-telegram-bot
43
+ ```
44
+
45
+ ### Opción B: Usar como Template
46
+
47
+ 1. Ve al repositorio en GitHub
48
+ 2. Click en "Use this template" → "Create a new repository"
49
+ 3. Clona tu nuevo repositorio
50
+
51
+ ## Paso 3: Instalar Dependencias
52
+
53
+ ```bash
54
+ bun install
55
+ ```
56
+
57
+ Esto instala todas las dependencias del workspace:
58
+ - `core/` - Bot principal
59
+ - `packages/utils/` - Utilidades compartidas
60
+ - `tools/` - CLI tools
61
+
62
+ ## Paso 4: Configurar el Entorno
63
+
64
+ ### Opción Recomendada: Setup Interactivo
65
+
66
+ ```bash
67
+ bun run setup
68
+ ```
69
+
70
+ El comando te preguntará:
71
+
72
+ 1. **Bot Token** - Pega el token de @BotFather
73
+ 2. **Modo de operación** - Selecciona "polling" para desarrollo
74
+ 3. **Entorno** - "local" para desarrollo
75
+ 4. **Streaming de logs** - Opcional, para ver logs en Telegram
76
+ 5. **Comandos de control** - Opcional, para comandos admin
77
+
78
+ ### Opción Manual: Editar Archivo .env
79
+
80
+ ```bash
81
+ cp core/.env.example core/.env.local
82
+ nano core/.env.local
83
+ ```
84
+
85
+ Edita las variables mínimas:
86
+
87
+ ```bash
88
+ # Required
89
+ TG_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
90
+ TG_MODE=polling
91
+ TG_ENV=local
92
+ ```
93
+
94
+ ## Paso 5: Verificar Configuración
95
+
96
+ ```bash
97
+ bun run doctor
98
+ ```
99
+
100
+ Este comando diagnostica tu configuración:
101
+
102
+ - ✓ Dependencias instaladas
103
+ - ✓ Archivos .env configurados
104
+ - ✓ Token de bot válido
105
+ - ✓ Puertos disponibles
106
+
107
+ Deberías ver:
108
+
109
+ ```
110
+ ✓ Node.js version Node.js v20.x.x (requires >= 20)
111
+ ✓ Bun installation Bun is installed
112
+ ✓ Dependencies All dependencies installed
113
+ ✓ Environment files Found: .env.local
114
+ ✓ Environment variables Required variables set
115
+ ✓ Bot token validation Bot token is valid
116
+ ✓ Temp directory core/tmp is writable
117
+ ✓ Port availability Port 3000 is available
118
+ ```
119
+
120
+ ## Paso 6: Arrancar el Bot
121
+
122
+ ### Modo Desarrollo (con Hot Reload)
123
+
124
+ ```bash
125
+ bun run dev
126
+ ```
127
+
128
+ El bot arrancará en modo polling con hot reload:
129
+
130
+ ```
131
+ [Bot] Bot started successfully
132
+ [Bot] Mode: polling
133
+ [Bot] Environment: local
134
+ ```
135
+
136
+ ### Modo Producción
137
+
138
+ ```bash
139
+ bun run start
140
+ ```
141
+
142
+ ## Paso 7: Probar el Bot
143
+
144
+ ### Enviar Comandos Básicos
145
+
146
+ Abre Telegram y busca tu bot (o usa el link que te dio @BotFather).
147
+
148
+ Envía estos comandos:
149
+
150
+ - `/start` - Mensaje de bienvenida
151
+ - `/health` - Estado del bot
152
+ - `/uptime` - Tiempo de ejecución
153
+ - `/stats` - Estadísticas
154
+
155
+ ### Respuesta Esperada
156
+
157
+ ```
158
+ ┌────────────────────────────────┐
159
+ │ 🤖 mks-telegram-bot │
160
+ │ │
161
+ │ ¡Hola! Soy tu bot de Telegram │
162
+ │ configurado con el template │
163
+ │ │
164
+ │ Comandos disponibles: │
165
+ │ /start - Iniciar el bot │
166
+ │ /health - Estado de salud │
167
+ │ /uptime - Tiempo activo │
168
+ │ /stats - Estadísticas │
169
+ └────────────────────────────────┘
170
+ ```
171
+
172
+ ## Siguientes Pasos
173
+
174
+ ### Aprende Más
175
+
176
+ - [Environment](./environment.mdx) - Configuración de variables
177
+ - [CLI Commands](./docs/cli-commands.md) - Comandos disponibles
178
+ - [Development](./docs/development.md) - Flujo de desarrollo
179
+
180
+ ### Personaliza tu Bot
181
+
182
+ 1. **Agregar comandos** - Ver [Development Guide](../CLAUDE.dev.md)
183
+ 2. **Configurar logging** - Ver [Environment](./environment.mdx)
184
+ 3. **Deploy a producción** - Ver [Deployment Guide](../CLAUDE.deploy.md)
185
+
186
+ ### Troubleshooting
187
+
188
+ Si algo no funciona:
189
+
190
+ - El bot no responde → Revisa el token y el modo
191
+ - Error de conexión → Verifica que `TG_MODE=polling`
192
+ - Puerto en uso → Cambia el puerto o mata el proceso
193
+
194
+ Ver [Troubleshooting](./troubleshooting.mdx) para más detalles.
195
+
196
+ ## Resumen Rápido
197
+
198
+ ```bash
199
+ # 1. Clonar el template
200
+ git clone <repo>
201
+ cd mks-telegram-bot
202
+
203
+ # 2. Instalar dependencias
204
+ bun install
205
+
206
+ # 3. Configurar entorno (setup interactivo)
207
+ bun run setup
208
+
209
+ # 4. Verificar configuración
210
+ bun run doctor
211
+
212
+ # 5. Arrancar en desarrollo
213
+ bun run dev
214
+
215
+ # 6. Probar en Telegram
216
+ # Envía /start a tu bot
217
+ ```
218
+
219
+ ## Referencias
220
+
221
+ - **@BotFather** - [@BotFather en Telegram](https://t.me/BotFather)
222
+ - **Telegram Bot API** - [Documentación oficial](https://core.telegram.org/bots/api)
223
+ - **Bun** - [bun.sh](https://bun.sh)