create-bunspace 0.2.5 → 0.3.1
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/dist/templates/monorepo/apps/example/package.json +1 -1
- package/dist/templates/monorepo/core/packages/utils/rolldown.config.ts +30 -0
- package/dist/templates/monorepo/tsconfig.json +3 -1
- package/dist/templates/telegram-bot/CLAUDE.deploy.md +2 -3
- package/dist/templates/telegram-bot/CLAUDE.dev.md +304 -5
- package/dist/templates/telegram-bot/CLAUDE.md +166 -89
- package/dist/templates/telegram-bot/README.md +252 -129
- package/dist/templates/telegram-bot/bun.lock +132 -3
- package/dist/templates/telegram-bot/core/.env.example +6 -0
- package/dist/templates/telegram-bot/core/package.json +11 -0
- package/dist/templates/telegram-bot/core/rolldown.config.ts +11 -0
- package/dist/templates/telegram-bot/core/src/config/env.ts +130 -1
- package/dist/templates/telegram-bot/core/src/config/logging.ts +4 -4
- package/dist/templates/telegram-bot/core/src/handlers/config-export.ts +123 -0
- package/dist/templates/telegram-bot/core/src/handlers/control.ts +46 -11
- package/dist/templates/telegram-bot/core/src/handlers/demo-full.ts +58 -0
- package/dist/templates/telegram-bot/core/src/handlers/demo-keyboard.ts +49 -0
- package/dist/templates/telegram-bot/core/src/handlers/demo-media.ts +163 -0
- package/dist/templates/telegram-bot/core/src/handlers/demo-text.ts +27 -0
- package/dist/templates/telegram-bot/core/src/handlers/health.ts +40 -37
- package/dist/templates/telegram-bot/core/src/handlers/info.ts +189 -0
- package/dist/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
- package/dist/templates/telegram-bot/core/src/handlers/logs.ts +16 -7
- package/dist/templates/telegram-bot/core/src/index.ts +49 -1
- package/dist/templates/telegram-bot/core/src/utils/formatters.ts +14 -33
- package/dist/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
- package/dist/templates/telegram-bot/core/src/utils/message-builder.ts +180 -0
- package/dist/templates/telegram-bot/core/tsconfig.json +2 -0
- package/dist/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
- package/dist/templates/telegram-bot/docs/cli-commands.md +514 -5
- package/dist/templates/telegram-bot/docs/environment.md +191 -3
- package/dist/templates/telegram-bot/docs/getting-started.md +202 -15
- package/dist/templates/telegram-bot/package.json +7 -3
- package/dist/templates/telegram-bot/packages/utils/package.json +12 -1
- package/dist/templates/telegram-bot/packages/utils/rolldown.config.ts +11 -0
- package/dist/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
- package/dist/templates/telegram-bot/packages/utils/tsconfig.json +10 -0
- package/dist/templates/telegram-bot/tools/commands/doctor.ts +62 -0
- package/dist/templates/telegram-bot/tools/commands/setup.ts +984 -170
- package/dist/templates/telegram-bot/tsconfig.json +7 -2
- package/package.json +1 -1
- package/templates/monorepo/apps/example/package.json +1 -1
- package/templates/monorepo/core/packages/utils/rolldown.config.ts +30 -0
- package/templates/monorepo/tsconfig.json +3 -1
- package/templates/telegram-bot/CLAUDE.deploy.md +2 -3
- package/templates/telegram-bot/CLAUDE.dev.md +304 -5
- package/templates/telegram-bot/CLAUDE.md +166 -89
- package/templates/telegram-bot/README.md +252 -129
- package/templates/telegram-bot/bun.lock +132 -3
- package/templates/telegram-bot/core/.env.example +6 -0
- package/templates/telegram-bot/core/package.json +11 -0
- package/templates/telegram-bot/core/rolldown.config.ts +11 -0
- package/templates/telegram-bot/core/src/config/env.ts +130 -1
- package/templates/telegram-bot/core/src/config/logging.ts +4 -4
- package/templates/telegram-bot/core/src/handlers/config-export.ts +123 -0
- package/templates/telegram-bot/core/src/handlers/control.ts +46 -11
- package/templates/telegram-bot/core/src/handlers/demo-full.ts +58 -0
- package/templates/telegram-bot/core/src/handlers/demo-keyboard.ts +49 -0
- package/templates/telegram-bot/core/src/handlers/demo-media.ts +163 -0
- package/templates/telegram-bot/core/src/handlers/demo-text.ts +27 -0
- package/templates/telegram-bot/core/src/handlers/health.ts +40 -37
- package/templates/telegram-bot/core/src/handlers/info.ts +189 -0
- package/templates/telegram-bot/core/src/handlers/listener.ts +168 -0
- package/templates/telegram-bot/core/src/handlers/logs.ts +16 -7
- package/templates/telegram-bot/core/src/index.ts +49 -1
- package/templates/telegram-bot/core/src/utils/formatters.ts +14 -33
- package/templates/telegram-bot/core/src/utils/instance-manager.ts +6 -2
- package/templates/telegram-bot/core/tsconfig.json +2 -0
- package/templates/telegram-bot/docs/automatizacion_integral_de_bots_de_telegram_con_type_script.md +326 -0
- package/templates/telegram-bot/docs/cli-commands.md +514 -5
- package/templates/telegram-bot/docs/environment.md +191 -3
- package/templates/telegram-bot/docs/getting-started.md +202 -15
- package/templates/telegram-bot/package.json +7 -3
- package/templates/telegram-bot/packages/utils/package.json +12 -1
- package/templates/telegram-bot/packages/utils/rolldown.config.ts +11 -0
- package/templates/telegram-bot/packages/utils/src/logger.ts +1 -0
- package/templates/telegram-bot/packages/utils/tsconfig.json +10 -0
- package/templates/telegram-bot/tools/commands/doctor.ts +62 -0
- package/templates/telegram-bot/tools/commands/setup.ts +984 -170
- package/templates/telegram-bot/tsconfig.json +7 -2
|
@@ -2,6 +2,7 @@ import type { Context } from 'telegraf'
|
|
|
2
2
|
import { updateConfig, getConfig } from '../config/index.js'
|
|
3
3
|
import { botLogger, controlLogger, badge, kv, colors, colorText } from '../middleware/logging.js'
|
|
4
4
|
import { botManager } from '../utils/bot-manager.js'
|
|
5
|
+
import { TelegramMessageBuilder } from '@mks2508/telegram-message-builder'
|
|
5
6
|
|
|
6
7
|
export async function handleStop(ctx: Context): Promise<void> {
|
|
7
8
|
const userId = ctx.from?.id ?? 'unknown'
|
|
@@ -13,7 +14,10 @@ export async function handleStop(ctx: Context): Promise<void> {
|
|
|
13
14
|
})}`
|
|
14
15
|
)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
const message = TelegramMessageBuilder.text()
|
|
18
|
+
.text('🛑 Shutting down bot...')
|
|
19
|
+
.build()
|
|
20
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
17
21
|
process.exit(0)
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -27,9 +31,17 @@ export async function handleRestart(ctx: Context): Promise<void> {
|
|
|
27
31
|
})}`
|
|
28
32
|
)
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
const message1 = TelegramMessageBuilder.text()
|
|
35
|
+
.text('🔄 Restarting bot...')
|
|
36
|
+
.build()
|
|
37
|
+
ctx.reply(message1.text || '', { parse_mode: (message1.parse_mode || 'HTML') as any })
|
|
38
|
+
|
|
31
39
|
botManager.resetStats()
|
|
32
|
-
|
|
40
|
+
|
|
41
|
+
const message2 = TelegramMessageBuilder.text()
|
|
42
|
+
.text('✅ Bot stats reset. Restarting...')
|
|
43
|
+
.build()
|
|
44
|
+
ctx.reply(message2.text || '', { parse_mode: (message2.parse_mode || 'HTML') as any })
|
|
33
45
|
process.exit(0)
|
|
34
46
|
}
|
|
35
47
|
|
|
@@ -40,22 +52,37 @@ export async function handleMode(ctx: Context): Promise<void> {
|
|
|
40
52
|
|
|
41
53
|
if (!mode || (mode !== 'polling' && mode !== 'webhook')) {
|
|
42
54
|
const config = getConfig()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
const message = TelegramMessageBuilder.text()
|
|
56
|
+
.title('📡 Current Mode')
|
|
57
|
+
.newline()
|
|
58
|
+
.line('Mode', config.mode, { code: true })
|
|
59
|
+
.newline()
|
|
60
|
+
.text('Usage: /mode <polling|webhook>')
|
|
61
|
+
.build()
|
|
62
|
+
|
|
63
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
46
64
|
return
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
if (mode === 'webhook') {
|
|
50
68
|
const config = getConfig()
|
|
51
69
|
if (!config.webhookUrl) {
|
|
52
|
-
|
|
70
|
+
const message = TelegramMessageBuilder.text()
|
|
71
|
+
.text('❌ Webhook URL not configured. Set TG_WEBHOOK_URL environment variable.')
|
|
72
|
+
.build()
|
|
73
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
53
74
|
return
|
|
54
75
|
}
|
|
55
76
|
}
|
|
56
77
|
|
|
57
78
|
updateConfig({ mode })
|
|
58
|
-
|
|
79
|
+
|
|
80
|
+
const message = TelegramMessageBuilder.text()
|
|
81
|
+
.text('✅ Mode changed to:')
|
|
82
|
+
.line('Mode', mode, { code: true })
|
|
83
|
+
.build()
|
|
84
|
+
|
|
85
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
59
86
|
|
|
60
87
|
controlLogger.info(
|
|
61
88
|
`${badge('MODE', 'rounded')} ${kv({
|
|
@@ -69,12 +96,20 @@ export async function handleWebhook(ctx: Context): Promise<void> {
|
|
|
69
96
|
const config = getConfig()
|
|
70
97
|
|
|
71
98
|
if (config.mode !== 'webhook') {
|
|
72
|
-
|
|
99
|
+
const message = TelegramMessageBuilder.text()
|
|
100
|
+
.text('❌ Bot is not in webhook mode. Use /mode webhook first.')
|
|
101
|
+
.build()
|
|
102
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
73
103
|
return
|
|
74
104
|
}
|
|
75
105
|
|
|
76
|
-
const message =
|
|
77
|
-
|
|
106
|
+
const message = TelegramMessageBuilder.text()
|
|
107
|
+
.title('🔗 Webhook Configuration')
|
|
108
|
+
.newline()
|
|
109
|
+
.line('URL', config.webhookUrl || 'Not set', { code: true })
|
|
110
|
+
.build()
|
|
111
|
+
|
|
112
|
+
ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
78
113
|
|
|
79
114
|
controlLogger.info(
|
|
80
115
|
`${badge('WEBHOOK', 'rounded')} ${kv({
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TelegramMessageBuilder, TelegramKeyboardBuilder } from '@mks2508/telegram-message-builder'
|
|
2
|
+
import type { Context } from 'telegraf'
|
|
3
|
+
import { handleMediaDemo } from './demo-media.js'
|
|
4
|
+
import { handleKeyboardDemo } from './demo-keyboard.js'
|
|
5
|
+
|
|
6
|
+
export async function handleFullDemo(ctx: Context): Promise<void> {
|
|
7
|
+
const message = TelegramMessageBuilder.text()
|
|
8
|
+
.title('🚀 telegram-message-builder v0.3.0')
|
|
9
|
+
.newline()
|
|
10
|
+
.section('Features')
|
|
11
|
+
.listItem('✨ Fluent API for text formatting')
|
|
12
|
+
.listItem('⌨️ Inline and reply keyboards')
|
|
13
|
+
.listItem('📸 5 media types support')
|
|
14
|
+
.listItem('🎨 HTML, Markdown, MarkdownV2')
|
|
15
|
+
.listItem('🔒 Type-safe with TypeScript')
|
|
16
|
+
.listItem('📦 Zero runtime dependencies')
|
|
17
|
+
.newline()
|
|
18
|
+
.section('Installation')
|
|
19
|
+
.codeBlock('bun add @mks2508/telegram-message-builder', 'bash')
|
|
20
|
+
.newline()
|
|
21
|
+
.section('Quick Start')
|
|
22
|
+
.codeBlock(`import { TelegramMessageBuilder } from '@mks2508/telegram-message-builder'
|
|
23
|
+
|
|
24
|
+
const message = TelegramMessageBuilder.text()
|
|
25
|
+
.title('Hello World')
|
|
26
|
+
.line('Status', 'Active', { bold: true })
|
|
27
|
+
.build()
|
|
28
|
+
|
|
29
|
+
ctx.reply(message.text, { parse_mode: message.parse_mode })`, 'typescript')
|
|
30
|
+
.build()
|
|
31
|
+
|
|
32
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
33
|
+
.urlButton('📦 npm Package', 'https://www.npmjs.com/package/@mks2508/telegram-message-builder')
|
|
34
|
+
.urlButton('📖 GitHub', 'https://github.com/MKS2508/telegram-message-builder')
|
|
35
|
+
.row()
|
|
36
|
+
.callbackButton('📸 Media Demo', 'full_demo_media')
|
|
37
|
+
.callbackButton('⌨️ Keyboard Demo', 'full_demo_keyboard')
|
|
38
|
+
.buildMarkup()
|
|
39
|
+
|
|
40
|
+
await ctx.reply(message.text || '', {
|
|
41
|
+
parse_mode: (message.parse_mode || 'HTML') as any,
|
|
42
|
+
reply_markup: keyboard as any,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function handleFullDemoCallback(ctx: Context): Promise<void> {
|
|
47
|
+
const callbackData = (ctx.callbackQuery as any)?.data
|
|
48
|
+
await ctx.answerCbQuery()
|
|
49
|
+
|
|
50
|
+
switch (callbackData) {
|
|
51
|
+
case 'full_demo_media':
|
|
52
|
+
await handleMediaDemo(ctx)
|
|
53
|
+
break
|
|
54
|
+
case 'full_demo_keyboard':
|
|
55
|
+
await handleKeyboardDemo(ctx)
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TelegramMessageBuilder, TelegramKeyboardBuilder } from '@mks2508/telegram-message-builder'
|
|
2
|
+
import type { Context } from 'telegraf'
|
|
3
|
+
|
|
4
|
+
export async function handleKeyboardDemo(ctx: Context): Promise<void> {
|
|
5
|
+
const message = TelegramMessageBuilder.text()
|
|
6
|
+
.title('⌨️ Keyboard Demo')
|
|
7
|
+
.newline()
|
|
8
|
+
.text('Try the buttons below:')
|
|
9
|
+
.build()
|
|
10
|
+
|
|
11
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
12
|
+
.urlButton('🌐 Visit Website', 'https://github.com/MKS2508/telegram-message-builder')
|
|
13
|
+
.callbackButton('✅ Yes', 'demo_yes')
|
|
14
|
+
.callbackButton('❌ No', 'demo_no')
|
|
15
|
+
.row()
|
|
16
|
+
.callbackButton('🔄 Refresh', 'demo_refresh')
|
|
17
|
+
.callbackButton('🔍 Search', 'demo_search')
|
|
18
|
+
.row()
|
|
19
|
+
.switchInlineQueryButton('🔍 Inline Query', 'query')
|
|
20
|
+
.buildMarkup()
|
|
21
|
+
|
|
22
|
+
await ctx.reply(message.text || '', {
|
|
23
|
+
parse_mode: (message.parse_mode || 'HTML') as any,
|
|
24
|
+
reply_markup: keyboard as any,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function handleKeyboardCallback(ctx: Context): Promise<void> {
|
|
29
|
+
const callbackData = (ctx.callbackQuery as any)?.data
|
|
30
|
+
let response = 'Unknown action'
|
|
31
|
+
|
|
32
|
+
switch (callbackData) {
|
|
33
|
+
case 'demo_yes':
|
|
34
|
+
response = '✅ You clicked YES!'
|
|
35
|
+
break
|
|
36
|
+
case 'demo_no':
|
|
37
|
+
response = '❌ You clicked NO!'
|
|
38
|
+
break
|
|
39
|
+
case 'demo_refresh':
|
|
40
|
+
response = '🔄 Content refreshed!'
|
|
41
|
+
break
|
|
42
|
+
case 'demo_search':
|
|
43
|
+
response = '🔍 Searching...'
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await ctx.answerCbQuery(response)
|
|
48
|
+
await ctx.reply(response)
|
|
49
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { TelegramMessageBuilder, TelegramMediaBuilder, TelegramKeyboardBuilder } from '@mks2508/telegram-message-builder'
|
|
2
|
+
import type { Context } from 'telegraf'
|
|
3
|
+
|
|
4
|
+
export async function handleMediaDemo(ctx: Context): Promise<void> {
|
|
5
|
+
const message = TelegramMessageBuilder.text()
|
|
6
|
+
.title('📸 Media Builder Demo')
|
|
7
|
+
.newline()
|
|
8
|
+
.text('Choose a media type to test:')
|
|
9
|
+
.listItem('Photo with caption')
|
|
10
|
+
.listItem('Video with options')
|
|
11
|
+
.listItem('Document with metadata')
|
|
12
|
+
.listItem('Audio with performer info')
|
|
13
|
+
.listItem('Voice message')
|
|
14
|
+
.build()
|
|
15
|
+
|
|
16
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
17
|
+
.callbackButton('📷 Photo', 'media_photo')
|
|
18
|
+
.callbackButton('🎥 Video', 'media_video')
|
|
19
|
+
.row()
|
|
20
|
+
.callbackButton('📄 Document', 'media_document')
|
|
21
|
+
.callbackButton('🎵 Audio', 'media_audio')
|
|
22
|
+
.row()
|
|
23
|
+
.callbackButton('🎤 Voice', 'media_voice')
|
|
24
|
+
.buildMarkup()
|
|
25
|
+
|
|
26
|
+
await ctx.reply(message.text || '', {
|
|
27
|
+
parse_mode: (message.parse_mode || 'HTML') as any,
|
|
28
|
+
reply_markup: keyboard as any,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function handleMediaCallback(ctx: Context): Promise<void> {
|
|
33
|
+
const callbackData = (ctx.callbackQuery as any)?.data
|
|
34
|
+
await ctx.answerCbQuery()
|
|
35
|
+
|
|
36
|
+
switch (callbackData) {
|
|
37
|
+
case 'media_photo':
|
|
38
|
+
await sendPhotoDemo(ctx)
|
|
39
|
+
break
|
|
40
|
+
case 'media_video':
|
|
41
|
+
await sendVideoDemo(ctx)
|
|
42
|
+
break
|
|
43
|
+
case 'media_document':
|
|
44
|
+
await sendDocumentDemo(ctx)
|
|
45
|
+
break
|
|
46
|
+
case 'media_audio':
|
|
47
|
+
await sendAudioDemo(ctx)
|
|
48
|
+
break
|
|
49
|
+
case 'media_voice':
|
|
50
|
+
await sendVoiceDemo(ctx)
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function sendPhotoDemo(ctx: Context): Promise<void> {
|
|
56
|
+
const photo = TelegramMediaBuilder.photo('https://picsum.photos/800/600')
|
|
57
|
+
.caption('📷 Photo Demo\n\nThis is a photo with caption formatting support!')
|
|
58
|
+
.setParseMode('html')
|
|
59
|
+
.build()
|
|
60
|
+
|
|
61
|
+
const media = typeof photo.media === 'string' ? photo.media : undefined
|
|
62
|
+
|
|
63
|
+
if (!media) {
|
|
64
|
+
await ctx.reply('❌ Media source must be a URL or file_id')
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await ctx.replyWithPhoto(media, {
|
|
69
|
+
caption: photo.caption || undefined,
|
|
70
|
+
parse_mode: photo.parse_mode as any,
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function sendVideoDemo(ctx: Context): Promise<void> {
|
|
75
|
+
const video = TelegramMediaBuilder.video('https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4')
|
|
76
|
+
.caption('🎥 Video Demo\n\nDuration: 10s\nResolution: 1280x720')
|
|
77
|
+
.duration(10)
|
|
78
|
+
.width(1280)
|
|
79
|
+
.height(720)
|
|
80
|
+
.enableStreaming()
|
|
81
|
+
.setParseMode('html')
|
|
82
|
+
.build()
|
|
83
|
+
|
|
84
|
+
const media = typeof video.media === 'string' ? video.media : undefined
|
|
85
|
+
|
|
86
|
+
if (!media) {
|
|
87
|
+
await ctx.reply('❌ Media source must be a URL or file_id')
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await ctx.replyWithVideo(media, {
|
|
92
|
+
caption: video.caption || undefined,
|
|
93
|
+
parse_mode: video.parse_mode as any,
|
|
94
|
+
width: video.width as number,
|
|
95
|
+
height: video.height as number,
|
|
96
|
+
duration: video.duration as number,
|
|
97
|
+
supports_streaming: true,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function sendDocumentDemo(ctx: Context): Promise<void> {
|
|
102
|
+
const doc = TelegramMediaBuilder.document('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
|
|
103
|
+
.caption('📄 Document Demo\n\nThis is a PDF document with custom filename.')
|
|
104
|
+
.fileName('sample-document.pdf')
|
|
105
|
+
.mimeType('application/pdf')
|
|
106
|
+
.build()
|
|
107
|
+
|
|
108
|
+
const media = typeof doc.media === 'string' ? doc.media : undefined
|
|
109
|
+
|
|
110
|
+
if (!media) {
|
|
111
|
+
await ctx.reply('❌ Media source must be a URL or file_id')
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await ctx.replyWithDocument(media, {
|
|
116
|
+
caption: doc.caption || undefined,
|
|
117
|
+
parse_mode: doc.parse_mode as any,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function sendAudioDemo(ctx: Context): Promise<void> {
|
|
122
|
+
const audio = TelegramMediaBuilder.audio('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3')
|
|
123
|
+
.caption('🎵 Audio Demo\n\nArtist: Demo Artist\nTitle: Demo Song')
|
|
124
|
+
.performer('Demo Artist')
|
|
125
|
+
.title('Demo Song')
|
|
126
|
+
.duration(180)
|
|
127
|
+
.build()
|
|
128
|
+
|
|
129
|
+
const media = typeof audio.media === 'string' ? audio.media : undefined
|
|
130
|
+
|
|
131
|
+
if (!media) {
|
|
132
|
+
await ctx.reply('❌ Media source must be a URL or file_id')
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
await ctx.replyWithAudio(media, {
|
|
137
|
+
caption: audio.caption || undefined,
|
|
138
|
+
parse_mode: audio.parse_mode as any,
|
|
139
|
+
performer: audio.performer as string,
|
|
140
|
+
title: audio.title as string,
|
|
141
|
+
duration: audio.duration as number,
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function sendVoiceDemo(ctx: Context): Promise<void> {
|
|
146
|
+
const voice = TelegramMediaBuilder.voice('https://sample-videos.com/audio/mp3/crowd-cheering.mp3')
|
|
147
|
+
.caption('🎤 Voice Demo\n\nThis is a voice message.')
|
|
148
|
+
.duration(5)
|
|
149
|
+
.build()
|
|
150
|
+
|
|
151
|
+
const media = typeof voice.media === 'string' ? voice.media : undefined
|
|
152
|
+
|
|
153
|
+
if (!media) {
|
|
154
|
+
await ctx.reply('❌ Media source must be a URL or file_id')
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await ctx.replyWithVoice(media, {
|
|
159
|
+
caption: voice.caption || undefined,
|
|
160
|
+
parse_mode: voice.parse_mode as any,
|
|
161
|
+
duration: voice.duration as number,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TelegramMessageBuilder, fmt } from '@mks2508/telegram-message-builder'
|
|
2
|
+
import type { Context } from 'telegraf'
|
|
3
|
+
|
|
4
|
+
export async function handleTextDemo(ctx: Context): Promise<void> {
|
|
5
|
+
const message = TelegramMessageBuilder.text()
|
|
6
|
+
.title('🎨 Text Formatting Demo')
|
|
7
|
+
.newline()
|
|
8
|
+
.section('Inline Formatting')
|
|
9
|
+
.line('Bold', fmt.bold('This is bold text'))
|
|
10
|
+
.line('Italic', fmt.italic('This is italic text'))
|
|
11
|
+
.line('Code', fmt.code('const x = 1'))
|
|
12
|
+
.line('Link', fmt.link('Click here', 'https://example.com'))
|
|
13
|
+
.newline()
|
|
14
|
+
.section('Special Elements')
|
|
15
|
+
.line('Mention', fmt.mention(123456, 'Username'))
|
|
16
|
+
.line('Hashtag', fmt.hashtag('telegram'))
|
|
17
|
+
.newline()
|
|
18
|
+
.codeBlock(`console.log('Hello from telegram-message-builder!')`, 'javascript')
|
|
19
|
+
.newline()
|
|
20
|
+
.separator()
|
|
21
|
+
.listItem('Feature 1: Fluent API')
|
|
22
|
+
.listItem('Feature 2: Type-safe')
|
|
23
|
+
.listItem('Feature 3: Zero dependencies')
|
|
24
|
+
.build()
|
|
25
|
+
|
|
26
|
+
await ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
27
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from 'telegraf'
|
|
2
2
|
import { getConfig } from '../config/index.js'
|
|
3
|
-
import {
|
|
3
|
+
import { formatUptime } from '../utils/formatters.js'
|
|
4
|
+
import { TelegramMessageBuilder } from '@mks2508/telegram-message-builder'
|
|
4
5
|
import { healthLogger, badge, kv, colors, colorText } from '../middleware/logging.js'
|
|
5
6
|
|
|
6
7
|
export async function handleHealth(ctx: Context): Promise<void> {
|
|
@@ -17,15 +18,21 @@ export async function handleHealth(ctx: Context): Promise<void> {
|
|
|
17
18
|
const uptime = Date.now() - (Date.now() - 10000)
|
|
18
19
|
const memoryUsage = process.memoryUsage()
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const mb = (bytes: number) => (bytes / 1024 / 1024).toFixed(2)
|
|
22
|
+
|
|
23
|
+
const message = TelegramMessageBuilder.text()
|
|
24
|
+
.title('🏥 Bot Health Status')
|
|
25
|
+
.newline()
|
|
26
|
+
.line('Status', 'RUNNING', { bold: true })
|
|
27
|
+
.line('Mode', config.mode.toUpperCase())
|
|
28
|
+
.line('Uptime', formatUptime(uptime))
|
|
29
|
+
.newline()
|
|
30
|
+
.section('Memory Usage')
|
|
31
|
+
.text(`RSS: ${mb(memoryUsage.rss)}MB`)
|
|
32
|
+
.text(`Heap: ${mb(memoryUsage.heapUsed)}/${mb(memoryUsage.heapTotal)}MB`)
|
|
33
|
+
.build()
|
|
34
|
+
|
|
35
|
+
await ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export async function handleUptime(ctx: Context): Promise<void> {
|
|
@@ -39,18 +46,13 @@ export async function handleUptime(ctx: Context): Promise<void> {
|
|
|
39
46
|
)
|
|
40
47
|
|
|
41
48
|
const uptime = Date.now() - (Date.now() - 10000)
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (hours > 0) formatted += `${hours}h `
|
|
50
|
-
if (minutes > 0) formatted += `${minutes}m `
|
|
51
|
-
formatted += `${seconds}s`
|
|
52
|
-
|
|
53
|
-
await ctx.reply(`⏱️ *Uptime:*\n${formatted}`, { parse_mode: 'Markdown' })
|
|
49
|
+
|
|
50
|
+
const message = TelegramMessageBuilder.text()
|
|
51
|
+
.title('⏱️ Uptime:')
|
|
52
|
+
.text(formatUptime(uptime))
|
|
53
|
+
.build()
|
|
54
|
+
|
|
55
|
+
await ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export async function handleStats(ctx: Context): Promise<void> {
|
|
@@ -65,19 +67,20 @@ export async function handleStats(ctx: Context): Promise<void> {
|
|
|
65
67
|
|
|
66
68
|
const config = getConfig()
|
|
67
69
|
|
|
68
|
-
const message =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
const message = TelegramMessageBuilder.text()
|
|
71
|
+
.title('📊 Bot Statistics')
|
|
72
|
+
.newline()
|
|
73
|
+
.section('Performance')
|
|
74
|
+
.line('Messages Processed', '0')
|
|
75
|
+
.line('Commands Executed', '0')
|
|
76
|
+
.line('Errors Encountered', '0')
|
|
77
|
+
.newline()
|
|
78
|
+
.section('Configuration')
|
|
79
|
+
.line('Mode', config.mode.toUpperCase())
|
|
80
|
+
.line('Log Level', config.logLevel.toUpperCase())
|
|
81
|
+
.line('Logging Enabled', config.logChatId ? '✅' : '❌')
|
|
82
|
+
.line('Control Enabled', config.controlChatId ? '✅' : '❌')
|
|
83
|
+
.build()
|
|
84
|
+
|
|
85
|
+
await ctx.reply(message.text || '', { parse_mode: (message.parse_mode || 'HTML') as any })
|
|
83
86
|
}
|