@xbibzlibrary/telebibz 0.1.18 → 0.1.19

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/CONTRIBUTING.md CHANGED
@@ -16,6 +16,7 @@ The project requires Node.js `>=20` and uses npm for release-compatible commands
16
16
  npm ci
17
17
  npm run typecheck
18
18
  npm run test:types
19
+ npm run test:examples
19
20
  npm run lint
20
21
  npm test
21
22
  npm run build
@@ -33,7 +34,7 @@ Create a focused branch from `main`. Keep unrelated refactors out of a feature o
33
34
 
34
35
  Public behavior must be implemented in TypeScript with strict typing. Do not add fake responses, silent stubs, undocumented breaking behavior, or untested branches. Preserve ESM and CommonJS builds, zero runtime vendor dependencies in the core package, Node.js `>=20` compatibility, and the existing package export map.
35
36
 
36
- Changes to routing, context, lifecycle, transport, storage, queue, scheduler, approval, generated API declarations, or release automation require regression tests. Changes to a public function, class, method, option, error, event, or generated method require a corresponding API documentation update. Changes that affect package contents must pass `release:check` and `npm pack --dry-run`.
37
+ Changes to routing, context, lifecycle, transport, storage, queue, scheduler, approval, generated API declarations, or release automation require regression tests. Changes to a public function, class, method, option, error, event, or generated method require a corresponding API documentation update. Changes to examples require `npm run test:examples` and must use placeholders instead of credentials. Changes that affect package contents must pass `release:check` and `npm pack --dry-run`.
37
38
 
38
39
  ## Pull request process
39
40
 
@@ -49,6 +50,10 @@ English is the default README language. Keep `README.id.md`, `README.zh-CN.md`,
49
50
 
50
51
  Normal pushes to `main` can trigger the protected auto-publish workflow. The workflow runs quality gates, computes an unused patch version, publishes the package, commits the version, creates a tag, and creates a GitHub Release. See [RELEASE_AUTOMATION.md](RELEASE_AUTOMATION.md) for the required `NPM_TOKEN` secret and private-source provenance constraint. Contributors must not publish directly to npm unless explicitly authorized by the maintainers.
51
52
 
53
+ ## Showcase submissions
54
+
55
+ Public projects using Telebibz may be submitted through a pull request to [SHOWCASE.md](SHOWCASE.md). Include only public links and a short description. Never include bot tokens, private endpoints, personal data, or confidential source code.
56
+
52
57
  ## Questions
53
58
 
54
59
  Use the question/support template for usage questions and consult the [English API reference](docs/API.md) first. Keep support requests free of credentials and private user data.
package/README.id.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ![telebibz logo](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-logo.png)
4
4
 
