@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,384 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import { TelegramMediaBuilder } from "./builder/media";
|
|
3
|
+
import { TelegramKeyboardBuilder } from "./keyboard";
|
|
4
|
+
import { TelegramMessageBuilder } from "./builder";
|
|
5
|
+
|
|
6
|
+
describe("Media Integration Tests", () => {
|
|
7
|
+
describe("Media + Keyboard Combination", () => {
|
|
8
|
+
it("should build photo with inline keyboard", () => {
|
|
9
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
10
|
+
.caption("Choose an option:")
|
|
11
|
+
.build();
|
|
12
|
+
|
|
13
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
14
|
+
.callbackButton("Like", "like_photo")
|
|
15
|
+
.callbackButton("Download", "download_photo")
|
|
16
|
+
.buildMarkup();
|
|
17
|
+
|
|
18
|
+
expect(media.type).toBe("photo");
|
|
19
|
+
expect(media.caption).toBe("Choose an option:");
|
|
20
|
+
expect(keyboard.inline_keyboard).toBeDefined();
|
|
21
|
+
expect(keyboard.inline_keyboard?.[0]?.length).toBe(2);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should build video with reply keyboard", () => {
|
|
25
|
+
const media = TelegramMediaBuilder.video("video.mp4")
|
|
26
|
+
.caption("Rate this video:")
|
|
27
|
+
.build();
|
|
28
|
+
|
|
29
|
+
const keyboard = TelegramKeyboardBuilder.reply()
|
|
30
|
+
.textButton("⭐ 5 stars")
|
|
31
|
+
.textButton("⭐⭐⭐⭐ 4 stars")
|
|
32
|
+
.row()
|
|
33
|
+
.textButton("⭐⭐⭐ 3 stars")
|
|
34
|
+
.buildReplyMarkup();
|
|
35
|
+
|
|
36
|
+
expect(media.type).toBe("video");
|
|
37
|
+
expect(media.caption).toBe("Rate this video:");
|
|
38
|
+
expect(keyboard.keyboard).toBeDefined();
|
|
39
|
+
expect(keyboard.keyboard?.length).toBe(2);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should build document with force reply", () => {
|
|
43
|
+
const media = TelegramMediaBuilder.document("form.pdf")
|
|
44
|
+
.caption("Please fill out the form")
|
|
45
|
+
.build();
|
|
46
|
+
|
|
47
|
+
const keyboard =
|
|
48
|
+
TelegramKeyboardBuilder.forceReply().buildForceReplyMarkup();
|
|
49
|
+
|
|
50
|
+
expect(media.type).toBe("document");
|
|
51
|
+
expect(media.caption).toBe("Please fill out the form");
|
|
52
|
+
expect(keyboard.force_reply).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("Media + Text Message Combination", () => {
|
|
57
|
+
it("should build text message before media", () => {
|
|
58
|
+
const text = TelegramMessageBuilder.text()
|
|
59
|
+
.title("📸 Photo Gallery")
|
|
60
|
+
.line("Status", "5 photos", { bold: true })
|
|
61
|
+
.build();
|
|
62
|
+
|
|
63
|
+
const media = TelegramMediaBuilder.photo("photo1.jpg")
|
|
64
|
+
.caption("1/5 - Sunset")
|
|
65
|
+
.build();
|
|
66
|
+
|
|
67
|
+
expect(text.text).toContain("📸 Photo Gallery");
|
|
68
|
+
expect(text.text).toContain("Status: <b>5 photos</b>");
|
|
69
|
+
expect(media.type).toBe("photo");
|
|
70
|
+
expect(media.caption).toBe("1/5 - Sunset");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("Cross-Mode Caption Formatting", () => {
|
|
75
|
+
it("should format caption consistently in all parse modes", () => {
|
|
76
|
+
const captionText = "*Bold* and _italic_ text";
|
|
77
|
+
|
|
78
|
+
const html = TelegramMediaBuilder.photo("photo.jpg")
|
|
79
|
+
.caption(captionText)
|
|
80
|
+
.setParseMode("html")
|
|
81
|
+
.build();
|
|
82
|
+
|
|
83
|
+
const md = TelegramMediaBuilder.photo("photo.jpg")
|
|
84
|
+
.caption(captionText)
|
|
85
|
+
.setParseMode("markdown")
|
|
86
|
+
.build();
|
|
87
|
+
|
|
88
|
+
const mdv2 = TelegramMediaBuilder.photo("photo.jpg")
|
|
89
|
+
.caption(captionText)
|
|
90
|
+
.setParseMode("markdownv2")
|
|
91
|
+
.build();
|
|
92
|
+
|
|
93
|
+
// HTML mode: * and _ are NOT special, should be left as-is
|
|
94
|
+
expect(html.caption).toBe("*Bold* and _italic_ text");
|
|
95
|
+
// Markdown escapes * and _
|
|
96
|
+
expect(md.caption).toContain("\\*");
|
|
97
|
+
expect(md.caption).toContain("\\_");
|
|
98
|
+
// MarkdownV2 escapes * and _
|
|
99
|
+
expect(mdv2.caption).toContain("\\*");
|
|
100
|
+
expect(mdv2.caption).toContain("\\_");
|
|
101
|
+
|
|
102
|
+
expect(html.parse_mode).toBe("html");
|
|
103
|
+
expect(md.parse_mode).toBe("markdown");
|
|
104
|
+
expect(mdv2.parse_mode).toBe("markdownv2");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should handle HTML tags in captions correctly", () => {
|
|
108
|
+
const caption = "<b>Bold</b> and <i>italic</i>";
|
|
109
|
+
|
|
110
|
+
const html = TelegramMediaBuilder.photo("photo.jpg")
|
|
111
|
+
.caption(caption)
|
|
112
|
+
.setParseMode("html")
|
|
113
|
+
.build();
|
|
114
|
+
|
|
115
|
+
// HTML mode should escape tags
|
|
116
|
+
expect(html.caption).toContain("<b>");
|
|
117
|
+
expect(html.caption).toContain("</b>");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("Real-World Scenarios", () => {
|
|
122
|
+
it("should build product photo with purchase options", () => {
|
|
123
|
+
const media = TelegramMediaBuilder.photo("product.jpg")
|
|
124
|
+
.caption(
|
|
125
|
+
"📱 iPhone 15 Pro - $999\n\n✅ 256GB Storage\n✅ Titanium Design\n✅ A17 Pro Chip",
|
|
126
|
+
)
|
|
127
|
+
.setParseMode("markdown")
|
|
128
|
+
.build();
|
|
129
|
+
|
|
130
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
131
|
+
.urlButton("Buy Now", "https://example.com/buy")
|
|
132
|
+
.callbackButton("Add to Cart", "add_cart")
|
|
133
|
+
.callbackButton("View Details", "view_details")
|
|
134
|
+
.buildMarkup();
|
|
135
|
+
|
|
136
|
+
expect(media.type).toBe("photo");
|
|
137
|
+
expect(media.caption).toContain("iPhone 15 Pro");
|
|
138
|
+
expect(media.parse_mode).toBe("markdown");
|
|
139
|
+
expect(keyboard.inline_keyboard?.[0]?.length).toBe(3);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should build video tutorial with chapters", () => {
|
|
143
|
+
const media = TelegramMediaBuilder.video("tutorial.mp4")
|
|
144
|
+
.caption("Chapter 1: Introduction\nDuration: 10:25")
|
|
145
|
+
.duration(625)
|
|
146
|
+
.thumbnail("thumb.jpg")
|
|
147
|
+
.enableStreaming()
|
|
148
|
+
.build();
|
|
149
|
+
|
|
150
|
+
expect(media.type).toBe("video");
|
|
151
|
+
expect(media.duration).toBe(625);
|
|
152
|
+
expect(media.support_streaming).toBe(true);
|
|
153
|
+
expect(media.thumb).toBe("thumb.jpg");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should build document with form", () => {
|
|
157
|
+
const media = TelegramMediaBuilder.document("application.pdf")
|
|
158
|
+
.caption("Please complete the attached application form")
|
|
159
|
+
.fileName("employment_application_2024.pdf")
|
|
160
|
+
.mimeType("application/pdf")
|
|
161
|
+
.build();
|
|
162
|
+
|
|
163
|
+
expect(media.type).toBe("document");
|
|
164
|
+
expect(media.file_name).toBe("employment_application_2024.pdf");
|
|
165
|
+
expect(media.mime_type).toBe("application/pdf");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should build audio playlist", () => {
|
|
169
|
+
const media = TelegramMediaBuilder.audio("song.mp3")
|
|
170
|
+
.caption(
|
|
171
|
+
"🎵 Now Playing: Summer Vibes\nArtist: Beach Boys\nAlbum: Summer Hits",
|
|
172
|
+
)
|
|
173
|
+
.duration(215)
|
|
174
|
+
.performer("Beach Boys")
|
|
175
|
+
.title("Summer Vibes")
|
|
176
|
+
.thumbnail("album_cover.jpg")
|
|
177
|
+
.build();
|
|
178
|
+
|
|
179
|
+
expect(media.type).toBe("audio");
|
|
180
|
+
expect(media.performer).toBe("Beach Boys");
|
|
181
|
+
expect(media.title).toBe("Summer Vibes");
|
|
182
|
+
expect(media.duration).toBe(215);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should build voice message with transcription", () => {
|
|
186
|
+
const media = TelegramMediaBuilder.voice("voice_note.ogg")
|
|
187
|
+
.caption("🎤 Voice note: Meeting notes")
|
|
188
|
+
.duration(45)
|
|
189
|
+
.build();
|
|
190
|
+
|
|
191
|
+
expect(media.type).toBe("voice");
|
|
192
|
+
expect(media.caption).toContain("Voice note");
|
|
193
|
+
expect(media.duration).toBe(45);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("Media Groups", () => {
|
|
198
|
+
it("should build multiple media items for an album", () => {
|
|
199
|
+
const photo1 = TelegramMediaBuilder.photo("photo1.jpg")
|
|
200
|
+
.caption("Sunset at the beach")
|
|
201
|
+
.build();
|
|
202
|
+
|
|
203
|
+
const photo2 = TelegramMediaBuilder.photo("photo2.jpg")
|
|
204
|
+
.caption("Sunrise over the mountains")
|
|
205
|
+
.build();
|
|
206
|
+
|
|
207
|
+
const photo3 = TelegramMediaBuilder.photo("photo3.jpg")
|
|
208
|
+
.caption("Golden hour in the city")
|
|
209
|
+
.build();
|
|
210
|
+
|
|
211
|
+
expect(photo1.type).toBe("photo");
|
|
212
|
+
expect(photo2.type).toBe("photo");
|
|
213
|
+
expect(photo3.type).toBe("photo");
|
|
214
|
+
|
|
215
|
+
// All would be sent together as a media group using sendMediaGroup
|
|
216
|
+
const mediaGroup = [photo1, photo2, photo3];
|
|
217
|
+
expect(mediaGroup.length).toBe(3);
|
|
218
|
+
expect(mediaGroup.every((m) => m.type === "photo")).toBe(true);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("Complex Integration Scenarios", () => {
|
|
223
|
+
it("should build complete product listing", () => {
|
|
224
|
+
const text = TelegramMessageBuilder.text()
|
|
225
|
+
.title("🛍️ New Product Arrival!")
|
|
226
|
+
.newline()
|
|
227
|
+
.line("Product", "Smart Watch Pro", { bold: true })
|
|
228
|
+
.line("Price", "$299", { bold: true })
|
|
229
|
+
.separator()
|
|
230
|
+
.listItem("Heart rate monitoring")
|
|
231
|
+
.listItem("GPS tracking")
|
|
232
|
+
.listItem("Water resistant")
|
|
233
|
+
.newline()
|
|
234
|
+
.link("View Details", "https://example.com/product")
|
|
235
|
+
.build();
|
|
236
|
+
|
|
237
|
+
const media = TelegramMediaBuilder.photo("product_photo.jpg")
|
|
238
|
+
.caption("Smart Watch Pro - Rose Gold")
|
|
239
|
+
.build();
|
|
240
|
+
|
|
241
|
+
const keyboard = TelegramKeyboardBuilder.inline()
|
|
242
|
+
.urlButton("🛒 Buy Now", "https://example.com/buy")
|
|
243
|
+
.callbackButton("📦 Add to Cart", "add_cart")
|
|
244
|
+
.row()
|
|
245
|
+
.callbackButton("⭐ Reviews", "reviews")
|
|
246
|
+
.callbackButton("❓ Questions", "questions")
|
|
247
|
+
.buildMarkup();
|
|
248
|
+
|
|
249
|
+
expect(text.text).toContain("🛍️ New Product Arrival!");
|
|
250
|
+
expect(text.text).toContain("Price: <b>$299</b>");
|
|
251
|
+
expect(media.type).toBe("photo");
|
|
252
|
+
expect(keyboard.inline_keyboard?.length).toBe(2);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should build news article with video", () => {
|
|
256
|
+
const text = TelegramMessageBuilder.text()
|
|
257
|
+
.title("📰 Breaking News")
|
|
258
|
+
.newline()
|
|
259
|
+
.section("Technology")
|
|
260
|
+
.text("Major breakthrough in quantum computing announced today.")
|
|
261
|
+
.newline()
|
|
262
|
+
.link("Read full article", "https://news.example.com/article")
|
|
263
|
+
.hashtag("tech")
|
|
264
|
+
.hashtag("quantum")
|
|
265
|
+
.build();
|
|
266
|
+
|
|
267
|
+
const media = TelegramMediaBuilder.video("news_report.mp4")
|
|
268
|
+
.caption("Watch the full report")
|
|
269
|
+
.duration(300)
|
|
270
|
+
.enableStreaming()
|
|
271
|
+
.build();
|
|
272
|
+
|
|
273
|
+
expect(text.text).toContain("📰 Breaking News");
|
|
274
|
+
expect(text.text).toContain("#tech");
|
|
275
|
+
expect(media.type).toBe("video");
|
|
276
|
+
expect(media.support_streaming).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("Security and Validation", () => {
|
|
281
|
+
it("should escape HTML in captions to prevent XSS", () => {
|
|
282
|
+
const caption = "<script>alert('xss')</script>";
|
|
283
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
284
|
+
.caption(caption)
|
|
285
|
+
.build();
|
|
286
|
+
|
|
287
|
+
expect(media.caption).not.toContain("<script>");
|
|
288
|
+
expect(media.caption).toContain("<script>");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("should escape MarkdownV2 special chars in captions", () => {
|
|
292
|
+
const caption = "Text with *bold* and _italic_ and ~strike~";
|
|
293
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
294
|
+
.caption(caption)
|
|
295
|
+
.setParseMode("markdownv2")
|
|
296
|
+
.build();
|
|
297
|
+
|
|
298
|
+
expect(media.caption).toContain("\\*");
|
|
299
|
+
expect(media.caption).toContain("\\_");
|
|
300
|
+
expect(media.caption).toContain("\\~");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("should handle very long captions without error", () => {
|
|
304
|
+
const longCaption = "A".repeat(2000); // Over 1024 limit
|
|
305
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
306
|
+
.caption(longCaption)
|
|
307
|
+
.build();
|
|
308
|
+
|
|
309
|
+
// Builder doesn't validate length - Telegram API will reject
|
|
310
|
+
expect(media.caption).toHaveLength(2000);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("should handle special unicode characters in captions", () => {
|
|
314
|
+
const caption = "🎉🎊🎈 Party time! 💃🕺🎭";
|
|
315
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
316
|
+
.caption(caption)
|
|
317
|
+
.build();
|
|
318
|
+
|
|
319
|
+
expect(media.caption).toContain("🎉");
|
|
320
|
+
expect(media.caption).toContain("💃");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("should handle RTL languages in captions", () => {
|
|
324
|
+
const caption = "مرحبا - Welcome! - שלום";
|
|
325
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
326
|
+
.caption(caption)
|
|
327
|
+
.build();
|
|
328
|
+
|
|
329
|
+
expect(media.caption).toContain("مرحبا");
|
|
330
|
+
expect(media.caption).toContain("Welcome!");
|
|
331
|
+
expect(media.caption).toContain("שלום");
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should handle CJK languages in captions", () => {
|
|
335
|
+
const caption = "标题 - タイトル - 제목";
|
|
336
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
337
|
+
.caption(caption)
|
|
338
|
+
.build();
|
|
339
|
+
|
|
340
|
+
expect(media.caption).toContain("标题");
|
|
341
|
+
expect(media.caption).toContain("タイトル");
|
|
342
|
+
expect(media.caption).toContain("제목");
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe("Type Safety Integration", () => {
|
|
347
|
+
it("should maintain type safety through build chain", () => {
|
|
348
|
+
const media = TelegramMediaBuilder.photo("photo.jpg")
|
|
349
|
+
.caption("Test")
|
|
350
|
+
.setParseMode("html")
|
|
351
|
+
.setOption("protect_content", true)
|
|
352
|
+
.build();
|
|
353
|
+
|
|
354
|
+
// Type assertion to verify structure
|
|
355
|
+
const hasMedia = "media" in media;
|
|
356
|
+
const hasType = "type" in media;
|
|
357
|
+
const hasCaption = "caption" in media;
|
|
358
|
+
|
|
359
|
+
expect(hasMedia).toBe(true);
|
|
360
|
+
expect(hasType).toBe(true);
|
|
361
|
+
expect(hasCaption).toBe(true);
|
|
362
|
+
expect(media.type).toBe("photo");
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("should work with Telegram Bot API structure", () => {
|
|
366
|
+
const media = TelegramMediaBuilder.video("video.mp4")
|
|
367
|
+
.caption("Video caption")
|
|
368
|
+
.duration(120)
|
|
369
|
+
.build();
|
|
370
|
+
|
|
371
|
+
// Simulate sending to Telegram Bot API
|
|
372
|
+
const apiPayload = {
|
|
373
|
+
video: media.media,
|
|
374
|
+
caption: media.caption,
|
|
375
|
+
duration: media.duration,
|
|
376
|
+
parse_mode: media.parse_mode,
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
expect(apiPayload.video).toBe("video.mp4");
|
|
380
|
+
expect(apiPayload.caption).toBe("Video caption");
|
|
381
|
+
expect(apiPayload.duration).toBe(120);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
});
|
package/src/types/index.d.ts
CHANGED
package/src/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
}
|
|
158
|
+
//# sourceMappingURL=media.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.types.d.ts","sourceRoot":"","sources":["media.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEhF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,8CAA8C;IAC9C,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC;IAC7B,iDAAiD;IACjD,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,6DAA6D;IAC7D,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,8CAA8C;IAC9C,YAAY,CAAC,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