@mks2508/telegram-message-builder 0.2.0 → 0.3.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/index.cjs +1057 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1022 -13
- package/dist/index.js.map +1 -1
- 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,178 @@
|
|
|
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
|
+
|
|
13
|
+
import type { ParseMode } from "./core.types";
|
|
14
|
+
import type { IInlineKeyboardMarkup, IReplyParameters } from "./keyboard.types";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Media source - can represent various input formats
|
|
18
|
+
*
|
|
19
|
+
* - `string` as file_id - Existing uploaded file on Telegram servers
|
|
20
|
+
* - `string` as URL - HTTPS URL to fetch file from
|
|
21
|
+
* - `Buffer` - Binary data for upload
|
|
22
|
+
* - `string` as file path - Local file path for upload
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const fileId: MediaSource = "AgACAgIAAxkBAAI...";
|
|
27
|
+
* const url: MediaSource = "https://example.com/photo.jpg";
|
|
28
|
+
* const buffer: MediaSource = Buffer.from(...);
|
|
29
|
+
* const filePath: MediaSource = "/path/to/photo.jpg";
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type MediaSource = string | Buffer;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Common media options shared across all media types
|
|
36
|
+
*
|
|
37
|
+
* Includes all possible options from all media types to allow
|
|
38
|
+
* flexible setOption() usage while maintaining type safety.
|
|
39
|
+
*/
|
|
40
|
+
export interface IMediaCommonOptions {
|
|
41
|
+
/** List of special entities in the caption */
|
|
42
|
+
caption_entities?: unknown[];
|
|
43
|
+
/** Show caption above media (True by default) */
|
|
44
|
+
show_caption_above_media?: boolean;
|
|
45
|
+
/** Disable automatic file type detection (documents only) */
|
|
46
|
+
disable_content_type_detection?: boolean;
|
|
47
|
+
/** Protect contents from forwarding/saving */
|
|
48
|
+
protect_content?: boolean;
|
|
49
|
+
/** Reply parameters for replying to messages */
|
|
50
|
+
reply_parameters?: IReplyParameters;
|
|
51
|
+
/** Inline keyboard attached to the message */
|
|
52
|
+
reply_markup?: IInlineKeyboardMarkup;
|
|
53
|
+
|
|
54
|
+
// Photo/Video/Document/Audio options
|
|
55
|
+
/** Thumbnail of the file sent */
|
|
56
|
+
thumb?: Buffer | string;
|
|
57
|
+
|
|
58
|
+
// Video/Audio/Voice options
|
|
59
|
+
/** Duration of the media in seconds */
|
|
60
|
+
duration?: number;
|
|
61
|
+
|
|
62
|
+
// Video options
|
|
63
|
+
/** Video width */
|
|
64
|
+
width?: number;
|
|
65
|
+
/** Video height */
|
|
66
|
+
height?: number;
|
|
67
|
+
/** Pass True to upload the video as a streaming video */
|
|
68
|
+
support_streaming?: boolean;
|
|
69
|
+
|
|
70
|
+
// Document options
|
|
71
|
+
/** Original filename */
|
|
72
|
+
file_name?: string;
|
|
73
|
+
/** MIME type of the file */
|
|
74
|
+
mime_type?: string;
|
|
75
|
+
|
|
76
|
+
// Audio options
|
|
77
|
+
/** Performer of the audio */
|
|
78
|
+
performer?: string;
|
|
79
|
+
/** Track name of the audio */
|
|
80
|
+
title?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Photo-specific options
|
|
85
|
+
*/
|
|
86
|
+
export interface IPhotoOptions extends IMediaCommonOptions {
|
|
87
|
+
/** Thumbnail of the file sent */
|
|
88
|
+
thumb?: Buffer | string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Video-specific options
|
|
93
|
+
*/
|
|
94
|
+
export interface IVideoOptions extends IMediaCommonOptions {
|
|
95
|
+
/** Duration of the video in seconds */
|
|
96
|
+
duration?: number;
|
|
97
|
+
/** Video width */
|
|
98
|
+
width?: number;
|
|
99
|
+
/** Video height */
|
|
100
|
+
height?: number;
|
|
101
|
+
/** Thumbnail of the video */
|
|
102
|
+
thumb?: Buffer | string;
|
|
103
|
+
/** Pass True to upload the video as a streaming video */
|
|
104
|
+
support_streaming?: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Document-specific options
|
|
109
|
+
*/
|
|
110
|
+
export interface IDocumentOptions extends IMediaCommonOptions {
|
|
111
|
+
/** Thumbnail of the document */
|
|
112
|
+
thumb?: Buffer | string;
|
|
113
|
+
/** Original filename */
|
|
114
|
+
file_name?: string;
|
|
115
|
+
/** MIME type of the file */
|
|
116
|
+
mime_type?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Audio-specific options
|
|
121
|
+
*/
|
|
122
|
+
export interface IAudioOptions extends IMediaCommonOptions {
|
|
123
|
+
/** Duration of the audio in seconds */
|
|
124
|
+
duration?: number;
|
|
125
|
+
/** Performer of the audio */
|
|
126
|
+
performer?: string;
|
|
127
|
+
/** Track name of the audio */
|
|
128
|
+
title?: string;
|
|
129
|
+
/** Thumbnail of the album cover */
|
|
130
|
+
thumb?: Buffer | string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Voice-specific options
|
|
135
|
+
*/
|
|
136
|
+
export interface IVoiceOptions extends IMediaCommonOptions {
|
|
137
|
+
/** Duration of the voice message in seconds */
|
|
138
|
+
duration?: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Media message types supported by Telegram
|
|
143
|
+
*/
|
|
144
|
+
export type MediaType = "photo" | "video" | "document" | "audio" | "voice";
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Complete media message interface
|
|
148
|
+
*/
|
|
149
|
+
export interface IMediaMessage {
|
|
150
|
+
/** Media source (file_id, URL, Buffer, or file path) */
|
|
151
|
+
media: MediaSource;
|
|
152
|
+
/** Type of media */
|
|
153
|
+
type: MediaType;
|
|
154
|
+
/** Caption for the media */
|
|
155
|
+
caption?: string;
|
|
156
|
+
/** Parse mode for caption formatting */
|
|
157
|
+
parse_mode?: ParseMode;
|
|
158
|
+
/** Additional options */
|
|
159
|
+
options: IMediaCommonOptions;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Result from TelegramMediaBuilder.build()
|
|
164
|
+
*
|
|
165
|
+
* Compatible with Telegram Bot API send* methods
|
|
166
|
+
*/
|
|
167
|
+
export interface IMediaBuildResult {
|
|
168
|
+
/** Media source */
|
|
169
|
+
media: MediaSource;
|
|
170
|
+
/** Media type */
|
|
171
|
+
type: MediaType;
|
|
172
|
+
/** Caption with formatting applied based on parse_mode */
|
|
173
|
+
caption?: string;
|
|
174
|
+
/** Parse mode used for caption */
|
|
175
|
+
parse_mode?: ParseMode;
|
|
176
|
+
/** Additional Telegram-specific options */
|
|
177
|
+
[key: string]: unknown;
|
|
178
|
+
}
|