5
+ [![CI](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml/badge.svg)](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
8
+ [![Node.js](https://img.shields.io/node/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
9
+
5
10
  **`@xbibzlibrary/telebibz`** adalah SDK dan framework Telegram Bot untuk Node.js dan TypeScript. Paket ini menyediakan API client, polling, router, middleware, context, keyboard builder, state/session, webhook handler, queue, scheduler, cache, plugin lifecycle, CLI, dan utilitas pengujian.
6
11
 
7
12
  [English](README.md) · **Bahasa Indonesia** · [简体中文](README.zh-CN.md)
@@ -10,6 +15,10 @@ Referensi API lengkap: [English](docs/API.md) · **Indonesia** · [中文](docs/
10
15
 
11
16
  Panduan GitHub Packages: [English](docs/GITHUB_PACKAGES.md) · [Bahasa Indonesia](docs/GITHUB_PACKAGES.id.md) · [简体中文](docs/GITHUB_PACKAGES.zh-CN.md)
12
17
 
18
+ Panduan mulai: [English](docs/GETTING_STARTED.md) · [Bahasa Indonesia](docs/GETTING_STARTED.id.md) · [简体中文](docs/GETTING_STARTED.zh-CN.md)
19
+
20
+ Showcase komunitas: [SHOWCASE.md](SHOWCASE.md)
21
+
13
22
  ![overview telebibz](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-readme-preview.png)
14
23
 
15
24
  ## Instalasi
@@ -27,14 +36,25 @@ import { Bot } from "@xbibzlibrary/telebibz";
27
36
 
28
37
  const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
29
38
 
30
- bot.command("start", (ctx) => ctx.reply("Bot aktif."));
31
- bot.onText("ping", (ctx) => ctx.reply("pong"));
39
+ bot.command("start", async (ctx) => { await ctx.reply("Bot aktif."); });
40
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
32
41
 
33
42
  await bot.start();
34
43
  ```
35
44
 
36
45
  `Bot.start()` menjalankan long polling. Untuk siklus hidup manual, gunakan `init()`, `launch({ mode: "polling" })`, `health()`, `stop()`, atau `restart()`.
37
46
 
47
+ ## Starter resmi
48
+
49
+ Repository menyediakan starter yang bisa langsung dijalankan untuk bot minimal, registration wizard multi-langkah, dan webhook Node.js. Lihat [`examples/README.md`](examples/README.md), atau jalankan starter minimal setelah mengatur `TELEGRAM_BOT_TOKEN`:
50
+
51
+ ```bash
52
+ export TELEGRAM_BOT_TOKEN="<token-bot-kamu>"
53
+ npx tsx examples/minimal.ts
54
+ ```
55
+
56
+ Semua examples di-typecheck oleh CI melalui `npm run test:examples` dan tidak berisi credential asli.
57
+
38
58
  ## Router dan middleware
39
59
 
40
60
  ```ts
@@ -44,9 +64,9 @@ bot.use(async (ctx, next) => {
44
64
  console.log(`processed in ${Date.now() - started}ms`);
45
65
  });
46
66
 
47
- bot.command("help", (ctx) => ctx.reply("Bantuan tersedia."));
48
- bot.onRegex(/^order:(\\d+)$/, (ctx) => ctx.reply("Order diterima."));
49
- bot.callback("profile:*", (ctx) => ctx.answerCallbackQuery("Dibuka."));
67
+ bot.command("help", async (ctx) => { await ctx.reply("Bantuan tersedia."); });
68
+ bot.onRegex(/^order:(\\d+)$/, async (ctx) => { await ctx.reply("Order diterima."); });
69
+ bot.callback("profile:*", async (ctx) => { await ctx.answerCallbackQuery("Dibuka."); });
50
70
  ```
51
71
 
52
72
  Router mendukung command, text, regex, pola callback, predikat kustom, router bersarang, middleware per rute, dan prioritas rute.
package/README.md CHANGED
@@ -3,6 +3,9 @@
3
3
  ![telebibz logo](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-logo.png)
4
4
 
5
5
  [![CI](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml/badge.svg)](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
8
+ [![Node.js](https://img.shields.io/node/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
6
9
 
7
10
  **`@xbibzlibrary/telebibz`** is a full-scale 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.
8
11
 
@@ -14,6 +17,10 @@ Complete API references: [English](docs/API.md) · [Indonesia](docs/API.id.md)
14
17
 
15
18
  GitHub Packages guide: [English](docs/GITHUB_PACKAGES.md) · [Bahasa Indonesia](docs/GITHUB_PACKAGES.id.md) · [简体中文](docs/GITHUB_PACKAGES.zh-CN.md)
16
19
 
20
+ Getting started: [English](docs/GETTING_STARTED.md) · [Bahasa Indonesia](docs/GETTING_STARTED.id.md) · [简体中文](docs/GETTING_STARTED.zh-CN.md)
21
+
22
+ Community showcase: [SHOWCASE.md](SHOWCASE.md)
23
+
17
24
  ![telebibz overview](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-readme-preview.png)
18
25
 
19
26
  ## Installation
@@ -31,14 +38,25 @@ import { Bot } from "@xbibzlibrary/telebibz";
31
38
 
32
39
  const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
33
40
 
34
- bot.command("start", (ctx) => ctx.reply("Bot is active."));
35
- bot.onText("ping", (ctx) => ctx.reply("pong"));
41
+ bot.command("start", async (ctx) => { await ctx.reply("Bot is active."); });
42
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
36
43
 
37
44
  await bot.start();
38
45
  ```
39
46
 
40
47
  `Bot.start()` runs long polling. For manual lifecycle control, use `init()`, `launch({ mode: "polling" })`, `health()`, `stop()`, or `restart()`.
41
48
 
49
+ ## Official starter examples
50
+
51
+ The repository includes runnable starters for a minimal bot, a multi-step registration wizard, and a Node.js webhook server. Browse [`examples/README.md`](examples/README.md), or run the minimal starter after setting `TELEGRAM_BOT_TOKEN`:
52
+
53
+ ```bash
54
+ export TELEGRAM_BOT_TOKEN="<your-bot-token>"
55
+ npx tsx examples/minimal.ts
56
+ ```
57
+
58
+ The examples are typechecked in CI with `npm run test:examples` and never contain real credentials.
59
+
42
60
  ## Router and middleware
43
61
 
44
62
  ```ts
@@ -48,9 +66,9 @@ bot.use(async (ctx, next) => {
48
66
  console.log(`processed in ${Date.now() - started}ms`);
49
67
  });
50
68
 
51
- bot.command("help", (ctx) => ctx.reply("Help is available."));
52
- bot.onRegex(/^order:(\\d+)$/, (ctx) => ctx.reply("Order received."));
53
- bot.callback("profile:*", (ctx) => ctx.answerCallbackQuery("Opened."));
69
+ bot.command("help", async (ctx) => { await ctx.reply("Help is available."); });
70
+ bot.onRegex(/^order:(\\d+)$/, async (ctx) => { await ctx.reply("Order received."); });
71
+ bot.callback("profile:*", async (ctx) => { await ctx.answerCallbackQuery("Opened."); });
54
72
  ```
55
73
 
56
74
  The router supports commands, exact text, regular expressions, callback patterns, custom predicates, nested routers, per-route middleware, and route priority.
@@ -109,7 +127,7 @@ const wizard = new Wizard()
109
127
 
110
128
  const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
111
129
  bot.useWizard(wizard);
112
- bot.command("start", (ctx) => wizard.run(ctx));
130
+ bot.command("start", async (ctx) => { await wizard.run(ctx); });
113
131
  await bot.start();
114
132
  ```
115
133
 
package/README.zh-CN.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ![telebibz 徽标](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-logo.png)
4
4
 
5
+ [![CI](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml/badge.svg)](https://github.com/XbibzOfficial777/telebibz/actions/workflows/ci.yml)
6
+ [![npm version](https://img.shields.io/npm/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
8
+ [![Node.js](https://img.shields.io/node/v/@xbibzlibrary/telebibz)](https://www.npmjs.com/package/@xbibzlibrary/telebibz)
9
+
5
10
  **`@xbibzlibrary/telebibz`** 是一个面向 Node.js 和 TypeScript 的 Telegram Bot SDK 和框架。该包提供 API 客户端、轮询、路由器、中间件、上下文、键盘构造器、状态/会话、Webhook 处理、队列、调度器、缓存、插件生命周期、CLI 以及测试工具。
6
11
 
7
12
  [English](README.md) · [Bahasa Indonesia](README.id.md) · **简体中文**
@@ -10,6 +15,10 @@
10
15
 
11
16
  GitHub Packages 指南:[English](docs/GITHUB_PACKAGES.md) · [Bahasa Indonesia](docs/GITHUB_PACKAGES.id.md) · [简体中文](docs/GITHUB_PACKAGES.zh-CN.md)
12
17
 
18
+ 入门指南:[English](docs/GETTING_STARTED.md) · [Bahasa Indonesia](docs/GETTING_STARTED.id.md) · [简体中文](docs/GETTING_STARTED.zh-CN.md)
19
+
20
+ 社区 showcase:[SHOWCASE.md](SHOWCASE.md)
21
+
13
22
  ![telebibz 概览](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-readme-preview.png)
14
23
 
15
24
  ## 安装
@@ -27,14 +36,25 @@ import { Bot } from "@xbibzlibrary/telebibz";
27
36
 
28
37
  const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
29
38
 
30
- bot.command("start", (ctx) => ctx.reply("Bot aktif."));
31
- bot.onText("ping", (ctx) => ctx.reply("pong"));
39
+ bot.command("start", async (ctx) => { await ctx.reply("Bot aktif."); });
40
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
32
41
 
33
42
  await bot.start();
34
43
  ```
35
44
 
36
45
  `Bot.start()` 会运行长轮询。要手动管理生命周期,请使用 `init()`, `launch({ mode: "polling" })`, `health()`, `stop()`, 或 `restart()`。
37
46
 
47
+ ## 官方 starter examples
48
+
49
+ repository 提供可直接运行的 minimal bot、多步骤 registration wizard 和 Node.js webhook starter。请查看 [`examples/README.md`](examples/README.md),或设置 `TELEGRAM_BOT_TOKEN` 后运行 minimal starter:
50
+
51
+ ```bash
52
+ export TELEGRAM_BOT_TOKEN="<your-bot-token>"
53
+ npx tsx examples/minimal.ts
54
+ ```
55
+
56
+ 所有 examples 都会通过 `npm run test:examples` 在 CI 中进行类型检查,并且不包含真实 credential。
57
+
38
58
  ## 路由器与中间件
39
59
 
40
60
  ```ts
@@ -44,9 +64,9 @@ bot.use(async (ctx, next) => {
44
64
  console.log(`processed in ${Date.now() - started}ms`);
45
65
  });
46
66
 
47
- bot.command("help", (ctx) => ctx.reply("Bantuan tersedia."));
48
- bot.onRegex(/^order:(\\d+)$/, (ctx) => ctx.reply("Order diterima."));
49
- bot.callback("profile:*", (ctx) => ctx.answerCallbackQuery("Dibuka."));
67
+ bot.command("help", async (ctx) => { await ctx.reply("Bantuan tersedia."); });
68
+ bot.onRegex(/^order:(\\d+)$/, async (ctx) => { await ctx.reply("Order diterima."); });
69
+ bot.callback("profile:*", async (ctx) => { await ctx.answerCallbackQuery("Dibuka."); });
50
70
  ```
51
71
 
52
72
  路由器支持命令、文本、正则、回调模式、自定义谓词、嵌套路由器、每条路由的中间件,以及路由优先级。
package/SHOWCASE.md ADDED
@@ -0,0 +1,29 @@
1
+ # Telebibz showcase
2
+
3
+ This page highlights projects built with Telebibz. If you are using Telebibz in a public project, open a pull request adding a short entry using the format below. Do not include bot tokens, private URLs, personal data, or confidential source code.
4
+
5
+ ## Projects
6
+
7
+ No community submissions yet. The first public project can be added here.
8
+
9
+ ### Submission format
10
+
11
+ ```markdown
12
+ ### Project name
13
+
14
+ - **Link:** https://example.com
15
+ - **Description:** One sentence describing what the bot does.
16
+ - **Telebibz features:** Commands, wizard, webhook, keyboard, plugin, or other features used.
17
+ - **Maintainer:** @github-handle
18
+ ```
19
+
20
+ ## Why submit a project?
21
+
22
+ A showcase entry helps other developers discover practical patterns and gives maintainers feedback about which parts of the framework are useful in real applications. Entries are reviewed for relevance, security, and respectful presentation. A listing is not an endorsement, and maintainers may remove entries that become unavailable or unsafe.
23
+
24
+ ## Related resources
25
+
26
+ - [Getting started](docs/GETTING_STARTED.md)
27
+ - [Runnable examples](examples/README.md)
28
+ - [Complete API reference](docs/API.md)
29
+ - [Contribution guide](CONTRIBUTING.md)
@@ -0,0 +1,85 @@
1
+ # Memulai dengan Telebibz
2
+
3
+ Panduan ini membawa developer baru dari instalasi hingga bot Telegram yang berjalan dalam beberapa menit.
4
+
5
+ ## 1. Buat token bot
6
+
7
+ Buat bot melalui akun resmi pengelola bot Telegram dan simpan token di environment deployment. Jangan pernah commit token ke source control.
8
+
9
+ ## 2. Instal Telebibz
10
+
11
+ ```bash
12
+ mkdir my-telebibz-bot && cd my-telebibz-bot
13
+ npm init -y
14
+ npm install @xbibzlibrary/telebibz
15
+ npm install --save-dev tsx typescript
16
+ ```
17
+
18
+ Atur secret melalui secret manager atau export variable pada shell:
19
+
20
+ ```bash
21
+ export TELEGRAM_BOT_TOKEN="<token-bot-kamu>"
22
+ ```
23
+
24
+ ## 3. Tulis bot pertama
25
+
26
+ Buat `index.ts`:
27
+
28
+ ```ts
29
+ import { Bot } from "@xbibzlibrary/telebibz";
30
+
31
+ const token = process.env.TELEGRAM_BOT_TOKEN;
32
+ if (!token) throw new Error("TELEGRAM_BOT_TOKEN wajib diisi.");
33
+
34
+ const bot = new Bot(token);
35
+ bot.command("start", async (ctx) => { await ctx.reply("Telebibz berhasil berjalan."); });
36
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
37
+
38
+ await bot.start();
39
+ ```
40
+
41
+ Jalankan:
42
+
43
+ ```bash
44
+ npx tsx index.ts
45
+ ```
46
+
47
+ Kirim `/start` atau `ping` ke bot. Terminal akan menampilkan branding Telebibz dan log terstruktur. Gunakan format logger `json` jika output akan dikonsumsi log collector.
48
+
49
+ ## 4. Tambahkan wizard multi-langkah
50
+
51
+ Gunakan `Wizard` dan `bot.useWizard()` ketika jawaban harus melanjutkan step aktif. Mulai flow secara eksplisit dengan `wizard.run(ctx)`:
52
+
53
+ ```ts
54
+ const wizard = new Wizard()
55
+ .step({ id: "name", run: async (flow) => {
56
+ flow.set("name", flow.ctx.message?.text?.trim()).next();
57
+ await flow.ctx.reply("Berapa umur kamu?");
58
+ }})
59
+ .step({ id: "age", run: async (flow) => {
60
+ const age = Number(flow.ctx.message?.text?.trim());
61
+ if (!Number.isInteger(age)) { await flow.ctx.reply("Kirim angka bulat."); return; }
62
+ flow.set("age", age).next();
63
+ await flow.ctx.reply("Registrasi selesai.");
64
+ }});
65
+
66
+ bot.useWizard(wizard);
67
+ bot.command("register", async (ctx) => {
68
+ await wizard.run(ctx);
69
+ await ctx.reply("Siapa nama kamu?");
70
+ });
71
+ ```
72
+
73
+ Conversation manager default tetap digunakan selama instance wizard hidup, sedangkan key dibuat dari identitas chat dan pengirim. `/cancel` membatalkan flow aktif secara default.
74
+
75
+ ## 5. Checklist production
76
+
77
+ Gunakan HTTPS untuk webhook, validasi secret webhook Telegram, simpan token di secret manager, gunakan structured JSON logs, tambahkan health check, gunakan persistent storage untuk session yang harus bertahan setelah restart, dan jalankan `npm run typecheck`, `npm run test:types`, `npm run test:examples`, `npm test`, `npm run build`, serta `npm run security` sebelum deploy.
78
+
79
+ ## Langkah berikutnya
80
+
81
+ - [Runnable examples](../examples/README.md)
82
+ - [Referensi API lengkap](API.id.md)
83
+ - [Webhook API](API.id.md#10-webhook)
84
+ - [Conversation dan wizard](API.id.md#8-state-session-and-conversations)
85
+ - [Panduan kontribusi](../CONTRIBUTING.md)
@@ -0,0 +1,85 @@
1
+ # Getting started with Telebibz
2
+
3
+ This guide takes a new developer from installation to a working Telegram bot in a few minutes.
4
+
5
+ ## 1. Create a bot token
6
+
7
+ Create a bot with Telegram's official bot management account and keep the token in your deployment environment. Never commit it to source control.
8
+
9
+ ## 2. Install Telebibz
10
+
11
+ ```bash
12
+ mkdir my-telebibz-bot && cd my-telebibz-bot
13
+ npm init -y
14
+ npm install @xbibzlibrary/telebibz
15
+ npm install --save-dev tsx typescript
16
+ ```
17
+
18
+ Create `.env` through your secret manager or export the variable in the shell:
19
+
20
+ ```bash
21
+ export TELEGRAM_BOT_TOKEN="<your-bot-token>"
22
+ ```
23
+
24
+ ## 3. Write the first bot
25
+
26
+ Create `index.ts`:
27
+
28
+ ```ts
29
+ import { Bot } from "@xbibzlibrary/telebibz";
30
+
31
+ const token = process.env.TELEGRAM_BOT_TOKEN;
32
+ if (!token) throw new Error("TELEGRAM_BOT_TOKEN is required.");
33
+
34
+ const bot = new Bot(token);
35
+ bot.command("start", async (ctx) => { await ctx.reply("Telebibz is working."); });
36
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
37
+
38
+ await bot.start();
39
+ ```
40
+
41
+ Run it with:
42
+
43
+ ```bash
44
+ npx tsx index.ts
45
+ ```
46
+
47
+ Send `/start` or `ping` to the bot. The terminal displays the Telebibz branding and structured logs. Set the logger format to `json` when a log collector consumes the output.
48
+
49
+ ## 4. Add a multi-step wizard
50
+
51
+ Use `Wizard` and `bot.useWizard()` when replies should continue through active steps. Start the flow explicitly with `wizard.run(ctx)`:
52
+
53
+ ```ts
54
+ const wizard = new Wizard()
55
+ .step({ id: "name", run: async (flow) => {
56
+ flow.set("name", flow.ctx.message?.text?.trim()).next();
57
+ await flow.ctx.reply("How old are you?");
58
+ }})
59
+ .step({ id: "age", run: async (flow) => {
60
+ const age = Number(flow.ctx.message?.text?.trim());
61
+ if (!Number.isInteger(age)) { await flow.ctx.reply("Send a whole number."); return; }
62
+ flow.set("age", age).next();
63
+ await flow.ctx.reply("Registration complete.");
64
+ }});
65
+
66
+ bot.useWizard(wizard);
67
+ bot.command("register", async (ctx) => {
68
+ await wizard.run(ctx);
69
+ await ctx.reply("What is your name?");
70
+ });
71
+ ```
72
+
73
+ The default conversation manager persists for the lifetime of the wizard instance, and the key is derived from chat and sender identity. `/cancel` cancels the active flow by default.
74
+
75
+ ## 5. Production checklist
76
+
77
+ Use HTTPS for webhooks, verify the Telegram webhook secret, keep tokens in a secret manager, configure structured JSON logs, add health checks, use persistent storage for sessions that must survive restarts, and run `npm run typecheck`, `npm run test:types`, `npm run test:examples`, `npm test`, `npm run build`, and `npm run security` before deployment.
78
+
79
+ ## Next steps
80
+
81
+ - [Runnable examples](../examples/README.md)
82
+ - [Complete API reference](API.md)
83
+ - [Webhook API](API.md#10-webhook)
84
+ - [Conversations and wizards](API.md#8-state-session-and-conversations)
85
+ - [Contribution guide](../CONTRIBUTING.md)
@@ -0,0 +1,85 @@
1
+ # Telebibz 入门
2
+
3
+ 本指南帮助新开发者在几分钟内完成安装并运行 Telegram bot。
4
+
5
+ ## 1. 创建 bot token
6
+
7
+ 通过 Telegram 官方 bot 管理账号创建 bot,并将 token 保存在部署环境中。不要把 token 提交到 source control。
8
+
9
+ ## 2. 安装 Telebibz
10
+
11
+ ```bash
12
+ mkdir my-telebibz-bot && cd my-telebibz-bot
13
+ npm init -y
14
+ npm install @xbibzlibrary/telebibz
15
+ npm install --save-dev tsx typescript
16
+ ```
17
+
18
+ 请使用 secret manager,或在 shell 中设置变量:
19
+
20
+ ```bash
21
+ export TELEGRAM_BOT_TOKEN="<your-bot-token>"
22
+ ```
23
+
24
+ ## 3. 编写第一个 bot
25
+
26
+ 创建 `index.ts`:
27
+
28
+ ```ts
29
+ import { Bot } from "@xbibzlibrary/telebibz";
30
+
31
+ const token = process.env.TELEGRAM_BOT_TOKEN;
32
+ if (!token) throw new Error("TELEGRAM_BOT_TOKEN is required.");
33
+
34
+ const bot = new Bot(token);
35
+ bot.command("start", async (ctx) => { await ctx.reply("Telebibz is working."); });
36
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
37
+
38
+ await bot.start();
39
+ ```
40
+
41
+ 运行:
42
+
43
+ ```bash
44
+ npx tsx index.ts
45
+ ```
46
+
47
+ 向 bot 发送 `/start` 或 `ping`。终端会显示 Telebibz branding 和 structured logs。如果日志会被 log collector 读取,请将 logger format 设置为 `json`。
48
+
49
+ ## 4. 添加多步骤 wizard
50
+
51
+ 当回复需要继续处理 active step 时,使用 `Wizard` 和 `bot.useWizard()`。使用 `wizard.run(ctx)` 显式开始 flow:
52
+
53
+ ```ts
54
+ const wizard = new Wizard()
55
+ .step({ id: "name", run: async (flow) => {
56
+ flow.set("name", flow.ctx.message?.text?.trim()).next();
57
+ await flow.ctx.reply("How old are you?");
58
+ }})
59
+ .step({ id: "age", run: async (flow) => {
60
+ const age = Number(flow.ctx.message?.text?.trim());
61
+ if (!Number.isInteger(age)) { await flow.ctx.reply("Send a whole number."); return; }
62
+ flow.set("age", age).next();
63
+ await flow.ctx.reply("Registration complete.");
64
+ }});
65
+
66
+ bot.useWizard(wizard);
67
+ bot.command("register", async (ctx) => {
68
+ await wizard.run(ctx);
69
+ await ctx.reply("What is your name?");
70
+ });
71
+ ```
72
+
73
+ default conversation manager 会在 wizard instance 生命周期内持续使用,key 会根据 chat 和 sender identity 生成。默认情况下,`/cancel` 会取消 active flow。
74
+
75
+ ## 5. Production checklist
76
+
77
+ Webhook 使用 HTTPS,验证 Telegram webhook secret,将 token 保存到 secret manager,配置 structured JSON logs,添加 health checks;如果 session 必须跨重启保留,请使用 persistent storage。部署前运行 `npm run typecheck`、`npm run test:types`、`npm run test:examples`、`npm test`、`npm run build` 和 `npm run security`。
78
+
79
+ ## 下一步
80
+
81
+ - [Runnable examples](../examples/README.md)
82
+ - [完整 API 参考](API.zh-CN.md)
83
+ - [Webhook API](API.zh-CN.md#10-webhook)
84
+ - [Conversation 和 wizard](API.zh-CN.md#8-state-session-and-conversations)
85
+ - [贡献指南](../CONTRIBUTING.md)
package/docs/README.md CHANGED
@@ -10,11 +10,19 @@ The default documentation language is **English**. Translated README and API ref
10
10
 
11
11
  ![telebibz overview](https://cdn.jsdelivr.net/npm/@xbibzlibrary/telebibz@latest/assets/telebibz-readme-preview.png)
12
12
 
13
- The API references are organized by lifecycle: bot startup and shutdown, API client and transport, update routing, middleware and context, state/session, interaction UI, background work, deployment, testing, and migration boundaries.
13
+ The documentation covers the complete lifecycle: onboarding, bot startup and shutdown, API client and transport, update routing, middleware and context, state/session, interaction UI, background work, deployment, testing, and migration boundaries.
14
+
15
+ | Resource | Purpose |
16
+ |---|---|
17
+ | [`GETTING_STARTED.md`](GETTING_STARTED.md) | Five-minute English onboarding from installation to a working bot. |
18
+ | [`GETTING_STARTED.id.md`](GETTING_STARTED.id.md) | Indonesian onboarding guide. |
19
+ | [`GETTING_STARTED.zh-CN.md`](GETTING_STARTED.zh-CN.md) | Simplified Chinese onboarding guide. |
20
+ | [`../examples/README.md`](../examples/README.md) | Runnable minimal, wizard, and webhook starters. |
21
+ | [`../SHOWCASE.md`](../SHOWCASE.md) | Community project showcase and submission format. |
14
22
 
15
23
  | Area | Status |
16
24
  |---|---|
17
- | Getting started | Available in all three README files |
25
+ | Getting started | Dedicated guides are available in English, Indonesian, and Simplified Chinese, with runnable examples. |
18
26
  | Complete API reference | Available in English, Indonesian, and Simplified Chinese |
19
27
  | Bot lifecycle, polling, webhook | Core implementation, per-update error isolation, reconnect backoff, and tests available |
20
28
  | API client and generated method list | Available; full vendored Telegram declarations are exposed through `TelegramTypes` |
@@ -25,8 +33,8 @@ The API references are organized by lifecycle: bot startup and shutdown, API cli
25
33
  | Plugins, services, observability | Lifecycle/plugin/service hooks available |
26
34
  | Mini Apps, payments, business features | Web App signature validation and PaymentsClient wrappers available; UI is application-owned |
27
35
  | Testing and security | Unit, integration, type-level, gated E2E, CI, and security policy available |
28
- | Deployment and migration | Release automation is documented in `RELEASE_AUTOMATION.md` |
29
- | Governance and community | `CODE_OF_CONDUCT.md`, `GOVERNANCE.md`, `CONTRIBUTING.md`, and `CONTRIBUTION_RULES.md` |
36
+ | Deployment and migration | Release automation is documented in `RELEASE_AUTOMATION.md`; webhook and deployment onboarding is in `GETTING_STARTED.md` |
37
+ | Governance and community | `CODE_OF_CONDUCT.md`, `GOVERNANCE.md`, `CONTRIBUTING.md`, `CONTRIBUTION_RULES.md`, and `SHOWCASE.md` |
30
38
  | Security and support | `SECURITY.md` and `SUPPORT.md` |
31
39
  | Third-party notices | `NOTICE.md` and `LICENSE` |
32
40
  | GitHub contribution templates | Bug, feature, documentation, question/support, security notice, and pull request templates under `.github/` |
@@ -0,0 +1,37 @@
1
+ # Telebibz examples
2
+
3
+ These examples are intentionally small, runnable starting points for developers evaluating Telebibz. They use environment variables for secrets and do not contain real Telegram credentials.
4
+
5
+ ## Run the examples
6
+
7
+ From the repository root:
8
+
9
+ ```bash
10
+ npm install
11
+ export TELEGRAM_BOT_TOKEN="<your-bot-token>"
12
+ npx tsx examples/minimal.ts
13
+ ```
14
+
15
+ The official npm package can be used from a separate project by replacing the local import path with `@xbibzlibrary/telebibz` and installing the package from npm.
16
+
17
+ ## Available starters
18
+
19
+ | Example | Demonstrates | Start command |
20
+ |---|---|---|
21
+ | `minimal.ts` | Commands, text routing, and a minimal long-polling bot. | `npx tsx examples/minimal.ts` |
22
+ | `wizard-registration.ts` | A two-step name/age conversation with automatic continuation across messages. | `npx tsx examples/wizard-registration.ts` |
23
+ | `webhook.ts` | A Node.js HTTP server, webhook secret validation, and Telegram update handling. | `TELEGRAM_WEBHOOK_SECRET=<secret> npx tsx examples/webhook.ts` |
24
+
25
+ The wizard example starts the flow with `/register`, asks for a name, then asks for an age. Send `/cancel` to cancel an active flow. The webhook example requires both `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET`; expose the server through HTTPS in a deployment environment and configure the matching Telegram webhook secret.
26
+
27
+ ## Production checklist
28
+
29
+ Use a secret manager or deployment environment for `TELEGRAM_BOT_TOKEN` and `TELEGRAM_WEBHOOK_SECRET`. Do not commit `.env` files or literal credentials. Run `npm run test:examples` before submitting changes. For production deployments, prefer a managed HTTPS endpoint, structured JSON logs, health checks, graceful shutdown, and a persistent storage adapter when conversations or sessions must survive restarts.
30
+
31
+ ## More documentation
32
+
33
+ - [English API reference](../docs/API.md)
34
+ - [Bahasa Indonesia API reference](../docs/API.id.md)
35
+ - [简体中文 API reference](../docs/API.zh-CN.md)
36
+ - [GitHub Packages guide](../docs/GITHUB_PACKAGES.md)
37
+ - [Contributing guide](../CONTRIBUTING.md)
@@ -0,0 +1,12 @@
1
+ import { Bot } from "@xbibzlibrary/telebibz";
2
+
3
+ const token = process.env.TELEGRAM_BOT_TOKEN;
4
+ if (!token) throw new Error("Set TELEGRAM_BOT_TOKEN before starting the example.");
5
+
6
+ const bot = new Bot(token);
7
+
8
+ bot.command("start", async (ctx) => { await ctx.reply("Hello from Telebibz. Send /help to see what I can do."); });
9
+ bot.command("help", async (ctx) => { await ctx.reply("Commands:\n/start — welcome message\n/help — show this help"); });
10
+ bot.onText("ping", async (ctx) => { await ctx.reply("pong"); });
11
+
12
+ await bot.start();
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "rootDir": ".."
6
+ },
7
+ "include": ["./**/*.ts"],
8
+ "exclude": ["node_modules", "dist", "dist-cjs"]
9
+ }
@@ -0,0 +1,42 @@
1
+ import { createServer } from "node:http";
2
+ import { Bot, createWebhookHandler } from "@xbibzlibrary/telebibz";
3
+
4
+ const token = process.env.TELEGRAM_BOT_TOKEN;
5
+ const webhookSecret = process.env.TELEGRAM_WEBHOOK_SECRET;
6
+ const port = Number(process.env.PORT ?? 3000);
7
+
8
+ if (!token) throw new Error("Set TELEGRAM_BOT_TOKEN before starting the example.");
9
+ if (!webhookSecret) throw new Error("Set TELEGRAM_WEBHOOK_SECRET before starting the example.");
10
+ if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error("PORT must be a valid TCP port.");
11
+
12
+ const bot = new Bot(token);
13
+ bot.command("start", async (ctx) => { await ctx.reply("Webhook bot is active."); });
14
+
15
+ const webhook = createWebhookHandler(bot, {
16
+ secretToken: webhookSecret,
17
+ onError: (error) => console.error("Webhook update failed", error),
18
+ });
19
+
20
+ const server = createServer(async (request, response) => {
21
+ try {
22
+ const body = await new Promise<Buffer>((resolve, reject) => {
23
+ const chunks: Buffer[] = [];
24
+ request.on("data", (chunk: Buffer | string) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
25
+ request.on("end", () => resolve(Buffer.concat(chunks)));
26
+ request.on("error", reject);
27
+ });
28
+ const headers = new Headers();
29
+ for (const [key, value] of Object.entries(request.headers)) if (typeof value === "string") headers.set(key, value);
30
+ const requestInit: RequestInit = { method: request.method ?? "GET", headers };
31
+ if (request.method === "POST") requestInit.body = body.toString("utf8");
32
+ const result = await webhook(new Request(`http://${request.headers.host ?? "localhost"}${request.url ?? "/"}`, requestInit));
33
+ response.writeHead(result.status, Object.fromEntries(result.headers));
34
+ response.end(await result.text());
35
+ } catch (error) {
36
+ response.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
37
+ response.end("Internal Server Error");
38
+ console.error("Webhook server failed", error);
39
+ }
40
+ });
41
+
42
+ server.listen(port, () => console.log(`Telebibz webhook listening on http://localhost:${port}`));
@@ -0,0 +1,42 @@
1
+ import { Bot, Wizard } from "@xbibzlibrary/telebibz";
2
+
3
+ const token = process.env.TELEGRAM_BOT_TOKEN;
4
+ if (!token) throw new Error("Set TELEGRAM_BOT_TOKEN before starting the example.");
5
+
6
+ const bot = new Bot(token);
7
+ const wizard = new Wizard();
8
+
9
+ wizard
10
+ .step({
11
+ id: "name",
12
+ run: async (flow) => {
13
+ const name = flow.ctx.message?.text?.trim();
14
+ if (!name) {
15
+ await flow.ctx.reply("Please send your name as text.");
16
+ return;
17
+ }
18
+ flow.set("name", name).next();
19
+ await flow.ctx.reply("How old are you?");
20
+ },
21
+ })
22
+ .step({
23
+ id: "age",
24
+ run: async (flow) => {
25
+ const age = Number(flow.ctx.message?.text?.trim());
26
+ if (!Number.isInteger(age) || age < 1 || age > 120) {
27
+ await flow.ctx.reply("Please send a valid age between 1 and 120.");
28
+ return;
29
+ }
30
+ const name = flow.get<string>("name") ?? "there";
31
+ flow.set("age", age).next();
32
+ await flow.ctx.reply(`Thanks, ${name}. Your registration is complete.`);
33
+ },
34
+ });
35
+
36
+ bot.useWizard(wizard);
37
+ bot.command("register", async (ctx) => {
38
+ await wizard.run(ctx);
39
+ await ctx.reply("What is your name?");
40
+ });
41
+
42
+ await bot.start();
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "@xbibzlibrary/telebibz",
3
- "version": "0.1.18",
4
- "description": "Production-grade, strongly typed Telegram Bot API SDK and framework for Node.js and TypeScript.",
3
+ "version": "0.1.19",
4
+ "description": "Production-grade Telegram Bot framework for Node.js and TypeScript with typed API, routing, webhooks, keyboards, conversations, plugins, queues, and colorful CLI logs.",
5
+ "keywords": [
6
+ "telegram",
7
+ "telegram-bot",
8
+ "telegram-bot-api",
9
+ "telegram-bot-framework",
10
+ "nodejs",
11
+ "typescript",
12
+ "telegram-webhook",
13
+ "long-polling",
14
+ "conversation-wizard",
15
+ "inline-keyboard",
16
+ "telegram-mini-app",
17
+ "bot-framework"
18
+ ],
5
19
  "type": "module",
6
20
  "private": false,
7
21
  "publishConfig": {
@@ -31,6 +45,7 @@
31
45
  "test:integration": "vitest run tests/integration/**/*.test.ts",
32
46
  "test:e2e": "vitest run tests/e2e",
33
47
  "test:types": "tsc -p tests/tsconfig.json --noEmit",
48
+ "test:examples": "tsc -p examples/tsconfig.json --noEmit",
34
49
  "benchmark": "tsx tests/benchmark.ts",
35
50
  "package:check": "npm run build && npm pack --dry-run",
36
51
  "security": "npm audit --audit-level=high --package-lock-only",
@@ -39,7 +54,7 @@
39
54
  "start": "tsx src/cli.ts start",
40
55
  "dev": "tsx examples/minimal.ts",
41
56
  "prepack": "npm run build",
42
- "prepublishOnly": "npm run typecheck && npm run test:types && npm run lint && npm test && npm run build && npm run security && npm run release:check"
57
+ "prepublishOnly": "npm run typecheck && npm run test:types && npm run test:examples && npm run lint && npm test && npm run build && npm run security && npm run release:check"
43
58
  },
44
59
  "bin": {
45
60
  "telebibz": "./bin/telebibz.mjs"
@@ -84,8 +99,10 @@
84
99
  "NOTICE.md",
85
100
  "RELEASE_POLICY.md",
86
101
  "RELEASE_AUTOMATION.md",
102
+ "SHOWCASE.md",
87
103
  "assets",
88
- "docs"
104
+ "docs",
105
+ "examples"
89
106
  ],
90
107
  "devDependencies": {
91
108
  "@types/node": "^22.10.0",