@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
package/examples/files.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File upload and download in one bot:
|
|
3
|
-
* - /doc <path> validates the file, then uploads it as multipart
|
|
4
|
-
* - /photo downloads the largest photo of the message back to disk
|
|
5
|
-
*
|
|
6
|
-
* Run: TELEGRAM_BOT_TOKEN=<token> npx tsx examples/files.ts
|
|
7
|
-
*/
|
|
8
|
-
import { stat } from "node:fs/promises";
|
|
9
|
-
import { Bot, assertValidUpload } from "@xbibzlibrary/telebibz";
|
|
10
|
-
|
|
11
|
-
const bot = new Bot(process.env.TELEGRAM_BOT_TOKEN!);
|
|
12
|
-
|
|
13
|
-
bot.command("doc", async (ctx) => {
|
|
14
|
-
const filePath = ctx.message?.text?.split(/\s+/)[1];
|
|
15
|
-
if (!filePath) {
|
|
16
|
-
await ctx.reply("Usage: /doc <path-to-file>");
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const info = await stat(filePath);
|
|
20
|
-
assertValidUpload(
|
|
21
|
-
{ sizeBytes: info.size, fileName: filePath },
|
|
22
|
-
{ maxBytes: 50 * 1024 * 1024 },
|
|
23
|
-
);
|
|
24
|
-
const message = await ctx.replyWithDocument({ source: filePath });
|
|
25
|
-
await ctx.reply(`Sent as document (message_id ${message.message_id}).`);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
bot.on("message:photo", async (ctx) => {
|
|
29
|
-
const photo = ctx.message?.photo?.at(-1);
|
|
30
|
-
if (!photo) return;
|
|
31
|
-
const downloaded = await ctx.downloadFile(photo.file_id, { destination: `downloads/${photo.file_unique_id}.jpg` });
|
|
32
|
-
await ctx.reply(`Downloaded ${downloaded.fileName} (${downloaded.sizeBytes} bytes) to ${downloaded.savedTo}.`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await bot.start();
|
package/examples/minimal.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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();
|
package/examples/tsconfig.json
DELETED
package/examples/webhook.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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}`));
|
|
@@ -1,42 +0,0 @@
|
|
|
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();
|