@xbibzlibrary/telebibz 0.4.4 → 3.0.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/CHANGELOG.md +35 -138
- package/LICENSE +1 -1
- package/NOTICE.md +9 -4
- package/README.md +173 -242
- package/examples/01-quickstart.js +13 -0
- package/examples/02-menu-tombol.js +22 -0
- package/examples/03-wizard.js +29 -0
- package/examples/04-broadcast.js +25 -0
- package/examples/05-kirim-file.js +19 -0
- package/examples/06-menu.js +35 -0
- package/examples/07-inline-query.js +18 -0
- package/index.d.ts +81 -0
- package/index.js +42 -0
- package/lib/api.js +154 -0
- package/lib/broadcast.js +35 -0
- package/lib/composer.js +174 -0
- package/lib/context.js +190 -0
- package/lib/errors.js +35 -0
- package/lib/file.js +41 -0
- package/lib/inline-query.js +28 -0
- package/lib/keyboard.js +83 -0
- package/lib/logger.js +38 -0
- package/lib/menus.js +90 -0
- package/lib/net.js +115 -0
- package/lib/ratelimit.js +61 -0
- package/lib/runner.js +45 -0
- package/lib/session.js +36 -0
- package/lib/telebibz.js +190 -0
- package/lib/wizard.js +81 -0
- package/package.json +35 -97
- package/test/all.test.js +334 -0
- package/CODE_OF_CONDUCT.md +0 -37
- package/CONTRIBUTING.md +0 -59
- package/CONTRIBUTION_RULES.md +0 -41
- package/GOVERNANCE.md +0 -47
- package/README.id.md +0 -292
- package/README.zh-CN.md +0 -292
- package/RELEASE_AUTOMATION.md +0 -78
- package/RELEASE_POLICY.md +0 -32
- package/SECURITY.md +0 -47
- package/SHOWCASE.md +0 -29
- package/SUPPORT.md +0 -30
- package/assets/readme-preview.html +0 -75
- package/assets/telebibz-logo.png +0 -0
- package/assets/telebibz-readme-preview.png +0 -0
- package/bin/telebibz.mjs +0 -3
- package/dist/generated/api.d.ts +0 -13
- package/dist/generated/api.d.ts.map +0 -1
- package/dist/generated/api.js +0 -192
- package/dist/generated/api.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -62
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -104
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/api/errors.d.ts +0 -45
- package/dist/src/api/errors.d.ts.map +0 -1
- package/dist/src/api/errors.js +0 -65
- package/dist/src/api/errors.js.map +0 -1
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js +0 -6
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/telegram-types/LICENSE +0 -21
- package/dist/src/api/telegram-types/api.d.ts +0 -22
- package/dist/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist/src/api/telegram-types/inline.d.ts +0 -692
- package/dist/src/api/telegram-types/langs.d.ts +0 -193
- package/dist/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist/src/api/telegram-types/markup.d.ts +0 -268
- package/dist/src/api/telegram-types/message.d.ts +0 -1537
- package/dist/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist/src/api/telegram-types/mod.d.ts +0 -14
- package/dist/src/api/telegram-types/passport.d.ts +0 -163
- package/dist/src/api/telegram-types/payment.d.ts +0 -570
- package/dist/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist/src/api/telegram-types/settings.d.ts +0 -120
- package/dist/src/api/telegram-types/story.d.ts +0 -89
- package/dist/src/api/telegram-types/update.d.ts +0 -84
- package/dist/src/api/telegram.d.ts +0 -7
- package/dist/src/api/telegram.d.ts.map +0 -1
- package/dist/src/api/telegram.js +0 -2
- package/dist/src/api/telegram.js.map +0 -1
- package/dist/src/api/transport.d.ts +0 -68
- package/dist/src/api/transport.d.ts.map +0 -1
- package/dist/src/api/transport.js +0 -264
- package/dist/src/api/transport.js.map +0 -1
- package/dist/src/api/types.d.ts +0 -466
- package/dist/src/api/types.d.ts.map +0 -1
- package/dist/src/api/types.js +0 -2
- package/dist/src/api/types.js.map +0 -1
- package/dist/src/branding/terminal.d.ts +0 -77
- package/dist/src/branding/terminal.d.ts.map +0 -1
- package/dist/src/branding/terminal.js +0 -328
- package/dist/src/branding/terminal.js.map +0 -1
- package/dist/src/broadcast/broadcast.d.ts +0 -50
- package/dist/src/broadcast/broadcast.d.ts.map +0 -1
- package/dist/src/broadcast/broadcast.js +0 -56
- package/dist/src/broadcast/broadcast.js.map +0 -1
- package/dist/src/cache/cache.d.ts +0 -34
- package/dist/src/cache/cache.d.ts.map +0 -1
- package/dist/src/cache/cache.js +0 -41
- package/dist/src/cache/cache.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -84
- package/dist/src/cli.js.map +0 -1
- package/dist/src/context/context.d.ts +0 -124
- package/dist/src/context/context.d.ts.map +0 -1
- package/dist/src/context/context.js +0 -302
- package/dist/src/context/context.js.map +0 -1
- package/dist/src/core/bot.d.ts +0 -204
- package/dist/src/core/bot.d.ts.map +0 -1
- package/dist/src/core/bot.js +0 -506
- package/dist/src/core/bot.js.map +0 -1
- package/dist/src/core/events.d.ts +0 -75
- package/dist/src/core/events.d.ts.map +0 -1
- package/dist/src/core/events.js +0 -35
- package/dist/src/core/events.js.map +0 -1
- package/dist/src/core/webhook-reply.d.ts +0 -34
- package/dist/src/core/webhook-reply.d.ts.map +0 -1
- package/dist/src/core/webhook-reply.js +0 -37
- package/dist/src/core/webhook-reply.js.map +0 -1
- package/dist/src/index.d.ts +0 -24
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/keyboard/index.d.ts +0 -46
- package/dist/src/keyboard/index.d.ts.map +0 -1
- package/dist/src/keyboard/index.js +0 -55
- package/dist/src/keyboard/index.js.map +0 -1
- package/dist/src/middleware/compose.d.ts +0 -5
- package/dist/src/middleware/compose.d.ts.map +0 -1
- package/dist/src/middleware/compose.js +0 -17
- package/dist/src/middleware/compose.js.map +0 -1
- package/dist/src/observability/logger.d.ts +0 -78
- package/dist/src/observability/logger.d.ts.map +0 -1
- package/dist/src/observability/logger.js +0 -285
- package/dist/src/observability/logger.js.map +0 -1
- package/dist/src/plugins/plugin.d.ts +0 -38
- package/dist/src/plugins/plugin.d.ts.map +0 -1
- package/dist/src/plugins/plugin.js +0 -59
- package/dist/src/plugins/plugin.js.map +0 -1
- package/dist/src/queue/queue.d.ts +0 -77
- package/dist/src/queue/queue.d.ts.map +0 -1
- package/dist/src/queue/queue.js +0 -213
- package/dist/src/queue/queue.js.map +0 -1
- package/dist/src/router/router.d.ts +0 -61
- package/dist/src/router/router.d.ts.map +0 -1
- package/dist/src/router/router.js +0 -183
- package/dist/src/router/router.js.map +0 -1
- package/dist/src/state/conversation.d.ts +0 -56
- package/dist/src/state/conversation.d.ts.map +0 -1
- package/dist/src/state/conversation.js +0 -133
- package/dist/src/state/conversation.js.map +0 -1
- package/dist/src/state/forms.d.ts +0 -34
- package/dist/src/state/forms.d.ts.map +0 -1
- package/dist/src/state/forms.js +0 -44
- package/dist/src/state/forms.js.map +0 -1
- package/dist/src/state/menu.d.ts +0 -78
- package/dist/src/state/menu.d.ts.map +0 -1
- package/dist/src/state/menu.js +0 -127
- package/dist/src/state/menu.js.map +0 -1
- package/dist/src/storage/storage.d.ts +0 -146
- package/dist/src/storage/storage.d.ts.map +0 -1
- package/dist/src/storage/storage.js +0 -195
- package/dist/src/storage/storage.js.map +0 -1
- package/dist/src/telegram-features.d.ts +0 -33
- package/dist/src/telegram-features.d.ts.map +0 -1
- package/dist/src/telegram-features.js +0 -71
- package/dist/src/telegram-features.js.map +0 -1
- package/dist/src/testing.d.ts +0 -24
- package/dist/src/testing.d.ts.map +0 -1
- package/dist/src/testing.js +0 -38
- package/dist/src/testing.js.map +0 -1
- package/dist/src/utils/concurrency.d.ts +0 -25
- package/dist/src/utils/concurrency.d.ts.map +0 -1
- package/dist/src/utils/concurrency.js +0 -52
- package/dist/src/utils/concurrency.js.map +0 -1
- package/dist/src/utils/files.d.ts +0 -45
- package/dist/src/utils/files.d.ts.map +0 -1
- package/dist/src/utils/files.js +0 -53
- package/dist/src/utils/files.js.map +0 -1
- package/dist/src/utils/text.d.ts +0 -39
- package/dist/src/utils/text.d.ts.map +0 -1
- package/dist/src/utils/text.js +0 -56
- package/dist/src/utils/text.js.map +0 -1
- package/dist/src/webhook/handler.d.ts +0 -19
- package/dist/src/webhook/handler.d.ts.map +0 -1
- package/dist/src/webhook/handler.js +0 -141
- package/dist/src/webhook/handler.js.map +0 -1
- package/dist-cjs/generated/api.js +0 -194
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/src/api/client.js +0 -107
- package/dist-cjs/src/api/errors.js +0 -74
- package/dist-cjs/src/api/index.js +0 -21
- package/dist-cjs/src/api/telegram-types/LICENSE +0 -21
- package/dist-cjs/src/api/telegram-types/api.d.ts +0 -22
- package/dist-cjs/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist-cjs/src/api/telegram-types/inline.d.ts +0 -692
- package/dist-cjs/src/api/telegram-types/langs.d.ts +0 -193
- package/dist-cjs/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist-cjs/src/api/telegram-types/markup.d.ts +0 -268
- package/dist-cjs/src/api/telegram-types/message.d.ts +0 -1537
- package/dist-cjs/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist-cjs/src/api/telegram-types/mod.d.ts +0 -14
- package/dist-cjs/src/api/telegram-types/passport.d.ts +0 -163
- package/dist-cjs/src/api/telegram-types/payment.d.ts +0 -570
- package/dist-cjs/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist-cjs/src/api/telegram-types/settings.d.ts +0 -120
- package/dist-cjs/src/api/telegram-types/story.d.ts +0 -89
- package/dist-cjs/src/api/telegram-types/update.d.ts +0 -84
- package/dist-cjs/src/api/telegram.js +0 -2
- package/dist-cjs/src/api/transport.js +0 -267
- package/dist-cjs/src/api/types.js +0 -2
- package/dist-cjs/src/branding/terminal.js +0 -338
- package/dist-cjs/src/broadcast/broadcast.js +0 -58
- package/dist-cjs/src/cache/cache.js +0 -45
- package/dist-cjs/src/cli.js +0 -86
- package/dist-cjs/src/context/context.js +0 -305
- package/dist-cjs/src/core/bot.js +0 -510
- package/dist-cjs/src/core/events.js +0 -38
- package/dist-cjs/src/core/webhook-reply.js +0 -42
- package/dist-cjs/src/index.js +0 -47
- package/dist-cjs/src/keyboard/index.js +0 -61
- package/dist-cjs/src/middleware/compose.js +0 -20
- package/dist-cjs/src/observability/logger.js +0 -293
- package/dist-cjs/src/plugins/plugin.js +0 -63
- package/dist-cjs/src/queue/queue.js +0 -219
- package/dist-cjs/src/router/router.js +0 -186
- package/dist-cjs/src/state/conversation.js +0 -139
- package/dist-cjs/src/state/forms.js +0 -47
- package/dist-cjs/src/state/menu.js +0 -133
- package/dist-cjs/src/storage/storage.js +0 -202
- package/dist-cjs/src/telegram-features.js +0 -76
- package/dist-cjs/src/testing.js +0 -45
- package/dist-cjs/src/utils/concurrency.js +0 -57
- package/dist-cjs/src/utils/files.js +0 -58
- package/dist-cjs/src/utils/text.js +0 -63
- package/dist-cjs/src/webhook/handler.js +0 -144
- package/docs/API.id.md +0 -1935
- package/docs/API.md +0 -1969
- package/docs/API.zh-CN.md +0 -1929
- package/docs/GETTING_STARTED.id.md +0 -85
- package/docs/GETTING_STARTED.md +0 -85
- package/docs/GETTING_STARTED.zh-CN.md +0 -85
- package/docs/GITHUB_PACKAGES.id.md +0 -82
- package/docs/GITHUB_PACKAGES.md +0 -82
- package/docs/GITHUB_PACKAGES.zh-CN.md +0 -82
- package/docs/README.md +0 -48
- package/docs/STORAGE.id.md +0 -105
- package/docs/STORAGE.md +0 -105
- package/docs/STORAGE.zh-CN.md +0 -105
- package/examples/README.md +0 -37
- package/examples/files.ts +0 -35
- package/examples/minimal.ts +0 -12
- package/examples/tsconfig.json +0 -9
- package/examples/webhook.ts +0 -42
- package/examples/wizard-registration.ts +0 -42
package/README.md
CHANGED
|
@@ -1,301 +1,232 @@
|
|
|
1
|
-
# telebibz
|
|
1
|
+
# 🤖 telebibz
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Library Telegram paling gampang untuk Node.js, set fitur penuh setara grammY** — recode mandiri atas arsitektur elegan [grammY](https://grammy.dev) (MIT — lihat [NOTICE.md](NOTICE.md)) dengan dependency produksi yang **benar-benar dipakai** (axios keep-alive, mime-types, https-proxy-agent, debug).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
|
|
7
|
-
[](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
|
|
8
|
-
[](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
|
|
9
|
-
|
|
10
|
-
**`@xbibzlibrary/telebibz`** is a Telegram Bot SDK and framework for Node.js and TypeScript. It provides a typed API client, polling, routing, middleware, context helpers, keyboard builders, state/session primitives, webhooks, queues, scheduling, caching, plugin lifecycle, colorful terminal logging, CLI tooling, and testing utilities.
|
|
11
|
-
|
|
12
|
-
## Documentation languages
|
|
13
|
-
|
|
14
|
-
**English (default)** · [Bahasa Indonesia](README.id.md) · [简体中文](README.zh-CN.md)
|
|
15
|
-
|
|
16
|
-
Complete API references: [English](docs/API.md) · [Indonesia](docs/API.id.md) · [中文](docs/API.zh-CN.md)
|
|
17
|
-
|
|
18
|
-
GitHub Packages guide: [English](docs/GITHUB_PACKAGES.md) · [Bahasa Indonesia](docs/GITHUB_PACKAGES.id.md) · [简体中文](docs/GITHUB_PACKAGES.zh-CN.md)
|
|
19
|
-
|
|
20
|
-
Storage quick start (Memory/JSON/Redis/SQL/Mongo): [English](docs/STORAGE.md) · [Bahasa Indonesia](docs/STORAGE.id.md) · [简体中文](docs/STORAGE.zh-CN.md)
|
|
21
|
-
|
|
22
|
-
Getting started: [English](docs/GETTING_STARTED.md) · [Bahasa Indonesia](docs/GETTING_STARTED.id.md) · [简体中文](docs/GETTING_STARTED.zh-CN.md)
|
|
23
|
-
|
|
24
|
-
Community showcase: [SHOWCASE.md](SHOWCASE.md)
|
|
25
|
-
|
|
26
|
-

|
|
27
|
-
|
|
28
|
-
## Installation
|
|
29
|
-
|
|
30
|
-
```bash
|
|
5
|
+
```
|
|
31
6
|
npm install @xbibzlibrary/telebibz
|
|
32
7
|
```
|
|
33
8
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
## 📊 FEATURE MATRIX (parity grammY)
|
|
10
|
+
|
|
11
|
+
| Fitur | grammY | telebibz |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| Proxy API **segala metode** (auto-generated) | ✅ `api.xyz()` | ✅ `api.xyz({...})` |
|
|
14
|
+
| ~60 shortcut bertipe (sendMessage, banChatMember…) | ✅ | ✅ |
|
|
15
|
+
| Context lengkap (~70 pintasan reply/edit/admin/react) | ✅ | ✅ |
|
|
16
|
+
| Context flavor business (`business_connection_id` otomatis) | plugin | ✅ bawaan |
|
|
17
|
+
| Filter `on('message:photo' / ':text' / 'chat_type:private' …)` | ✅ | ✅ |
|
|
18
|
+
| `cmd / hears / action / inlineQuery` | ✅ | ✅ (+ inlineQuery matcher) |
|
|
19
|
+
| `branch / filter / drop / route / lazy / fork` | ✅ | ✅ |
|
|
20
|
+
| Error boundary + catch | ✅ | ✅ (semua shortcut otomatis terlindungi) |
|
|
21
|
+
| Session + storage swappable | ✅ | ✅ |
|
|
22
|
+
| Transformer API (`api.config.use`) | ✅ | ✅ |
|
|
23
|
+
| `auto-retry` 429 hormati `retry_after` | plugin (@grammyjs/auto-retry) | ✅ bawaan `autoRetry()` |
|
|
24
|
+
| Throttler antre-rate-limit | plugin | ✅ bawaan `throttler()` |
|
|
25
|
+
| Rate limit per-user | plugin | ✅ bawaan `limiter()` |
|
|
26
|
+
| `InputFile` Buffer/path/stream + multipart attach:// | ✅ | ✅ |
|
|
27
|
+
| `InputMedia` builder + media group | ✅ | ✅ `InputMediaBuilder` |
|
|
28
|
+
| Download file (`getFile`/`downloadFile`) | plugin grammy/files | ✅ bawaan |
|
|
29
|
+
| Keyboard & InlineKeyboard fluent class | ✅ | ✅ |
|
|
30
|
+
| Menu interaktif | plugin @grammyjs/menu | ✅ bawaan `Menu/MenuContainer` |
|
|
31
|
+
| Wizard/percakapan | plugin conversations | ✅ bawaan `wizard()` (lebih simpel) |
|
|
32
|
+
| Long polling tahan-409 | ❌ (fatal crash) | ✅ bawaan (auto-retry 5 dtk) |
|
|
33
|
+
| Broadcast siap pakai | ❌ | ✅ `bot.broadcast()` |
|
|
34
|
+
| Humanisasi error + saran (🇮🇩) | ❌ | ✅ `humanize()` |
|
|
35
|
+
| Banner boot cantik + log debug | ❌ | ✅ (`DEBUG=telebibz*`) |
|
|
36
|
+
| Proxy HTTP(S) untuk VPS | ⚠️ via config manual | ✅ opsi `proxy` transport |
|
|
37
|
+
| TypeScript | ✅ full | d.ts longgar (JS-first) |
|
|
38
|
+
| Docs bahasa | en | **🇮🇩 Indonesia-first** |
|
|
39
|
+
|
|
40
|
+
## Dependensi (semuanya dipakai nyata — tertest)
|
|
41
|
+
| Paket | Untuk |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `axios ^1.20` | transport keep-alive + streaming downloadFile |
|
|
44
|
+
| `mime-types ^3.0` | deteksi content-type upload |
|
|
45
|
+
| `https-proxy-agent ^9.1` | opsi proxy transport VPS |
|
|
46
|
+
| `debug ^4.4` | logging `DEBUG=telebibz:net,telebibz:ratelimit` |
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
> ❓ *"Kenapa bukan protobuf?"* — Bot API memakai **JSON/HTTP murni**, protobuf hanya relevan di dunia MTProto (user-client). Menambahkannya = dependency mati, melanggar prinsip *"semua library harus berfungsi"*.
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
|
|
50
|
+
---
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
```
|
|
52
|
+
## 🚀 Mulai dalam 6 baris
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
```js
|
|
55
|
+
const { TeleBibz } = require('@xbibzlibrary/telebibz');
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
const bot = new TeleBibz('TOKEN_DARI_BOTFATHER');
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
bot.cmd('start', (ctx) => ctx.reply('Halo!'));
|
|
60
|
+
bot.hears(/halo/i, (ctx) => ctx.reply('halo juga 👋'));
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
export TELEGRAM_BOT_TOKEN="<your-bot-token>"
|
|
57
|
-
npx tsx examples/minimal.ts
|
|
62
|
+
bot.launch();
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
The examples are typechecked in CI with `npm run test:examples` and never contain real credentials.
|
|
61
|
-
|
|
62
|
-
## Router and middleware
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
bot.use(async (ctx, next) => {
|
|
66
|
-
const started = Date.now();
|
|
67
|
-
await next();
|
|
68
|
-
console.log(`processed in ${Date.now() - started}ms`);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
bot.command("help", async (ctx) => { await ctx.reply("Help is available."); });
|
|
72
|
-
bot.onRegex(/^order:(\d+)$/, async (ctx) => { await ctx.reply("Order received."); });
|
|
73
|
-
bot.callback("profile:*", async (ctx) => { await ctx.answerCallbackQuery("Opened."); });
|
|
74
|
-
bot.action("menu:open", async (ctx) => { await ctx.answerCallbackQuery("Menu opened."); });
|
|
75
|
-
bot.on("message:photo", async (ctx) => { await ctx.reply("Nice photo."); });
|
|
76
|
-
bot.on(["message:text", "callback_query:data"], async (ctx) => { await ctx.reply("Got it."); });
|
|
77
|
-
bot.hears("ping", async (ctx) => { await ctx.reply("pong"); });
|
|
78
|
-
bot.catch(async (error, ctx) => { await ctx.reply("Something went wrong."); });
|
|
79
65
|
```
|
|
80
|
-
|
|
81
|
-
The router supports commands, exact text, regular expressions, callback patterns, update-type filters (`on`), custom predicates, nested routers, per-route middleware, and route priority. `bot.catch()` registers an error boundary: handler failures are routed there instead of rejecting the update.
|
|
82
|
-
|
|
83
|
-
## Telegram API
|
|
84
|
-
|
|
85
|
-
Generated method access and raw access are available through the API client:
|
|
86
|
-
|
|
87
|
-
```ts
|
|
88
|
-
await bot.api.methods.getMe();
|
|
89
|
-
await bot.api.methods.sendMessage({ chat_id: 123456789, text: "Hello." });
|
|
90
|
-
await bot.api.call("sendMessage", { chat_id: 123456789, text: "Hello." });
|
|
91
|
-
await bot.api.raw("futureTelegramMethod", { value: true });
|
|
66
|
+
BOT_TOKEN=123:abc node index.js
|
|
92
67
|
```
|
|
93
68
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## Keyboard builders
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
import { InlineKeyboard } from "@xbibzlibrary/telebibz";
|
|
100
|
-
|
|
101
|
-
const keyboard = new InlineKeyboard()
|
|
102
|
-
.text("Profile", "profile")
|
|
103
|
-
.url("Documentation", "https://core.telegram.org/bots/api")
|
|
104
|
-
.build();
|
|
105
|
-
|
|
106
|
-
await ctx.reply("Choose an option:", { reply_markup: keyboard });
|
|
69
|
+
Output terminal:
|
|
107
70
|
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
const bot = new Bot({
|
|
117
|
-
token: process.env.TELEGRAM_BOT_TOKEN!,
|
|
118
|
-
logger: { level: "debug", format: "pretty", color: true },
|
|
119
|
-
});
|
|
71
|
+
┌────────────────────────┐
|
|
72
|
+
│ 🤖 TeleBibz ON │
|
|
73
|
+
│ bot : @botkamu │
|
|
74
|
+
│ engine : grammY 1.46│
|
|
75
|
+
│ brand : //—Xbibz Official—//
|
|
76
|
+
└────────────────────────┘
|
|
77
|
+
✔ menunggu update… (Ctrl+C untuk berhenti)
|
|
120
78
|
```
|
|
121
79
|
|
|
80
|
+
> **Hidup di VPS:** kalau ada instance bot lain yang masih polling (409 Conflict — misal deploy
|
|
81
|
+
> ganda atau hosting restart), telebibz **otomatis retry tiap 5 detik tanpa crash** dan menyalakan
|
|
82
|
+
> diri begitu jalur bebas. Tidak perlu PM2 babysitter.
|
|
122
83
|
|
|
123
|
-
|
|
84
|
+
---
|
|
124
85
|
|
|
125
|
-
|
|
86
|
+
## 📚 API lengkap (semuanya!)
|
|
126
87
|
|
|
127
|
-
|
|
128
|
-
import { Bot, Wizard } from "@xbibzlibrary/telebibz";
|
|
88
|
+
### Perintah & teks
|
|
129
89
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
bot.
|
|
137
|
-
bot.command("start", async (ctx) => { await wizard.run(ctx); });
|
|
138
|
-
await bot.start();
|
|
90
|
+
```js
|
|
91
|
+
bot.cmd('ping', (ctx) => ctx.reply('pong')); // /ping
|
|
92
|
+
bot.cmd(['a', 'b'], handler); // /a ATAU /b
|
|
93
|
+
bot.hears('daftar', handler); // teks persis "daftar"
|
|
94
|
+
bot.hears(/kampret/i, handler); // regex bebas
|
|
95
|
+
bot.on('message:photo', handler); // filter grammY apa pun
|
|
96
|
+
bot.use(middleware); // middleware manual
|
|
139
97
|
```
|
|
140
98
|
|
|
141
|
-
|
|
99
|
+
### Tombol (keyboard) — berwarna & ikon animated
|
|
142
100
|
|
|
143
|
-
|
|
101
|
+
```js
|
|
102
|
+
const { btn, url, webApp, copy, kb } = require('@xbibzlibrary/telebibz');
|
|
144
103
|
|
|
145
|
-
|
|
146
|
-
|
|
104
|
+
bot.cmd('menu', (ctx) =>
|
|
105
|
+
ctx.reply('Pilih:', kb([
|
|
106
|
+
[btn('💎 Premium', 'prem', 'primary'), // biru/ungu
|
|
107
|
+
btn('✅ Daftar', 'reg', 'success')], // hijau
|
|
108
|
+
[url('🌐 Web', 'https://situsmu.com')],
|
|
109
|
+
[btn('❌ Tutup', 'close', 'danger', '5408846744727334338')], // merah + IKON ANIMASI
|
|
110
|
+
])));
|
|
147
111
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
bot.action('prem', async (ctx) => {
|
|
113
|
+
await ctx.answerCallbackQuery('Menuju premium…');
|
|
114
|
+
await ctx.reply('halaman premium');
|
|
151
115
|
});
|
|
152
116
|
```
|
|
153
117
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
## High-load updates and broadcast
|
|
157
|
-
|
|
158
|
-
telebibz is built for bursts of 1000+ messages with no artificial cooldown:
|
|
118
|
+
- Warna (`primary`/`success`/`danger`) butuh aplikasi Telegram rilis ≥ Feb 2026 — versi lama tampil biasa, tidak error.
|
|
119
|
+
- Ikon animated (`icon_custom_emoji_id`) butuh **owner bot ber-Premium** atau username Fragment. Cari ID-nya: kirim custom emoji ke bot + lihat entity `custom_emoji` di update (atau sediakan `/emojiid` sendiri, 5 baris lewat `bot.on('message')`).
|
|
159
120
|
|
|
160
|
-
|
|
161
|
-
- **No proactive throttling.** Outgoing requests are never delayed by the library. When Telegram answers 429, the transport waits exactly the `retry_after` window Telegram ordered (a global "flood gate" protects all in-flight traffic) and retries automatically — so bursts deliver completely instead of failing. For your own downstream limits, `Limiter` and `mapWithConcurrency()` rate-shape any workload.
|
|
162
|
-
- **Broadcast to 1000+ users at once.** `bot.broadcast()` attempts every chat immediately, retries 429s per Telegram's own `retry_after`, and returns a full report.
|
|
163
|
-
- **Graceful shutdown.** `bot.stop()` first waits for in-flight handlers to finish (bounded by `handlerTimeout`) and only then stops the plugin manager — active conversations are never truncated mid-write.
|
|
121
|
+
### Wizard — form tanya-jawab tanpa boilerplate
|
|
164
122
|
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
)
|
|
171
|
-
|
|
123
|
+
```js
|
|
124
|
+
bot.wizard('daftar', {
|
|
125
|
+
steps: [
|
|
126
|
+
{ key: 'nama', ask: 'Siapa namamu?' },
|
|
127
|
+
{ key: 'umur', ask: 'Umur?', parse: Number,
|
|
128
|
+
validate: (n) => (n > 0 && n < 120 ? null : 'Angka saja ya:') },
|
|
129
|
+
],
|
|
130
|
+
done: async (ans, ctx) => ctx.reply(`Oke ${ans.nama} (${ans.umur})!`),
|
|
131
|
+
});
|
|
132
|
+
// user tinggal /daftar → bot bertanya-bertanya sampai selesai.
|
|
133
|
+
// ketik "batal" kapan pun untuk berhenti. Sesi otomatis aktif, tak perlu setup.
|
|
172
134
|
```
|
|
173
135
|
|
|
174
|
-
|
|
136
|
+
### Broadcast aman rate-limit
|
|
175
137
|
|
|
176
|
-
|
|
138
|
+
```js
|
|
139
|
+
const hasil = await bot.broadcast([111, 222, 333], 'Pengumuman!', { delay: 35 });
|
|
140
|
+
// → { terkirim: 3, gagal: 0, errors: [] } (yang diblokir-mu tercatat di errors)
|
|
141
|
+
```
|
|
177
142
|
|
|
178
|
-
|
|
143
|
+
### Kirim file
|
|
179
144
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- **Polls, games, payments** — `ctx.replyWithQuiz`, `ctx.stopPoll`, `ctx.editMessageLiveLocation`, `ctx.stopMessageLiveLocation`, `ctx.replyWithGame`, `ctx.setGameScore`, `ctx.getGameHighScores`, `ctx.replyWithInvoice`
|
|
185
|
-
- **Forum topics** — `ctx.createForumTopic`, `ctx.closeForumTopic`, `ctx.editGeneralForumTopic`, and nine more
|
|
186
|
-
- **Launch options** — `handlerTimeout` (default 90s, like Telegraf) rejects hung updates with `UpdateTimeoutError` while the handler keeps running; `0` disables the timeout; `contextType` plugs in your own `Context` subclass; `dropPendingUpdates` on `start()/launch()`
|
|
187
|
-
- **Webhook replies** — opt-in `webhookReply: true` answers the first API call through the webhook HTTP response itself (Telegraf-style), with the lazy `getMe` never claiming the slot
|
|
188
|
-
- **Drop-in handler aliases** — `bot.action(...)` registers a callback-query handler just like `bot.callback(...)`, so handlers written for Telegraf migrate unchanged
|
|
145
|
+
```js
|
|
146
|
+
const { InputFile } = require('@xbibzlibrary/telebibz');
|
|
147
|
+
bot.cmd('foto', (ctx) => ctx.replyWithPhoto(new InputFile(buf, 'x.jpg')));
|
|
148
|
+
```
|
|
189
149
|
|
|
190
|
-
|
|
150
|
+
### Error yang bisa dibaca manusia
|
|
191
151
|
|
|
192
|
-
|
|
152
|
+
Default-nya setiap error dilaporkan dengan **saran penyelesaian**:
|
|
153
|
+
```
|
|
154
|
+
✖ Telegram error (403): Forbidden: bot was blocked by the user
|
|
155
|
+
💡 saran: Bot diblokir pengguna — jangan kirim ulang, hapus dari daftar broadcast.
|
|
156
|
+
```
|
|
157
|
+
Kustom: `new TeleBibz(token, { onError: (err, ctx) => { ... } })`.
|
|
193
158
|
|
|
194
|
-
|
|
159
|
+
### Opsi konstruktor
|
|
195
160
|
|
|
196
|
-
|
|
161
|
+
| Opsi | Default | Fungsi |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| `allowedUpdates` | semua tipe umum + Business | batasi update yang diterima |
|
|
164
|
+
| `onError` | reporter cantik bawaan | handle error sendiri |
|
|
165
|
+
| `silent` | `false` | tanpa banner boot |
|
|
166
|
+
| `dropPending` | `false` | buang update lama saat start |
|
|
167
|
+
| `grammy` | `{}` | opsi mentah `new Bot()` grammY |
|
|
197
168
|
|
|
198
|
-
|
|
169
|
+
### Webhook / serverless
|
|
199
170
|
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
171
|
+
```js
|
|
172
|
+
// express:
|
|
173
|
+
app.use('/tg', bot.webhook('express'));
|
|
174
|
+
// atau serverless manual:
|
|
175
|
+
await bot.handleUpdate(req.body);
|
|
205
176
|
```
|
|
206
177
|
|
|
207
|
-
|
|
178
|
+
### Escape hatch penuh
|
|
208
179
|
|
|
209
|
-
|
|
180
|
+
Kapan pun butuh API mentah: `bot.api.sendMessage(...)`, `bot.bot` (instance grammY), `ctx.reply(...)`, `ctx.api.*` — grammar lengkap grammY tetap berlaku 100%.
|
|
210
181
|
|
|
211
|
-
|
|
182
|
+
---
|
|
212
183
|
|
|
213
|
-
|
|
214
|
-
npm start
|
|
215
|
-
npx telebibz init my-bot
|
|
216
|
-
npx telebibz doctor
|
|
217
|
-
npx telebibz build
|
|
218
|
-
npx telebibz test
|
|
219
|
-
```
|
|
184
|
+
## 🧩 Contoh siap jalan (`examples/`)
|
|
220
185
|
|
|
221
|
-
|
|
186
|
+
| File | Isi |
|
|
187
|
+
|---|---|
|
|
188
|
+
| `01-quickstart.js` | bot jalan dalam 6 baris |
|
|
189
|
+
| `02-menu-tombol.js` | keyboard berwarna + ikon |
|
|
190
|
+
| `03-wizard.js` | form pendaftaran |
|
|
191
|
+
| `04-broadcast.js` | blast admin |
|
|
192
|
+
| `05-kirim-file.js` | foto & dokumen dari buffer |
|
|
222
193
|
|
|
223
|
-
|
|
224
|
-
import { printTeleBibzBanner, printTerminalBranding } from "@xbibzlibrary/telebibz";
|
|
194
|
+
## 🔬 Test & bukti live
|
|
225
195
|
|
|
226
|
-
printTeleBibzBanner({ subtitle: "My bot" });
|
|
227
|
-
printTerminalBranding();
|
|
228
196
|
```
|
|
229
|
-
|
|
230
|
-
## Testing
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
npm run typecheck
|
|
234
|
-
npm run test:types
|
|
235
|
-
npm run lint
|
|
236
|
-
npm test
|
|
237
|
-
npm run build
|
|
238
|
-
npm run security
|
|
239
|
-
npm run release:check
|
|
197
|
+
npm test # 14 kasus, TANPA jaringan (transport disuntik)
|
|
240
198
|
```
|
|
241
199
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
## Web Apps and payments
|
|
200
|
+
Tervalidasi **24/24 offline + 10 live** pada bot produksi @xbibzrat_bot: getMe, keyboard berwarna & ikon animasi asli,
|
|
201
|
+
upload multipart (photo+document), edit keyboard, broadcast, deleteMessage, polling 409 retry.
|
|
245
202
|
|
|
246
|
-
|
|
203
|
+
## 📂 Isi repo (11 file inti)
|
|
247
204
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
Everything below ships from the package entry point unless a subpath is given. Full signatures for every export are documented in [docs/API.md](docs/API.md) (also [docs/API.id.md](docs/API.id.md) and [docs/API.zh-CN.md](docs/API.zh-CN.md)).
|
|
251
|
-
|
|
252
|
-
| Area | Exports |
|
|
253
|
-
|---|---|
|
|
254
|
-
| Bot & lifecycle | `Bot` with `on`, `onText`, `onRegex`, `command`, `hears`, `callback`, `action`, `catch`, `use`, `usePlugin`, `useWizard`, `handleUpdate`, `handleUpdates`, `start`/`launch`, `stop`, `restart`, `init`, `health`, `broadcast`, `getMe`, `setCommands`, `deleteCommands`, `downloadFile`; `UpdateTimeoutError` |
|
|
255
|
-
| Context | `Context`, `ContextOptions`, `contextType` launch option; ~80 shortcuts on `ctx` for replies, admin actions, chat management, invite links, polls, games, payments, and forum topics |
|
|
256
|
-
| Telegram API | `ApiClient` with `call()`, `request()`, `raw()`, `downloadFile()`, and `methods` (all generated Bot API methods); `FetchTransport` with automatic 429/5xx retries, a global flood gate, multipart uploads (Blob/bytes/path/streams), and file downloads |
|
|
257
|
-
| Errors | `TelegramError` with a `kind` taxonomy (`retryable`, `rate-limit`, `authentication`, `validation`, `network`, `server`, `unknown`) and `retryAfter`, plus `TelegramRateLimitError`, `TelegramAuthError`, `TelegramValidationError`, `TelegramNetworkError` |
|
|
258
|
-
| Router & middleware | `Router`, `compose`, 24 update filters (`message:photo`, `callback_query:data`, …), `matchMode` (`first`/`all`) |
|
|
259
|
-
| Keyboards | `InlineKeyboard`, `ReplyKeyboard`, `removeKeyboard()`, `forceReply()` |
|
|
260
|
-
| Storage | `MemoryStorage` (TTL, per-key serialization), `JsonFileStorage`, `RedisStorage`, `SqlStorage`, `MongoStorage`, plus the small driver interfaces they build on |
|
|
261
|
-
| Cache & limiting | `MemoryCache`, `TokenBucketLimiter`, `Limiter`, `mapWithConcurrency()` |
|
|
262
|
-
| Queue & scheduler | `TaskQueue` (priority, retry, backoff, delay, cancel), `Scheduler` (intervals, one-shot, cron), `parseCronExpression()`, `nextCronOccurrence()` |
|
|
263
|
-
| State & dialogs | `Wizard`, `ConversationManager`, `ConversationFlow`, `Form` with `validators`, permission-aware `Menu`, `MenuController`, `paginate()` |
|
|
264
|
-
| Webhook | `createWebhookHandler()` (Web `Request`/`Response`), `webhookCallback()` for Express/Koa/Fastify/Node `http`, `runWithWebhookReply()`, `claimWebhookReply()` |
|
|
265
|
-
| Web Apps & payments | `parseWebAppInitData()`, `validateWebAppInitData()`, `PaymentsClient`, `TelegramTypes` (vendored Telegram declarations) |
|
|
266
|
-
| Observability | `Logger` (levels, redaction, JSON format), `EventBus` with the `update:*`, `bot:*`, and `broadcast:*` event maps, `redact()` |
|
|
267
|
-
| Terminal | `printTeleBibzBanner()`, `printTerminalBranding()`, `buildTerminalBranding()`, `runStartupSequence()`, `startTeleBibzBanner()`, `paintRainbow()`, `printStatusLine()` |
|
|
268
|
-
| Text utilities | `splitMessage()`, `splitCaption()`, `escapeMarkdownV2()`, `escapeHtml()`, `md`, `html`, `template()` |
|
|
269
|
-
| File utilities | `validateUpload()`, `assertValidUpload()`, `UploadValidationError` (size, MIME, extension rules) |
|
|
270
|
-
| Testing (`@xbibzlibrary/telebibz/testing`) | `MockTransport` (with mock downloads), `createTestBot()`, `createMockUpdate()`, `createMockCallbackUpdate()`, `createMockContext()` |
|
|
271
|
-
| CLI (`telebibz …`) | `init`, `doctor`, `build`, `test`, `start`, `webhook`, `generate` |
|
|
272
|
-
|
|
273
|
-
## API targets and limitations
|
|
274
|
-
|
|
275
|
-
The generated method list is derived from the Telegram Bot API schema when it is updated. Runtime access is available for detected official methods, while specialized request/result inference remains concentrated on the core method map. The complete vendored Telegram object, union, enum, and method declarations are available through `TelegramTypes`. See [FEATURE_MATRIX.md](FEATURE_MATRIX.md) for implementation status and [docs/API.md](docs/API.md) for the complete API reference.
|
|
276
|
-
|
|
277
|
-
For every exported class, function, method, type, error, lifecycle hook, CLI command, and generated Telegram method, see the [complete English API reference](docs/API.md).
|
|
278
|
-
|
|
279
|
-
## Release automation
|
|
280
|
-
|
|
281
|
-
The GitHub repository includes CI and an auto-publish workflow. A push to `main` runs the quality gates and derives the next version from the pushed Conventional Commits: `feat:` commits and breaking changes bump the minor version while the package is pre-1.0 (`BREAKING-CHANGE` footers or `type!:` subjects bump the major from 1.0.0 onward), everything else bumps the patch version. A version already declared in `package.json` ahead of npm publishes exactly as declared, and the workflow never publishes a version at or below the latest npm release. The workflow commits the version, creates the tag, publishes to npm (with provenance disabled via `--provenance=false`), and creates a GitHub Release. Commits containing `[skip release]` do not trigger a publication. Configure the `NPM_TOKEN` GitHub Actions secret before relying on automatic publication. See [RELEASE_AUTOMATION.md](RELEASE_AUTOMATION.md).
|
|
282
|
-
|
|
283
|
-
## Project policies and contribution
|
|
284
|
-
|
|
285
|
-
| Document | Purpose |
|
|
205
|
+
| File | Peran |
|
|
286
206
|
|---|---|
|
|
287
|
-
|
|
|
288
|
-
|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
291
|
-
|
|
|
292
|
-
|
|
|
293
|
-
|
|
|
294
|
-
|
|
|
295
|
-
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
##
|
|
300
|
-
|
|
301
|
-
|
|
207
|
+
| `lib/net.js` | transport HTTP fetch murni + multipart `attach://` |
|
|
208
|
+
| `lib/api.js` | metode Bot API + `api.callApi()` untuk segala metode |
|
|
209
|
+
| `lib/composer.js` | middleware, filter `on('message:photo')`, `errorBoundary` |
|
|
210
|
+
| `lib/context.js` | objek ctx + pintasan reply/edit/delete/callback |
|
|
211
|
+
| `lib/session.js` | sesi per user:chat (dapat ditukar storagenya) |
|
|
212
|
+
| `lib/runner.js` | long polling: retry 409, backoff jaringan, drop pending |
|
|
213
|
+
| `lib/file.js` | `File`/`InputFile` (Buffer/path/stream) |
|
|
214
|
+
| `lib/keyboard.js` | builder + `InlineKeyboard`/`Keyboard` fluent class |
|
|
215
|
+
| `lib/wizard.js` | percakapan tanya-jawab berurutan |
|
|
216
|
+
| `lib/broadcast.js` | blast aman rate limit |
|
|
217
|
+
| `lib/errors.js` + `lib/logger.js` | error manusiawi + log berbingkai |
|
|
218
|
+
|
|
219
|
+
## 🆚 Kenapa recode?
|
|
220
|
+
|
|
221
|
+
| | v0.4 lama | v1.0 |
|
|
222
|
+
|---|---|---|
|
|
223
|
+
| Baris file sumber | 152 file TS | 7 file JS |
|
|
224
|
+
| Build step | tsc ×2 + script | — |
|
|
225
|
+
| Dependency runtime | — | **0 (nol)** |
|
|
226
|
+
| Bot API | manual update | 9.x penuh (uji live asli) |
|
|
227
|
+
| Hello world | kelas + config | 6 baris |
|
|
228
|
+
| Docs | 3 bahasa × belasan file | README ini |
|
|
229
|
+
|
|
230
|
+
## 📄 Lisensi
|
|
231
|
+
|
|
232
|
+
MIT · //—Xbibz Official—//
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// examples/01-quickstart.js — bot jalan dalam 6 baris kode.
|
|
2
|
+
// BOT_TOKEN=123:abc node examples/01-quickstart.js
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { TeleBibz } = require('..');
|
|
6
|
+
|
|
7
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
8
|
+
|
|
9
|
+
bot.cmd('start', (ctx) => ctx.reply(`Halo ${ctx.from.first_name}! Aku hidup 🎉`));
|
|
10
|
+
bot.hears(/halo|hai/i, (ctx) => ctx.reply('Halo juga! 👋'));
|
|
11
|
+
bot.hears('ping', (ctx) => ctx.reply('pong 🏓'));
|
|
12
|
+
|
|
13
|
+
bot.launch();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// examples/02-menu-tombol.js — inline keyboard berwarna + ikon animated.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { TeleBibz, btn, url, kb } = require('..');
|
|
5
|
+
|
|
6
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
7
|
+
|
|
8
|
+
bot.cmd('menu', (ctx) =>
|
|
9
|
+
ctx.reply('Pilih menu:', kb([
|
|
10
|
+
[btn('💎 Premium', 'premium', 'primary'), btn('📞 Bantuan', 'bantuan')],
|
|
11
|
+
[url('🌐 Website', 'https://example.com', 'success')],
|
|
12
|
+
[btn('❌ Tutup', 'tutup', 'danger')],
|
|
13
|
+
])));
|
|
14
|
+
|
|
15
|
+
bot.action('premium', async (ctx) => {
|
|
16
|
+
await ctx.answerCallbackQuery('Menuju halaman premium…');
|
|
17
|
+
await ctx.reply('💎 Daftar paket premium…');
|
|
18
|
+
});
|
|
19
|
+
bot.action('bantuan', (ctx) => ctx.answerCallbackQuery({ text: 'Hubungi @admin ya!', show_alert: true }));
|
|
20
|
+
bot.action('tutup', (ctx) => ctx.deleteMessage().catch(() => {}));
|
|
21
|
+
|
|
22
|
+
bot.launch();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// examples/03-wizard.js — form pendaftaran tanya-jawab, 0 boilerplate.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { TeleBibz } = require('..');
|
|
5
|
+
|
|
6
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
7
|
+
|
|
8
|
+
bot.wizard('daftar', {
|
|
9
|
+
steps: [
|
|
10
|
+
{ key: 'nama', ask: '1️⃣ Siapa nama lengkapmu?' },
|
|
11
|
+
{
|
|
12
|
+
key: 'umur',
|
|
13
|
+
ask: '2️⃣ Umur berapa?',
|
|
14
|
+
parse: (t) => parseInt(t, 10),
|
|
15
|
+
validate: (n) => (Number.isFinite(n) && n > 0 && n < 120 ? null : 'Umur tidak valid — ketik angka saja ya:'),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: 'kota',
|
|
19
|
+
ask: '3️⃣ Tinggal di kota mana? (ketik "batal" untuk berhenti)',
|
|
20
|
+
validate: (t) => (t && t.length >= 3 ? null : 'Nama kota minimal 3 huruf:'),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
done: async (ans, ctx) => {
|
|
24
|
+
await ctx.reply(`✅ Terdaftar!\nNama : ${ans.nama}\nUmur : ${ans.umur}\nKota : ${ans.kota}`);
|
|
25
|
+
},
|
|
26
|
+
onCancel: (ctx) => ctx.reply('👋 Pendaftaran dibatalkan.'),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
bot.launch();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// examples/04-broadcast.js — blast pesan ke banyak chat tanpa kena limit.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { TeleBibz, kb, url } = require('..');
|
|
5
|
+
|
|
6
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
7
|
+
const subscribers = new Set(); // produksi: simpan di DB
|
|
8
|
+
|
|
9
|
+
bot.cmd('start', (ctx) => {
|
|
10
|
+
subscribers.add(ctx.chat.id);
|
|
11
|
+
ctx.reply('Kamu terdaftar! Admin bisa /blast untuk info ke semua.');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
bot.cmd('blast', async (ctx) => {
|
|
15
|
+
if (String(ctx.from.id) !== process.env.ADMIN_ID) return ctx.reply('Khusus admin.');
|
|
16
|
+
const teks = ctx.message.text.replace(/^\/blast\s*/i, '').trim();
|
|
17
|
+
if (!teks) return ctx.reply('Pakai: /blast isi pesannya');
|
|
18
|
+
|
|
19
|
+
const proses = await ctx.reply(`Mengirim ke ${subscribers.size} chat…`);
|
|
20
|
+
const hasil = await bot.broadcast([...subscribers], { text: teks, ...kb([[url('Info', 'https://example.com')]]) });
|
|
21
|
+
await ctx.reply(`Selesai ✅ terkirim ${hasil.terkirim}, gagal ${hasil.gagal}`);
|
|
22
|
+
await ctx.api.deleteMessage(ctx.chat.id, proses.message_id).catch(() => {});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
bot.launch();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// examples/05-kirim-file.js — kirim foto dari URL & dokumen dari Buffer.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { TeleBibz, InputFile } = require('..');
|
|
5
|
+
|
|
6
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
7
|
+
|
|
8
|
+
bot.cmd('kucing', async (ctx) => {
|
|
9
|
+
const r = await fetch('https://cataas.com/cat');
|
|
10
|
+
const buf = Buffer.from(await r.arrayBuffer());
|
|
11
|
+
await ctx.replyWithPhoto(new InputFile(buf, 'kucing.jpg'), { caption: 'Meong 🐱' });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
bot.cmd('laporan', async (ctx) => {
|
|
15
|
+
const data = Buffer.from(`Laporan ${new Date().toISOString()}\nHalo dunia!`);
|
|
16
|
+
await ctx.replyWithDocument(new InputFile(data, 'laporan.txt'));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
bot.launch();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// examples/06-menu.js — Menu inline ala @grammyjs/menu dengan submenu.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { TeleBibz, MenuContainer } = require('..');
|
|
5
|
+
|
|
6
|
+
const bot = new TeleBibz(process.env.BOT_TOKEN);
|
|
7
|
+
const mc = new MenuContainer();
|
|
8
|
+
|
|
9
|
+
const utama = mc.create('utama');
|
|
10
|
+
const setelan = mc.create('setelan');
|
|
11
|
+
|
|
12
|
+
const state = { notif: true };
|
|
13
|
+
|
|
14
|
+
utama
|
|
15
|
+
.text('⚙️ Setelan', async (ctx) => {
|
|
16
|
+
await ctx.editMessageReplyMarkup({ reply_markup: await setelan.render(ctx) });
|
|
17
|
+
await ctx.answerCallbackQuery();
|
|
18
|
+
})
|
|
19
|
+
.row()
|
|
20
|
+
.url('📚 Dokumentasi', 'https://github.com/XbibzOfficial777/telebibz');
|
|
21
|
+
|
|
22
|
+
setelan
|
|
23
|
+
.text('🔔 Toggle Notif', async (ctx) => {
|
|
24
|
+
state.notif = !state.notif;
|
|
25
|
+
await ctx.answerCallbackQuery({ text: `Notif ${state.notif ? 'ON ✅' : 'OFF ❌'}` });
|
|
26
|
+
})
|
|
27
|
+
.back('◀️ Kembali', 'utama');
|
|
28
|
+
|
|
29
|
+
bot.use(mc);
|
|
30
|
+
|
|
31
|
+
bot.cmd('menu', async (ctx) => {
|
|
32
|
+
await ctx.reply('Pilih menu:', { reply_markup: await utama.render(ctx) });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
bot.launch();
|