@mks2508/telegram-message-builder 0.2.0 → 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/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.cjs +1057 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1022 -13
- package/dist/index.js.map +1 -1
- 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
- package/src/builder/builder.d.ts +55 -0
- package/src/builder/builder.d.ts.map +1 -1
- package/src/builder/builder.ts +145 -10
- package/src/builder/index.d.ts +2 -1
- package/src/builder/index.d.ts.map +1 -1
- package/src/builder/index.ts +2 -1
- package/src/builder/media.d.ts +352 -0
- package/src/builder/media.d.ts.map +1 -0
- package/src/builder/media.test.ts +664 -0
- package/src/builder/media.ts +484 -0
- package/src/builder.test.ts +465 -0
- package/src/escaping.test.ts +2 -2
- package/src/formatters/index.d.ts +47 -0
- package/src/formatters/index.d.ts.map +1 -1
- package/src/formatters/index.ts +92 -1
- package/src/formatters/markdown.d.ts +179 -0
- package/src/formatters/markdown.d.ts.map +1 -0
- package/src/formatters/markdown.test.ts +417 -0
- package/src/formatters/markdown.ts +220 -0
- package/src/formatters/markdownv2.d.ts +184 -0
- package/src/formatters/markdownv2.d.ts.map +1 -0
- package/src/formatters/markdownv2.ts +235 -0
- package/src/formatters.test.ts +17 -7
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.ts +12 -0
- package/src/integration.test.ts +523 -0
- package/src/media-integration.test.ts +384 -0
- package/src/types/index.d.ts +1 -0
- package/src/types/index.d.ts.map +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/media.types.d.ts +158 -0
- package/src/types/media.types.d.ts.map +1 -0
- package/src/types/media.types.ts +178 -0
- package/src/types.test.ts +539 -0
- package/src/utils/index.d.ts +1 -1
- package/src/utils/index.ts +0 -5
|
@@ -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;
|