@xbibzlibrary/telebibz 0.1.6 → 0.1.7
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/README.id.md +14 -9
- package/README.md +14 -9
- package/README.zh-CN.md +14 -9
- package/dist/src/approval/approval.d.ts +4 -9
- package/dist/src/approval/approval.d.ts.map +1 -1
- package/dist/src/approval/approval.js +14 -10
- package/dist/src/approval/approval.js.map +1 -1
- package/dist/src/branding/terminal.d.ts +15 -0
- package/dist/src/branding/terminal.d.ts.map +1 -0
- package/dist/src/branding/terminal.js +70 -0
- package/dist/src/branding/terminal.js.map +1 -0
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +31 -6
- package/dist/src/cli.js.map +1 -1
- package/dist/src/core/bot.d.ts +1 -1
- package/dist/src/core/bot.d.ts.map +1 -1
- package/dist/src/core/bot.js +23 -10
- package/dist/src/core/bot.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/testing.d.ts.map +1 -1
- package/dist/src/testing.js +13 -1
- package/dist/src/testing.js.map +1 -1
- package/dist-cjs/src/approval/approval.js +14 -10
- package/dist-cjs/src/branding/terminal.js +75 -0
- package/dist-cjs/src/cli.js +31 -6
- package/dist-cjs/src/core/bot.js +23 -10
- package/dist-cjs/src/index.js +4 -0
- package/dist-cjs/src/testing.js +13 -1
- package/docs/API.id.md +11 -18
- package/docs/API.md +11 -18
- package/docs/API.zh-CN.md +11 -18
- package/package.json +2 -1
package/docs/API.md
CHANGED
|
@@ -73,7 +73,7 @@ type BotStatus =
|
|
|
73
73
|
| `polling.allowedUpdates` | `string[]` | `[]` | Telegram update filters. |
|
|
74
74
|
| `polling.retryDelayMs` | `number` | `500` | Initial delay when polling fails. |
|
|
75
75
|
| `polling.maxRetryDelayMs` | `number` | `30000` | Maximum reconnect delay. |
|
|
76
|
-
| `approval` | `ApprovalOptions` |
|
|
76
|
+
| `approval` | `ApprovalOptions` | `{}` | Optional label, cooldown, and approval storage only; the developer approval target is fixed internally. |
|
|
77
77
|
|
|
78
78
|
### Constructor `Bot`
|
|
79
79
|
|
|
@@ -83,7 +83,7 @@ new Bot<S extends object = Record<string, unknown>>(
|
|
|
83
83
|
): Bot<S>
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
If the argument is a string, it is treated as the token. The constructor creates `ApiClient`, router, event bus, plugin manager, session storage, and approval gate
|
|
86
|
+
If the argument is a string, it is treated as the token. The constructor creates `ApiClient`, router, event bus, plugin manager, session storage, and an always-on developer approval gate. The constructor emits the `bot:created` event asynchronously.
|
|
87
87
|
|
|
88
88
|
The constructor throws `Error` if the token is empty or does not match the Telegram token pattern.
|
|
89
89
|
|
|
@@ -156,7 +156,7 @@ Registers a plugin. Plugin names must be unique.
|
|
|
156
156
|
init(): Promise<this>
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
Calls `getMe()`, stores the bot information,
|
|
159
|
+
Calls `getMe()`, stores the bot information, requests developer approval, then runs plugin lifecycle `setup()` and `start()` only after approval.
|
|
160
160
|
|
|
161
161
|
If approval has not been granted, the method sets the status to `"awaiting-approval"`, notifies the owner via the `ApprovalGate`, and returns the bot without marking it as `initialized`. Subsequent calls can be used after the owner grants approval.
|
|
162
162
|
|
|
@@ -1269,16 +1269,13 @@ new Menu(id: string): Menu
|
|
|
1269
1269
|
|
|
1270
1270
|
## 12. Approval Gate
|
|
1271
1271
|
|
|
1272
|
-
The approval gate sends
|
|
1272
|
+
The always-on approval gate sends the branded notification to the library developer when a bot uses telebibz for the first time. The target chat and authorized decision-maker are fixed internally and are not part of the public configuration or notification output. The message includes the bot ID/username and provides `Izinkan` and `Tidak Diizinkan` buttons.
|
|
1273
1273
|
|
|
1274
1274
|
### `ApprovalOptions`
|
|
1275
1275
|
|
|
1276
1276
|
| Property | Type | Default | Description |
|
|
1277
1277
|
|---|---|---:|---|
|
|
1278
|
-
| `
|
|
1279
|
-
| `ownerUserId` | `number` | wajib | User ID allowed to press the buttons. |
|
|
1280
|
-
| `ownerLabel` | `string` | `Dev Gantenggg` | Label on the notification. |
|
|
1281
|
-
| `requireApproval` | `boolean` | `true` | `false` disables the gate. |
|
|
1278
|
+
| `ownerLabel` | `string` | `Dev Gantenggg` | Display label only; it cannot change the target developer. |
|
|
1282
1279
|
| `notificationCooldownMs` | `number` | `600000` | Pending notification cooldown. |
|
|
1283
1280
|
| `store` | `ApprovalStore` | `MemoryApprovalStore` | Custom approval storage. |
|
|
1284
1281
|
|
|
@@ -1291,7 +1288,6 @@ interface ApprovalRecord {
|
|
|
1291
1288
|
key: string;
|
|
1292
1289
|
botId: number;
|
|
1293
1290
|
botUsername?: string;
|
|
1294
|
-
ownerUserId?: number;
|
|
1295
1291
|
status: ApprovalStatus;
|
|
1296
1292
|
nonce: string;
|
|
1297
1293
|
requestedAt: number;
|
|
@@ -1302,12 +1298,11 @@ interface ApprovalRecord {
|
|
|
1302
1298
|
|
|
1303
1299
|
interface ApprovalIdentity {
|
|
1304
1300
|
bot: User;
|
|
1305
|
-
configuredOwnerUserId?: number;
|
|
1306
1301
|
}
|
|
1307
1302
|
|
|
1308
1303
|
interface ApprovalCheck {
|
|
1309
1304
|
allowed: boolean;
|
|
1310
|
-
status: ApprovalStatus
|
|
1305
|
+
status: ApprovalStatus;
|
|
1311
1306
|
record?: ApprovalRecord;
|
|
1312
1307
|
}
|
|
1313
1308
|
```
|
|
@@ -1340,20 +1335,18 @@ new ApprovalGate(api: ApiClient, options: ApprovalOptions): ApprovalGate
|
|
|
1340
1335
|
|---|---|---|
|
|
1341
1336
|
| `check` | `check(identity): Promise<ApprovalCheck>` | Returns approved if the record status is approved; sends a new request if none exists or the cooldown has expired. |
|
|
1342
1337
|
| `handleCallback` | `handleCallback(callback): Promise<{ handled: boolean; status?: ApprovalStatus }>` | Validates the nonce and owner, then performs approve/deny. Invalid callbacks or non-approval callbacks are returned as `handled: false`. |
|
|
1343
|
-
| `isAllowed` | `isAllowed(botId): Promise<boolean>` | True if
|
|
1338
|
+
| `isAllowed` | `isAllowed(botId): Promise<boolean>` | True only if the fixed developer approval record is approved. |
|
|
1344
1339
|
| `revoke` | `revoke(botId): Promise<boolean>` | Deletes the record if the store supports delete. |
|
|
1345
1340
|
|
|
1346
|
-
Callbacks can only be decided by the
|
|
1341
|
+
Callbacks can only be decided by the fixed internal developer identity; caller-supplied owner IDs are ignored by the production API. A random 16-character hexadecimal nonce prevents old callbacks from being reused. The developer ID is not included in terminal or Telegram notification output. Expired callbacks produce an expiration alert.
|
|
1347
1342
|
|
|
1348
1343
|
```ts
|
|
1349
1344
|
const bot = new Bot({
|
|
1350
1345
|
token: process.env.TELEGRAM_BOT_TOKEN!,
|
|
1351
|
-
approval: {
|
|
1352
|
-
ownerChatId: 7377733784,
|
|
1353
|
-
ownerUserId: 7377733784,
|
|
1354
|
-
ownerLabel: "Dev Gantenggg",
|
|
1355
|
-
},
|
|
1346
|
+
approval: { ownerLabel: "Dev Gantenggg" },
|
|
1356
1347
|
});
|
|
1348
|
+
|
|
1349
|
+
// The approval target is fixed internally; it cannot be changed through this object.
|
|
1357
1350
|
```
|
|
1358
1351
|
|
|
1359
1352
|
---
|
package/docs/API.zh-CN.md
CHANGED
|
@@ -74,7 +74,7 @@ type BotStatus =
|
|
|
74
74
|
| `polling.allowedUpdates` | `string[]` | `[]` | Telegram 更新过滤器。 |
|
|
75
75
|
| `polling.retryDelayMs` | `number` | `500` | 轮询失败时的初始延迟(毫秒)。 |
|
|
76
76
|
| `polling.maxRetryDelayMs` | `number` | `30000` | 重连延迟的最大值(毫秒)。 |
|
|
77
|
-
| `approval` | `ApprovalOptions` |
|
|
77
|
+
| `approval` | `ApprovalOptions` | `{}` | 仅用于 label、cooldown 和 storage;developer target 在内部固定。 |
|
|
78
78
|
|
|
79
79
|
### `Bot` constructor
|
|
80
80
|
|
|
@@ -84,7 +84,7 @@ new Bot<S extends object = Record<string, unknown>>(
|
|
|
84
84
|
): Bot<S>
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
Jika argumen berupa string, string tersebut dianggap sebagai token. Constructor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan approval gate
|
|
87
|
+
Jika argumen berupa string, string tersebut dianggap sebagai token. Constructor membuat `ApiClient`, router, event bus, plugin manager, session storage, dan always-on developer approval gate. Constructor langsung memancarkan event `bot:created` secara asynchronous.
|
|
88
88
|
|
|
89
89
|
Constructor melempar `Error` jika token kosong atau tidak sesuai pola token Telegram.
|
|
90
90
|
|
|
@@ -157,7 +157,7 @@ usePlugin(plugin: Plugin<Context<S>>): this
|
|
|
157
157
|
init(): Promise<this>
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
调用 `getMe()`,保存 bot
|
|
160
|
+
调用 `getMe()`,保存 bot 信息,请求 developer approval,然后仅在批准后运行插件生命周期的 `setup()` 和 `start()`。
|
|
161
161
|
|
|
162
162
|
若尚未获得批准,方法会将状态置为 `"awaiting-approval"`,通过 `ApprovalGate` 向 owner 发送通知,并返回 bot 而不设置为 `initialized`。在 owner 批准后后续调用仍可使用。
|
|
163
163
|
|
|
@@ -1264,16 +1264,13 @@ new Menu(id: string): Menu
|
|
|
1264
1264
|
|
|
1265
1265
|
## 12. 审批门
|
|
1266
1266
|
|
|
1267
|
-
Approval gate
|
|
1267
|
+
Approval gate 始终在机器人首次使用 telebibz 时向 library developer 发送 branded notification。目标 chat 和决策者在内部固定,不属于 public configuration,也不会显示在 notification 中。消息包含 bot ID/用户名,并提供 `Izinkan` 和 `Tidak Diizinkan` 按钮。
|
|
1268
1268
|
|
|
1269
1269
|
### `ApprovalOptions`
|
|
1270
1270
|
|
|
1271
1271
|
| 属性 | 类型 | 默认 | 描述 |
|
|
1272
1272
|
|---|---|---:|---|
|
|
1273
|
-
| `
|
|
1274
|
-
| `ownerUserId` | `number` | wajib | 可以按下按钮的用户 ID。 |
|
|
1275
|
-
| `ownerLabel` | `string` | `Dev Gantenggg` | 通知上的标签。 |
|
|
1276
|
-
| `requireApproval` | `boolean` | `true` | `false` 会禁用 gate。 |
|
|
1273
|
+
| `ownerLabel` | `string` | `Dev Gantenggg` | 仅显示 label,不能改变 developer target。 |
|
|
1277
1274
|
| `notificationCooldownMs` | `number` | `600000` | 等待通知的冷却时间(毫秒)。 |
|
|
1278
1275
|
| `store` | `ApprovalStore` | `MemoryApprovalStore` | 自定义 approval 存储。 |
|
|
1279
1276
|
|
|
@@ -1286,7 +1283,6 @@ interface ApprovalRecord {
|
|
|
1286
1283
|
key: string;
|
|
1287
1284
|
botId: number;
|
|
1288
1285
|
botUsername?: string;
|
|
1289
|
-
ownerUserId?: number;
|
|
1290
1286
|
status: ApprovalStatus;
|
|
1291
1287
|
nonce: string;
|
|
1292
1288
|
requestedAt: number;
|
|
@@ -1297,12 +1293,11 @@ interface ApprovalRecord {
|
|
|
1297
1293
|
|
|
1298
1294
|
interface ApprovalIdentity {
|
|
1299
1295
|
bot: User;
|
|
1300
|
-
configuredOwnerUserId?: number;
|
|
1301
1296
|
}
|
|
1302
1297
|
|
|
1303
1298
|
interface ApprovalCheck {
|
|
1304
1299
|
allowed: boolean;
|
|
1305
|
-
status: ApprovalStatus
|
|
1300
|
+
status: ApprovalStatus;
|
|
1306
1301
|
record?: ApprovalRecord;
|
|
1307
1302
|
}
|
|
1308
1303
|
```
|
|
@@ -1335,20 +1330,18 @@ new ApprovalGate(api: ApiClient, options: ApprovalOptions): ApprovalGate
|
|
|
1335
1330
|
|---|---|---|
|
|
1336
1331
|
| `check` | `check(identity): Promise<ApprovalCheck>` | 若记录已批准则返回 approved;若不存在记录或冷却期已过则发送新的请求。 |
|
|
1337
1332
|
| `handleCallback` | `handleCallback(callback): Promise<{ handled: boolean; status?: ApprovalStatus }>` | 验证 nonce 和 owner,然后批准/拒绝。非审批回调返回 `handled: false`。 |
|
|
1338
|
-
| `isAllowed` | `isAllowed(botId): Promise<boolean>` |
|
|
1333
|
+
| `isAllowed` | `isAllowed(botId): Promise<boolean>` | 仅当固定 developer approval record 为 approved 时返回 True。 |
|
|
1339
1334
|
| `revoke` | `revoke(botId): Promise<boolean>` | 如果 store 支持 delete,则删除记录。 |
|
|
1340
1335
|
|
|
1341
|
-
|
|
1336
|
+
回调只能由内部固定的 developer identity 决定;生产 API 不使用 caller 提供的 owner ID。随机的 16 个十六进制字符 nonce 可以防止旧的回调被重用。developer ID 不会显示在 terminal 或 Telegram notification 中。过时的回调会产生过期提醒。
|
|
1342
1337
|
|
|
1343
1338
|
```ts
|
|
1344
1339
|
const bot = new Bot({
|
|
1345
1340
|
token: process.env.TELEGRAM_BOT_TOKEN!,
|
|
1346
|
-
approval: {
|
|
1347
|
-
ownerChatId: 7377733784,
|
|
1348
|
-
ownerUserId: 7377733784,
|
|
1349
|
-
ownerLabel: "Dev Gantenggg",
|
|
1350
|
-
},
|
|
1341
|
+
approval: { ownerLabel: "Dev Gantenggg" },
|
|
1351
1342
|
});
|
|
1343
|
+
|
|
1344
|
+
// Approval target is fixed internally and cannot be changed through this object.
|
|
1352
1345
|
```
|
|
1353
1346
|
|
|
1354
1347
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xbibzlibrary/telebibz",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Production-grade, strongly typed Telegram Bot API SDK and framework for Node.js and TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"security": "npm audit --audit-level=high --package-lock-only",
|
|
37
37
|
"release:check": "node scripts/release-check.mjs",
|
|
38
38
|
"doctor": "tsx src/cli.ts doctor",
|
|
39
|
+
"start": "tsx src/cli.ts start",
|
|
39
40
|
"dev": "tsx examples/minimal.ts",
|
|
40
41
|
"prepack": "npm run build",
|
|
41
42
|
"prepublishOnly": "npm run typecheck && npm run test:types && npm run lint && npm test && npm run build && npm run security && npm run release:check"
|