@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,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.3.1",
|
|
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",
|
package/src/builder/builder.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import type { TelegramMessage, ParseMode } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* Telegram Message Builder - Fluent API for building formatted Telegram messages
|
|
4
|
+
*
|
|
5
|
+
* Supports all three Telegram parse modes: HTML, Markdown, and MarkdownV2
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // HTML mode (default)
|
|
10
|
+
* const msg1 = TelegramMessageBuilder.text()
|
|
11
|
+
* .title("Welcome")
|
|
12
|
+
* .line("Status", "Active", { bold: true })
|
|
13
|
+
* .build();
|
|
14
|
+
*
|
|
15
|
+
* // Markdown mode
|
|
16
|
+
* const msg2 = TelegramMessageBuilder.text()
|
|
17
|
+
* .setParseMode("markdown")
|
|
18
|
+
* .title("Welcome")
|
|
19
|
+
* .build();
|
|
20
|
+
*
|
|
21
|
+
* // MarkdownV2 mode
|
|
22
|
+
* const msg3 = TelegramMessageBuilder.text()
|
|
23
|
+
* .setParseMode("markdownv2")
|
|
24
|
+
* .title("Welcome")
|
|
25
|
+
* .build();
|
|
26
|
+
* ```
|
|
4
27
|
*/
|
|
5
28
|
export declare class TelegramMessageBuilder {
|
|
6
29
|
private parts;
|
|
@@ -9,6 +32,38 @@ export declare class TelegramMessageBuilder {
|
|
|
9
32
|
private constructor();
|
|
10
33
|
static text(): TelegramMessageBuilder;
|
|
11
34
|
setParseMode(mode: ParseMode): this;
|
|
35
|
+
/**
|
|
36
|
+
* Formats text as bold based on current parse mode
|
|
37
|
+
*/
|
|
38
|
+
private bold;
|
|
39
|
+
/**
|
|
40
|
+
* Formats text as italic based on current parse mode
|
|
41
|
+
*/
|
|
42
|
+
private italic;
|
|
43
|
+
/**
|
|
44
|
+
* Formats text as underline based on current parse mode
|
|
45
|
+
*/
|
|
46
|
+
private underline;
|
|
47
|
+
/**
|
|
48
|
+
* Formats text as code based on current parse mode
|
|
49
|
+
*/
|
|
50
|
+
private code;
|
|
51
|
+
/**
|
|
52
|
+
* Formats text as code block based on current parse mode
|
|
53
|
+
*/
|
|
54
|
+
private codeBlockFormat;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a link based on current parse mode
|
|
57
|
+
*/
|
|
58
|
+
private linkFormat;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a mention based on current parse mode
|
|
61
|
+
*/
|
|
62
|
+
private mentionFormat;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a hashtag based on current parse mode
|
|
65
|
+
*/
|
|
66
|
+
private hashtagFormat;
|
|
12
67
|
title(text: string): this;
|
|
13
68
|
section(text: string): this;
|
|
14
69
|
line(key: string, value: string, opts?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG3D
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAA+B;IAE9C,OAAO,eAEN;IAED,MAAM,CAAC,IAAI,IAAI,sBAAsB,CAEpC;IAED,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAGlC;IAED;;OAEG;IACH,OAAO,CAAC,IAAI;IAWZ;;OAEG;IACH,OAAO,CAAC,MAAM;IAWd;;OAEG;IACH,OAAO,CAAC,SAAS;IAWjB;;OAEG;IACH,OAAO,CAAC,IAAI;IAWZ;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,UAAU;IAWlB;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGxB;IAED,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAG1B;IAED,IAAI,CACF,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GACA,IAAI,CAeN;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAG/C;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAG3B;IAED,OAAO,CAAC,KAAK,GAAE,MAAU,GAAG,IAAI,CAK/B;IAED,SAAS,IAAI,IAAI,CAGhB;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGvB;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAGpC;IAED,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAG3C;IAED,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAGzB;IAED,KAAK,IAAI,eAAe,CAMvB;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAG3C;IAED,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAGjD;IAED,YAAY,IAAI,SAAS,CAExB;CACF"}
|
package/src/builder/builder.ts
CHANGED
|
@@ -3,6 +3,29 @@ import * as fmt from "../formatters";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Telegram Message Builder - Fluent API for building formatted Telegram messages
|
|
6
|
+
*
|
|
7
|
+
* Supports all three Telegram parse modes: HTML, Markdown, and MarkdownV2
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // HTML mode (default)
|
|
12
|
+
* const msg1 = TelegramMessageBuilder.text()
|
|
13
|
+
* .title("Welcome")
|
|
14
|
+
* .line("Status", "Active", { bold: true })
|
|
15
|
+
* .build();
|
|
16
|
+
*
|
|
17
|
+
* // Markdown mode
|
|
18
|
+
* const msg2 = TelegramMessageBuilder.text()
|
|
19
|
+
* .setParseMode("markdown")
|
|
20
|
+
* .title("Welcome")
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // MarkdownV2 mode
|
|
24
|
+
* const msg3 = TelegramMessageBuilder.text()
|
|
25
|
+
* .setParseMode("markdownv2")
|
|
26
|
+
* .title("Welcome")
|
|
27
|
+
* .build();
|
|
28
|
+
* ```
|
|
6
29
|
*/
|
|
7
30
|
export class TelegramMessageBuilder {
|
|
8
31
|
private parts: string[] = [];
|
|
@@ -22,13 +45,125 @@ export class TelegramMessageBuilder {
|
|
|
22
45
|
return this;
|
|
23
46
|
}
|
|
24
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Formats text as bold based on current parse mode
|
|
50
|
+
*/
|
|
51
|
+
private bold(text: string): string {
|
|
52
|
+
switch (this.parseMode) {
|
|
53
|
+
case "html":
|
|
54
|
+
return fmt.bold(text);
|
|
55
|
+
case "markdown":
|
|
56
|
+
return fmt.boldMD(text);
|
|
57
|
+
case "markdownv2":
|
|
58
|
+
return fmt.boldMDv2(text);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Formats text as italic based on current parse mode
|
|
64
|
+
*/
|
|
65
|
+
private italic(text: string): string {
|
|
66
|
+
switch (this.parseMode) {
|
|
67
|
+
case "html":
|
|
68
|
+
return fmt.italic(text);
|
|
69
|
+
case "markdown":
|
|
70
|
+
return fmt.italicMD(text);
|
|
71
|
+
case "markdownv2":
|
|
72
|
+
return fmt.italicMDv2(text);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Formats text as underline based on current parse mode
|
|
78
|
+
*/
|
|
79
|
+
private underline(text: string): string {
|
|
80
|
+
switch (this.parseMode) {
|
|
81
|
+
case "html":
|
|
82
|
+
return fmt.underline(text);
|
|
83
|
+
case "markdown":
|
|
84
|
+
return fmt.underlineMD(text);
|
|
85
|
+
case "markdownv2":
|
|
86
|
+
return fmt.underlineMDv2(text);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Formats text as code based on current parse mode
|
|
92
|
+
*/
|
|
93
|
+
private code(text: string): string {
|
|
94
|
+
switch (this.parseMode) {
|
|
95
|
+
case "html":
|
|
96
|
+
return fmt.code(text);
|
|
97
|
+
case "markdown":
|
|
98
|
+
return fmt.codeMD(text);
|
|
99
|
+
case "markdownv2":
|
|
100
|
+
return fmt.codeMDv2(text);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Formats text as code block based on current parse mode
|
|
106
|
+
*/
|
|
107
|
+
private codeBlockFormat(text: string, language?: string): string {
|
|
108
|
+
switch (this.parseMode) {
|
|
109
|
+
case "html":
|
|
110
|
+
return fmt.codeBlock(text, language);
|
|
111
|
+
case "markdown":
|
|
112
|
+
return fmt.codeBlockMD(text, language);
|
|
113
|
+
case "markdownv2":
|
|
114
|
+
return fmt.codeBlockMDv2(text, language);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a link based on current parse mode
|
|
120
|
+
*/
|
|
121
|
+
private linkFormat(text: string, url: string): string {
|
|
122
|
+
switch (this.parseMode) {
|
|
123
|
+
case "html":
|
|
124
|
+
return fmt.link(text, url);
|
|
125
|
+
case "markdown":
|
|
126
|
+
return fmt.linkMD(text, url);
|
|
127
|
+
case "markdownv2":
|
|
128
|
+
return fmt.linkMDv2(text, url);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a mention based on current parse mode
|
|
134
|
+
*/
|
|
135
|
+
private mentionFormat(userId: number, name?: string): string {
|
|
136
|
+
switch (this.parseMode) {
|
|
137
|
+
case "html":
|
|
138
|
+
return fmt.mention(userId, name);
|
|
139
|
+
case "markdown":
|
|
140
|
+
return fmt.mentionMD(userId, name);
|
|
141
|
+
case "markdownv2":
|
|
142
|
+
return fmt.mentionMDv2(userId, name);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Creates a hashtag based on current parse mode
|
|
148
|
+
*/
|
|
149
|
+
private hashtagFormat(tag: string): string {
|
|
150
|
+
switch (this.parseMode) {
|
|
151
|
+
case "html":
|
|
152
|
+
return fmt.hashtag(tag);
|
|
153
|
+
case "markdown":
|
|
154
|
+
return fmt.hashtagMD(tag);
|
|
155
|
+
case "markdownv2":
|
|
156
|
+
return fmt.hashtagMDv2(tag);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
25
160
|
title(text: string): this {
|
|
26
|
-
this.parts.push(
|
|
161
|
+
this.parts.push(this.bold(text));
|
|
27
162
|
return this;
|
|
28
163
|
}
|
|
29
164
|
|
|
30
165
|
section(text: string): this {
|
|
31
|
-
this.parts.push(
|
|
166
|
+
this.parts.push(this.underline(text));
|
|
32
167
|
return this;
|
|
33
168
|
}
|
|
34
169
|
|
|
@@ -45,13 +180,13 @@ export class TelegramMessageBuilder {
|
|
|
45
180
|
let formattedValue = value;
|
|
46
181
|
|
|
47
182
|
if (opts?.bold) {
|
|
48
|
-
formattedValue =
|
|
183
|
+
formattedValue = this.bold(value);
|
|
49
184
|
} else if (opts?.italic) {
|
|
50
|
-
formattedValue =
|
|
185
|
+
formattedValue = this.italic(value);
|
|
51
186
|
} else if (opts?.code) {
|
|
52
|
-
formattedValue =
|
|
187
|
+
formattedValue = this.code(value);
|
|
53
188
|
} else if (opts?.underline) {
|
|
54
|
-
formattedValue =
|
|
189
|
+
formattedValue = this.underline(value);
|
|
55
190
|
}
|
|
56
191
|
|
|
57
192
|
this.parts.push(`${key}: ${formattedValue}`);
|
|
@@ -59,7 +194,7 @@ export class TelegramMessageBuilder {
|
|
|
59
194
|
}
|
|
60
195
|
|
|
61
196
|
codeBlock(text: string, language?: string): this {
|
|
62
|
-
this.parts.push(
|
|
197
|
+
this.parts.push(this.codeBlockFormat(text, language));
|
|
63
198
|
return this;
|
|
64
199
|
}
|
|
65
200
|
|
|
@@ -86,17 +221,17 @@ export class TelegramMessageBuilder {
|
|
|
86
221
|
}
|
|
87
222
|
|
|
88
223
|
link(text: string, url: string): this {
|
|
89
|
-
this.parts.push(
|
|
224
|
+
this.parts.push(this.linkFormat(text, url));
|
|
90
225
|
return this;
|
|
91
226
|
}
|
|
92
227
|
|
|
93
228
|
mention(userId: number, name?: string): this {
|
|
94
|
-
this.parts.push(
|
|
229
|
+
this.parts.push(this.mentionFormat(userId, name));
|
|
95
230
|
return this;
|
|
96
231
|
}
|
|
97
232
|
|
|
98
233
|
hashtag(tag: string): this {
|
|
99
|
-
this.parts.push(
|
|
234
|
+
this.parts.push(this.hashtagFormat(tag));
|
|
100
235
|
return this;
|
|
101
236
|
}
|
|
102
237
|
|
package/src/builder/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/src/builder/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./builder
|
|
1
|
+
export * from "./builder";
|
|
2
|
+
export * from "./media";
|