@mks2508/telegram-message-builder 0.3.0 → 0.4.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/dist/builder/builder.d.ts +87 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/media.d.ts +351 -0
- package/dist/formatters/index.d.ts +86 -0
- package/dist/formatters/markdown.d.ts +178 -0
- package/dist/formatters/markdownv2.d.ts +183 -0
- package/dist/index.d.ts +11 -0
- package/dist/keyboard/index.d.ts +113 -0
- package/dist/types/constants.d.ts +13 -0
- package/dist/types/core.types.d.ts +74 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/keyboard-types.index.d.ts +1 -0
- package/dist/types/keyboard.types.d.ts +95 -0
- package/dist/types/main.types.d.ts +22 -0
- package/dist/types/media.types.d.ts +157 -0
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MarkdownV2 Formatters
|
|
3
|
+
* @description Text formatting functions for Telegram's MarkdownV2 parse mode
|
|
4
|
+
* @module telegram-message-builder/formatters
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://core.telegram.org/bots/api#markdownv2-style | Telegram Bot API - MarkdownV2 Style}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Formats text as bold in MarkdownV2
|
|
10
|
+
*
|
|
11
|
+
* @param text - The text to format
|
|
12
|
+
* @returns Bold formatted text
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* boldMDv2("Hello") // "*Hello*"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function boldMDv2(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Formats text as italic in MarkdownV2
|
|
21
|
+
*
|
|
22
|
+
* @param text - The text to format
|
|
23
|
+
* @returns Italic formatted text
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* italicMDv2("Hello") // "_Hello_"
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function italicMDv2(text: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Formats text as underline in MarkdownV2
|
|
32
|
+
*
|
|
33
|
+
* @param text - The text to format
|
|
34
|
+
* @returns Underline formatted text
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* underlineMDv2("Hello") // "__Hello__"
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function underlineMDv2(text: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Formats text as strikethrough in MarkdownV2
|
|
43
|
+
*
|
|
44
|
+
* @param text - The text to format
|
|
45
|
+
* @returns Strikethrough formatted text
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* strikethroughMDv2("Hello") // "~Hello~"
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function strikethroughMDv2(text: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Formats text as spoiler in MarkdownV2
|
|
54
|
+
*
|
|
55
|
+
* @param text - The text to format
|
|
56
|
+
* @returns Spoiler formatted text
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* spoilerMDv2("Secret") // "||Secret||"
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function spoilerMDv2(text: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Formats text as monospace code in MarkdownV2
|
|
65
|
+
*
|
|
66
|
+
* @param text - The text to format
|
|
67
|
+
* @returns Code formatted text
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* codeMDv2("const x = 1") // "`const x = 1`"
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function codeMDv2(text: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Formats text as a code block in MarkdownV2
|
|
76
|
+
*
|
|
77
|
+
* @param text - The code to format
|
|
78
|
+
* @param language - Optional programming language for syntax highlighting
|
|
79
|
+
* @returns Code block formatted text
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* codeBlockMDv2("console.log('Hello')") // "```console.log('Hello')```"
|
|
83
|
+
* codeBlockMDv2("const x = 1", "javascript") // "```javascript\nconst x = 1\n```"
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function codeBlockMDv2(text: string, language?: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a link in MarkdownV2 format
|
|
89
|
+
*
|
|
90
|
+
* @param text - The link text
|
|
91
|
+
* @param url - The URL to link to
|
|
92
|
+
* @returns Link formatted text
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* linkMDv2("Google", "https://google.com") // "[Google](https://google.com)"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function linkMDv2(text: string, url: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a user mention link in MarkdownV2 format
|
|
101
|
+
*
|
|
102
|
+
* @param userId - The user's ID
|
|
103
|
+
* @param name - Optional display name (ignored in MarkdownV2)
|
|
104
|
+
* @returns Mention formatted text
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* mentionMDv2(123456) // "[user](tg://user?id=123456)"
|
|
108
|
+
* mentionMDv2(123456, "John") // "[John](tg://user?id=123456)"
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function mentionMDv2(userId: number, name?: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a hashtag link in MarkdownV2 format
|
|
114
|
+
*
|
|
115
|
+
* @param tag - The hashtag text (without #)
|
|
116
|
+
* @returns Hashtag formatted text
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* hashtagMDv2("test") // "#test"
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function hashtagMDv2(tag: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* Creates an email link in MarkdownV2 format
|
|
125
|
+
*
|
|
126
|
+
* @param email - The email address
|
|
127
|
+
* @returns Email link formatted text
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* emailMDv2("test@example.com") // "[test@example.com](mailto:test@example.com)"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function emailMDv2(email: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Creates a URL link in MarkdownV2 format
|
|
136
|
+
*
|
|
137
|
+
* @param url - The URL
|
|
138
|
+
* @returns URL link formatted text
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* urlMDv2("https://example.com") // "[https://example.com](https://example.com)"
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function urlMDv2(url: string): string;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a custom emoji in MarkdownV2 format
|
|
147
|
+
*
|
|
148
|
+
* Note: Custom emoji syntax in MarkdownV2 uses a special format with the emoji
|
|
149
|
+
* ID wrapped in special syntax.
|
|
150
|
+
*
|
|
151
|
+
* @param emojiId - The custom emoji ID
|
|
152
|
+
* @returns Custom emoji formatted text
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* customEmojiMDv2("5368324170672642286") // "👻 [Custom emoji](tg://emoji?id=5368324170672642286)"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function customEmojiMDv2(emojiId: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Raw MarkdownV2 string - bypasses any automatic formatting
|
|
161
|
+
*
|
|
162
|
+
* @param markdown - Pre-formatted MarkdownV2 string
|
|
163
|
+
* @returns The MarkdownV2 string unchanged
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* rawMDv2("*Hello*") // "*Hello*"
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function rawMDv2(markdown: string): string;
|
|
170
|
+
/**
|
|
171
|
+
* Pre-escapes text for safe use in MarkdownV2 formatting
|
|
172
|
+
*
|
|
173
|
+
* MarkdownV2 requires careful character escaping. This function escapes
|
|
174
|
+
* all reserved characters for safe use in formatted text.
|
|
175
|
+
*
|
|
176
|
+
* @param text - The text to escape
|
|
177
|
+
* @returns Escaped text safe for MarkdownV2
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* escapeMDv2("Hello_World") // "Hello\\_World"
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare function escapeMDv2(text: string): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./formatters";
|
|
3
|
+
export * from "./keyboard";
|
|
4
|
+
export * from "./builder";
|
|
5
|
+
export type { ParseMode, FormatOpts, LineOpts, TelegramMessage, BuildResult, ValidationError, } from "./types/core.types";
|
|
6
|
+
export type { IInlineKeyboardMarkup, IInlineKeyboardButton, IReplyKeyboardMarkup, IKeyboardButton, IForceReplyMarkup, } from "./types/keyboard.types";
|
|
7
|
+
export type { MediaSource, MediaType, IMediaCommonOptions, IMediaBuildResult, IPhotoOptions, IVideoOptions, IDocumentOptions, IAudioOptions, IVoiceOptions, } from "./types/media.types";
|
|
8
|
+
export { fmt } from "./formatters";
|
|
9
|
+
export { TelegramMessageBuilder } from "./builder";
|
|
10
|
+
export { TelegramKeyboardBuilder } from "./keyboard";
|
|
11
|
+
export { TelegramMediaBuilder } from "./builder";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Keyboard Builders
|
|
3
|
+
* @description Fluent API for building Telegram keyboards
|
|
4
|
+
* @module telegram-message-builder/keyboard
|
|
5
|
+
*/
|
|
6
|
+
import type { IInlineKeyboardMarkup, IInlineKeyboardButton, IReplyKeyboardMarkup, IKeyboardButton, IForceReplyMarkup } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Telegram Keyboard Builder - Fluent API for building keyboards
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const keyboard = TelegramKeyboardBuilder.inline()
|
|
13
|
+
* .urlButton('Google', 'https://google.com')
|
|
14
|
+
* .row()
|
|
15
|
+
* .callbackButton('Yes', 'yes')
|
|
16
|
+
* .callbackButton('No', 'no')
|
|
17
|
+
* .buildMarkup()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class TelegramKeyboardBuilder {
|
|
21
|
+
private rows;
|
|
22
|
+
private type;
|
|
23
|
+
private currentRow;
|
|
24
|
+
private constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Create an inline keyboard builder
|
|
27
|
+
*/
|
|
28
|
+
static inline(): TelegramKeyboardBuilder;
|
|
29
|
+
/**
|
|
30
|
+
* Create a reply keyboard builder
|
|
31
|
+
*/
|
|
32
|
+
static reply(): TelegramKeyboardBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Create a force reply builder
|
|
35
|
+
*/
|
|
36
|
+
static forceReply(): TelegramKeyboardBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* Add a URL button (inline only)
|
|
39
|
+
*/
|
|
40
|
+
urlButton(text: string, url: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Add a callback button (inline only)
|
|
43
|
+
*/
|
|
44
|
+
callbackButton(text: string, data: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Add a web app button (inline only)
|
|
47
|
+
*/
|
|
48
|
+
webAppButton(text: string, url: string): this;
|
|
49
|
+
/**
|
|
50
|
+
* Add a login button (inline only)
|
|
51
|
+
*/
|
|
52
|
+
loginButton(text: string, url: string, options?: {
|
|
53
|
+
forwardText?: string;
|
|
54
|
+
botUsername?: string;
|
|
55
|
+
requestWriteAccess?: boolean;
|
|
56
|
+
}): this;
|
|
57
|
+
/**
|
|
58
|
+
* Add a switch inline query button (inline only)
|
|
59
|
+
*/
|
|
60
|
+
switchInlineQueryButton(text: string, query: string): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add a switch inline query current chat button (inline only)
|
|
63
|
+
*/
|
|
64
|
+
switchInlineQueryCurrentChatButton(text: string, query: string): this;
|
|
65
|
+
/**
|
|
66
|
+
* Add a callback game button (inline only)
|
|
67
|
+
*/
|
|
68
|
+
callbackGameButton(text: string, shortName: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add a pay button (inline only)
|
|
71
|
+
*/
|
|
72
|
+
payButton(text: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Add a text button (reply keyboard only)
|
|
75
|
+
*/
|
|
76
|
+
textButton(text: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* Add a request contact button (reply keyboard only)
|
|
79
|
+
*/
|
|
80
|
+
requestContactButton(text: string): this;
|
|
81
|
+
/**
|
|
82
|
+
* Add a request location button (reply keyboard only)
|
|
83
|
+
*/
|
|
84
|
+
requestLocationButton(text: string): this;
|
|
85
|
+
/**
|
|
86
|
+
* Add a request poll button (reply keyboard only)
|
|
87
|
+
*/
|
|
88
|
+
requestPollButton(text: string, pollType: string): this;
|
|
89
|
+
/**
|
|
90
|
+
* Add a custom button to current row
|
|
91
|
+
*/
|
|
92
|
+
button(button: IInlineKeyboardButton | IKeyboardButton): this;
|
|
93
|
+
/**
|
|
94
|
+
* Finish current row and start a new one
|
|
95
|
+
*/
|
|
96
|
+
row(): this;
|
|
97
|
+
/**
|
|
98
|
+
* Build inline keyboard markup
|
|
99
|
+
*/
|
|
100
|
+
buildMarkup(): IInlineKeyboardMarkup;
|
|
101
|
+
/**
|
|
102
|
+
* Build reply keyboard markup
|
|
103
|
+
*/
|
|
104
|
+
buildReplyMarkup(): IReplyKeyboardMarkup;
|
|
105
|
+
/**
|
|
106
|
+
* Build force reply markup
|
|
107
|
+
*/
|
|
108
|
+
buildForceReplyMarkup(): IForceReplyMarkup;
|
|
109
|
+
/**
|
|
110
|
+
* Build markup based on keyboard type
|
|
111
|
+
*/
|
|
112
|
+
build(): IInlineKeyboardMarkup | IReplyKeyboardMarkup | IForceReplyMarkup;
|
|
113
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core types for Telegram Message Builder
|
|
3
|
+
* @description Defines the base types used throughout the message builder
|
|
4
|
+
* @module telegram-message-builder/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parse mode for Telegram messages
|
|
8
|
+
*/
|
|
9
|
+
export type ParseMode = "html" | "markdown" | "markdownv2";
|
|
10
|
+
/**
|
|
11
|
+
* Format options for inline formatting
|
|
12
|
+
*/
|
|
13
|
+
export interface FormatOpts {
|
|
14
|
+
/** Make text bold */
|
|
15
|
+
bold?: boolean;
|
|
16
|
+
/** Make text italic */
|
|
17
|
+
italic?: boolean;
|
|
18
|
+
/** Make text monospace (code) */
|
|
19
|
+
code?: boolean;
|
|
20
|
+
/** Make text underlined */
|
|
21
|
+
underline?: boolean;
|
|
22
|
+
/** Make text strikethrough */
|
|
23
|
+
strikethrough?: boolean;
|
|
24
|
+
/** Make text spoiler */
|
|
25
|
+
spoiler?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for line formatting
|
|
29
|
+
*/
|
|
30
|
+
export interface LineOpts extends FormatOpts {
|
|
31
|
+
/** Custom format string instead of key: value */
|
|
32
|
+
format?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generic Telegram message type
|
|
36
|
+
*/
|
|
37
|
+
export interface TelegramMessage {
|
|
38
|
+
/** Message text */
|
|
39
|
+
text?: string;
|
|
40
|
+
/** Message caption (for media) */
|
|
41
|
+
caption?: string;
|
|
42
|
+
/** Parse mode for the message */
|
|
43
|
+
parse_mode?: ParseMode | undefined;
|
|
44
|
+
/** Reply markup (inline or reply keyboard) */
|
|
45
|
+
reply_markup?: unknown;
|
|
46
|
+
/** Disable web page preview */
|
|
47
|
+
disable_web_page_preview?: boolean;
|
|
48
|
+
/** Disable notification */
|
|
49
|
+
disable_notification?: boolean;
|
|
50
|
+
/** Protect content from forwarding */
|
|
51
|
+
protect_content?: boolean;
|
|
52
|
+
/** Reply to specific message */
|
|
53
|
+
reply_to_message_id?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build result
|
|
57
|
+
*/
|
|
58
|
+
export interface BuildResult {
|
|
59
|
+
/** Formatted message text or caption */
|
|
60
|
+
text: string;
|
|
61
|
+
/** Parse mode for the message */
|
|
62
|
+
parse_mode: ParseMode;
|
|
63
|
+
/** Reply markup if any */
|
|
64
|
+
reply_markup?: unknown;
|
|
65
|
+
/** Additional options */
|
|
66
|
+
options?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Validation error
|
|
70
|
+
*/
|
|
71
|
+
export interface ValidationError {
|
|
72
|
+
message: string;
|
|
73
|
+
code: string;
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./keyboard.types";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Keyboard Types
|
|
3
|
+
* @description Types for inline and reply keyboards
|
|
4
|
+
* @module telegram-message-builder/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Inline keyboard button
|
|
8
|
+
*/
|
|
9
|
+
export interface IInlineKeyboardButton {
|
|
10
|
+
text: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
callback_data?: string;
|
|
13
|
+
web_app?: {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
login_url?: {
|
|
17
|
+
url: string;
|
|
18
|
+
forward_text?: string;
|
|
19
|
+
bot_username?: string;
|
|
20
|
+
request_write_access?: boolean;
|
|
21
|
+
};
|
|
22
|
+
switch_inline_query?: string;
|
|
23
|
+
switch_inline_query_current_chat?: string;
|
|
24
|
+
callback_game?: string;
|
|
25
|
+
pay?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Inline keyboard markup
|
|
29
|
+
*/
|
|
30
|
+
export interface IInlineKeyboardMarkup {
|
|
31
|
+
inline_keyboard: IInlineKeyboardButton[][];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reply keyboard button
|
|
35
|
+
*/
|
|
36
|
+
export interface IKeyboardButton {
|
|
37
|
+
text: string;
|
|
38
|
+
request_contact?: boolean;
|
|
39
|
+
request_location?: boolean;
|
|
40
|
+
request_poll?: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
request_chat?: {
|
|
44
|
+
chat_is_channel: boolean;
|
|
45
|
+
chat_is_forum?: boolean;
|
|
46
|
+
chat_has_username?: boolean;
|
|
47
|
+
chat_is_created: boolean;
|
|
48
|
+
user_administrator_rights?: number[];
|
|
49
|
+
bot_is_member?: boolean;
|
|
50
|
+
};
|
|
51
|
+
request_user?: {
|
|
52
|
+
request_id: number;
|
|
53
|
+
user_is_bot: boolean;
|
|
54
|
+
user_is_premium: boolean;
|
|
55
|
+
};
|
|
56
|
+
web_app?: {
|
|
57
|
+
url: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reply keyboard markup
|
|
62
|
+
*/
|
|
63
|
+
export interface IReplyKeyboardMarkup {
|
|
64
|
+
keyboard: IKeyboardButton[][];
|
|
65
|
+
resize_keyboard?: boolean;
|
|
66
|
+
one_time_keyboard?: boolean;
|
|
67
|
+
input_field_placeholder?: string;
|
|
68
|
+
selective?: boolean;
|
|
69
|
+
is_persistent?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Force reply markup
|
|
73
|
+
*/
|
|
74
|
+
export interface IForceReplyMarkup {
|
|
75
|
+
force_reply: true;
|
|
76
|
+
input_field_placeholder?: string;
|
|
77
|
+
selective?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reply parameters
|
|
81
|
+
*/
|
|
82
|
+
export interface IReplyParameters {
|
|
83
|
+
message_id: number;
|
|
84
|
+
allow_sending_without_reply?: boolean;
|
|
85
|
+
quote?: {
|
|
86
|
+
text: string;
|
|
87
|
+
entities?: unknown[];
|
|
88
|
+
parse_mode?: "html" | "markdown" | "markdownv2";
|
|
89
|
+
quote_position?: number;
|
|
90
|
+
};
|
|
91
|
+
quote_parse_mode?: "html" | "markdown" | "markdownv2";
|
|
92
|
+
quote_text?: string;
|
|
93
|
+
quote_entities?: unknown[];
|
|
94
|
+
quote_position?: number;
|
|
95
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tipos del dominio principal.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Opciones de configuracion para saludos.
|
|
8
|
+
*/
|
|
9
|
+
export interface IGreetOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Prefijo del saludo (default: "Hello").
|
|
12
|
+
*/
|
|
13
|
+
prefix?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Sufijo del saludo (default: "!").
|
|
16
|
+
*/
|
|
17
|
+
suffix?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Callback para notificar eventos.
|
|
21
|
+
*/
|
|
22
|
+
export type IEventCallback = (event: string) => void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Media Types
|
|
3
|
+
* @description Type definitions for media messages in Telegram Bot API
|
|
4
|
+
* @module telegram-message-builder/types
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://core.telegram.org/bots/api#sendphoto | Telegram Bot API - sendPhoto}
|
|
7
|
+
* @see {@link https://core.telegram.org/bots/api#sendvideo | Telegram Bot API - sendVideo}
|
|
8
|
+
* @see {@link https://core.telegram.org/bots/api#senddocument | Telegram Bot API - sendDocument}
|
|
9
|
+
* @see {@link https://core.telegram.org/bots/api#sendaudio | Telegram Bot API - sendAudio}
|
|
10
|
+
* @see {@link https://core.telegram.org/bots/api#sendvoice | Telegram Bot API - sendVoice}
|
|
11
|
+
*/
|
|
12
|
+
import type { ParseMode } from "./core.types";
|
|
13
|
+
import type { IInlineKeyboardMarkup, IReplyParameters } from "./keyboard.types";
|
|
14
|
+
/**
|
|
15
|
+
* Media source - can represent various input formats
|
|
16
|
+
*
|
|
17
|
+
* - `string` as file_id - Existing uploaded file on Telegram servers
|
|
18
|
+
* - `string` as URL - HTTPS URL to fetch file from
|
|
19
|
+
* - `Buffer` - Binary data for upload
|
|
20
|
+
* - `string` as file path - Local file path for upload
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const fileId: MediaSource = "AgACAgIAAxkBAAI...";
|
|
25
|
+
* const url: MediaSource = "https://example.com/photo.jpg";
|
|
26
|
+
* const buffer: MediaSource = Buffer.from(...);
|
|
27
|
+
* const filePath: MediaSource = "/path/to/photo.jpg";
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type MediaSource = string | Buffer;
|
|
31
|
+
/**
|
|
32
|
+
* Common media options shared across all media types
|
|
33
|
+
*
|
|
34
|
+
* Includes all possible options from all media types to allow
|
|
35
|
+
* flexible setOption() usage while maintaining type safety.
|
|
36
|
+
*/
|
|
37
|
+
export interface IMediaCommonOptions {
|
|
38
|
+
/** List of special entities in the caption */
|
|
39
|
+
caption_entities?: unknown[];
|
|
40
|
+
/** Show caption above media (True by default) */
|
|
41
|
+
show_caption_above_media?: boolean;
|
|
42
|
+
/** Disable automatic file type detection (documents only) */
|
|
43
|
+
disable_content_type_detection?: boolean;
|
|
44
|
+
/** Protect contents from forwarding/saving */
|
|
45
|
+
protect_content?: boolean;
|
|
46
|
+
/** Reply parameters for replying to messages */
|
|
47
|
+
reply_parameters?: IReplyParameters;
|
|
48
|
+
/** Inline keyboard attached to the message */
|
|
49
|
+
reply_markup?: IInlineKeyboardMarkup;
|
|
50
|
+
/** Thumbnail of the file sent */
|
|
51
|
+
thumb?: Buffer | string;
|
|
52
|
+
/** Duration of the media in seconds */
|
|
53
|
+
duration?: number;
|
|
54
|
+
/** Video width */
|
|
55
|
+
width?: number;
|
|
56
|
+
/** Video height */
|
|
57
|
+
height?: number;
|
|
58
|
+
/** Pass True to upload the video as a streaming video */
|
|
59
|
+
support_streaming?: boolean;
|
|
60
|
+
/** Original filename */
|
|
61
|
+
file_name?: string;
|
|
62
|
+
/** MIME type of the file */
|
|
63
|
+
mime_type?: string;
|
|
64
|
+
/** Performer of the audio */
|
|
65
|
+
performer?: string;
|
|
66
|
+
/** Track name of the audio */
|
|
67
|
+
title?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Photo-specific options
|
|
71
|
+
*/
|
|
72
|
+
export interface IPhotoOptions extends IMediaCommonOptions {
|
|
73
|
+
/** Thumbnail of the file sent */
|
|
74
|
+
thumb?: Buffer | string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Video-specific options
|
|
78
|
+
*/
|
|
79
|
+
export interface IVideoOptions extends IMediaCommonOptions {
|
|
80
|
+
/** Duration of the video in seconds */
|
|
81
|
+
duration?: number;
|
|
82
|
+
/** Video width */
|
|
83
|
+
width?: number;
|
|
84
|
+
/** Video height */
|
|
85
|
+
height?: number;
|
|
86
|
+
/** Thumbnail of the video */
|
|
87
|
+
thumb?: Buffer | string;
|
|
88
|
+
/** Pass True to upload the video as a streaming video */
|
|
89
|
+
support_streaming?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Document-specific options
|
|
93
|
+
*/
|
|
94
|
+
export interface IDocumentOptions extends IMediaCommonOptions {
|
|
95
|
+
/** Thumbnail of the document */
|
|
96
|
+
thumb?: Buffer | string;
|
|
97
|
+
/** Original filename */
|
|
98
|
+
file_name?: string;
|
|
99
|
+
/** MIME type of the file */
|
|
100
|
+
mime_type?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Audio-specific options
|
|
104
|
+
*/
|
|
105
|
+
export interface IAudioOptions extends IMediaCommonOptions {
|
|
106
|
+
/** Duration of the audio in seconds */
|
|
107
|
+
duration?: number;
|
|
108
|
+
/** Performer of the audio */
|
|
109
|
+
performer?: string;
|
|
110
|
+
/** Track name of the audio */
|
|
111
|
+
title?: string;
|
|
112
|
+
/** Thumbnail of the album cover */
|
|
113
|
+
thumb?: Buffer | string;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Voice-specific options
|
|
117
|
+
*/
|
|
118
|
+
export interface IVoiceOptions extends IMediaCommonOptions {
|
|
119
|
+
/** Duration of the voice message in seconds */
|
|
120
|
+
duration?: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Media message types supported by Telegram
|
|
124
|
+
*/
|
|
125
|
+
export type MediaType = "photo" | "video" | "document" | "audio" | "voice";
|
|
126
|
+
/**
|
|
127
|
+
* Complete media message interface
|
|
128
|
+
*/
|
|
129
|
+
export interface IMediaMessage {
|
|
130
|
+
/** Media source (file_id, URL, Buffer, or file path) */
|
|
131
|
+
media: MediaSource;
|
|
132
|
+
/** Type of media */
|
|
133
|
+
type: MediaType;
|
|
134
|
+
/** Caption for the media */
|
|
135
|
+
caption?: string;
|
|
136
|
+
/** Parse mode for caption formatting */
|
|
137
|
+
parse_mode?: ParseMode;
|
|
138
|
+
/** Additional options */
|
|
139
|
+
options: IMediaCommonOptions;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Result from TelegramMediaBuilder.build()
|
|
143
|
+
*
|
|
144
|
+
* Compatible with Telegram Bot API send* methods
|
|
145
|
+
*/
|
|
146
|
+
export interface IMediaBuildResult {
|
|
147
|
+
/** Media source */
|
|
148
|
+
media: MediaSource;
|
|
149
|
+
/** Media type */
|
|
150
|
+
type: MediaType;
|
|
151
|
+
/** Caption with formatting applied based on parse_mode */
|
|
152
|
+
caption?: string;
|
|
153
|
+
/** Parse mode used for caption */
|
|
154
|
+
parse_mode?: ParseMode;
|
|
155
|
+
/** Additional Telegram-specific options */
|
|
156
|
+
[key: string]: unknown;
|
|
157
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mks2508/telegram-message-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Telegram bot messaging utilities suite with focus on good DX. Template Strings Native. Keyboard Builder, Media Types Full Support, Zero Runtime Dependencies, Fully typed and schema validated, 100% telegraf compatible. Bot API v9.3+.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|