@xbibzlibrary/telebibz 3.1.2 → 3.1.4

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE.md +15 -8
  4. package/README.id.md +312 -43
  5. package/README.md +312 -43
  6. package/examples/08-rich-message.js +34 -0
  7. package/index.d.ts +303 -96
  8. package/index.js +8 -2
  9. package/lib/api.js +20 -6
  10. package/lib/composer.js +14 -2
  11. package/lib/context.js +83 -21
  12. package/lib/file.js +8 -1
  13. package/lib/inline-query.js +6 -1
  14. package/lib/logger.js +44 -14
  15. package/lib/ratelimit.js +16 -3
  16. package/lib/rich.js +175 -0
  17. package/lib/runner.js +14 -5
  18. package/lib/session.js +12 -4
  19. package/lib/telebibz.js +40 -24
  20. package/lib/telegram-methods.js +192 -0
  21. package/package.json +14 -10
  22. package/test/audit.test.js +355 -0
  23. package/test/types.test.ts +40 -0
  24. package/types/telegram-bot-api/LICENSE +21 -0
  25. package/types/telegram-bot-api/api.d.ts +22 -0
  26. package/types/telegram-bot-api/checklist.d.ts +72 -0
  27. package/types/telegram-bot-api/inline.d.ts +692 -0
  28. package/types/telegram-bot-api/langs.d.ts +193 -0
  29. package/types/telegram-bot-api/manage.d.ts +1153 -0
  30. package/types/telegram-bot-api/markup.d.ts +278 -0
  31. package/types/telegram-bot-api/message.d.ts +1557 -0
  32. package/types/telegram-bot-api/methods.d.ts +2860 -0
  33. package/types/telegram-bot-api/mod.d.ts +14 -0
  34. package/types/telegram-bot-api/passport.d.ts +163 -0
  35. package/types/telegram-bot-api/payment.d.ts +576 -0
  36. package/types/telegram-bot-api/rich.d.ts +1198 -0
  37. package/types/telegram-bot-api/settings.d.ts +120 -0
  38. package/types/telegram-bot-api/story.d.ts +89 -0
  39. package/types/telegram-bot-api/update.d.ts +86 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased — Telegram Bot API 10.3 / Rich Messages
4
+
5
+ ### API surface and types
6
+
7
+ - Added a runtime registry containing **185 Bot API method names**. An audit test compares the registry exactly with all vendored method signatures and rejects duplicates.
8
+ - Vendored `@grammyjs/types@5.0.0` declarations (MIT; attribution/license in `NOTICE.md` and `types/telegram-bot-api/LICENSE`) for Bot API methods, objects, updates and payloads. These declarations add **no runtime dependency**; TypeScript is a development-only dependency for type tests.
9
+ - `api.callApi(method, payload)` and `api.raw(...)` now provide method-specific parameter and result typing for all methods in the vendored schema. `TelegramTypes`, `TelegramMethodName`, `TelegramMethodPayload<M>`, `TelegramMethodResult<M>`, `TelegramApiMethods` and `TelegramApiPayloads` are exported. The dynamic API Proxy remains available but is not runtime schema validation.
10
+
11
+ ### Rich Message authoring
12
+
13
+ - Added `rich.html()`, `rich.markdown()`, `rich.blocks()`, `inputRichMessage()`, and `RichMessageBuilder` (`html`, `markdown`, `blocks`, `add`, `media`, `rtl`, `skipEntityDetection`, `build`, `buildDraft`). Exactly one content mode—HTML, Markdown or blocks—is required.
14
+ - Added RichText entity builders for bold/italic/underline/strikethrough/spoiler/marked/code/subscript/superscript, date-time, mentions, custom emoji, math, links, email/phone/card, hashtag/cashtag/bot command, anchors/references, and inline rich-text buttons.
15
+ - Added block builders for paragraph, heading, preformatted text, footer, divider, math, anchor, list, block/expandable/pull quotations, collage, slideshow, table, details, map, animation, audio, document, photo, video, voice note, buttons and draft-only thinking blocks.
16
+ - `rich.button()` now builds a `RichMessageButton` for the buttons block; `rich.buttonText()` builds the separate inline `RichTextButton` entity. Runtime validation checks the one-action rule, supported style/alignment and 1–8 button count. This correction followed a live Telegram parse error.
17
+ - Added draft-safe `rich.draftHtml()`, `rich.draftMarkdown()`, `rich.draftBlocks()` and `RichMessageBuilder.buildDraft()`. They reject new `File` uploads; use existing Telegram file IDs for draft media.
18
+ - Added animated custom emoji support via `rich.customEmoji(customEmojiId, alternativeText)` and rich-message embedding of media through `tg://...` references plus `media` entries.
19
+
20
+ ### Bot API 10.x helpers and media
21
+
22
+ - Added/typed API and Context support for `sendRichMessage`, `editMessageText` with `rich_message`, `sendLivePhoto`, `sendMessageDraft`, `sendRichMessageDraft`, `answerGuestQuery`, ephemeral send/edit/delete methods, and `iq.richArticle()`.
23
+ - Added live-photo and paid-media builders (`InputMediaBuilder.livePhoto()` and `InputPaidMediaBuilder.livePhoto()`). Existing multipart transport now has audit coverage for nested rich-media attachments.
24
+ - Added Context helpers: `replyWithRichMessage`, `editRichMessage`, `replyWithLivePhoto`, `sendMessageDraft`, `sendRichMessageDraft`, `replyEphemeral`, `editEphemeralRichMessage`, ephemeral media/caption/reply-markup edits, and `deleteEphemeralMessage`.
25
+ - Added `examples/08-rich-message.js` and expanded both English and Indonesian README sections with usage, helper catalogs, typing, media, drafts, animated emoji, limits/permissions and troubleshooting.
26
+
27
+ ### Verification, live-test findings and publishing
28
+
29
+ - Automated suite: **30/30** existing feature checks + **18/18** audit checks (**48 total**); `npm run typecheck`, JavaScript syntax, workflow YAML, `npm pack --dry-run`, `git diff --check`, and `npm audit --omit=dev` pass.
30
+ - Live smoke test: rich blocks, HTML/Markdown, animated custom emoji, plain/rich drafts, photo/audio/document/video/voice-note media blocks, collage/slideshow, standalone live photo, GIF with `sendAnimation`, and rich HTML media references succeeded. For a rich `animation` block, MP4 succeeded while GIF returned `RICH_MESSAGE_VIDEO_INVALID`; the same GIF worked with standalone `sendAnimation`.
31
+ - Live ephemeral sends returned Telegram `BOT_NOT_ADMIN`; paid-media sending was not attempted because it can involve Telegram Stars. Callback execution and all 185 endpoints were not live-tested; see `VERIFIKASI-MENDALAM.md`. No bot token or user/chat identifier is recorded in repo documentation.
32
+ - CI/release workflows now run TypeScript checks. Auto-publish remains gated by GitHub Environment `npm-release` and secret `NPM_TOKEN`; no credential is committed and no release is implied by this Unreleased entry.
33
+
3
34
  ## 3.1.0 — wizard: tombol pilihan + mode edit/delete (2026-09-13)
