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,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
|