@xbibzlibrary/telebibz 0.4.5 → 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 -256
- 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 -306
- package/README.zh-CN.md +0 -306
- 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/COOKBOOK.id.md +0 -321
- package/docs/COOKBOOK.md +0 -321
- package/docs/COOKBOOK.zh-CN.md +0 -321
- package/docs/ERRORS.id.md +0 -194
- package/docs/ERRORS.md +0 -194
- package/docs/ERRORS.zh-CN.md +0 -194
- package/docs/FILES.id.md +0 -243
- package/docs/FILES.md +0 -243
- package/docs/FILES.zh-CN.md +0 -243
- package/docs/GETTING_STARTED.id.md +0 -89
- package/docs/GETTING_STARTED.md +0 -89
- package/docs/GETTING_STARTED.zh-CN.md +0 -89
- 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/MIGRATION_TELEGRAF.id.md +0 -147
- package/docs/MIGRATION_TELEGRAF.md +0 -154
- package/docs/MIGRATION_TELEGRAF.zh-CN.md +0 -147
- package/docs/README.md +0 -67
- package/docs/STORAGE.id.md +0 -105
- package/docs/STORAGE.md +0 -105
- package/docs/STORAGE.zh-CN.md +0 -105
- package/docs/TESTING.id.md +0 -203
- package/docs/TESTING.md +0 -203
- package/docs/TESTING.zh-CN.md +0 -203
- package/docs/WEBHOOK.id.md +0 -212
- package/docs/WEBHOOK.md +0 -215
- package/docs/WEBHOOK.zh-CN.md +0 -212
- 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
|
@@ -1,89 +0,0 @@
|
|
|
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
|
-
- [文件:上传与下载](FILES.zh-CN.md)
|
|
84
|
-
- [错误处理与限流](ERRORS.zh-CN.md)
|
|
85
|
-
- [Webhook 部署](WEBHOOK.zh-CN.md)
|
|
86
|
-
- [离线测试你的 bot](TESTING.zh-CN.md)
|
|
87
|
-
- [从 Telegraf 迁移](MIGRATION_TELEGRAF.zh-CN.md)
|
|
88
|
-
- [生产实战手册](COOKBOOK.zh-CN.md)
|
|
89
|
-
- [贡献指南](../CONTRIBUTING.md)
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# GitHub Packages
|
|
2
|
-
|
|
3
|
-
`@xbibzlibrary/telebibz` dirilis ke [npmjs](https://www.npmjs.com/package/@xbibzlibrary/telebibz) dan registry npm GitHub Packages. Repository GitHub resminya adalah [XbibzOfficial777/telebibz](https://github.com/XbibzOfficial777/telebibz).
|
|
4
|
-
|
|
5
|
-
## Registry
|
|
6
|
-
|
|
7
|
-
URL registry GitHub Packages:
|
|
8
|
-
|
|
9
|
-
```text
|
|
10
|
-
https://npm.pkg.github.com
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Mapping scope npm:
|
|
14
|
-
|
|
15
|
-
```ini
|
|
16
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Workflow release mempublikasikan tarball yang sama ke npmjs dan GitHub Packages setelah typecheck, test, build, security audit, dan release check berhasil. Workflow menggunakan `GITHUB_TOKEN` dengan permission `packages: write`; personal access token GitHub tidak disimpan di repository atau workflow.
|
|
20
|
-
|
|
21
|
-
## Instalasi package
|
|
22
|
-
|
|
23
|
-
Untuk package public, tambahkan mapping berikut pada `.npmrc` project yang memakai package:
|
|
24
|
-
|
|
25
|
-
```ini
|
|
26
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Jika package atau repository bersifat private, gunakan **personal access token (classic)** dengan minimal akses `read:packages`. Simpan token di luar repository, sebaiknya melalui environment variable reference pada konfigurasi npm user:
|
|
30
|
-
|
|
31
|
-
```ini
|
|
32
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
33
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Kemudian jalankan:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
export GITHUB_PACKAGES_TOKEN="<token-read-packages-kamu>"
|
|
40
|
-
npm install @xbibzlibrary/telebibz
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Jangan mengganti placeholder dengan token asli di file yang di-commit. Jangan commit `.npmrc` yang berisi kredensial literal, dan jangan memasukkan token ke issue, pull request, log, atau chat.
|
|
44
|
-
|
|
45
|
-
## Publikasi lokal
|
|
46
|
-
|
|
47
|
-
Cara yang direkomendasikan adalah workflow GitHub Actions yang telah dilindungi. Workflow memeriksa versi dan hanya publish setelah seluruh release gate berhasil. Publikasi lokal hanya untuk maintainer yang memiliki personal access token (classic) dengan `write:packages` serta permission repository:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
export GITHUB_PACKAGES_TOKEN="<token-write-packages-kamu>"
|
|
51
|
-
printf '@xbibzlibrary:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}\n' > "$HOME/.npmrc"
|
|
52
|
-
npm run build
|
|
53
|
-
npm pack
|
|
54
|
-
npm publish ./xbibzlibrary-telebibz-<version>.tgz --registry=https://npm.pkg.github.com --access public
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Gunakan semantic version baru untuk setiap publikasi. Versi registry bersifat immutable dan tidak boleh ditimpa.
|
|
58
|
-
|
|
59
|
-
## Permission GitHub Actions
|
|
60
|
-
|
|
61
|
-
Workflow release menggunakan permission minimum berikut:
|
|
62
|
-
|
|
63
|
-
```yaml
|
|
64
|
-
permissions:
|
|
65
|
-
contents: write
|
|
66
|
-
packages: write
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`NPM_TOKEN` tetap menjadi environment secret untuk publikasi ke npmjs. GitHub Packages menggunakan `GITHUB_TOKEN` otomatis, sehingga tidak memerlukan secret GitHub tambahan untuk package milik repository ini. Jika kebijakan organisasi menonaktifkan pewarisan akses package, hubungkan package ke repository dan berikan akses workflow melalui pengaturan package.
|
|
70
|
-
|
|
71
|
-
## Troubleshooting
|
|
72
|
-
|
|
73
|
-
Respons `401 Unauthorized` biasanya berarti token tidak ada, sudah kedaluwarsa, atau tidak mempunyai scope package yang benar. Respons `403 Forbidden` biasanya berarti akun atau workflow tidak memiliki permission package, atau kebijakan organisasi memblokir publikasi. Respons `404 Not Found` dapat muncul ketika package private diakses tanpa autentikasi atau scope belum diarahkan ke `https://npm.pkg.github.com`.
|
|
74
|
-
|
|
75
|
-
Untuk instalasi dari npmjs, hapus mapping GitHub scope atau gunakan registry npm default. Kedua registry berisi nama package dan versi yang sama, tetapi autentikasi dan access control dikelola secara terpisah.
|
|
76
|
-
|
|
77
|
-
## Referensi
|
|
78
|
-
|
|
79
|
-
1. [Working with the npm registry — GitHub Docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry)
|
|
80
|
-
2. [About permissions for GitHub Packages — GitHub Docs](https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages)
|
|
81
|
-
3. [Publishing and installing a package with GitHub Actions — GitHub Docs](https://docs.github.com/en/packages/quickstart)
|
|
82
|
-
4. [npm package.json publishConfig — npm Docs](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#publishconfig)
|
package/docs/GITHUB_PACKAGES.md
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# GitHub Packages
|
|
2
|
-
|
|
3
|
-
`@xbibzlibrary/telebibz` is released to both [npmjs](https://www.npmjs.com/package/@xbibzlibrary/telebibz) and the GitHub Packages npm registry. The canonical GitHub repository is [XbibzOfficial777/telebibz](https://github.com/XbibzOfficial777/telebibz).
|
|
4
|
-
|
|
5
|
-
## Registry
|
|
6
|
-
|
|
7
|
-
GitHub Packages uses the following npm registry URL:
|
|
8
|
-
|
|
9
|
-
```text
|
|
10
|
-
https://npm.pkg.github.com
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
The package scope is mapped to GitHub Packages with:
|
|
14
|
-
|
|
15
|
-
```ini
|
|
16
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
The release workflow publishes the same verified tarball to npmjs and GitHub Packages after the type checks, tests, build, security audit, and release checks pass. The workflow uses `GITHUB_TOKEN` with `packages: write`; no GitHub personal access token is stored in the repository or workflow file.
|
|
20
|
-
|
|
21
|
-
## Installing the package
|
|
22
|
-
|
|
23
|
-
For a public package, use a GitHub Packages-aware `.npmrc` in the consuming project:
|
|
24
|
-
|
|
25
|
-
```ini
|
|
26
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
If the package or repository is private, authenticate with a **personal access token (classic)** that has at least `read:packages` access. Store the token outside the repository, preferably in the user-level npm configuration or an environment-variable reference:
|
|
30
|
-
|
|
31
|
-
```ini
|
|
32
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
33
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Then install the package:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
export GITHUB_PACKAGES_TOKEN="<your-read-packages-token>"
|
|
40
|
-
npm install @xbibzlibrary/telebibz
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Do not replace the placeholder with a real token in a committed file. Do not commit `.npmrc` files containing literal credentials, and do not paste tokens into issues, pull requests, logs, or chat.
|
|
44
|
-
|
|
45
|
-
## Publishing locally
|
|
46
|
-
|
|
47
|
-
The recommended publishing path is the protected GitHub Actions workflow. It verifies the version and publishes only after all release gates succeed. Local publishing is intended for maintainers who have a classic personal access token with `write:packages` and repository permission to publish packages:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
export GITHUB_PACKAGES_TOKEN="<your-write-packages-token>"
|
|
51
|
-
printf '@xbibzlibrary:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}\n' > "$HOME/.npmrc"
|
|
52
|
-
npm run build
|
|
53
|
-
npm pack
|
|
54
|
-
npm publish ./xbibzlibrary-telebibz-<version>.tgz --registry=https://npm.pkg.github.com --access public
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Use a new semantic version for every publication. Registry versions are immutable; an existing version must never be overwritten.
|
|
58
|
-
|
|
59
|
-
## GitHub Actions permissions
|
|
60
|
-
|
|
61
|
-
The release workflow declares the minimum package permission required for publication:
|
|
62
|
-
|
|
63
|
-
```yaml
|
|
64
|
-
permissions:
|
|
65
|
-
contents: write
|
|
66
|
-
packages: write
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`NPM_TOKEN` remains an environment secret for npmjs publication. GitHub Packages uses the automatically provided `GITHUB_TOKEN`, so no additional GitHub token secret is required for the repository's own package. If organization policy disables automatic package access inheritance, connect the package to the repository and grant the workflow access under the package's settings.
|
|
70
|
-
|
|
71
|
-
## Troubleshooting
|
|
72
|
-
|
|
73
|
-
A `401 Unauthorized` response normally means the token is missing, expired, or lacks the required package scope. A `403 Forbidden` response usually means the account or workflow does not have permission to the package, or that organization policy blocks publication. A `404 Not Found` response can occur when a private package is queried without authentication or when the scope is not mapped to `https://npm.pkg.github.com`.
|
|
74
|
-
|
|
75
|
-
For npmjs installation, omit the GitHub scope mapping or use the default npm registry. Both registries contain the same package name and release version, but authentication and access control are handled independently.
|
|
76
|
-
|
|
77
|
-
## References
|
|
78
|
-
|
|
79
|
-
1. [Working with the npm registry — GitHub Docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry)
|
|
80
|
-
2. [About permissions for GitHub Packages — GitHub Docs](https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages)
|
|
81
|
-
3. [Publishing and installing a package with GitHub Actions — GitHub Docs](https://docs.github.com/en/packages/quickstart)
|
|
82
|
-
4. [npm package.json publishConfig — npm Docs](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#publishconfig)
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# GitHub Packages
|
|
2
|
-
|
|
3
|
-
`@xbibzlibrary/telebibz` 同时发布到 [npmjs](https://www.npmjs.com/package/@xbibzlibrary/telebibz) 和 GitHub Packages npm registry。官方 GitHub 仓库是 [XbibzOfficial777/telebibz](https://github.com/XbibzOfficial777/telebibz)。
|
|
4
|
-
|
|
5
|
-
## Registry
|
|
6
|
-
|
|
7
|
-
GitHub Packages 使用以下 npm registry 地址:
|
|
8
|
-
|
|
9
|
-
```text
|
|
10
|
-
https://npm.pkg.github.com
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
npm scope 映射如下:
|
|
14
|
-
|
|
15
|
-
```ini
|
|
16
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
release workflow 会在 typecheck、测试、构建、安全审计和 release check 全部通过后,将同一个经过验证的 tarball 发布到 npmjs 和 GitHub Packages。workflow 使用具有 `packages: write` 权限的 `GITHUB_TOKEN`,不会把 GitHub personal access token 存储在仓库或 workflow 文件中。
|
|
20
|
-
|
|
21
|
-
## 安装 package
|
|
22
|
-
|
|
23
|
-
对于 public package,可以在使用方项目的 `.npmrc` 中加入:
|
|
24
|
-
|
|
25
|
-
```ini
|
|
26
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
如果 package 或 repository 是 private,请使用具有至少 `read:packages` 权限的 **personal access token (classic)**。请将 token 保存在仓库之外,建议使用 npm 用户配置中的环境变量引用:
|
|
30
|
-
|
|
31
|
-
```ini
|
|
32
|
-
@xbibzlibrary:registry=https://npm.pkg.github.com
|
|
33
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
然后执行:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
export GITHUB_PACKAGES_TOKEN="<your-read-packages-token>"
|
|
40
|
-
npm install @xbibzlibrary/telebibz
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
不要把真实 token 写入已经提交的文件。不要提交包含明文凭据的 `.npmrc`,也不要在 issue、pull request、日志或聊天中粘贴 token。
|
|
44
|
-
|
|
45
|
-
## 本地发布
|
|
46
|
-
|
|
47
|
-
推荐使用受保护的 GitHub Actions workflow 发布。workflow 会检查版本,并且只有所有 release gate 成功后才会发布。本地发布仅适用于拥有 `write:packages` classic token 以及 repository 发布权限的 maintainer:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
export GITHUB_PACKAGES_TOKEN="<your-write-packages-token>"
|
|
51
|
-
printf '@xbibzlibrary:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}\n' > "$HOME/.npmrc"
|
|
52
|
-
npm run build
|
|
53
|
-
npm pack
|
|
54
|
-
npm publish ./xbibzlibrary-telebibz-<version>.tgz --registry=https://npm.pkg.github.com --access public
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
每次发布必须使用新的 semantic version。registry 中的版本是 immutable,不能覆盖已有版本。
|
|
58
|
-
|
|
59
|
-
## GitHub Actions 权限
|
|
60
|
-
|
|
61
|
-
release workflow 声明了发布所需的最小权限:
|
|
62
|
-
|
|
63
|
-
```yaml
|
|
64
|
-
permissions:
|
|
65
|
-
contents: write
|
|
66
|
-
packages: write
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`NPM_TOKEN` 仍然作为 npmjs 发布所需的 environment secret。GitHub Packages 使用自动提供的 `GITHUB_TOKEN`,因此本仓库的 package 不需要额外的 GitHub token secret。如果组织策略关闭了 package 权限自动继承,请在 package 设置中连接 repository,并授予 workflow 访问权限。
|
|
70
|
-
|
|
71
|
-
## 故障排查
|
|
72
|
-
|
|
73
|
-
`401 Unauthorized` 通常表示 token 缺失、过期或没有正确的 package scope。`403 Forbidden` 通常表示账号或 workflow 没有 package 权限,或者组织策略禁止发布。访问 private package 时没有认证,或 scope 没有映射到 `https://npm.pkg.github.com`,也可能得到 `404 Not Found`。
|
|
74
|
-
|
|
75
|
-
从 npmjs 安装时,请删除 GitHub scope mapping 或使用默认 npm registry。两个 registry 包含相同的 package 名称和版本,但认证和 access control 独立管理。
|
|
76
|
-
|
|
77
|
-
## 参考资料
|
|
78
|
-
|
|
79
|
-
1. [Working with the npm registry — GitHub Docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry)
|
|
80
|
-
2. [About permissions for GitHub Packages — GitHub Docs](https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages)
|
|
81
|
-
3. [Publishing and installing a package with GitHub Actions — GitHub Docs](https://docs.github.com/en/packages/quickstart)
|
|
82
|
-
4. [npm package.json publishConfig — npm Docs](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#publishconfig)
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# Migrasi dari Telegraf (Bahasa Indonesia)
|
|
2
|
-
|
|
3
|
-
telebibz mengimplementasikan surface context dan opsi launch Telegraf secara sengaja, sehingga sebagian besar handler bisa dipindah dengan sedikit atau tanpa perubahan. Panduan ini memetakan setiap bagian bot Telegraf ke padanannya di telebibz.
|
|
4
|
-
|
|
5
|
-
## Daftar isi
|
|
6
|
-
|
|
7
|
-
1. [Side-by-side: satu bot utuh](#1-side-by-side-satu-bot-utuh)
|
|
8
|
-
2. [Peta konsep](#2-peta-konsep)
|
|
9
|
-
3. [Method Context](#3-method-context)
|
|
10
|
-
4. [Opsi launch](#4-opsi-launch)
|
|
11
|
-
5. [Scenes → Wizards](#5-scenes--wizards)
|
|
12
|
-
6. [Penyimpanan session](#6-penyimpanan-session)
|
|
13
|
-
7. [Webhook](#7-webhook)
|
|
14
|
-
8. [Yang tidak punya ekuivalen langsung](#8-yang-tidak-punya-ekuivalen-langsung)
|
|
15
|
-
|
|
16
|
-
## 1. Side-by-side: satu bot utuh
|
|
17
|
-
|
|
18
|
-
**Telegraf**
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { Telegraf } from "telegraf";
|
|
22
|
-
|
|
23
|
-
const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN!);
|
|
24
|
-
|
|
25
|
-
bot.use(async (ctx, next) => { console.time("update"); await next(); console.timeEnd("update"); });
|
|
26
|
-
bot.start((ctx) => ctx.reply("Welcome!"));
|
|
27
|
-
bot.command("help", (ctx) => ctx.reply("Help"));
|
|
28
|
-
bot.action("menu:open", async (ctx) => { await ctx.answerCbQuery(); await ctx.reply("Menu"); });
|
|
29
|
-
bot.on("message", (ctx) => ctx.reply("got it"));
|
|
30
|
-
bot.catch((error) => console.error(error));
|
|
31
|
-
|
|
32
|
-
bot.launch({ dropPendingUpdates: true });
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**telebibz**
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { Bot } from "@xbibzlibrary/telebibz";
|
|
39
|
-
|
|
40
|
-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
|
|
41
|
-
|
|
42
|
-
bot.use(async (ctx, next) => { console.time("update"); await next(); console.timeEnd("update"); });
|
|
43
|
-
bot.command("start", async (ctx) => { await ctx.reply("Welcome!"); }); // command bernama, bukan bot.start()
|
|
44
|
-
bot.command("help", async (ctx) => { await ctx.reply("Help"); });
|
|
45
|
-
bot.action("menu:open", async (ctx) => { await ctx.answerCallbackQuery(); await ctx.reply("Menu"); });
|
|
46
|
-
bot.on("message", async (ctx) => { await ctx.reply("got it"); });
|
|
47
|
-
bot.catch(async (error) => { console.error(error); });
|
|
48
|
-
|
|
49
|
-
await bot.launch({ dropPendingUpdates: true }); // nama opsi sama
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Hanya dua perbedaan mekanis: `bot.start(handler)` menjadi `bot.command("start", handler)`, dan `answerCbQuery()` menjadi `answerCallbackQuery()`.
|
|
53
|
-
|
|
54
|
-
## 2. Peta konsep
|
|
55
|
-
|
|
56
|
-
| Telegraf | telebibz | Catatan |
|
|
57
|
-
|---|---|---|
|
|
58
|
-
| `new Telegraf(token)` | `new Bot(token)` atau `new Bot({ token, ... })` | |
|
|
59
|
-
| `bot.launch()` | `bot.launch()` / `bot.start()` | `mode: "polling"` eksplisit di `launch` |
|
|
60
|
-
| `bot.stop()` | `bot.stop()` | telebibz men-drain handler yang sedang berjalan lebih dulu |
|
|
61
|
-
| `bot.use(mw)` | `bot.use(mw)` | signature middleware sama `(ctx, next)` |
|
|
62
|
-
| `bot.command(name, h)` | `bot.command(name, h)` | |
|
|
63
|
-
| `bot.on(filter, h)` | `bot.on(filter, h)` | grammar filter sama (`message:photo`, array) |
|
|
64
|
-
| `bot.hears(trigger, h)` | `bot.hears(trigger, h)` | string dan RegExp |
|
|
65
|
-
| `bot.action(pattern, h)` | `bot.action(pattern, h)` | alias drop-in dari `bot.callback` |
|
|
66
|
-
| `bot.catch(handler)` | `bot.catch(handler)` | menerima `(error, ctx)` |
|
|
67
|
-
|
|
68
|
-
## 3. Method Context
|
|
69
|
-
|
|
70
|
-
Setiap shortcut context Telegraf ada — termasuk yang di Telegraf diserahkan ke plugin:
|
|
71
|
-
|
|
72
|
-
- **Balasan**: `reply`, `replyWithPhoto`, `replyWithDocument`, `replyWithVideo`, `replyWithAudio`, `replyWithVoice`, `replyWithAnimation`, `replyWithVideoNote`, `replyWithSticker`, `replyWithMediaGroup`, `replyWithLocation`, `replyWithVenue`, `replyWithContact`, `replyWithPoll`, `replyWithQuiz`, `replyWithDice`, `replyWithGame`, `replyWithInvoice`, `replyWithHTML`, `replyWithMarkdown` (+V2)
|
|
73
|
-
- **Admin/moderasi**: `banChatMember`, `unbanChatMember`, `restrictChatMember`, `promoteChatMember`, `banChatSenderChat`, `unbanChatSenderChat`
|
|
74
|
-
- **Chat**: `setChatTitle`, `setChatDescription`, `setChatPhoto`, `deleteChatPhoto`, `setChatPermissions`, `leaveChat`, `unpinAllChatMessages`, `setChatStickerSet`, `deleteChatStickerSet`
|
|
75
|
-
- **Info**: `getChat`, `getChatAdministrators`, `getChatMemberCount`, `getChatMember`
|
|
76
|
-
- **Invite link/join request**: `exportChatInviteLink`, `createChatInviteLink`, `editChatInviteLink`, `revokeChatInviteLink`, `approveChatJoinRequest`, `declineChatJoinRequest`
|
|
77
|
-
- **Live location/poll/game**: `editMessageLiveLocation`, `stopMessageLiveLocation`, `stopPoll`, `setGameScore`, `getGameHighScores`
|
|
78
|
-
- **Forum**: set topik lengkap (`createForumTopic` … `unhideGeneralForumTopic`)
|
|
79
|
-
- **Baru, melampaui core Telegraf**: `getFile` (typed), `downloadFile`, `edit` (menulis ulang teks pesan saat ini), plus helper mandiri yang diekspor dari root paket — `validateUpload`/`assertValidUpload` — yang bukan method context
|
|
80
|
-
|
|
81
|
-
Perbedaan penamaan yang harus diperbaiki saat porting: `answerCbQuery` → `answerCallbackQuery`; `ctx.telegram` → `ctx.api`; helper keyboard berasal dari root paket (`InlineKeyboard`, `ReplyKeyboard`, `removeKeyboard`, `forceReply`) alih-alih `Markup`.
|
|
82
|
-
|
|
83
|
-
## 4. Opsi launch
|
|
84
|
-
|
|
85
|
-
| Telegraf | telebibz |
|
|
86
|
-
|---|---|
|
|
87
|
-
| `launch({ dropPendingUpdates })` | `launch({ dropPendingUpdates })` — identik |
|
|
88
|
-
| `handlerTimeout` (default 90 000) | `handlerTimeout` (default 90 000; `0` menonaktifkan) |
|
|
89
|
-
| Opsi `contextType` | Opsi `contextType` — subclass `Context` Anda diinstansiasi untuk setiap update |
|
|
90
|
-
| `webhookReply` (per-update) | `webhookReply` pada opsi handler / `handleUpdate` |
|
|
91
|
-
| `telegraf.use(session(...))` | `new Bot({ session: new MemoryStorage() })` (atau JSON/Redis/SQL/Mongo) |
|
|
92
|
-
|
|
93
|
-
## 5. Scenes → Wizards
|
|
94
|
-
|
|
95
|
-
`WizardScene` + `Stage` milik Telegraf menjadi satu `Wizard` dengan step eksplisit dan tanpa kunci session global:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
import { Bot, Wizard } from "@xbibzlibrary/telebibz";
|
|
99
|
-
|
|
100
|
-
const wizard = new Wizard()
|
|
101
|
-
.step({ id: "ask-name", run: async (flow) => { flow.next(); await flow.ctx.reply("Nama?"); } })
|
|
102
|
-
.step({ id: "save", run: async (flow) => { await flow.ctx.reply(`Hai ${flow.ctx.message?.text}!`); } });
|
|
103
|
-
|
|
104
|
-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
|
|
105
|
-
bot.useWizard(wizard); // menggantikan middleware Stage
|
|
106
|
-
bot.command("start", async (ctx) => { await wizard.run(ctx); }); // menggantikan scene.enter()
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
- Kunci wizard diturunkan otomatis dari chat + pengirim — tanpa pengelolaan kunci manual.
|
|
110
|
-
- `flow.set(key, value)` / `flow.get(key)` menggantikan `ctx.scene.session`.
|
|
111
|
-
- `/cancel` membatalkan; conversation selesai otomatis setelah step terakhir.
|
|
112
|
-
- Untuk graf non-linear, susun `ConversationManager` dengan router (telebibz sengaja menjadikan orkestrasi scene milik aplikasi; lihat "Design decisions" di FEATURE_MATRIX).
|
|
113
|
-
|
|
114
|
-
## 6. Penyimpanan session
|
|
115
|
-
|
|
116
|
-
Telegraf menyimpan session di memori secara default dan butuh plugin store untuk persistensi. telebibz menerima storage di constructor — ganti adapter, pertahankan kode:
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
import { Bot, MemoryStorage, JsonFileStorage, RedisStorage } from "@xbibzlibrary/telebibz";
|
|
120
|
-
|
|
121
|
-
const bot = new Bot({
|
|
122
|
-
token: process.env.TELEGRAM_BOT_TOKEN!,
|
|
123
|
-
session: new JsonFileStorage("state/sessions.json"), // atau MemoryStorage / RedisStorage / SqlStorage / MongoStorage
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Resep wiring lengkap untuk setiap adapter: [STORAGE.id.md](STORAGE.id.md).
|
|
128
|
-
|
|
129
|
-
## 7. Webhook
|
|
130
|
-
|
|
131
|
-
```ts
|
|
132
|
-
// Telegraf: webhookCallback(bot, app)
|
|
133
|
-
// telebibz: framework eksplisit
|
|
134
|
-
import { webhookCallback } from "@xbibzlibrary/telebibz";
|
|
135
|
-
app.post("/telegram", webhookCallback(bot, "express", { secretToken: process.env.TELEGRAM_WEBHOOK_SECRET }));
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
`createWebhookHandler()` tambahan menyediakan handler Web-standard `Request → Response` untuk Bun/Deno/edge. Panduan deployment lengkap: [WEBHOOK.id.md](WEBHOOK.id.md).
|
|
139
|
-
|
|
140
|
-
## 8. Yang tidak punya ekuivalen langsung
|
|
141
|
-
|
|
142
|
-
- **Client low-level `bot.telegram`** — pakai `bot.api` (`call`, `raw`, `methods`, `downloadFile`); flood gate dan retry terpasang di transport, bukan dikonfigurasi per panggilan.
|
|
143
|
-
- **Ekosistem plugin Telegraf** — port plugin sebagai objek `Plugin` dengan lifecycle eksplisit (`install`, `onStop`, `dispose`); plugin manager di-restart dengan bersih.
|
|
144
|
-
- **`Composer.mount`/scene dinamis** — bangun dengan nesting `Router` dan `matchMode: "all"`.
|
|
145
|
-
- **Rantai helper Markup** (`Markup.keyboard(...).resize()`) — pakai `new ReplyKeyboard().text("A").resized().build()`; payload sama, gaya builder.
|
|
146
|
-
|
|
147
|
-
English: [MIGRATION_TELEGRAF.md](MIGRATION_TELEGRAF.md) · 简体中文: [MIGRATION_TELEGRAF.zh-CN.md](MIGRATION_TELEGRAF.zh-CN.md)
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
# Migrating from Telegraf (English)
|
|
2
|
-
|
|
3
|
-
telebibz implements the Telegraf context surface and launch options deliberately, so most handlers port with little or no change. This guide maps every part of a Telegraf bot to its telebibz equivalent.
|
|
4
|
-
|
|
5
|
-
## Contents
|
|
6
|
-
|
|
7
|
-
1. [Side-by-side: a whole bot](#1-side-by-side-a-whole-bot)
|
|
8
|
-
2. [Concept map](#2-concept-map)
|
|
9
|
-
3. [Context methods](#3-context-methods)
|
|
10
|
-
4. [Launch options](#4-launch-options)
|
|
11
|
-
5. [Scenes → Wizards](#5-scenes--wizards)
|
|
12
|
-
6. [Session storage](#6-session-storage)
|
|
13
|
-
7. [Webhooks](#7-webhooks)
|
|
14
|
-
8. [What has no direct equivalent](#8-what-has-no-direct-equivalent)
|
|
15
|
-
|
|
16
|
-
## 1. Side-by-side: a whole bot
|
|
17
|
-
|
|
18
|
-
**Telegraf**
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { Telegraf } from "telegraf";
|
|
22
|
-
|
|
23
|
-
const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN!);
|
|
24
|
-
|
|
25
|
-
bot.use(async (ctx, next) => { console.time("update"); await next(); console.timeEnd("update"); });
|
|
26
|
-
bot.start((ctx) => ctx.reply("Welcome!"));
|
|
27
|
-
bot.command("help", (ctx) => ctx.reply("Help"));
|
|
28
|
-
bot.action("menu:open", async (ctx) => { await ctx.answerCbQuery(); await ctx.reply("Menu"); });
|
|
29
|
-
bot.on("message", (ctx) => ctx.reply("got it"));
|
|
30
|
-
bot.catch((error) => console.error(error));
|
|
31
|
-
|
|
32
|
-
bot.launch({ dropPendingUpdates: true });
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**telebibz**
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { Bot } from "@xbibzlibrary/telebibz";
|
|
39
|
-
|
|
40
|
-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
|
|
41
|
-
|
|
42
|
-
bot.use(async (ctx, next) => { console.time("update"); await next(); console.timeEnd("update"); });
|
|
43
|
-
bot.command("start", async (ctx) => { await ctx.reply("Welcome!"); }); // named command, not bot.start()
|
|
44
|
-
bot.command("help", async (ctx) => { await ctx.reply("Help"); });
|
|
45
|
-
bot.action("menu:open", async (ctx) => { await ctx.answerCallbackQuery(); await ctx.reply("Menu"); });
|
|
46
|
-
bot.on("message", async (ctx) => { await ctx.reply("got it"); });
|
|
47
|
-
bot.catch(async (error) => { console.error(error); });
|
|
48
|
-
|
|
49
|
-
await bot.launch({ dropPendingUpdates: true }); // same option name
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Only two mechanical differences: `bot.start(handler)` becomes `bot.command("start", handler)`, and `answerCbQuery()` becomes `answerCallbackQuery()`.
|
|
53
|
-
|
|
54
|
-
## 2. Concept map
|
|
55
|
-
|
|
56
|
-
| Telegraf | telebibz | Notes |
|
|
57
|
-
|---|---|---|
|
|
58
|
-
| `new Telegraf(token)` | `new Bot(token)` or `new Bot({ token, ... })` | |
|
|
59
|
-
| `bot.launch()` | `bot.launch()` / `bot.start()` | `mode: "polling"` is explicit on `launch` |
|
|
60
|
-
| `bot.stop()` | `bot.stop()` | telebibz drains in-flight handlers first |
|
|
61
|
-
| `bot.use(mw)` | `bot.use(mw)` | same middleware signature `(ctx, next)` |
|
|
62
|
-
| `bot.command(name, h)` | `bot.command(name, h)` | |
|
|
63
|
-
| `bot.on(filter, h)` | `bot.on(filter, h)` | same filter grammar (`message:photo`, arrays) |
|
|
64
|
-
| `bot.hears(trigger, h)` | `bot.hears(trigger, h)` | strings and RegExp |
|
|
65
|
-
| `bot.action(pattern, h)` | `bot.action(pattern, h)` | drop-in alias of `bot.callback` |
|
|
66
|
-
| `bot.catch(handler)` | `bot.catch(handler)` | receives `(error, ctx)` |
|
|
67
|
-
| `ctx.reply(text, extra)` | `ctx.reply(text, extra)` | |
|
|
68
|
-
| `ctx.telegram.callApi(m, p)` | `ctx.api.call(m, p)` / `ctx.api.raw(m, p)` | `raw` needs no type map entry |
|
|
69
|
-
| `ctx.telegram.api.config` | `transportOptions` on the `Bot` options | timeout, retries, flood gate |
|
|
70
|
-
| `Scenes.WizardScene` + `Stage` | `Wizard` + `bot.useWizard()` | see section 5 |
|
|
71
|
-
| `session` middleware | built-in `session` storage option | see section 6 |
|
|
72
|
-
| `webhookCallback(bot, app)` | `webhookCallback(bot, "express")` | framework is now an argument |
|
|
73
|
-
| Telegraf plugins (`telegraf-i18n`, …) | `bot.usePlugin({ install, onStop, dispose })` | explicit lifecycle |
|
|
74
|
-
|
|
75
|
-
## 3. Context methods
|
|
76
|
-
|
|
77
|
-
Every Telegraf context shortcut exists — including the ones Telegraf leaves to plugins:
|
|
78
|
-
|
|
79
|
-
- **Replies**: `reply`, `replyWithPhoto`, `replyWithDocument`, `replyWithVideo`, `replyWithAudio`, `replyWithVoice`, `replyWithAnimation`, `replyWithVideoNote`, `replyWithSticker`, `replyWithMediaGroup`, `replyWithLocation`, `replyWithVenue`, `replyWithContact`, `replyWithPoll`, `replyWithQuiz`, `replyWithDice`, `replyWithGame`, `replyWithInvoice`, `replyWithHTML`, `replyWithMarkdown` (+V2)
|
|
80
|
-
- **Admin/moderation**: `banChatMember`, `unbanChatMember`, `restrictChatMember`, `promoteChatMember`, `banChatSenderChat`, `unbanChatSenderChat`
|
|
81
|
-
- **Chat**: `setChatTitle`, `setChatDescription`, `setChatPhoto`, `deleteChatPhoto`, `setChatPermissions`, `leaveChat`, `unpinAllChatMessages`, `setChatStickerSet`, `deleteChatStickerSet`
|
|
82
|
-
- **Info**: `getChat`, `getChatAdministrators`, `getChatMemberCount`, `getChatMember`
|
|
83
|
-
- **Invite links/join requests**: `exportChatInviteLink`, `createChatInviteLink`, `editChatInviteLink`, `revokeChatInviteLink`, `approveChatJoinRequest`, `declineChatJoinRequest`
|
|
84
|
-
- **Live location/polls/games**: `editMessageLiveLocation`, `stopMessageLiveLocation`, `stopPoll`, `setGameScore`, `getGameHighScores`
|
|
85
|
-
- **Forum**: full topic set (`createForumTopic` … `unhideGeneralForumTopic`)
|
|
86
|
-
- **New beyond Telegraf core**: `getFile` (typed), `downloadFile`, `edit` (rewrites the current message's text), plus standalone helpers exported from the package root — `validateUpload`/`assertValidUpload` — which are not context methods
|
|
87
|
-
|
|
88
|
-
Naming differences to fix while porting: `answerCbQuery` → `answerCallbackQuery`; `ctx.telegram` → `ctx.api`; keyboard helpers come from the package root (`InlineKeyboard`, `ReplyKeyboard`, `removeKeyboard`, `forceReply`) instead of `Markup`.
|
|
89
|
-
|
|
90
|
-
## 4. Launch options
|
|
91
|
-
|
|
92
|
-
| Telegraf | telebibz |
|
|
93
|
-
|---|---|
|
|
94
|
-
| `launch({ dropPendingUpdates })` | `launch({ dropPendingUpdates })` — identical |
|
|
95
|
-
| `handlerTimeout` (90 000 default) | `handlerTimeout` (90 000 default; `0` disables) |
|
|
96
|
-
| `contextType` option | `contextType` option — your `Context` subclass is instantiated for every update |
|
|
97
|
-
| `webhookReply` (per-update) | `webhookReply` on the handler / `handleUpdate` options |
|
|
98
|
-
| `telegraf.use(session(...))` | `new Bot({ session: new MemoryStorage() })` (or JSON/Redis/SQL/Mongo) |
|
|
99
|
-
|
|
100
|
-
## 5. Scenes → Wizards
|
|
101
|
-
|
|
102
|
-
Telegraf's `WizardScene` + `Stage` becomes a single `Wizard` with explicit steps and no global session keys:
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
import { Bot, Wizard } from "@xbibzlibrary/telebibz";
|
|
106
|
-
|
|
107
|
-
const wizard = new Wizard()
|
|
108
|
-
.step({ id: "ask-name", run: async (flow) => { flow.next(); await flow.ctx.reply("Name?"); } })
|
|
109
|
-
.step({ id: "save", run: async (flow) => { await flow.ctx.reply(`Hi ${flow.ctx.message?.text}!`); } });
|
|
110
|
-
|
|
111
|
-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
|
|
112
|
-
bot.useWizard(wizard); // replaces Stage middleware
|
|
113
|
-
bot.command("start", async (ctx) => { await wizard.run(ctx); }); // replaces scene.enter()
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
- The wizard key derives automatically from chat + sender — no manual key management.
|
|
117
|
-
- `flow.set(key, value)` / `flow.get(key)` replace `ctx.scene.session`.
|
|
118
|
-
- `/cancel` cancels; the conversation completes automatically after the last step.
|
|
119
|
-
- For non-linear graphs, compose `ConversationManager` with the router (telebibz deliberately keeps scene orchestration application-owned; see FEATURE_MATRIX "Design decisions").
|
|
120
|
-
|
|
121
|
-
## 6. Session storage
|
|
122
|
-
|
|
123
|
-
Telegraf stores sessions in memory by default and needs a store plugin for persistence. telebibz takes storage on the constructor — swap the adapter, keep the code:
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
import { Bot, MemoryStorage, JsonFileStorage, RedisStorage } from "@xbibzlibrary/telebibz";
|
|
127
|
-
|
|
128
|
-
const bot = new Bot({
|
|
129
|
-
token: process.env.TELEGRAM_BOT_TOKEN!,
|
|
130
|
-
session: new JsonFileStorage("state/sessions.json"), // or MemoryStorage / RedisStorage / SqlStorage / MongoStorage
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Full wiring recipes for every adapter: [STORAGE.md](STORAGE.md).
|
|
135
|
-
|
|
136
|
-
## 7. Webhooks
|
|
137
|
-
|
|
138
|
-
```ts
|
|
139
|
-
// Telegraf: webhookCallback(bot, app)
|
|
140
|
-
// telebibz: framework is explicit
|
|
141
|
-
import { webhookCallback } from "@xbibzlibrary/telebibz";
|
|
142
|
-
app.post("/telegram", webhookCallback(bot, "express", { secretToken: process.env.TELEGRAM_WEBHOOK_SECRET }));
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
`createWebhookHandler()` additionally provides a Web-standard `Request → Response` handler for Bun/Deno/edge. Full deployment guide: [WEBHOOK.md](WEBHOOK.md).
|
|
146
|
-
|
|
147
|
-
## 8. What has no direct equivalent
|
|
148
|
-
|
|
149
|
-
- **`bot.telegram` low-level client** — use `bot.api` (`call`, `raw`, `methods`, `downloadFile`); the flood gate and retries are built into the transport rather than configurable per call.
|
|
150
|
-
- **Telegraf's plugin ecosystem** — port plugins as `Plugin` objects with an explicit lifecycle (`install`, `onStop`, `dispose`); the plugin manager restarts cleanly.
|
|
151
|
-
- **`Composer.mount`/dynamic scenes** — build with `Router` nesting and `matchMode: "all"` instead.
|
|
152
|
-
- **Markup helper chains** (`Markup.keyboard(...).resize()`) — use `new ReplyKeyboard().text("A").resized().build()`; same payloads, builder style.
|
|
153
|
-
|
|
154
|
-
Bahasa Indonesia: [MIGRATION_TELEGRAF.id.md](MIGRATION_TELEGRAF.id.md) · 简体中文: [MIGRATION_TELEGRAF.zh-CN.md](MIGRATION_TELEGRAF.zh-CN.md)
|