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,280 @@
|
|
|
1
|
+
# CLAUDE.md - mks-telegram-bot
|
|
2
|
+
|
|
3
|
+
> **Template**: Monorepo para bots de Telegram con Bun, Telegraf y TypeScript
|
|
4
|
+
> **Versión**: 0.1.0
|
|
5
|
+
|
|
6
|
+
Template monorepo diseñado para ser usado como `bun create mks2508/mks-telegram-bot` o como GitHub template repository.
|
|
7
|
+
|
|
8
|
+
**Objetivo**: Template reutilizable para crear bots de Telegram con las mejores prácticas, tipado estricto y arquitectura modular.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Clonar o usar como template
|
|
16
|
+
bun create mks2508/mks-telegram-bot my-bot
|
|
17
|
+
|
|
18
|
+
# Instalar dependencias
|
|
19
|
+
bun install
|
|
20
|
+
|
|
21
|
+
# Configurar variables de entorno
|
|
22
|
+
cp core/.env.example core/.env
|
|
23
|
+
|
|
24
|
+
# Desarrollo
|
|
25
|
+
bun run dev
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Contextos Especializados
|
|
31
|
+
|
|
32
|
+
Este template tiene contextos separados por dominio:
|
|
33
|
+
|
|
34
|
+
| Archivo | Propósito |
|
|
35
|
+
| ------- | --------- |
|
|
36
|
+
| [CLAUDE.dev.md](./CLAUDE.dev.md) | Desarrollo, patterns, testing |
|
|
37
|
+
| [CLAUDE.deploy.md](./CLAUDE.deploy.md) | Deployment, Docker, entornos |
|
|
38
|
+
| [docs/](./docs/) | Documentación web (MDX, futuro) |
|
|
39
|
+
|
|
40
|
+
### CLAUDE.dev.md
|
|
41
|
+
|
|
42
|
+
Ver [CLAUDE.dev.md](./CLAUDE.dev.md) para:
|
|
43
|
+
- Development standards y code style
|
|
44
|
+
- Cómo agregar commands y middleware
|
|
45
|
+
- Testing patterns
|
|
46
|
+
- Result type pattern y Singleton pattern
|
|
47
|
+
- Better Logger usage
|
|
48
|
+
|
|
49
|
+
### CLAUDE.deploy.md
|
|
50
|
+
|
|
51
|
+
Ver [CLAUDE.deploy.md](./CLAUDE.deploy.md) para:
|
|
52
|
+
- Multi-environment (local, staging, production)
|
|
53
|
+
- Multi-instance management
|
|
54
|
+
- Docker deployment
|
|
55
|
+
- ngrok integration
|
|
56
|
+
- VPS deployment guide
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Critical Files for Claude
|
|
61
|
+
|
|
62
|
+
When modifying this codebase, prioritize understanding:
|
|
63
|
+
|
|
64
|
+
- `core/src/index.ts` - Bot entry point, command registration
|
|
65
|
+
- `core/src/config/env.ts` - Environment schema validation
|
|
66
|
+
- `core/src/utils/instance-manager.ts` - Multi-instance locking
|
|
67
|
+
- `packages/utils/src/` - Shared utilities (logger, result)
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Session Context Template
|
|
72
|
+
|
|
73
|
+
When starting a new session, include:
|
|
74
|
+
- **User's goal**: developing vs deploying vs extending
|
|
75
|
+
- **Current environment**: local/staging/production
|
|
76
|
+
- **Any errors or issues encountered**: Paste error messages
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Monorepo Structure
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
mks-telegram-bot/
|
|
84
|
+
├── core/ # @mks2508/telegram-bot-core
|
|
85
|
+
│ ├── .env.local # Local development
|
|
86
|
+
│ ├── .env.staging # Staging environment
|
|
87
|
+
│ ├── .env.production # Production environment
|
|
88
|
+
│ ├── tmp/ # Instance lock files
|
|
89
|
+
│ └── src/ # Bot source code
|
|
90
|
+
├── packages/ # Shared code
|
|
91
|
+
│ └── utils/ # @mks2508/telegram-bot-utils
|
|
92
|
+
├── tools/ # CLI tools
|
|
93
|
+
│ └── commands/ # ngrok, status
|
|
94
|
+
├── apps/ # Future: examples, docs
|
|
95
|
+
├── docs/ # Future MDX site
|
|
96
|
+
├── Dockerfile # Multi-stage build
|
|
97
|
+
└── docker-compose.yml # Local dev containers
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Commands
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Development
|
|
106
|
+
bun run dev # Hot reload (watch mode)
|
|
107
|
+
bun run start # Production mode
|
|
108
|
+
|
|
109
|
+
# CLI tools
|
|
110
|
+
bun run status # Show running instances
|
|
111
|
+
bun run ngrok # Start ngrok tunnel
|
|
112
|
+
|
|
113
|
+
# Quality
|
|
114
|
+
bun run typecheck # Type check (tsgo ~10x faster)
|
|
115
|
+
bun run lint # Lint (oxlint)
|
|
116
|
+
bun run format # Format (prettier)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Environment Variables
|
|
122
|
+
|
|
123
|
+
### Multi-Environment Support
|
|
124
|
+
|
|
125
|
+
El proyecto soporta múltiples entornos con archivos `.env` separados:
|
|
126
|
+
|
|
127
|
+
| Archivo | Uso |
|
|
128
|
+
| ------- | --- |
|
|
129
|
+
| `core/.env.local` | Desarrollo local (polling mode) |
|
|
130
|
+
| `core/.env.staging` | Testing con bot de test |
|
|
131
|
+
| `core/.env.production` | Producción con bot real |
|
|
132
|
+
|
|
133
|
+
La variable `TG_ENV` (default: `local`) determina cuál archivo cargar.
|
|
134
|
+
|
|
135
|
+
### Required Variables
|
|
136
|
+
|
|
137
|
+
| Variable | Tipo | Description |
|
|
138
|
+
| -------- | ---- | ----------- |
|
|
139
|
+
| `TG_BOT_TOKEN` | string | Bot token from @BotFather |
|
|
140
|
+
| `TG_MODE` | enum | `polling` or `webhook` |
|
|
141
|
+
|
|
142
|
+
### Instance Detection Variables
|
|
143
|
+
|
|
144
|
+
| Variable | Default | Description |
|
|
145
|
+
| -------- | ------- | ----------- |
|
|
146
|
+
| `TG_ENV` | `local` | Environment: local/staging/production |
|
|
147
|
+
| `TG_INSTANCE_NAME` | `mks-bot` | Unique instance name for locking |
|
|
148
|
+
| `TG_INSTANCE_CHECK` | `true` | Enable instance conflict detection |
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Technology Stack
|
|
153
|
+
|
|
154
|
+
| Tool | Purpose | Version |
|
|
155
|
+
| ---- | ------- | ------- |
|
|
156
|
+
| **Bun** | Runtime & package manager | 1.3+ |
|
|
157
|
+
| **Telegraf** | Telegram Bot API | 4.16+ |
|
|
158
|
+
| **TypeScript** | Language | 5.9+ |
|
|
159
|
+
| **tsgo** | Type-checking | native-preview |
|
|
160
|
+
| **Zod** | Schema validation | 3.24+ |
|
|
161
|
+
| **Better Logger** | Logging | 4.0.0 |
|
|
162
|
+
| **@mks2508/no-throw** | Result type | 0.1.0 |
|
|
163
|
+
| **oxlint** | Linting | latest |
|
|
164
|
+
| **prettier** | Formatting | 3.4+ |
|
|
165
|
+
| **commander** | CLI framework | 14.0+ |
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Architecture Overview
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
173
|
+
│ Telegram API (Telegraf) │
|
|
174
|
+
└─────────────────────────┬───────────────────────────────────┘
|
|
175
|
+
│
|
|
176
|
+
┌─────────────────┼─────────────────┐
|
|
177
|
+
│ │ │
|
|
178
|
+
┌────▼────┐ ┌───────▼───────┐ ┌──────▼──────┐
|
|
179
|
+
│Middleware│ │ Handlers │ │ BotManager │
|
|
180
|
+
│ • auth │ │ • health │ │ InstanceMgr │
|
|
181
|
+
│ • error │ │ • control │ │ • stats │
|
|
182
|
+
│ • topics │ │ • logs │ │ • lifecycle │
|
|
183
|
+
└──────────┘ └──────────────┘ └─────────────┘
|
|
184
|
+
│ │
|
|
185
|
+
└────────────┬───────────────────┘
|
|
186
|
+
│
|
|
187
|
+
┌────────▼────────┐
|
|
188
|
+
│ InstanceManager │
|
|
189
|
+
│ • acquireLock │
|
|
190
|
+
│ • releaseLock │
|
|
191
|
+
└─────────────────┘
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Bot Commands
|
|
197
|
+
|
|
198
|
+
### Public Commands
|
|
199
|
+
|
|
200
|
+
| Command | Handler | Description |
|
|
201
|
+
| ------- | ------- | ----------- |
|
|
202
|
+
| `/start` | inline | Welcome message |
|
|
203
|
+
| `/health` | handleHealth | Bot health status |
|
|
204
|
+
| `/uptime` | handleUptime | Uptime information |
|
|
205
|
+
| `/stats` | handleStats | Bot statistics |
|
|
206
|
+
| `/logs` | handleLogs | Log streaming status |
|
|
207
|
+
|
|
208
|
+
### Control Commands (requires auth)
|
|
209
|
+
|
|
210
|
+
| Command | Handler | Description |
|
|
211
|
+
| ------- | ------- | ----------- |
|
|
212
|
+
| `/stop` | handleStop | Graceful shutdown |
|
|
213
|
+
| `/restart` | handleRestart | Restart with stats reset |
|
|
214
|
+
| `/mode` | handleMode | Switch polling/webhook |
|
|
215
|
+
| `/webhook` | handleWebhook | Show webhook config |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Development Workflow
|
|
220
|
+
|
|
221
|
+
### Before Commit
|
|
222
|
+
|
|
223
|
+
- [ ] `bun run typecheck` → 0 errores
|
|
224
|
+
- [ ] `bun run lint` → 0 warnings, 0 errors
|
|
225
|
+
- [ ] `bun test` → all tests pass (if tests exist)
|
|
226
|
+
- [ ] No `console.*` (use Better Logger)
|
|
227
|
+
|
|
228
|
+
### Code Style
|
|
229
|
+
|
|
230
|
+
- TypeScript strict mode enabled
|
|
231
|
+
- `noUncheckedIndexedAccess: true` - arrays need undefined checks
|
|
232
|
+
- Semi: false, singleQuote: true
|
|
233
|
+
- Result type pattern para error handling
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Documentation Web
|
|
238
|
+
|
|
239
|
+
Ver [docs/](./docs/) para documentación completa (futuro MDX site con Astro/Starlight).
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Future Apps
|
|
244
|
+
|
|
245
|
+
El directorio `apps/` está preparado para:
|
|
246
|
+
- `apps/example/` - Ejemplo de bot completo
|
|
247
|
+
- `apps/docs/` - Documentación interactiva
|
|
248
|
+
- `apps/cli/` - CLI extendida para gestión
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Deployment
|
|
253
|
+
|
|
254
|
+
### Docker
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# Build image
|
|
258
|
+
docker build -t mks-telegram-bot .
|
|
259
|
+
|
|
260
|
+
# Run with docker-compose
|
|
261
|
+
docker-compose up bot-production
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Multi-Instance
|
|
265
|
+
|
|
266
|
+
El template soporta múltiples instancias simultáneas con detección de conflictos:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Ver instancias corriendo
|
|
270
|
+
bun run status
|
|
271
|
+
|
|
272
|
+
# Iniciar en entorno específico
|
|
273
|
+
TG_ENV=staging bun run start
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Build stage
|
|
2
|
+
FROM oven/bun:1.3 AS builder
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
|
|
5
|
+
# Copy package files
|
|
6
|
+
COPY package.json bun.lock ./
|
|
7
|
+
COPY core/package.json core/
|
|
8
|
+
|
|
9
|
+
# Install dependencies
|
|
10
|
+
RUN bun install --frozen-lockfile
|
|
11
|
+
|
|
12
|
+
# Copy TypeScript config and source
|
|
13
|
+
COPY tsconfig.json ./
|
|
14
|
+
COPY core/tsconfig.json core/
|
|
15
|
+
COPY core/src core/src
|
|
16
|
+
|
|
17
|
+
# Production stage
|
|
18
|
+
FROM oven/bun:1.3 AS production
|
|
19
|
+
WORKDIR /app
|
|
20
|
+
|
|
21
|
+
# Copy node_modules from builder
|
|
22
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
23
|
+
COPY --from=builder /app/core/node_modules ./core/node_modules
|
|
24
|
+
|
|
25
|
+
# Copy source and config files
|
|
26
|
+
COPY --from=builder /app/core/src ./core/src
|
|
27
|
+
COPY --from=builder /app/core/package.json ./core/
|
|
28
|
+
COPY --from=builder /app/core/tsconfig.json ./core/
|
|
29
|
+
|
|
30
|
+
# Create necessary directories
|
|
31
|
+
RUN mkdir -p /app/core/tmp /app/core/logs
|
|
32
|
+
|
|
33
|
+
# Set environment variables
|
|
34
|
+
ENV TG_ENV=production
|
|
35
|
+
ENV NODE_ENV=production
|
|
36
|
+
ENV TG_MODE=webhook
|
|
37
|
+
|
|
38
|
+
# Healthcheck
|
|
39
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
40
|
+
CMD bun run cli status || exit 1
|
|
41
|
+
|
|
42
|
+
# Expose webhook port
|
|
43
|
+
EXPOSE 3000
|
|
44
|
+
|
|
45
|
+
# Run the bot
|
|
46
|
+
CMD ["bun", "run", "start"]
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# mks-telegram-bot
|
|
2
|
+
|
|
3
|
+
> Template monorepo para bots de Telegram con Bun, Telegraf y TypeScript
|
|
4
|
+
|
|
5
|
+
[](https://github.com/MKS2508/mks-telegram-bot/generate)
|
|
6
|
+
|
|
7
|
+
Template listo para producción con soporte multi-entorno, multi-instancia, y las mejores prácticas de desarrollo.
|
|
8
|
+
|
|
9
|
+
## Quick Start (5 min)
|
|
10
|
+
|
|
11
|
+
### 1. Crear el Bot
|
|
12
|
+
|
|
13
|
+
Habla con [@BotFather](https://t.me/BotFather) en Telegram:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
/newbot
|
|
17
|
+
→ Nombre: MyBot
|
|
18
|
+
→ Username: my_awesome_bot
|
|
19
|
+
→ Copia el token (ej: 123456:ABC-DEF1234...)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Instalar y Configurar
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Usar el template
|
|
26
|
+
# Click en "Use this template" arriba → Create a new repository
|
|
27
|
+
# O con CLI: gh repo create my-bot --template MKS2508/mks-telegram-bot
|
|
28
|
+
|
|
29
|
+
# Clonar tu nuevo repo
|
|
30
|
+
git clone https://github.com/TU_USUARIO/my-bot.git
|
|
31
|
+
cd my-bot
|
|
32
|
+
|
|
33
|
+
# Instalar dependencias
|
|
34
|
+
bun install
|
|
35
|
+
|
|
36
|
+
# Setup interactivo (crea .env.local)
|
|
37
|
+
bun run setup
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
El comando `setup` te preguntará:
|
|
41
|
+
- Bot token (pega el token de @BotFather)
|
|
42
|
+
- Modo (polling para desarrollo)
|
|
43
|
+
- Chat IDs opcionales
|
|
44
|
+
|
|
45
|
+
### 3. Arrancar en Desarrollo
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
bun run dev
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 4. Probar
|
|
52
|
+
|
|
53
|
+
Envía `/start` o `/health` a tu bot en Telegram.
|
|
54
|
+
|
|
55
|
+
## Comandos CLI
|
|
56
|
+
|
|
57
|
+
| Comando | Descripción |
|
|
58
|
+
| ------- | ----------- |
|
|
59
|
+
| `bun run setup` | Configuración interactiva de entorno |
|
|
60
|
+
| `bun run setup:staging` | Setup para entorno staging |
|
|
61
|
+
| `bun run setup:production` | Setup para producción |
|
|
62
|
+
| `bun run doctor` | Diagnóstico de configuración |
|
|
63
|
+
| `bun run cli status` | Ver instancias corriendo |
|
|
64
|
+
| `bun run ngrok` | ngrok con webhook auto-config |
|
|
65
|
+
|
|
66
|
+
## Scripts de Desarrollo
|
|
67
|
+
|
|
68
|
+
| Script | Descripción |
|
|
69
|
+
| ------ | ----------- |
|
|
70
|
+
| `bun run dev` | Hot reload (development) |
|
|
71
|
+
| `bun run start` | Production start |
|
|
72
|
+
| `bun run build` | Typecheck + lint |
|
|
73
|
+
| `bun run test` | Ejecutar tests |
|
|
74
|
+
| `bun run typecheck` | Type-check con tsgo |
|
|
75
|
+
| `bun run lint` | Lint con oxlint |
|
|
76
|
+
|
|
77
|
+
## Documentación
|
|
78
|
+
|
|
79
|
+
| Documento | Descripción |
|
|
80
|
+
| --------- | ----------- |
|
|
81
|
+
| [Getting Started](./docs/getting-started.md) | Guía de inicio paso a paso |
|
|
82
|
+
| [Environment](./docs/environment.md) | Variables de entorno |
|
|
83
|
+
| [CLI Commands](./docs/cli-commands.md) | Comandos CLI disponibles |
|
|
84
|
+
| [Development](./docs/development.md) | Flujo de desarrollo |
|
|
85
|
+
| [Troubleshooting](./docs/troubleshooting.md) | Problemas comunes |
|
|
86
|
+
|
|
87
|
+
**Documentación adicional:**
|
|
88
|
+
- [CLAUDE.md](./CLAUDE.md) - Entry point principal
|
|
89
|
+
- [CLAUDE.dev.md](./CLAUDE.dev.md) - Guía de desarrollo
|
|
90
|
+
- [CLAUDE.deploy.md](./CLAUDE.deploy.md) - Deployment y entornos
|
|
91
|
+
|
|
92
|
+
## Estructura del Monorepo
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
mks-telegram-bot/
|
|
96
|
+
├── core/ # Bot principal (@mks2508/telegram-bot-core)
|
|
97
|
+
│ ├── src/
|
|
98
|
+
│ │ ├── index.ts # Entry point
|
|
99
|
+
│ │ ├── config/ # Configuration & env validation
|
|
100
|
+
│ │ ├── handlers/ # Command handlers
|
|
101
|
+
│ │ ├── middleware/ # Telegraf middleware
|
|
102
|
+
│ │ ├── types/ # TypeScript types & Result pattern
|
|
103
|
+
│ │ └── utils/ # Utilities (bot-manager, instance-manager)
|
|
104
|
+
│ └── .env.example # Template de variables de entorno
|
|
105
|
+
├── packages/utils/ # Utilidades compartidas (@mks2508/telegram-bot-utils)
|
|
106
|
+
│ └── src/
|
|
107
|
+
│ ├── logger.ts # Better Logger setup
|
|
108
|
+
│ └── result.ts # Result type pattern
|
|
109
|
+
├── tools/ # CLI tools
|
|
110
|
+
│ └── commands/
|
|
111
|
+
│ ├── setup.ts # Interactive setup
|
|
112
|
+
│ ├── doctor.ts # Diagnostics
|
|
113
|
+
│ ├── status.ts # Instance status
|
|
114
|
+
│ └── ngrok.ts # ngrok integration
|
|
115
|
+
├── docs/ # Documentación
|
|
116
|
+
│ ├── getting-started.md
|
|
117
|
+
│ ├── environment.md
|
|
118
|
+
│ ├── cli-commands.md
|
|
119
|
+
│ ├── development.md
|
|
120
|
+
│ ├── troubleshooting.md
|
|
121
|
+
│ └── examples/ # Ejemplos de código
|
|
122
|
+
└── apps/ # Apps de ejemplo (futuro)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Stack Tecnológico
|
|
126
|
+
|
|
127
|
+
| Herramienta | Versión | Uso |
|
|
128
|
+
| ----------- | ------ | --- |
|
|
129
|
+
| **Bun** | 1.3+ | Runtime & package manager |
|
|
130
|
+
| **TypeScript** | 5.9+ | Lenguaje |
|
|
131
|
+
| **Telegraf** | 4.16+ | Telegram Bot API |
|
|
132
|
+
| **Zod** | 3.24+ | Schema validation |
|
|
133
|
+
| **Better Logger** | 4.0.0 | Logging |
|
|
134
|
+
| **@mks2508/no-throw** | 0.1.0 | Result type pattern |
|
|
135
|
+
| **tsgo** | native-preview | Type checking |
|
|
136
|
+
| **oxlint** | latest | Linting |
|
|
137
|
+
| **prettier** | 3.4+ | Formatting |
|
|
138
|
+
|
|
139
|
+
## Features
|
|
140
|
+
|
|
141
|
+
### Core
|
|
142
|
+
- ✅ Result type pattern para error handling sin excepciones
|
|
143
|
+
- ✅ TypeScript strict mode con tipado completo
|
|
144
|
+
- ✅ Soporte polling y webhook modes
|
|
145
|
+
- ✅ Configuración centralizada con Zod validation
|
|
146
|
+
- ✅ Singleton pattern para BotManager y Config
|
|
147
|
+
|
|
148
|
+
### Multi-Entorno
|
|
149
|
+
- ✅ Soporte para local, staging, production
|
|
150
|
+
- ✅ Archivos `.env.{environment}` separados
|
|
151
|
+
- ✅ Selección vía `TG_ENV`
|
|
152
|
+
- ✅ Setup CLI interactivo
|
|
153
|
+
|
|
154
|
+
### Multi-Instancia
|
|
155
|
+
- ✅ Lock management con archivos PID
|
|
156
|
+
- ✅ Detección de conflictos
|
|
157
|
+
- ✅ Status CLI para ver instancias
|
|
158
|
+
- ✅ Doctor CLI para diagnóstico
|
|
159
|
+
|
|
160
|
+
### Logging System
|
|
161
|
+
Tres destinos de logging usando Better Logger 4.0.0:
|
|
162
|
+
|
|
163
|
+
1. **Console** - Colored output con preset cyberpunk
|
|
164
|
+
2. **File** - Logs persistentes con rotación automática
|
|
165
|
+
3. **Telegram** - Streaming a chat con buffering
|
|
166
|
+
|
|
167
|
+
### Bot Commands
|
|
168
|
+
|
|
169
|
+
**Public Commands**:
|
|
170
|
+
- `/start` - Welcome message
|
|
171
|
+
- `/health` - Health check
|
|
172
|
+
- `/uptime` - Uptime info
|
|
173
|
+
- `/stats` - Statistics
|
|
174
|
+
- `/logs` - Log streaming status
|
|
175
|
+
|
|
176
|
+
**Control Commands** (requieren autorización):
|
|
177
|
+
- `/stop` - Graceful shutdown
|
|
178
|
+
- `/restart` - Restart con stats reset
|
|
179
|
+
- `/mode` - Switch polling/webhook
|
|
180
|
+
- `/webhook` - Webhook configuration
|
|
181
|
+
|
|
182
|
+
## Development Workflow
|
|
183
|
+
|
|
184
|
+
### Setup Inicial
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Instalar dependencias
|
|
188
|
+
bun install
|
|
189
|
+
|
|
190
|
+
# Setup interactivo
|
|
191
|
+
bun run setup
|
|
192
|
+
|
|
193
|
+
# Verificar configuración
|
|
194
|
+
bun run doctor
|
|
195
|
+
|
|
196
|
+
# Arrancar en desarrollo
|
|
197
|
+
bun run dev
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Antes de Commitear
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# Verificar tipo y lint
|
|
204
|
+
bun run build
|
|
205
|
+
|
|
206
|
+
# Ejecutar tests
|
|
207
|
+
bun test
|
|
208
|
+
|
|
209
|
+
# O usar precommit
|
|
210
|
+
bun run precommit
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Code Style
|
|
214
|
+
|
|
215
|
+
- TypeScript strict mode
|
|
216
|
+
- Semi: false, singleQuote: true
|
|
217
|
+
- Result type pattern para error handling
|
|
218
|
+
- Better Logger para logging (no console.*)
|
|
219
|
+
|
|
220
|
+
## Examples
|
|
221
|
+
|
|
222
|
+
Ver [`docs/examples/`](./docs/examples/) para ejemplos completos:
|
|
223
|
+
|
|
224
|
+
- [Simple Command](./docs/examples/simple-command.md) - Crear comandos
|
|
225
|
+
- [Auth Middleware](./docs/examples/middleware-auth.md) - Middleware de autenticación
|
|
226
|
+
- [Webhook Setup](./docs/examples/webhook-setup.md) - Configurar webhook
|
|
227
|
+
|
|
228
|
+
## Deployment
|
|
229
|
+
|
|
230
|
+
El template incluye configuración para:
|
|
231
|
+
|
|
232
|
+
- **Docker** - Dockerfile multi-stage incluido
|
|
233
|
+
- **VPS** - Guía para deployment en VPS
|
|
234
|
+
- **ngrok** - Integración para testing local
|
|
235
|
+
- **Multi-entorno** - local, staging, production
|
|
236
|
+
|
|
237
|
+
Ver [CLAUDE.deploy.md](./CLAUDE.deploy.md) para guía completa de deployment.
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
MIT
|
|
242
|
+
|
|
243
|
+
## Autor
|
|
244
|
+
|
|
245
|
+
[@mks2508](https://github.com/mks2508)
|
|
File without changes
|