create-bunspace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -0
- package/dist/bin.js +5755 -0
- package/dist/templates/monorepo/CLAUDE.md +164 -0
- package/dist/templates/monorepo/LICENSE +21 -0
- package/dist/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/dist/templates/monorepo/README.md +74 -0
- package/dist/templates/monorepo/SYNC_VERIFICATION.md +1 -0
- package/dist/templates/monorepo/apps/example/package.json +19 -0
- package/dist/templates/monorepo/apps/example/src/index.ts +23 -0
- package/dist/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/dist/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/dist/templates/monorepo/core/packages/main/package.json +41 -0
- package/dist/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/dist/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/dist/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/dist/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/core/packages/utils/package.json +43 -0
- package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/dist/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/dist/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/dist/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/dist/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/dist/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/dist/templates/monorepo/oxlint.json +14 -0
- package/dist/templates/monorepo/package.json +39 -0
- package/dist/templates/monorepo/tsconfig.json +35 -0
- package/dist/templates/telegram-bot/.oxlintrc.json +33 -0
- package/dist/templates/telegram-bot/.prettierignore +5 -0
- package/dist/templates/telegram-bot/.prettierrc +26 -0
- package/dist/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/dist/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/dist/templates/telegram-bot/CLAUDE.md +280 -0
- package/dist/templates/telegram-bot/Dockerfile +46 -0
- package/dist/templates/telegram-bot/README.md +245 -0
- package/dist/templates/telegram-bot/apps/.gitkeep +0 -0
- package/dist/templates/telegram-bot/bun.lock +208 -0
- package/dist/templates/telegram-bot/core/.env.example +71 -0
- package/dist/templates/telegram-bot/core/README.md +1067 -0
- package/dist/templates/telegram-bot/core/package.json +15 -0
- package/dist/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/dist/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/dist/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/dist/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/dist/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/dist/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/dist/templates/telegram-bot/core/src/index.ts +161 -0
- package/dist/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/dist/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/dist/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/dist/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/dist/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/dist/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/dist/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/dist/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/dist/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/dist/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/dist/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/dist/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/dist/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/dist/templates/telegram-bot/core/tsconfig.json +9 -0
- package/dist/templates/telegram-bot/docker-compose.yml +37 -0
- package/dist/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/dist/templates/telegram-bot/docs/development.md +363 -0
- package/dist/templates/telegram-bot/docs/environment.md +460 -0
- package/dist/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/dist/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/dist/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/dist/templates/telegram-bot/docs/getting-started.md +223 -0
- package/dist/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/dist/templates/telegram-bot/package.json +49 -0
- package/dist/templates/telegram-bot/packages/utils/package.json +12 -0
- package/dist/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/dist/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/dist/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/dist/templates/telegram-bot/tools/README.md +47 -0
- package/dist/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/dist/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/dist/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/dist/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/dist/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/dist/templates/telegram-bot/tools/index.ts +16 -0
- package/dist/templates/telegram-bot/tools/package.json +12 -0
- package/dist/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/dist/templates/telegram-bot/tsconfig.json +22 -0
- package/dist/templates/telegram-bot/vitest.config.ts +29 -0
- package/package.json +35 -0
- package/templates/monorepo/CLAUDE.md +164 -0
- package/templates/monorepo/LICENSE +21 -0
- package/templates/monorepo/MUST-FOLLOW-GUIDELINES.md +269 -0
- package/templates/monorepo/README.md +74 -0
- package/templates/monorepo/apps/example/package.json +19 -0
- package/templates/monorepo/apps/example/src/index.ts +23 -0
- package/templates/monorepo/apps/example/src/types/index.ts +7 -0
- package/templates/monorepo/apps/example/src/utils/index.ts +7 -0
- package/templates/monorepo/core/packages/main/package.json +41 -0
- package/templates/monorepo/core/packages/main/rolldown.config.ts +24 -0
- package/templates/monorepo/core/packages/main/src/index.ts +80 -0
- package/templates/monorepo/core/packages/main/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/main/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/main/src/types/main.types.ts +25 -0
- package/templates/monorepo/core/packages/main/src/utils/index.ts +5 -0
- package/templates/monorepo/core/packages/utils/package.json +43 -0
- package/templates/monorepo/core/packages/utils/rolldown.config.ts +34 -0
- package/templates/monorepo/core/packages/utils/src/index.ts +2 -0
- package/templates/monorepo/core/packages/utils/src/logger.ts +68 -0
- package/templates/monorepo/core/packages/utils/src/result.ts +146 -0
- package/templates/monorepo/core/packages/utils/src/types/constants.ts +15 -0
- package/templates/monorepo/core/packages/utils/src/types/index.ts +8 -0
- package/templates/monorepo/core/packages/utils/src/types/utils.types.ts +32 -0
- package/templates/monorepo/core/packages/utils/src/utils/index.ts +5 -0
- package/templates/monorepo/oxlint.json +14 -0
- package/templates/monorepo/package.json +39 -0
- package/templates/monorepo/tsconfig.json +35 -0
- package/templates/telegram-bot/.oxlintrc.json +33 -0
- package/templates/telegram-bot/.prettierignore +5 -0
- package/templates/telegram-bot/.prettierrc +26 -0
- package/templates/telegram-bot/CLAUDE.deploy.md +356 -0
- package/templates/telegram-bot/CLAUDE.dev.md +266 -0
- package/templates/telegram-bot/CLAUDE.md +280 -0
- package/templates/telegram-bot/Dockerfile +46 -0
- package/templates/telegram-bot/README.md +245 -0
- package/templates/telegram-bot/apps/.gitkeep +0 -0
- package/templates/telegram-bot/bun.lock +208 -0
- package/templates/telegram-bot/core/.env.example +71 -0
- package/templates/telegram-bot/core/README.md +1067 -0
- package/templates/telegram-bot/core/package.json +15 -0
- package/templates/telegram-bot/core/src/config/env.ts +131 -0
- package/templates/telegram-bot/core/src/config/index.ts +97 -0
- package/templates/telegram-bot/core/src/config/logging.ts +110 -0
- package/templates/telegram-bot/core/src/handlers/control.ts +85 -0
- package/templates/telegram-bot/core/src/handlers/health.ts +83 -0
- package/templates/telegram-bot/core/src/handlers/logs.ts +126 -0
- package/templates/telegram-bot/core/src/index.ts +161 -0
- package/templates/telegram-bot/core/src/middleware/auth.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/error-handler.ts +41 -0
- package/templates/telegram-bot/core/src/middleware/logging.ts +1 -0
- package/templates/telegram-bot/core/src/middleware/topics.ts +55 -0
- package/templates/telegram-bot/core/src/types/bot.ts +92 -0
- package/templates/telegram-bot/core/src/types/constants.ts +50 -0
- package/templates/telegram-bot/core/src/types/result.ts +1 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.test.ts +111 -0
- package/templates/telegram-bot/core/src/utils/bot-manager.ts +201 -0
- package/templates/telegram-bot/core/src/utils/commands.ts +63 -0
- package/templates/telegram-bot/core/src/utils/formatters.ts +82 -0
- package/templates/telegram-bot/core/src/utils/instance-manager.ts +189 -0
- package/templates/telegram-bot/core/src/utils/memory.ts +33 -0
- package/templates/telegram-bot/core/src/utils/result.ts +26 -0
- package/templates/telegram-bot/core/src/utils/telegram.ts +31 -0
- package/templates/telegram-bot/core/src/utils/type-guards.ts +71 -0
- package/templates/telegram-bot/core/tsconfig.json +9 -0
- package/templates/telegram-bot/docker-compose.yml +37 -0
- package/templates/telegram-bot/docs/cli-commands.md +377 -0
- package/templates/telegram-bot/docs/development.md +363 -0
- package/templates/telegram-bot/docs/environment.md +460 -0
- package/templates/telegram-bot/docs/examples/middleware-auth.md +335 -0
- package/templates/telegram-bot/docs/examples/simple-command.md +207 -0
- package/templates/telegram-bot/docs/examples/webhook-setup.md +362 -0
- package/templates/telegram-bot/docs/getting-started.md +223 -0
- package/templates/telegram-bot/docs/troubleshooting.md +489 -0
- package/templates/telegram-bot/package.json +49 -0
- package/templates/telegram-bot/packages/utils/package.json +12 -0
- package/templates/telegram-bot/packages/utils/src/index.ts +2 -0
- package/templates/telegram-bot/packages/utils/src/logger.ts +72 -0
- package/templates/telegram-bot/packages/utils/src/result.ts +80 -0
- package/templates/telegram-bot/tools/README.md +47 -0
- package/templates/telegram-bot/tools/commands/doctor.ts +460 -0
- package/templates/telegram-bot/tools/commands/index.ts +35 -0
- package/templates/telegram-bot/tools/commands/ngrok.ts +207 -0
- package/templates/telegram-bot/tools/commands/setup.ts +368 -0
- package/templates/telegram-bot/tools/commands/status.ts +140 -0
- package/templates/telegram-bot/tools/index.ts +16 -0
- package/templates/telegram-bot/tools/package.json +12 -0
- package/templates/telegram-bot/tools/utils/index.ts +13 -0
- package/templates/telegram-bot/tsconfig.json +22 -0
- package/templates/telegram-bot/vitest.config.ts +29 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Guía de solución de problemas comunes del bot.
|
|
4
|
+
|
|
5
|
+
## Bot No Responde
|
|
6
|
+
|
|
7
|
+
### Síntomas
|
|
8
|
+
|
|
9
|
+
- El bot no responde a ningún comando
|
|
10
|
+
- Telegram muestra "bot is not running"
|
|
11
|
+
- Timeouts en `/health`
|
|
12
|
+
|
|
13
|
+
### Causas Comunes
|
|
14
|
+
|
|
15
|
+
#### 1. Token Inválido o Incorrecto
|
|
16
|
+
|
|
17
|
+
**Verificar**:
|
|
18
|
+
```bash
|
|
19
|
+
grep TG_BOT_TOKEN core/.env.local
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Solución**:
|
|
23
|
+
1. Ve a @BotFather
|
|
24
|
+
2. `/mybots` → selecciona tu bot → `API Token`
|
|
25
|
+
3. Copia el token correcto
|
|
26
|
+
4. Actualiza `core/.env.local`
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Editar el archivo
|
|
30
|
+
nano core/.env.local
|
|
31
|
+
|
|
32
|
+
# O usar setup
|
|
33
|
+
bun run setup --token "CORRECT_TOKEN"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### 2. Modo Incorrecto
|
|
37
|
+
|
|
38
|
+
**Verificar**:
|
|
39
|
+
```bash
|
|
40
|
+
grep TG_MODE core/.env.local
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Solución**:
|
|
44
|
+
|
|
45
|
+
Para desarrollo:
|
|
46
|
+
```bash
|
|
47
|
+
TG_MODE=polling
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Para producción con webhook:
|
|
51
|
+
```bash
|
|
52
|
+
TG_MODE=webhook
|
|
53
|
+
TG_WEBHOOK_URL=https://your-domain.com/webhook
|
|
54
|
+
TG_WEBHOOK_SECRET=secret_min_16_chars
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### 3. Bot No Iniciado
|
|
58
|
+
|
|
59
|
+
**Verificar**:
|
|
60
|
+
```bash
|
|
61
|
+
bun run cli status
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Solución**:
|
|
65
|
+
```bash
|
|
66
|
+
bun run dev
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### 4. Puerto en Uso
|
|
70
|
+
|
|
71
|
+
**Error**:
|
|
72
|
+
```
|
|
73
|
+
Error: listen EADDRINUSE: address already in use :::3000
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Verificar**:
|
|
77
|
+
```bash
|
|
78
|
+
lsof -i :3000
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Solución**:
|
|
82
|
+
```bash
|
|
83
|
+
# Matar el proceso
|
|
84
|
+
kill -9 $(lsof -t -i:3000)
|
|
85
|
+
|
|
86
|
+
# O cambiar puerto en .env
|
|
87
|
+
# (necesita implementación adicional)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Diagnóstico Completo
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
bun run doctor
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Webhook No Funciona
|
|
97
|
+
|
|
98
|
+
### Síntomas
|
|
99
|
+
|
|
100
|
+
- Webhook configurado pero no llegan updates
|
|
101
|
+
- Error "webhook not set"
|
|
102
|
+
- 404 en endpoint del webhook
|
|
103
|
+
|
|
104
|
+
### Causas Comunes
|
|
105
|
+
|
|
106
|
+
#### 1. URL No Pública
|
|
107
|
+
|
|
108
|
+
**Error**: Webhook URL no es accesible públicamente
|
|
109
|
+
|
|
110
|
+
**Verificar**:
|
|
111
|
+
```bash
|
|
112
|
+
curl https://your-domain.com/webhook
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Solución**:
|
|
116
|
+
- Usa ngrok para desarrollo: `bun run ngrok`
|
|
117
|
+
- O deploy a VPS/Cloud con dominio público
|
|
118
|
+
|
|
119
|
+
#### 2. URL No es HTTPS
|
|
120
|
+
|
|
121
|
+
**Error**:
|
|
122
|
+
```
|
|
123
|
+
Error: webhook URL must be HTTPS
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Solución**:
|
|
127
|
+
- Telegram requiere HTTPS obligatoriamente
|
|
128
|
+
- Usa certificados SSL (Let's Encrypt gratis)
|
|
129
|
+
|
|
130
|
+
#### 3. Webhook Secret No Coincide
|
|
131
|
+
|
|
132
|
+
**Error**: Validación de webhook falla
|
|
133
|
+
|
|
134
|
+
**Verificar**:
|
|
135
|
+
```bash
|
|
136
|
+
grep TG_WEBHOOK_SECRET core/.env.production
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Solución**:
|
|
140
|
+
- Asegúrate que el secret coincide en bot y servidor
|
|
141
|
+
- Mínimo 16 caracteres
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
TG_WEBHOOK_SECRET=super_secret_token_min_16_chars
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### 4. Firewall Bloquea
|
|
148
|
+
|
|
149
|
+
**Síntoma**: curl local funciona pero Telegram no
|
|
150
|
+
|
|
151
|
+
**Verificar**:
|
|
152
|
+
```bash
|
|
153
|
+
# Desde otro servidor
|
|
154
|
+
curl https://your-domain.com/webhook
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Solución**:
|
|
158
|
+
```bash
|
|
159
|
+
# Abrir puerto (ufw)
|
|
160
|
+
sudo ufw allow 443/tcp
|
|
161
|
+
sudo ufw allow 80/tcp
|
|
162
|
+
|
|
163
|
+
# O en iptables
|
|
164
|
+
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### ngrok Troubleshooting
|
|
168
|
+
|
|
169
|
+
#### ngrok No Inicia
|
|
170
|
+
|
|
171
|
+
**Error**:
|
|
172
|
+
```
|
|
173
|
+
Error: ngrok is not installed
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Solución**:
|
|
177
|
+
```bash
|
|
178
|
+
# Instalar ngrok
|
|
179
|
+
brew install ngrok # macOS
|
|
180
|
+
# O desde https://ngrok.com
|
|
181
|
+
|
|
182
|
+
# Autenticar
|
|
183
|
+
ngrok config add-authtoken YOUR_TOKEN
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### ngrok Tunnel Falla
|
|
187
|
+
|
|
188
|
+
**Error**: `ERR_NGROK_6024`
|
|
189
|
+
|
|
190
|
+
**Solución**:
|
|
191
|
+
1. Verifica que ngrok está autenticado
|
|
192
|
+
2. Verifica que puerto 4040 está libre
|
|
193
|
+
3. Usa otro puerto: `bun run ngrok --port 3001`
|
|
194
|
+
|
|
195
|
+
## Instance Conflict
|
|
196
|
+
|
|
197
|
+
### Síntomas
|
|
198
|
+
|
|
199
|
+
**Error**:
|
|
200
|
+
```
|
|
201
|
+
INSTANCE_CONFLICT - Another instance is already running
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Causas
|
|
205
|
+
|
|
206
|
+
Otra instancia del bot está corriendo con el mismo nombre.
|
|
207
|
+
|
|
208
|
+
### Soluciones
|
|
209
|
+
|
|
210
|
+
#### 1. Ver Instancias
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
bun run cli status
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### 2. Parar Instancia Existente
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Matar el proceso
|
|
220
|
+
kill -9 <PID>
|
|
221
|
+
|
|
222
|
+
# O usar el comando kill
|
|
223
|
+
bun run cli kill <instance_name>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### 3. Remover Lock Files Stale
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
rm -f core/tmp/*.lock core/tmp/*.pid
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### 4. Usar Nombre Diferente
|
|
233
|
+
|
|
234
|
+
En `core/.env.local`:
|
|
235
|
+
```bash
|
|
236
|
+
TG_INSTANCE_NAME=my-bot-2
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### 5. Deshabilitar Check (No Recomendado)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
TG_INSTANCE_CHECK=false
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Error de Dependencias
|
|
246
|
+
|
|
247
|
+
### Module Not Found
|
|
248
|
+
|
|
249
|
+
**Error**:
|
|
250
|
+
```
|
|
251
|
+
Error: Cannot find module '@mks2508/telegram-bot-utils'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Solución**:
|
|
255
|
+
```bash
|
|
256
|
+
bun install
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Workspace Issues
|
|
260
|
+
|
|
261
|
+
**Error**:
|
|
262
|
+
```
|
|
263
|
+
Error: Workspace package not found
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Solución**:
|
|
267
|
+
```bash
|
|
268
|
+
# Limpiar y reinstalar
|
|
269
|
+
bun run clean
|
|
270
|
+
bun install
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## TypeCheck Errors
|
|
274
|
+
|
|
275
|
+
### Error: Cannot Find Module
|
|
276
|
+
|
|
277
|
+
**Error**:
|
|
278
|
+
```
|
|
279
|
+
TS2307: Cannot find module './handlers/mycommand.js'
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
**Causa**: Extension `.js` en imports ES modules
|
|
283
|
+
|
|
284
|
+
**Solución**: Asegúrate de usar `.js` en imports:
|
|
285
|
+
```typescript
|
|
286
|
+
// ✅ Correcto
|
|
287
|
+
import { handleMyCommand } from './handlers/mycommand.js'
|
|
288
|
+
|
|
289
|
+
// ❌ Incorrecto
|
|
290
|
+
import { handleMyCommand } from './handlers/mycommand'
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Type Errors con Telegraf
|
|
294
|
+
|
|
295
|
+
**Error**:
|
|
296
|
+
```
|
|
297
|
+
TS2345: Argument of type 'Context' is not assignable to...
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Solución**: Usa type assertions o proper typing:
|
|
301
|
+
```typescript
|
|
302
|
+
import type { Context } from 'telegraf'
|
|
303
|
+
|
|
304
|
+
export async function handleMyCommand(ctx: Context): Promise<void> {
|
|
305
|
+
// ...
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Environment Variables Issues
|
|
310
|
+
|
|
311
|
+
### Variables No Cargadas
|
|
312
|
+
|
|
313
|
+
**Síntoma**: Variables undefined en runtime
|
|
314
|
+
|
|
315
|
+
**Verificar**:
|
|
316
|
+
```bash
|
|
317
|
+
# Archivo existe
|
|
318
|
+
ls -la core/.env.local
|
|
319
|
+
|
|
320
|
+
# Contenido
|
|
321
|
+
cat core/.env.local
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Solución**:
|
|
325
|
+
1. Verifica formato: `KEY=value` (sin espacios alrededor de `=`)
|
|
326
|
+
2. Verifica que el archivo se llama `.env.local` (no `.env.local.txt`)
|
|
327
|
+
3. Revisa comillas: no usar comillas alrededor de valores
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# ✅ Correcto
|
|
331
|
+
TG_BOT_TOKEN=123:ABC
|
|
332
|
+
|
|
333
|
+
# ❌ Incorrecto
|
|
334
|
+
TG_BOT_TOKEN = 123:ABC
|
|
335
|
+
TG_BOT_TOKEN="123:ABC"
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### TG_ENV No Funciona
|
|
339
|
+
|
|
340
|
+
**Síntoma**: Siempre carga `.env.local`
|
|
341
|
+
|
|
342
|
+
**Verificar**:
|
|
343
|
+
```bash
|
|
344
|
+
echo $TG_ENV
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Solución**:
|
|
348
|
+
```bash
|
|
349
|
+
# Setear explícitamente
|
|
350
|
+
TG_ENV=staging bun run start
|
|
351
|
+
|
|
352
|
+
# O exportar
|
|
353
|
+
export TG_ENV=staging
|
|
354
|
+
bun run start
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## Permission Issues
|
|
358
|
+
|
|
359
|
+
### core/tmp No Writable
|
|
360
|
+
|
|
361
|
+
**Error**:
|
|
362
|
+
```
|
|
363
|
+
Error: EACCES: permission denied, mkdir 'core/tmp'
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**Solución**:
|
|
367
|
+
```bash
|
|
368
|
+
# Crear directorio
|
|
369
|
+
mkdir -p core/tmp
|
|
370
|
+
|
|
371
|
+
# Dar permisos
|
|
372
|
+
chmod 755 core/tmp
|
|
373
|
+
|
|
374
|
+
# Verificar
|
|
375
|
+
ls -la core/
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Logs Directory Issues
|
|
379
|
+
|
|
380
|
+
**Error**:
|
|
381
|
+
```
|
|
382
|
+
Error: EACCES: permission denied, open 'core/logs/info.log'
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Solución**:
|
|
386
|
+
```bash
|
|
387
|
+
mkdir -p core/logs
|
|
388
|
+
chmod 755 core/logs
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Performance Issues
|
|
392
|
+
|
|
393
|
+
### Bot Lento
|
|
394
|
+
|
|
395
|
+
**Causas**:
|
|
396
|
+
1. Operaciones async bloqueantes
|
|
397
|
+
2. No usar async/await correctamente
|
|
398
|
+
3. Demasiados logs en producción
|
|
399
|
+
|
|
400
|
+
**Soluciones**:
|
|
401
|
+
|
|
402
|
+
1. Usar timeouts en operaciones externas:
|
|
403
|
+
```typescript
|
|
404
|
+
const controller = new AbortController()
|
|
405
|
+
setTimeout(() => controller.abort(), 5000)
|
|
406
|
+
|
|
407
|
+
await fetch(url, { signal: controller.signal })
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
2. Reducir log level en producción:
|
|
411
|
+
```bash
|
|
412
|
+
LOG_LEVEL=warn
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
3. Usar rate limiting:
|
|
416
|
+
```bash
|
|
417
|
+
TG_RATE_LIMIT=30
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Memoria Alta
|
|
421
|
+
|
|
422
|
+
**Verificar**:
|
|
423
|
+
```bash
|
|
424
|
+
bun run dev
|
|
425
|
+
# En otra terminal:
|
|
426
|
+
ps aux | grep "bun.*index.ts"
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
**Soluciones**:
|
|
430
|
+
1. Limitar buffer de logs
|
|
431
|
+
2. Usar file logging en lugar de streaming
|
|
432
|
+
3. Revisar memory leaks en código custom
|
|
433
|
+
|
|
434
|
+
## Getting Help
|
|
435
|
+
|
|
436
|
+
### Diagnosticar Antes de Pedir Ayuda
|
|
437
|
+
|
|
438
|
+
1. **Ejecutar doctor**:
|
|
439
|
+
```bash
|
|
440
|
+
bun run doctor
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
2. **Ver logs completos**:
|
|
444
|
+
```bash
|
|
445
|
+
tail -50 core/logs/error.log
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
3. **Ver variables de entorno**:
|
|
449
|
+
```bash
|
|
450
|
+
cat core/.env.local
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
4. **Ver instancias**:
|
|
454
|
+
```bash
|
|
455
|
+
bun run cli status
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Información a Incluir
|
|
459
|
+
|
|
460
|
+
Al pedir ayuda, incluye:
|
|
461
|
+
|
|
462
|
+
1. **Versión de Bun**:
|
|
463
|
+
```bash
|
|
464
|
+
bun --version
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
2. **Output de doctor**:
|
|
468
|
+
```bash
|
|
469
|
+
bun run doctor
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
3. **Error completo** (stack trace)
|
|
473
|
+
|
|
474
|
+
4. **Sistema operativo**:
|
|
475
|
+
```bash
|
|
476
|
+
uname -a
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Recursos
|
|
480
|
+
|
|
481
|
+
- **Troubleshooting Telegram**: [Bot FAQ](https://core.telegram.org/bots/faq)
|
|
482
|
+
- **Telegraf Issues**: [GitHub Issues](https://github.com/telegraf/telegraf/issues)
|
|
483
|
+
- **Template Issues**: Crea issue en el repo
|
|
484
|
+
|
|
485
|
+
## Referencias
|
|
486
|
+
|
|
487
|
+
- [Getting Started](./getting-started.md) - Primeros pasos
|
|
488
|
+
- [CLI Commands](./cli-commands.md) - Comandos útiles
|
|
489
|
+
- [Development](./development.md) - Debugging
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mks-telegram-bot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"workspaces": [
|
|
7
|
+
"core",
|
|
8
|
+
"packages/*",
|
|
9
|
+
"apps/*"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"dev": "bun run --filter @mks2508/telegram-bot-core dev",
|
|
13
|
+
"start": "bun run --filter @mks2508/telegram-bot-core start",
|
|
14
|
+
"cli": "bun run tools/index.ts",
|
|
15
|
+
"ngrok": "bun run tools/index.ts ngrok",
|
|
16
|
+
"typecheck": "tsgo",
|
|
17
|
+
"typecheck:core": "bun run --filter @mks2508/telegram-bot-core typecheck",
|
|
18
|
+
"lint": "oxlint .",
|
|
19
|
+
"lint:fix": "oxlint --fix .",
|
|
20
|
+
"format": "prettier --write .",
|
|
21
|
+
"format:check": "prettier --check .",
|
|
22
|
+
"test": "bun test",
|
|
23
|
+
"test:watch": "bun test --watch",
|
|
24
|
+
"test:coverage": "bun test --coverage",
|
|
25
|
+
"clean": "rm -rf node_modules apps/*/node_modules core/node_modules packages/*/node_modules",
|
|
26
|
+
"setup": "bun run tools/index.ts setup",
|
|
27
|
+
"setup:staging": "bun run tools/index.ts setup --environment staging",
|
|
28
|
+
"setup:production": "bun run tools/index.ts setup --environment production",
|
|
29
|
+
"doctor": "bun run tools/index.ts doctor",
|
|
30
|
+
"build": "bun run typecheck && bun run lint",
|
|
31
|
+
"precommit": "bun run build && bun test",
|
|
32
|
+
"clean:logs": "rm -rf core/logs/* core/tmp/*.lock core/tmp/*.pid",
|
|
33
|
+
"clean:all": "bun run clean && rm -rf core/logs core/tmp"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/bun": "latest",
|
|
37
|
+
"@typescript/native-preview": "latest",
|
|
38
|
+
"oxlint": "latest",
|
|
39
|
+
"prettier": "^3.4.2",
|
|
40
|
+
"typescript": "^5"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@inquirer/prompts": "^8.1.0",
|
|
44
|
+
"chalk": "^5.6.2",
|
|
45
|
+
"commander": "^14.0.2",
|
|
46
|
+
"dotenv": "^17.2.3",
|
|
47
|
+
"glob": "^13.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared logging utilities for mks-telegram-bot monorepo
|
|
3
|
+
* Wraps @mks2508/better-logger with bot-specific presets
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import logger, {
|
|
7
|
+
formatKeyValue,
|
|
8
|
+
formatBadge,
|
|
9
|
+
formatWithRightAlign,
|
|
10
|
+
getANSIForeground,
|
|
11
|
+
getColorCapability,
|
|
12
|
+
ANSI,
|
|
13
|
+
type BadgeStyle,
|
|
14
|
+
component,
|
|
15
|
+
} from '@mks2508/better-logger'
|
|
16
|
+
|
|
17
|
+
let colorCapability = getColorCapability()
|
|
18
|
+
|
|
19
|
+
export function setupLogger(options?: { debug?: boolean; logLevel?: string }) {
|
|
20
|
+
if (options?.debug || options?.logLevel === 'debug') {
|
|
21
|
+
logger.preset('debug')
|
|
22
|
+
logger.showLocation()
|
|
23
|
+
} else {
|
|
24
|
+
logger.preset('cyberpunk')
|
|
25
|
+
}
|
|
26
|
+
logger.showTimestamp()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const botLogger = component('Bot')
|
|
30
|
+
export const configLogger = component('Config')
|
|
31
|
+
export const commandLogger = component('Command')
|
|
32
|
+
export const healthLogger = component('Health')
|
|
33
|
+
export const controlLogger = component('Control')
|
|
34
|
+
export const streamLogger = component('LogStream')
|
|
35
|
+
export const errorLogger = component('Error')
|
|
36
|
+
|
|
37
|
+
export function kv(data: Record<string, unknown>, separator = ' │ '): string {
|
|
38
|
+
return formatKeyValue(data, colorCapability, { separator })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function badge(name: string, style: BadgeStyle = 'pill'): string {
|
|
42
|
+
return formatBadge(name, style, colorCapability, '#00ffff')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function colorText(text: string, hexColor: string): string {
|
|
46
|
+
if (colorCapability === 'none') return text
|
|
47
|
+
return `${getANSIForeground(hexColor, colorCapability)}${text}${ANSI.reset}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function withRightAlign(message: string, rightValue: string): string {
|
|
51
|
+
return formatWithRightAlign(message, rightValue)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function formatDuration(ms: number): string {
|
|
55
|
+
if (ms < 1000) return `${ms}ms`
|
|
56
|
+
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`
|
|
57
|
+
const mins = Math.floor(ms / 60000)
|
|
58
|
+
const secs = Math.floor((ms % 60000) / 1000)
|
|
59
|
+
return `${mins}m${secs}s`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const colors = {
|
|
63
|
+
success: '#00ff88',
|
|
64
|
+
error: '#ff4466',
|
|
65
|
+
warning: '#ffaa00',
|
|
66
|
+
info: '#00ffff',
|
|
67
|
+
user: '#ff00ff',
|
|
68
|
+
command: '#ffff00',
|
|
69
|
+
dim: '#888888',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { logger }
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Result<T,E> monad for type-safe error handling without exceptions.
|
|
3
|
+
* Re-exports from @mks2508/no-throw with Telegram Bot-specific types.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Re-export everything from @mks2508/no-throw
|
|
7
|
+
export {
|
|
8
|
+
ok,
|
|
9
|
+
err,
|
|
10
|
+
isOk,
|
|
11
|
+
isErr,
|
|
12
|
+
unwrap,
|
|
13
|
+
unwrapOr,
|
|
14
|
+
unwrapOrElse,
|
|
15
|
+
map,
|
|
16
|
+
mapErr,
|
|
17
|
+
flatMap,
|
|
18
|
+
tap,
|
|
19
|
+
tapErr,
|
|
20
|
+
match,
|
|
21
|
+
collect,
|
|
22
|
+
all,
|
|
23
|
+
resultError,
|
|
24
|
+
UNKNOWN_ERROR,
|
|
25
|
+
type Result,
|
|
26
|
+
type Ok,
|
|
27
|
+
type Err,
|
|
28
|
+
} from '@mks2508/no-throw'
|
|
29
|
+
|
|
30
|
+
import type { ResultError as GenericResultError, ErrorCode as ErrorCodeHelper } from '@mks2508/no-throw'
|
|
31
|
+
import { err, resultError } from '@mks2508/no-throw'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Telegram Bot-specific error codes.
|
|
35
|
+
*/
|
|
36
|
+
export const BotErrorCode = {
|
|
37
|
+
BotNotRunning: 'BOT_NOT_RUNNING',
|
|
38
|
+
InvalidMode: 'INVALID_MODE',
|
|
39
|
+
WebhookNotConfigured: 'WEBHOOK_NOT_CONFIGURED',
|
|
40
|
+
Unauthorized: 'UNAUTHORIZED',
|
|
41
|
+
TopicNotFound: 'TOPIC_NOT_FOUND',
|
|
42
|
+
MessageFailed: 'MESSAGE_FAILED',
|
|
43
|
+
BotStopped: 'BOT_STOPPED',
|
|
44
|
+
StartFailed: 'START_FAILED',
|
|
45
|
+
StopFailed: 'STOP_FAILED',
|
|
46
|
+
RestartFailed: 'RESTART_FAILED',
|
|
47
|
+
ModeSwitchFailed: 'MODE_SWITCH_FAILED',
|
|
48
|
+
ConfigError: 'CONFIG_ERROR',
|
|
49
|
+
InvalidCommandArgs: 'INVALID_COMMAND_ARGS',
|
|
50
|
+
RateLimitExceeded: 'RATE_LIMIT_EXCEEDED',
|
|
51
|
+
CommandTimeout: 'COMMAND_TIMEOUT',
|
|
52
|
+
WebhookSetupFailed: 'WEBHOOK_SETUP_FAILED',
|
|
53
|
+
InstanceConflict: 'INSTANCE_CONFLICT',
|
|
54
|
+
Unknown: 'UNKNOWN',
|
|
55
|
+
} as const
|
|
56
|
+
|
|
57
|
+
export type BotErrorCode = ErrorCodeHelper<typeof BotErrorCode>
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Telegram Bot-specific ResultError with typed error codes.
|
|
61
|
+
*/
|
|
62
|
+
export type BotError = GenericResultError<BotErrorCode>
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a BotError with the given code, message, and optional cause.
|
|
66
|
+
*/
|
|
67
|
+
export function botError(code: BotErrorCode, message: string, cause?: Error): BotError {
|
|
68
|
+
return resultError(code, message, cause)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates a failure Result with a BotError.
|
|
73
|
+
*/
|
|
74
|
+
export function fail(
|
|
75
|
+
code: BotErrorCode,
|
|
76
|
+
message: string,
|
|
77
|
+
cause?: Error
|
|
78
|
+
): { ok: false; error: BotError } {
|
|
79
|
+
return err(botError(code, message, cause))
|
|
80
|
+
}
|