4
35
 
5
36
  - **Wizard mendukung tombol pilihan**: `step.buttons` sebagai reply keyboard
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Xbibz Official
3
+ Copyright (c) 2026 Xbibz Technology ID
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/NOTICE.md CHANGED
@@ -1,12 +1,19 @@
1
1
  # NOTICE
2
2
 
3
- telebibz v2 adalah recode mandiri (JavaScript, 0 dependency) atas konsep arsitektur
4
- Bot API framework **grammY** (https://github.com/grammyjs/grammY} — lisensi MIT).
3
+ ## Arsitektur dan implementasi JavaScript
5
4
 
6
- Setiap berkas sumber di lib/ ditulis ulang: net (transport multipart), api, composer
7
- (middleware/routing filter), context, session, runner (polling tahan-409), file,
8
- keyboard, wizard, broadcast, errors, logger.
5
+ telebibz adalah recode mandiri dengan konsep arsitektur yang terinspirasi oleh
6
+ Bot API framework **grammY** (https://github.com/grammyjs/grammY, lisensi MIT).
7
+ Implementasi JavaScript pada `lib/` ditulis untuk repo ini; referensi tersebut
8
+ adalah atribusi konseptual.
9
9
 
10
- Terima kasih untuk grammY & komunitasnya atas rancangan API yang elegan.
11
- Tidak ada kode grammY yang disalin verbatim; pemakaian nama "grammY" bersifat
12
- atribusi konseptual sesuai semangat lisensi MIT.
10
+ ## Type declarations Bot API
11
+
12
+ Berkas deklarasi TypeScript pada `types/telegram-bot-api/` diambil dari
13
+ [`@grammyjs/types` v5.0.0](https://github.com/grammyjs/types), proyek grammY
14
+ berlisensi MIT. Salinan lisensinya ada di [`types/telegram-bot-api/LICENSE`](types/telegram-bot-api/LICENSE).
15
+ Deklarasi tersebut digunakan sebagai model tipe Bot API 10.3; implementasi
16
+ runtime telebibz tetap menggunakan transport dan proxy milik repo ini.
17
+
18
+ Terima kasih kepada grammY dan komunitas Telegram bot atas dokumentasi dan
19
+ rancangan API yang membantu proyek ini.
package/README.id.md CHANGED
@@ -19,14 +19,14 @@ produksi yang *benar-benar dipakai*, dokumentasi 🇮🇩 Indonesia-first, dan n
19
19
  [![npm version](https://img.shields.io/npm/v/@xbibzlibrary/telebibz?style=for-the-badge&logo=npm&logoColor=white&color=CB3837&label=telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
20
20
  [![downloads](https://img.shields.io/npm/dm/@xbibzlibrary/telebibz?style=for-the-badge&logo=npm&logoColor=white&color=green&label=unduh%2Fbulan)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
21
21
  [![node](https://img.shields.io/node/v/@xbibzlibrary/telebibz?style=for-the-badge&logo=node.js&logoColor=white&color=339933&label=node)](https://nodejs.org)
22
- [![tests](https://img.shields.io/badge/test-30%2F30%20lulus-brightgreen?style=for-the-badge&logo=checkmarx&logoColor=white)](#-test--bukti-live)
23
- [![size](https://img.shields.io/badge/kode-1.7k%20baris-orange?style=for-the-badge&logo=codeigniter&logoColor=white)](#-analitik--statistik)
22
+ [![tests](https://img.shields.io/badge/test-48%2F48%20lulus-brightgreen?style=for-the-badge&logo=checkmarx&logoColor=white)](#-test--bukti-live)
23
+ [![size](https://img.shields.io/badge/kode-2.1k%20baris-orange?style=for-the-badge&logo=codeigniter&logoColor=white)](#-analitik--statistik)
24
24
  [![license](https://img.shields.io/npm/l/@xbibzlibrary/telebibz?style=for-the-badge&color=blue)](LICENSE)
25
25
  [![views](https://komarev.com/ghpvc/?username=XbibzOfficial777&repo=telebibz&style=for-the-badge&color=blueviolet&label=kunjungan+repo)](https://github.com/XbibzOfficial777/telebibz)
26
26
 
27
27
  <br>
28
28
 
29
- `//—Xbibz Official—//`
29
+ `Xbibz Technology ID`
30
30
 
31
31
  </div>
32
32
 
@@ -38,7 +38,7 @@ produksi yang *benar-benar dipakai*, dokumentasi 🇮🇩 Indonesia-first, dan n
38
38
  |---|---|---|
39
39
  | ⚡ [Kenapa telebibz?](#kenapa) | 📊 [Matriks fitur vs grammY](#matriks) | 📥 [Instalasi & persyaratan](#instalasi) |
40
40
  | 🚀 [Mulai cepat](#mulai) | 🧠 [Cara kerja (arsitektur)](#arsitektur) | 📖 [Dokumentasi lengkap](#dokumentasi) |
41
- | 🎛️ [Handler & filter](#handler) | 💬 [Shortcut Context](#context) | 🔘 [Keyboard & tombol](#keyboard) |
41
+ | 🎛️ [Handler & filter](#handler) | 💬 [Shortcut Context](#context) | 🧱 [Rich Message & Bot API 10.3](#rich-messages) |
42
42
  | 🍽️ [Menu interaktif](#menu) | 🧙 [Wizard (form + tombol + edit/delete)](#wizard) | ❓ [Mode inline](#inline) |
43
43
  | 📣 [Broadcast](#broadcast) | 📎 [File & media](#file) | 🛡️ [Keandalan & rate limit](#ratelimit) |
44
44
  | 🗃️ [Session](#session) | 🇮🇩 [Error manusiawi](#error) | 🕸️ [Webhook & serverless](#webhook) |
@@ -67,6 +67,8 @@ produksi yang *benar-benar dipakai*, dokumentasi 🇮🇩 Indonesia-first, dan n
67
67
  | Fitur | grammY | telebibz |
68
68
  |---|:---:|:---:|
69
69
  | Proxy API **segala metode** (auto-generated) | ✅ | ✅ |
70
+ | **185 signature payload Bot API spesifik** (`callApi`) | ✅ | ✅ |
71
+ | Rich Message: block, entity, draft, media, emoji bergerak | beragam per API | ✅ bawaan |
70
72
  | ~60 shortcut bertipe (sendMessage, banChatMember…) | ✅ | ✅ |
71
73
  | Context lengkap (~70 pintasan reply/edit/admin/react) | ✅ | ✅ |
72
74
  | Context flavor business (`business_connection_id` otomatis) | plugin | ✅ bawaan |
@@ -90,7 +92,7 @@ produksi yang *benar-benar dipakai*, dokumentasi 🇮🇩 Indonesia-first, dan n
90
92
  | Humanisasi error + saran (🇮🇩) | ❌ | ✅ `humanize()` |
91
93
  | Banner boot + log debug | ❌ | ✅ (`DEBUG=telebibz*`) |
92
94
  | Proxy HTTP(S) untuk VPS | ⚠️ manual | ✅ opsi `proxy` transport |
93
- | TypeScript | ✅ full | d.ts longgar (JS-first) |
95
+ | TypeScript | ✅ full | ✅ tipe spesifik untuk 185 metode Bot API |
94
96
  | Bahasa dokumentasi | en | **🇬🇧 + 🇮🇩** |
95
97
 
96
98
  <a id="instalasi"></a>
@@ -138,13 +140,14 @@ BOT_TOKEN=123:abc node index.js
138
140
  ```
139
141
 
140
142
  ```
141
- ┌──────────────────────────────────┐
142
- │ 🤖 TeleBibz ON │
143
- │ bot : @botkamu (id 123456) │
144
- │ mode : long-polling │
145
- │ library : telebibz 3.1.0 │
146
- │ brand : //—Xbibz Official—// │
147
- └──────────────────────────────────┘
143
+ ◆ DEVELOPER Xbibz Technology ID
144
+ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
145
+ ┃ 🤖 TeleBibz ON ┃
146
+ ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
147
+ ┃ bot : @botkamu (id 123456) ┃
148
+ ┃ mode : long-polling ┃
149
+ ┃ library : telebibz 3.1.2 (Node.js) ┃
150
+ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
148
151
  ✔ menunggu update… (Ctrl+C untuk berhenti)
149
152
  ```
150
153
 
@@ -266,6 +269,258 @@ callback, inline…) dengan accessor seragam: `chat`, `from`, `chatId`, `msgId`,
266
269
  Akun business: balasan dalam konteks business otomatis menyertakan
267
270
  `business_connection_id`.
268
271
 
272
+ <a id="rich-messages"></a>
273
+ ### 🧱 Rich Message, emoji bergerak, media & draft (Bot API 10.3)
274
+
275
+ **Rich Message** adalah format Telegram terstruktur: satu pesan dapat memuat rich-text entities, heading, list, kutipan, tabel, peta, tombol, blok media, dan elemen lainnya. TeleBibz menyediakan builder dan shortcut Context; [referensi resmi Telegram Bot API](https://core.telegram.org/bots/api) tetap menjadi sumber otoritatif untuk batasan dan kelayakan fitur.
276
+
277
+ > **Catatan cakupan:** schema memuat **185 nama metode Bot API** dan payload bertipe melalui `api.callApi()`. Ini tidak berarti seluruh 185 endpoint aman atau bermakna untuk dites live: sebagian memerlukan update nyata, hak admin, pembayaran, atau chat tertentu. Matriks live test dan batasannya ada di [`VERIFIKASI-MENDALAM.md`](VERIFIKASI-MENDALAM.md).
278
+
279
+ #### 1. Pilih tepat satu mode konten
280
+
281
+ Satu rich message harus memakai tepat satu sumber konten: `html`, `markdown`, atau `blocks`. Opsi seperti `media`, `is_rtl`, dan `skip_entity_detection` bersifat tambahan, bukan mode konten.
282
+
283
+ ```js
284
+ const { TeleBibz, rich, RichMessageBuilder } = require('@xbibzlibrary/telebibz');
285
+ const bot = new TeleBibz(process.env.BOT_TOKEN);
286
+
287
+ bot.cmd('laporan', async (ctx) => {
288
+ const message = rich.blocks([
289
+ rich.heading('Laporan mingguan', 2),
290
+ rich.paragraph(['Pesanan: ', rich.bold('42'), ' · status ', rich.italic('siap')]),
291
+ rich.table([
292
+ [
293
+ { text: 'Metrik', is_header: true, align: 'left', valign: 'middle' },
294
+ { text: 'Nilai', is_header: true, align: 'right', valign: 'middle' },
295
+ ],
296
+ [
297
+ { text: 'Pendapatan', align: 'left', valign: 'middle' },
298
+ { text: 'Rp1.250.000', align: 'right', valign: 'middle' },
299
+ ],
300
+ ], { bordered: true, striped: true, compact: true, caption: 'Minggu ini' }),
301
+ rich.details('Informasi tambahan', [rich.paragraph('Bagian ini dapat dibuka.')]),
302
+ rich.buttons([
303
+ rich.button('Buka dashboard', { url: 'https://example.com' }, 'primary'),
304
+ rich.button('Konfirmasi', { callback_data: 'report:ack' }, 'success'),
305
+ ], 'center'),
306
+ ]);
307
+ return ctx.replyWithRichMessage(message);
308
+ });
309
+
310
+ bot.launch();
311
+ ```
312
+
313
+ Konstruktor tingkat rendah: `rich.html(html, options)`, `rich.markdown(markdown, options)`, dan `rich.blocks(blocks, options)`. `inputRichMessage(content, options)` memvalidasi pemilihan satu mode. Untuk merakit pesan bertahap, gunakan `RichMessageBuilder`:
314
+
315
+ ```js
316
+ const message = new RichMessageBuilder()
317
+ .blocks([rich.heading('Pengumuman', 2)])
318
+ .add(rich.paragraph('Blok berikutnya bisa ditambahkan.'))
319
+ .rtl(false)
320
+ .skipEntityDetection()
321
+ .build();
322
+ await ctx.replyWithRichMessage(message);
323
+ ```
324
+
325
+ Pada satu builder, pemanggilan `.html()`, `.markdown()`, atau `.blocks()` kedua akan error. Buat builder baru untuk mode lain. `.media()` digunakan bersama konten HTML/Markdown yang menunjuk media melalui tautan `tg://...`.
326
+
327
+ #### 2. Rich-text entities
328
+
329
+ Rich text dapat berupa string biasa, array campuran string dan objek entity, atau objek rich-text bertingkat. Helper yang tersedia:
330
+
331
+ | Helper | Entity | Kegunaan |
332
+ |---|---|---|
333
+ | `rich.bold(text)`, `rich.italic(text)`, `rich.underline(text)`, `rich.strikethrough(text)` | penekanan | format teks inline |
334
+ | `rich.spoiler(text)`, `rich.marked(text)`, `rich.code(text)` | spoiler / marked / code | teks tersembunyi atau teknis |
335
+ | `rich.subscript(text)`, `rich.superscript(text)` | posisi huruf | rumus dan referensi |
336
+ | `rich.dateTime(text, unixTime, format)` | tanggal/waktu | timestamp lokal atau relatif |
337
+ | `rich.url(text, url)`, `rich.email(text, email)`, `rich.phone(text, phone)` | tautan/kontak | tautan atau informasi kontak |
338
+ | `rich.mention(text, username)`, `rich.textMention(text, user)` | mention | username atau objek User |
339
+ | `rich.hashtag(text, value)`, `rich.cashtag(text, value)`, `rich.botCommand(text, value)` | entity Telegram | tag dan command |
340
+ | `rich.customEmoji(customEmojiId, alternativeText)` | custom emoji | custom emoji statis maupun bergerak |
341
+ | `rich.mathText(expression)`, `rich.anchorText(name)`, `rich.anchorLink(text, name)`, `rich.reference(text, name)`, `rich.referenceLink(text, name)` | rumus/navigasi | teks panjang terstruktur |
342
+ | `rich.buttonText(text, action, style)` | tombol di rich-text inline | entity tombol di dalam satu rangkaian teks |
343
+
344
+ Contoh custom emoji bergerak (gunakan **ID custom emoji yang nyata** dan dapat dipakai bot):
345
+
346
+ ```js
347
+ const emojiId = 'CUSTOM_EMOJI_ID';
348
+ const [sticker] = await ctx.api.callApi('getCustomEmojiStickers', {
349
+ custom_emoji_ids: [emojiId],
350
+ });
351
+ if (!sticker) throw new Error('Custom emoji ID tidak ditemukan');
352
+ await ctx.replyWithRichMessage(rich.blocks([
353
+ rich.paragraph(['Status build: ', rich.bold('lulus'), ' ', rich.customEmoji(emojiId, '👍')]),
354
+ ]));
355
+ ```
356
+
357
+ Emoji Unicode biasa tidak otomatis menjadi emoji custom bergerak. ID harus valid dan dapat digunakan bot; Telegram dapat menolak ID atau fitur yang tidak tersedia bagi bot tersebut.
358
+
359
+ #### 3. Katalog blok terstruktur
360
+
361
+ Setiap helper menghasilkan objek `InputRichBlock`. Blok dapat disusun bertingkat sesuai schema Telegram.
362
+
363
+ | Kelompok | Helper | Catatan |
364
+ |---|---|---|
365
+ | Teks | `paragraph(text)`, `heading(text, size)`, `pre(text, language)`, `footer(text)`, `divider()` | ukuran heading 1–6; `pre` dapat menyebut bahasa kode |
366
+ | Rumus/navigasi | `mathBlock(expression)`, `anchor(name)` | pasangan entity inline tersedia untuk isi teks |
367
+ | List/kutipan | `list(items)`, `quote(blocks, credit)`, `expandableQuote(text, credit)`, `pullQuote(text, credit)` | item list bisa string atau item terstruktur; kutipan dapat berisi blok lain |
368
+ | Tabel/disclosure | `table(cells, options)`, `details(summary, blocks, open)` | tiap sel memberi `align` dan `valign`; opsi tabel: `bordered`, `striped`, `compact`, `caption` |
369
+ | Lokasi | `map(location, zoom, width, height, caption, credit)` | `location` berbentuk `{ latitude, longitude }` |
370
+ | Media | `animation(media, caption)`, `audio(media, caption)`, `document(media, caption)`, `photo(media, caption)`, `video(media, caption)`, `voiceNote(media, caption)` | `media` adalah objek `InputMedia*`; upload `File` dikumpulkan menjadi multipart `attach://` |
371
+ | Tata letak | `collage(blocks, caption, credit)`, `slideshow(blocks, caption, credit)` | gabungkan blok media yang didukung menjadi galeri atau urutan |
372
+ | Tombol | `buttons(buttons, align)`, `button(text, action, style)` | 1–8 tombol; `align`: `left`, `center`, atau `right` |
373
+ | Khusus draft | `thinking(text)` | hanya untuk `sendRichMessageDraft`, bukan pesan rich yang disimpan |
374
+
375
+ Setiap sel tabel berbentuk `{ text, align: 'left'|'center'|'right', valign: 'top'|'middle'|'bottom' }`; sel header dapat memakai `is_header: true`. Satu tombol harus memilih tepat satu aksi seperti `url`, `callback_data`, `web_app`, `copy_text`, atau `disabled`. `rich.button()` menghasilkan objek tombol untuk block `buttons`; `rich.buttonText()` menghasilkan bentuk entity RichText yang berbeda. Style `link` hanya berlaku untuk tombol callback.
376
+
377
+ #### 4. Upload media di dalam rich message
378
+
379
+ Gunakan `file_id` Telegram untuk file yang sudah ada di server, atau bungkus bytes/path/stream dengan `File`/`InputFile` agar transport membuat multipart upload:
380
+
381
+ ```js
382
+ const fs = require('node:fs');
383
+ const { File, InputMediaBuilder } = require('@xbibzlibrary/telebibz');
384
+ const image = new File(fs.readFileSync('./hero.png'), 'hero.png');
385
+ const video = new File(fs.readFileSync('./clip.mp4'), 'clip.mp4');
386
+
387
+ await ctx.replyWithRichMessage(rich.blocks([
388
+ rich.paragraph('Contoh blok media:'),
389
+ rich.photo(InputMediaBuilder.photo(image)),
390
+ rich.video(InputMediaBuilder.video(video)),
391
+ ]));
392
+ ```
393
+
394
+ HTML/Markdown dapat merujuk media menggunakan ID unik dan entri `media` yang cocok:
395
+
396
+ ```js
397
+ const photo = new File(fs.readFileSync('./hero.png'), 'hero.png');
398
+ await ctx.replyWithRichMessage(rich.html(
399
+ '<b>Foto utama</b><br><a href="tg://photo?id=hero">Buka foto</a>',
400
+ { media: [{ id: 'hero', media: InputMediaBuilder.photo(photo) }] },
401
+ ));
402
+ ```
403
+
404
+ Live smoke test berhasil mengirim media multipart bertingkat, blok photo/audio/document/video/voice note, collage/slideshow, dan media reference HTML. Pada server Telegram yang diuji, MP4 diterima sebagai rich `animation`, sedangkan GIF pada blok itu menghasilkan `RICH_MESSAGE_VIDEO_INVALID`. Metode standalone `sendAnimation` menerima GIF yang sama. Jika blok rich animation ditolak, coba MP4. Live photo dikirim lewat metode terpisah, bukan tipe `InputRichBlock`.
405
+
406
+ #### 5. Draft dan preview streaming
407
+
408
+ Draft hanya preview sementara, bukan pesan chat yang tersimpan. Kirim pesan final secara terpisah untuk menyimpan jawaban. Blok `thinking` hanya untuk rich draft. Builder draft menolak upload baru melalui `File`; gunakan `file_id` Telegram jika draft perlu media.
409
+
410
+ ```js
411
+ bot.cmd('preview', async (ctx) => {
412
+ const draftId = Date.now(); // tidak nol dan unik untuk draft ini
413
+ await ctx.sendMessageDraft(draftId, 'Sedang menyiapkan jawaban…', { can_stop: true });
414
+ await ctx.sendRichMessageDraft(draftId + 1, rich.draftBlocks([
415
+ rich.paragraph(['Menyiapkan ', rich.bold('laporan Anda'), '…']),
416
+ rich.thinking('Mengumpulkan data'),
417
+ ]), { can_stop: true, keep_on_stop: true });
418
+ // Kirim jawaban final agar tersimpan:
419
+ return ctx.replyWithRichMessage(rich.markdown('**Laporan siap**'));
420
+ });
421
+ ```
422
+
423
+ Konstruktor khusus draft: `rich.draftHtml()`, `rich.draftMarkdown()`, `rich.draftBlocks()`, dan `new RichMessageBuilder()...buildDraft()`. Hasilnya mengikuti schema `sendRichMessageDraft` yang tidak menerima upload `File` baru. `sendMessageDraft` dan `sendRichMessageDraft` juga bisa dipanggil dengan payload object tepat melalui `ctx.api.callApi()`.
424
+
425
+ #### 6. Live photo, paid media, ephemeral, dan edit
426
+
427
+ **Live photo** mengirim pasangan video dan foto statis yang terkait. Keduanya bisa berupa `file_id` atau `File`/`InputFile`; URL tidak didukung oleh schema metode saat ini.
428
+
429
+ ```js
430
+ await ctx.replyWithLivePhoto('VIDEO_FILE_ID', 'PHOTO_FILE_ID', { caption: 'Sebuah momen' });
431
+ // Atau API mentah bertipe:
432
+ await ctx.api.sendLivePhoto({ chat_id: ctx.chatId, live_photo: videoFile, photo: photoFile });
433
+ ```
434
+
435
+ `InputMediaBuilder.livePhoto(video, photo)` dan `InputPaidMediaBuilder.livePhoto(video, photo)` membangun objek media. `sendPaidMedia` membutuhkan `star_count` antara 1 dan 25.000:
436
+
437
+ ```js
438
+ const fs = require('node:fs');
439
+ const { File, InputPaidMediaBuilder } = require('@xbibzlibrary/telebibz');
440
+ const paidPhoto = new File(fs.readFileSync('./paid.png'), 'paid.png');
441
+ await ctx.api.callApi('sendPaidMedia', {
442
+ chat_id: ctx.chatId,
443
+ star_count: 1,
444
+ media: [InputPaidMediaBuilder.photo(paidPhoto)],
445
+ caption: 'Contoh foto berbayar',
446
+ });
447
+ ```
448
+
449
+ Fitur ini membuat paywall/pembayaran sungguhan: jangan dites ke pengguna tanpa persetujuan dan periksa penggunaan Telegram Stars sebelum memublikasikan konten berbayar.
450
+
451
+ **Pesan ephemeral** ditujukan ke penerima melalui `ephemeral_message_parameters`; kelayakannya bergantung pada aturan dan izin Telegram untuk bot/chat terkait. Helper Context meliputi `replyEphemeral(text, receiverUserId)`, `editEphemeralMessageText`, `editEphemeralRichMessage`, `editEphemeralMessageMedia`, `editEphemeralMessageCaption`, `editEphemeralMessageReplyMarkup`, dan `deleteEphemeralMessage`.
452
+
453
+ ```js
454
+ await ctx.replyEphemeral('Pemberitahuan sementara', ctx.from.id);
455
+ const sent = await ctx.api.callApi('sendRichMessage', {
456
+ chat_id: ctx.chatId,
457
+ rich_message: rich.blocks([rich.paragraph('Preview rich privat')]),
458
+ ephemeral_message_parameters: { receiver_user_id: ctx.from.id },
459
+ });
460
+ // Jika Telegram mengembalikan ephemeral_message_id, ID tersebut dapat dipakai untuk edit/hapus.
461
+ if (sent.ephemeral_message_id) {
462
+ await ctx.editEphemeralRichMessage(ctx.from.id, sent.ephemeral_message_id,
463
+ rich.blocks([rich.paragraph('Pemberitahuan sementara diperbarui')]));
464
+ }
465
+ ```
466
+
467
+ Telegram bisa menolak dengan `BOT_NOT_ADMIN` atau error izin lain; baca `ApiError` yang diterima dan jangan menganggap payload lolos test lokal berarti bot pasti berhak mengirimnya.
468
+
469
+ Untuk mengedit rich message biasa, gunakan `ctx.editRichMessage(content, extra)`. API di bawahnya adalah `editMessageText` dengan `rich_message` dan target `chat_id`/`message_id` (atau `inline_message_id`). Operasi edit mengubah pesan yang ada; gunakan pesan khusus test.
470
+
471
+ #### 7. Shortcut Context dan metode Bot API modern
472
+
473
+ | Helper | Fungsi / argumen |
474
+ |---|---|
475
+ | `ctx.replyWithRichMessage(content, extra?)` | kirim rich message tersimpan ke chat saat ini |
476
+ | `ctx.editRichMessage(content, extra?)` | edit rich message saat ini; mendukung callback dan inline target |
477
+ | `ctx.replyWithLivePhoto(video, photo, extra?)` | kirim live photo ke chat saat ini |
478
+ | `ctx.sendMessageDraft(draftId, text, extra?)` | preview teks sementara |
479
+ | `ctx.sendRichMessageDraft(draftId, richMessage, extra?)` | preview rich sementara |
480
+ | `ctx.replyEphemeral(text, receiverUserId, extra?)` | kirim teks ephemeral ke penerima tertentu |
481
+ | `ctx.guestQueryId`, `ctx.answerGuestQuery(result)` | proses update `guest_message` yang nyata |
482
+ | `ctx.editEphemeralRichMessage(...)`, `ctx.deleteEphemeralMessage(...)` | edit/hapus pesan ephemeral milik penerima |
483
+
484
+ Jawaban guest query membutuhkan `guest_query_id` dari update masuk yang asli; ID buatan tidak dapat dipakai untuk tes live yang bermakna. Artikel inline rich dapat dibuat dengan `iq.richArticle(id, title, richMessage, extra)` lalu dikembalikan saat menangani inline query sungguhan.
485
+
486
+ #### 8. Akses penuh Bot API dengan tipe
487
+
488
+ Semua **185 nama metode dan signature payload** pada schema Bot API vendored tersedia lewat `api.callApi()` dan `api.raw()` di TypeScript:
489
+
490
+ ```js
491
+ // JavaScript maupun TypeScript: nama metode + object payload
492
+ await ctx.api.callApi('sendRichMessage', {
493
+ chat_id: ctx.chatId,
494
+ rich_message: rich.markdown('**Halo**'),
495
+ });
496
+
497
+ await ctx.api.callApi('sendMessageDraft', {
498
+ chat_id: ctx.chatId,
499
+ draft_id: Date.now(),
500
+ text: 'Preview',
501
+ can_stop: false,
502
+ });
503
+ ```
504
+
505
+ Namespace `TelegramTypes` mengekspor tipe object Telegram. Alias yang berguna: `TelegramMethodName`, `TelegramMethodPayload<M>`, `TelegramMethodResult<M>`, `TelegramApiMethods`, dan `TelegramApiPayloads`. Proxy runtime juga menerima `ctx.api.metodeApaPun({ ...payload })` untuk metode baru, tetapi shorthand dinamis ini tidak memvalidasi schema saat runtime. Pengecekan TypeScript terjadi ketika compile saja. Jalankan `npm run typecheck` untuk memeriksa deklarasi dan contoh consumer.
506
+
507
+ Deklarasi ini vendored dari `@grammyjs/types@5.0.0` berlisensi MIT (lihat [`NOTICE.md`](NOTICE.md) dan lisensi di folder types); tidak ada dependency runtime baru. Referensi/changelog Telegram resmi—bukan package vendored—tetap otoritas saat ada perbedaan field, izin, atau batasan.
508
+
509
+ #### Batas payload dan pemecahan masalah
510
+
511
+ Schema tipe Bot API 10.3 mencatat batas Rich Message berikut: **32.768 karakter UTF-8**, **500 block** (termasuk konten nested/list/tabel/kutipan/details), **16 level nesting**, **50 attachment media**, dan **20 kolom tabel**. Block map memakai zoom 0–24 dan lebar/tinggi 0–10.000; block tombol berisi 1–8 tombol. Batas Telegram dapat berubah, jadi cek [referensi resmi](https://core.telegram.org/bots/api) sebelum membuat payload besar. Server Telegram tetap validator terakhir.
512
+
513
+ Error yang umum:
514
+
515
+ - `RICH_MESSAGE_VIDEO_INVALID`: server yang diuji menolak GIF pada block Rich Message `animation`; coba MP4. Endpoint standalone `sendAnimation` menerima GIF tersebut.
516
+ - `BOT_NOT_ADMIN` pada pesan ephemeral: respons ini terkait izin/kelayakan Telegram, bukan bukti bahwa bentuk JSON salah. Periksa akses bot/chat dan syarat metode resmi.
517
+ - `chat not found`: pada private chat, penerima biasanya perlu membuka bot dan menekan **Start** sebelum bot dapat mengirim pesan.
518
+ - Error upload: bungkus bytes/path/stream dengan `File`/`InputFile` dan pastikan tipe helper cocok dengan file.
519
+
520
+ #### Hasil live test dan batasan
521
+
522
+ Pada 2026-09-28, smoke test live dengan bot yang diberikan pengguna berhasil untuk rich blocks, HTML, Markdown, custom emoji bergerak, draft teks/rich, multipart media, blok photo/audio/document/video/voice-note, collage/slideshow, live photo, GIF melalui `sendAnimation`, dan HTML media reference. Ephemeral `sendMessage`/`sendRichMessage` ditolak Telegram dengan `BOT_NOT_ADMIN`; paid media tidak dikirim karena dapat melibatkan Stars; callback tidak diklik; seluruh 185 endpoint tidak dijalankan live. Rincian hasil dan batas cakupan ada di [`VERIFIKASI-MENDALAM.md`](VERIFIKASI-MENDALAM.md).
523
+
269
524
  <a id="keyboard"></a>
270
525
  ### 🔘 Keyboard & tombol
271
526
 
@@ -512,12 +767,12 @@ await bot.api.sendDiceCustom({ chat_id: 1, emoji: '🎲' });
512
767
 
513
768
  | Metrik | Nilai |
514
769
  |---|---|
515
- | 📦 Modul sumber | **16 file** di `lib/` |
516
- | 📝 Total baris kode | **±1.700** (tanpa build step) |
517
- | 🔌 Metode Bot API | **90+** — 75 shortcut bertipe + Proxy tanpa batas |
770
+ | 📦 Modul sumber | **18 file** di `lib/` |
771
+ | 📝 Total baris kode | **2.105** di `lib/` (tanpa build step) |
772
+ | 🔌 Metode Bot API | **185 signature bertipe** lewat `api.callApi()` + dynamic Proxy |
518
773
  | ⌨️ Shortcut Context | **50+** (reply/edit/delete/admin/react…) |
519
- | 🧪 Test offline | **30/30 lulus**, tanpa jaringan |
520
- | 🧩 Contoh siap jalan | **7** di `examples/` |
774
+ | 🧪 Test offline | **48/48 lulus**, termasuk transport HTTP lokal dan fitur Bot API 10.3 |
775
+ | 🧩 Contoh siap jalan | **8** di `examples/` |
521
776
  | 📦 Dependency runtime | **4** — semuanya terpakai & ter-test |
522
777
 
523
778
  ### ⬇️ Download & popularitas (live dari npm)
@@ -529,23 +784,27 @@ await bot.api.sendDiceCustom({ chat_id: 1, emoji: '🎲' });
529
784
 
530
785
  ### 📏 Peta ukuran modul (baris kode)
531
786
 
532
- ```
533
- wizard.js █████████████████████████ 247 ← form + tombol + edit/delete
534
- telebibz.js ███████████████████▎ 193 ← kelas utama & siklus hidup
535
- context.js ███████████████████ 190 ← ctx + 50-an shortcut
536
- composer.js █████████████████▍ 174 ← mesin middleware & filter
537
- api.js ███████████████▍ 154 ← 75 shortcut + Proxy + transformer
538
- net.js ███████████▌ 115 ← transport axios + multipart
539
- menus.js █████████ 90 ← Menu/MenuContainer
540
- keyboard.js ████████▎ 83 ← btn/url/kb + kelas fluent
541
- ratelimit.js ██████ 61 ← autoRetry · throttler · limiter
542
- runner.js ████▌ 45 ← polling tahan-409
543
- file.js ████ 41 ← InputFile + InputMediaBuilder
544
- logger.js ███▊ 38 ← log + banner
545
- session.js ███▌ 36 ← session swappable
546
- errors.js ███▌ 35 ← humanize error 🇮
547
- broadcast.js ███▌ 35 ← blast aman rate-limit
548
- inline-query.js██▊ 28 ← matcher + builder hasil
787
+ Angka berikut dihitung dari source terkini `lib/*.js`; ini informasi source, bukan ukuran bundle.
788
+
789
+ ```text
790
+ context.js 250 accessor Context, reply, edit dan helper
791
+ wizard.js 247 form terpandu, tombol, mode edit/delete
792
+ telebibz.js 209 kelas bot, lifecycle dan dispatch update
793
+ telegram-methods.js 192 registry runtime 185 nama metode Bot API
794
+ composer.js 185 komposisi middleware dan filter
795
+ rich.js 175 builder Rich Message, entity dan block
796
+ api.js 168 adapter API, Proxy dan transformer
797
+ net.js 115 transport HTTP dan multipart upload
798
+ menus.js 90 Menu dan MenuContainer
799
+ keyboard.js 83 builder keyboard dan fluent class
800
+ ratelimit.js 74 retry, throttler dan limiter
801
+ logger.js 68 log dan banner boot
802
+ runner.js 54 polling dan retry
803
+ file.js 48 File/InputFile dan media builder
804
+ session.js 44 session storage swappable
805
+ errors.js 35 terjemahan error
806
+ broadcast.js 35 helper broadcast
807
+ inline-query.js 33 pencocokan inline dan builder hasil
549
808
  ```
550
809
 
551
810
  ### 🗺️ Kesehatan repo
@@ -575,6 +834,7 @@ inline-query.js██▊ 28 ← matcher + builder hasil
575
834
  | `05-kirim-file.js` | foto & dokumen dari buffer |
576
835
  | `06-menu.js` | menu interaktif + submenu |
577
836
  | `07-inline-query.js` | mode inline dengan builder hasil |
837
+ | `08-rich-message.js` | rich messages, live photo, draft, ephemeral, dan raw method API |
578
838
 
579
839
  Jalankan dengan `BOT_TOKEN=123:abc node examples/01-quickstart.js`.
580
840
 
@@ -582,23 +842,23 @@ Jalankan dengan `BOT_TOKEN=123:abc node examples/01-quickstart.js`.
582
842
  ## 🔬 Test & Bukti Live
583
843
 
584
844
  ```bash
585
- npm test # 30 kasus, TANPA jaringan (transport disuntik)
845
+ npm test # 48 test offline (mock + HTTP server lokal), tanpa token Telegram
846
+ npm run typecheck # cek declaration TypeScript + payload method-specific
586
847
  ```
587
848
 
588
- Tervalidasi **30/30 offline + 10 live** pada bot produksi `@xbibzrat_bot`:
589
- getMe · keyboard berwarna & ikon animasi asli · upload multipart
590
- (photo+document) · edit keyboard · broadcast · deleteMessage · polling 409
591
- retry · wizard tombol & edit/delete.
849
+ 48 test otomatis dan `npm run typecheck` berjalan offline dengan mock tanpa token bot. Secara terpisah dilakukan live smoke test pada bot uji milik pengguna: rich blocks, HTML/Markdown, custom emoji bergerak, draft, blok media, collage/slideshow, live photo, dan referensi media multipart berhasil. Pengiriman ephemeral ditolak Telegram dengan `BOT_NOT_ADMIN`; paid media dan semua 185 endpoint tidak diuji live. Lihat [`VERIFIKASI-MENDALAM.md`](VERIFIKASI-MENDALAM.md) untuk matriks lengkap, batasan, serta hasil yang gagal.
592
850
 
593
851
  Log debug: `DEBUG=telebibz:net,telebibz:ratelimit node botkamu.js`.
594
852
 
595
853
  <a id="struktur"></a>
596
- ## 📂 Struktur Repo (16 file inti)
854
+ ## 📂 Struktur Repo (18 modul JavaScript + tipe API vendored)
597
855
 
598
856
  | File | Peran |
599
857
  |---|---|
600
858
  | `lib/net.js` | transport axios keep-alive + multipart `attach://` |
601
859
  | `lib/api.js` | metode Bot API + Proxy segala metode + transformer |
860
+ | `lib/rich.js` | entity Rich Message, builder block, helper draft-safe |
861
+ | `lib/telegram-methods.js` | registry 185 nama metode Bot API |
602
862
  | `lib/composer.js` | middleware, filter `on('message:photo')`, `errorBoundary` |
603
863
  | `lib/context.js` | objek ctx + 50-an pintasan reply/edit/delete/callback |
604
864
  | `lib/session.js` | sesi per user:chat (storage swappable) |
@@ -612,11 +872,13 @@ Log debug: `DEBUG=telebibz:net,telebibz:ratelimit node botkamu.js`.
612
872
  | `lib/inline-query.js` | matcher query + builder hasil inline |
613
873
  | `lib/errors.js` | humanisasi error + saran |
614
874
  | `lib/logger.js` | log berbingkai + banner boot |
615
- | `index.js` / `index.d.ts` | pintu ekspor + tipe TypeScript |
875
+ | `types/telegram-bot-api/` | tipe Bot API vendored (MIT), tanpa kode runtime |
876
+ | `index.js` / `index.d.ts` | ekspor dan surface method/payload bertipe |
616
877
 
617
878
  <a id="changelog"></a>
618
879
  ## 🕐 Changelog
619
880
 
881
+ - **Unreleased — Bot API 10.3** — rich message, emoji bergerak, draft, live photo, payload bertipe untuk 185 metode; 48 test offline dan live verification lebih luas. Detail: [`CHANGELOG.md`](CHANGELOG.md).
620
882
  - **3.1.0** — wizard: tombol pilihan (reply/inline), mode `edit`/`delete`, cleanup otomatis, helper programatis · test 24 → 30
621
883
  - **3.0.0** — parity grammY production-grade: axios keep-alive, transformer, menu, inline query, limiter
622
884
  - **2.0.0** — engine ditulis ulang dari nol, transport multipart, webhook Node murni
@@ -624,16 +886,23 @@ Log debug: `DEBUG=telebibz:net,telebibz:ratelimit node botkamu.js`.
624
886
 
625
887
  > Detail lengkap di [`CHANGELOG.md`](CHANGELOG.md). Studi arsitektur mendalam: [`ANALISIS-telebibz.md`](ANALISIS-telebibz.md).
626
888
 
889
+ <a id="publishing"></a>
890
+ ## 📦 Publikasi npm otomatis
891
+
892
+ Workflow `.github/workflows/auto-publish.yml` menerbitkan saat ada push ke `main` (kecuali commit rilis yang memuat `[skip release]`) atau manual dari branch `main` lewat **Actions → Auto publish to npm → Run workflow** (workflow menolak dispatch dari branch lain). Sebelum mengaktifkannya, buat GitHub Actions Environment bernama `npm-release`, lalu tambahkan secret **`NPM_TOKEN`** yang berizin menerbitkan `@xbibzlibrary/telebibz`. Token tidak disimpan di repo.
893
+
894
+ Workflow memilih patch berikutnya berdasarkan versi yang lebih tinggi antara repo dan versi terbaru npm; lalu menjalankan test runtime, typecheck TypeScript, pemeriksaan sintaks JS, simulasi paket, dan audit dependency produksi. Workflow mem-publish sebagai paket publik, commit bump `package.json`/lockfile, membuat tag anotasi `vX.Y.Z`, dan GitHub Release. Validasi yang gagal menghentikan workflow sebelum publish. Konfigurasi ditinjau secara lokal; verifikasi Actions nyata dan publish memerlukan akses repo dan secret tersebut.
895
+
627
896
  <a id="lisensi"></a>
628
897
  ## 📄 Lisensi
629
898
 
630
- **MIT** © Xbibz Official — arsitektur terinspirasi [grammY](https://grammy.dev) (MIT, lihat [`NOTICE.md`](NOTICE.md)).
899
+ **MIT** © Xbibz Technology ID — arsitektur terinspirasi [grammY](https://grammy.dev) (MIT, lihat [`NOTICE.md`](NOTICE.md)).
631
900
 
632
901
  ---
633
902
 
634
903
  <div align="center">
635
904
 
636
- **Dibuat dengan ❤️ oleh //—Xbibz Official—//**
905
+ **Dibuat dengan ❤️ oleh Xbibz Technology ID**
637
906
 
638
907
  Kalau telebibz membantumu, bintang ⭐ repo ini sangat berarti.
639
908