@xbibzlibrary/telebibz 0.4.4 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -138
- package/LICENSE +1 -1
- package/NOTICE.md +9 -4
- package/README.md +173 -242
- package/examples/01-quickstart.js +13 -0
- package/examples/02-menu-tombol.js +22 -0
- package/examples/03-wizard.js +29 -0
- package/examples/04-broadcast.js +25 -0
- package/examples/05-kirim-file.js +19 -0
- package/examples/06-menu.js +35 -0
- package/examples/07-inline-query.js +18 -0
- package/index.d.ts +81 -0
- package/index.js +42 -0
- package/lib/api.js +154 -0
- package/lib/broadcast.js +35 -0
- package/lib/composer.js +174 -0
- package/lib/context.js +190 -0
- package/lib/errors.js +35 -0
- package/lib/file.js +41 -0
- package/lib/inline-query.js +28 -0
- package/lib/keyboard.js +83 -0
- package/lib/logger.js +38 -0
- package/lib/menus.js +90 -0
- package/lib/net.js +115 -0
- package/lib/ratelimit.js +61 -0
- package/lib/runner.js +45 -0
- package/lib/session.js +36 -0
- package/lib/telebibz.js +190 -0
- package/lib/wizard.js +81 -0
- package/package.json +35 -97
- package/test/all.test.js +334 -0
- package/CODE_OF_CONDUCT.md +0 -37
- package/CONTRIBUTING.md +0 -59
- package/CONTRIBUTION_RULES.md +0 -41
- package/GOVERNANCE.md +0 -47
- package/README.id.md +0 -292
- package/README.zh-CN.md +0 -292
- package/RELEASE_AUTOMATION.md +0 -78
- package/RELEASE_POLICY.md +0 -32
- package/SECURITY.md +0 -47
- package/SHOWCASE.md +0 -29
- package/SUPPORT.md +0 -30
- package/assets/readme-preview.html +0 -75
- package/assets/telebibz-logo.png +0 -0
- package/assets/telebibz-readme-preview.png +0 -0
- package/bin/telebibz.mjs +0 -3
- package/dist/generated/api.d.ts +0 -13
- package/dist/generated/api.d.ts.map +0 -1
- package/dist/generated/api.js +0 -192
- package/dist/generated/api.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -62
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -104
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/api/errors.d.ts +0 -45
- package/dist/src/api/errors.d.ts.map +0 -1
- package/dist/src/api/errors.js +0 -65
- package/dist/src/api/errors.js.map +0 -1
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js +0 -6
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/telegram-types/LICENSE +0 -21
- package/dist/src/api/telegram-types/api.d.ts +0 -22
- package/dist/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist/src/api/telegram-types/inline.d.ts +0 -692
- package/dist/src/api/telegram-types/langs.d.ts +0 -193
- package/dist/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist/src/api/telegram-types/markup.d.ts +0 -268
- package/dist/src/api/telegram-types/message.d.ts +0 -1537
- package/dist/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist/src/api/telegram-types/mod.d.ts +0 -14
- package/dist/src/api/telegram-types/passport.d.ts +0 -163
- package/dist/src/api/telegram-types/payment.d.ts +0 -570
- package/dist/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist/src/api/telegram-types/settings.d.ts +0 -120
- package/dist/src/api/telegram-types/story.d.ts +0 -89
- package/dist/src/api/telegram-types/update.d.ts +0 -84
- package/dist/src/api/telegram.d.ts +0 -7
- package/dist/src/api/telegram.d.ts.map +0 -1
- package/dist/src/api/telegram.js +0 -2
- package/dist/src/api/telegram.js.map +0 -1
- package/dist/src/api/transport.d.ts +0 -68
- package/dist/src/api/transport.d.ts.map +0 -1
- package/dist/src/api/transport.js +0 -264
- package/dist/src/api/transport.js.map +0 -1
- package/dist/src/api/types.d.ts +0 -466
- package/dist/src/api/types.d.ts.map +0 -1
- package/dist/src/api/types.js +0 -2
- package/dist/src/api/types.js.map +0 -1
- package/dist/src/branding/terminal.d.ts +0 -77
- package/dist/src/branding/terminal.d.ts.map +0 -1
- package/dist/src/branding/terminal.js +0 -328
- package/dist/src/branding/terminal.js.map +0 -1
- package/dist/src/broadcast/broadcast.d.ts +0 -50
- package/dist/src/broadcast/broadcast.d.ts.map +0 -1
- package/dist/src/broadcast/broadcast.js +0 -56
- package/dist/src/broadcast/broadcast.js.map +0 -1
- package/dist/src/cache/cache.d.ts +0 -34
- package/dist/src/cache/cache.d.ts.map +0 -1
- package/dist/src/cache/cache.js +0 -41
- package/dist/src/cache/cache.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -84
- package/dist/src/cli.js.map +0 -1
- package/dist/src/context/context.d.ts +0 -124
- package/dist/src/context/context.d.ts.map +0 -1
- package/dist/src/context/context.js +0 -302
- package/dist/src/context/context.js.map +0 -1
- package/dist/src/core/bot.d.ts +0 -204
- package/dist/src/core/bot.d.ts.map +0 -1
- package/dist/src/core/bot.js +0 -506
- package/dist/src/core/bot.js.map +0 -1
- package/dist/src/core/events.d.ts +0 -75
- package/dist/src/core/events.d.ts.map +0 -1
- package/dist/src/core/events.js +0 -35
- package/dist/src/core/events.js.map +0 -1
- package/dist/src/core/webhook-reply.d.ts +0 -34
- package/dist/src/core/webhook-reply.d.ts.map +0 -1
- package/dist/src/core/webhook-reply.js +0 -37
- package/dist/src/core/webhook-reply.js.map +0 -1
- package/dist/src/index.d.ts +0 -24
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/keyboard/index.d.ts +0 -46
- package/dist/src/keyboard/index.d.ts.map +0 -1
- package/dist/src/keyboard/index.js +0 -55
- package/dist/src/keyboard/index.js.map +0 -1
- package/dist/src/middleware/compose.d.ts +0 -5
- package/dist/src/middleware/compose.d.ts.map +0 -1
- package/dist/src/middleware/compose.js +0 -17
- package/dist/src/middleware/compose.js.map +0 -1
- package/dist/src/observability/logger.d.ts +0 -78
- package/dist/src/observability/logger.d.ts.map +0 -1
- package/dist/src/observability/logger.js +0 -285
- package/dist/src/observability/logger.js.map +0 -1
- package/dist/src/plugins/plugin.d.ts +0 -38
- package/dist/src/plugins/plugin.d.ts.map +0 -1
- package/dist/src/plugins/plugin.js +0 -59
- package/dist/src/plugins/plugin.js.map +0 -1
- package/dist/src/queue/queue.d.ts +0 -77
- package/dist/src/queue/queue.d.ts.map +0 -1
- package/dist/src/queue/queue.js +0 -213
- package/dist/src/queue/queue.js.map +0 -1
- package/dist/src/router/router.d.ts +0 -61
- package/dist/src/router/router.d.ts.map +0 -1
- package/dist/src/router/router.js +0 -183
- package/dist/src/router/router.js.map +0 -1
- package/dist/src/state/conversation.d.ts +0 -56
- package/dist/src/state/conversation.d.ts.map +0 -1
- package/dist/src/state/conversation.js +0 -133
- package/dist/src/state/conversation.js.map +0 -1
- package/dist/src/state/forms.d.ts +0 -34
- package/dist/src/state/forms.d.ts.map +0 -1
- package/dist/src/state/forms.js +0 -44
- package/dist/src/state/forms.js.map +0 -1
- package/dist/src/state/menu.d.ts +0 -78
- package/dist/src/state/menu.d.ts.map +0 -1
- package/dist/src/state/menu.js +0 -127
- package/dist/src/state/menu.js.map +0 -1
- package/dist/src/storage/storage.d.ts +0 -146
- package/dist/src/storage/storage.d.ts.map +0 -1
- package/dist/src/storage/storage.js +0 -195
- package/dist/src/storage/storage.js.map +0 -1
- package/dist/src/telegram-features.d.ts +0 -33
- package/dist/src/telegram-features.d.ts.map +0 -1
- package/dist/src/telegram-features.js +0 -71
- package/dist/src/telegram-features.js.map +0 -1
- package/dist/src/testing.d.ts +0 -24
- package/dist/src/testing.d.ts.map +0 -1
- package/dist/src/testing.js +0 -38
- package/dist/src/testing.js.map +0 -1
- package/dist/src/utils/concurrency.d.ts +0 -25
- package/dist/src/utils/concurrency.d.ts.map +0 -1
- package/dist/src/utils/concurrency.js +0 -52
- package/dist/src/utils/concurrency.js.map +0 -1
- package/dist/src/utils/files.d.ts +0 -45
- package/dist/src/utils/files.d.ts.map +0 -1
- package/dist/src/utils/files.js +0 -53
- package/dist/src/utils/files.js.map +0 -1
- package/dist/src/utils/text.d.ts +0 -39
- package/dist/src/utils/text.d.ts.map +0 -1
- package/dist/src/utils/text.js +0 -56
- package/dist/src/utils/text.js.map +0 -1
- package/dist/src/webhook/handler.d.ts +0 -19
- package/dist/src/webhook/handler.d.ts.map +0 -1
- package/dist/src/webhook/handler.js +0 -141
- package/dist/src/webhook/handler.js.map +0 -1
- package/dist-cjs/generated/api.js +0 -194
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/src/api/client.js +0 -107
- package/dist-cjs/src/api/errors.js +0 -74
- package/dist-cjs/src/api/index.js +0 -21
- package/dist-cjs/src/api/telegram-types/LICENSE +0 -21
- package/dist-cjs/src/api/telegram-types/api.d.ts +0 -22
- package/dist-cjs/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist-cjs/src/api/telegram-types/inline.d.ts +0 -692
- package/dist-cjs/src/api/telegram-types/langs.d.ts +0 -193
- package/dist-cjs/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist-cjs/src/api/telegram-types/markup.d.ts +0 -268
- package/dist-cjs/src/api/telegram-types/message.d.ts +0 -1537
- package/dist-cjs/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist-cjs/src/api/telegram-types/mod.d.ts +0 -14
- package/dist-cjs/src/api/telegram-types/passport.d.ts +0 -163
- package/dist-cjs/src/api/telegram-types/payment.d.ts +0 -570
- package/dist-cjs/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist-cjs/src/api/telegram-types/settings.d.ts +0 -120
- package/dist-cjs/src/api/telegram-types/story.d.ts +0 -89
- package/dist-cjs/src/api/telegram-types/update.d.ts +0 -84
- package/dist-cjs/src/api/telegram.js +0 -2
- package/dist-cjs/src/api/transport.js +0 -267
- package/dist-cjs/src/api/types.js +0 -2
- package/dist-cjs/src/branding/terminal.js +0 -338
- package/dist-cjs/src/broadcast/broadcast.js +0 -58
- package/dist-cjs/src/cache/cache.js +0 -45
- package/dist-cjs/src/cli.js +0 -86
- package/dist-cjs/src/context/context.js +0 -305
- package/dist-cjs/src/core/bot.js +0 -510
- package/dist-cjs/src/core/events.js +0 -38
- package/dist-cjs/src/core/webhook-reply.js +0 -42
- package/dist-cjs/src/index.js +0 -47
- package/dist-cjs/src/keyboard/index.js +0 -61
- package/dist-cjs/src/middleware/compose.js +0 -20
- package/dist-cjs/src/observability/logger.js +0 -293
- package/dist-cjs/src/plugins/plugin.js +0 -63
- package/dist-cjs/src/queue/queue.js +0 -219
- package/dist-cjs/src/router/router.js +0 -186
- package/dist-cjs/src/state/conversation.js +0 -139
- package/dist-cjs/src/state/forms.js +0 -47
- package/dist-cjs/src/state/menu.js +0 -133
- package/dist-cjs/src/storage/storage.js +0 -202
- package/dist-cjs/src/telegram-features.js +0 -76
- package/dist-cjs/src/testing.js +0 -45
- package/dist-cjs/src/utils/concurrency.js +0 -57
- package/dist-cjs/src/utils/files.js +0 -58
- package/dist-cjs/src/utils/text.js +0 -63
- package/dist-cjs/src/webhook/handler.js +0 -144
- package/docs/API.id.md +0 -1935
- package/docs/API.md +0 -1969
- package/docs/API.zh-CN.md +0 -1929
- package/docs/GETTING_STARTED.id.md +0 -85
- package/docs/GETTING_STARTED.md +0 -85
- package/docs/GETTING_STARTED.zh-CN.md +0 -85
- package/docs/GITHUB_PACKAGES.id.md +0 -82
- package/docs/GITHUB_PACKAGES.md +0 -82
- package/docs/GITHUB_PACKAGES.zh-CN.md +0 -82
- package/docs/README.md +0 -48
- package/docs/STORAGE.id.md +0 -105
- package/docs/STORAGE.md +0 -105
- package/docs/STORAGE.zh-CN.md +0 -105
- package/examples/README.md +0 -37
- package/examples/files.ts +0 -35
- package/examples/minimal.ts +0 -12
- package/examples/tsconfig.json +0 -9
- package/examples/webhook.ts +0 -42
- package/examples/wizard-registration.ts +0 -42
package/dist/src/utils/text.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export declare function escapeMarkdownV2(value: string): string;
|
|
2
|
-
export declare function escapeHtml(value: string): string;
|
|
3
|
-
export declare const md: {
|
|
4
|
-
bold: (value: string) => string;
|
|
5
|
-
italic: (value: string) => string;
|
|
6
|
-
underline: (value: string) => string;
|
|
7
|
-
strikethrough: (value: string) => string;
|
|
8
|
-
spoiler: (value: string) => string;
|
|
9
|
-
link: (label: string, url: string) => string;
|
|
10
|
-
code: (value: string) => string;
|
|
11
|
-
pre: (value: string, language?: string) => string;
|
|
12
|
-
blockquote: (value: string) => string;
|
|
13
|
-
expandableBlockquote: (value: string) => string;
|
|
14
|
-
customEmoji: (emoji: string, customEmojiId: string) => string;
|
|
15
|
-
userMention: (label: string, userId: number | string) => string;
|
|
16
|
-
escape: typeof escapeMarkdownV2;
|
|
17
|
-
};
|
|
18
|
-
export declare const html: {
|
|
19
|
-
escape: typeof escapeHtml;
|
|
20
|
-
bold: (value: string) => string;
|
|
21
|
-
italic: (value: string) => string;
|
|
22
|
-
underline: (value: string) => string;
|
|
23
|
-
strikethrough: (value: string) => string;
|
|
24
|
-
spoiler: (value: string) => string;
|
|
25
|
-
link: (label: string, url: string) => string;
|
|
26
|
-
code: (value: string) => string;
|
|
27
|
-
pre: (value: string, language?: string) => string;
|
|
28
|
-
blockquote: (value: string) => string;
|
|
29
|
-
expandableBlockquote: (value: string) => string;
|
|
30
|
-
customEmoji: (emoji: string, customEmojiId: string) => string;
|
|
31
|
-
userMention: (label: string, userId: number | string) => string;
|
|
32
|
-
};
|
|
33
|
-
export declare function splitMessage(text: string, options?: {
|
|
34
|
-
limit?: number;
|
|
35
|
-
parseMode?: "Markdown" | "MarkdownV2" | "HTML";
|
|
36
|
-
}): string[];
|
|
37
|
-
export declare function splitCaption(text: string): string[];
|
|
38
|
-
export declare function template(templateText: string, values: Record<string, unknown>): string;
|
|
39
|
-
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/utils/text.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAgE;AACvH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAA2I;AAE5L,eAAO,MAAM,EAAE;kBACC,MAAM;oBACJ,MAAM;uBACH,MAAM;2BACF,MAAM;qBACZ,MAAM;kBACT,MAAM,OAAO,MAAM;kBACnB,MAAM;iBACP,MAAM;wBACC,MAAM;kCACI,MAAM;yBACf,MAAM,iBAAiB,MAAM;yBAC7B,MAAM,UAAU,MAAM,GAAG,MAAM;;CAErD,CAAC;AAEF,eAAO,MAAM,IAAI;;kBAED,MAAM;oBACJ,MAAM;uBACH,MAAM;2BACF,MAAM;qBACZ,MAAM;kBACT,MAAM,OAAO,MAAM;kBACnB,MAAM;iBACP,MAAM,aAAa,MAAM;wBAClB,MAAM;kCACI,MAAM;yBACf,MAAM,iBAAiB,MAAM;yBAC7B,MAAM,UAAU,MAAM,GAAG,MAAM;CACrD,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,MAAM,CAAA;CAAO,GAAG,MAAM,EAAE,CAerI;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAkE;AACtH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAuU"}
|
package/dist/src/utils/text.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const TELEGRAM_TEXT_LIMIT = 4096;
|
|
2
|
-
const TELEGRAM_CAPTION_LIMIT = 1024;
|
|
3
|
-
export function escapeMarkdownV2(value) { return value.replace(/[\\_*\[\]()~`>#+\-=|{}.!]/g, "\\$&"); }
|
|
4
|
-
export function escapeHtml(value) { return value.replace(/[&<>\"]/g, (character) => ({ "&": "&", "<": "<", ">": ">", "\"": """ })[character] ?? character); }
|
|
5
|
-
export const md = {
|
|
6
|
-
bold: (value) => `*${escapeMarkdownV2(value)}*`,
|
|
7
|
-
italic: (value) => `_${escapeMarkdownV2(value)}_`,
|
|
8
|
-
underline: (value) => `__${escapeMarkdownV2(value)}__`,
|
|
9
|
-
strikethrough: (value) => `~${escapeMarkdownV2(value)}~`,
|
|
10
|
-
spoiler: (value) => `||${escapeMarkdownV2(value)}||`,
|
|
11
|
-
link: (label, url) => `[${escapeMarkdownV2(label)}](${url.replace(/[()\\]/g, "\\$&")})`,
|
|
12
|
-
code: (value) => `\`${value.replace(/[`\\]/g, "\\$&")}\``,
|
|
13
|
-
pre: (value, language = "") => `\`\`\`${language}\n${value.replace(/[`\\]/g, "\\$&")}\n\`\`\``,
|
|
14
|
-
blockquote: (value) => value.split("\n").map((line) => `>${escapeMarkdownV2(line)}`).join("\n"),
|
|
15
|
-
expandableBlockquote: (value) => `**>${value.split("\n").map((line) => escapeMarkdownV2(line)).join("\n>")}||`,
|
|
16
|
-
customEmoji: (emoji, customEmojiId) => ``,
|
|
17
|
-
userMention: (label, userId) => `[${escapeMarkdownV2(label)}](tg://user?id=${userId})`,
|
|
18
|
-
escape: escapeMarkdownV2,
|
|
19
|
-
};
|
|
20
|
-
export const html = {
|
|
21
|
-
escape: escapeHtml,
|
|
22
|
-
bold: (value) => `<b>${escapeHtml(value)}</b>`,
|
|
23
|
-
italic: (value) => `<i>${escapeHtml(value)}</i>`,
|
|
24
|
-
underline: (value) => `<u>${escapeHtml(value)}</u>`,
|
|
25
|
-
strikethrough: (value) => `<s>${escapeHtml(value)}</s>`,
|
|
26
|
-
spoiler: (value) => `<tg-spoiler>${escapeHtml(value)}</tg-spoiler>`,
|
|
27
|
-
link: (label, url) => `<a href="${escapeHtml(url)}">${escapeHtml(label)}</a>`,
|
|
28
|
-
code: (value) => `<code>${escapeHtml(value)}</code>`,
|
|
29
|
-
pre: (value, language) => language ? `<pre><code class="language-${escapeHtml(language)}">${escapeHtml(value)}</code></pre>` : `<pre>${escapeHtml(value)}</pre>`,
|
|
30
|
-
blockquote: (value) => `<blockquote>${escapeHtml(value)}</blockquote>`,
|
|
31
|
-
expandableBlockquote: (value) => `<blockquote expandable>${escapeHtml(value)}</blockquote>`,
|
|
32
|
-
customEmoji: (emoji, customEmojiId) => `<tg-emoji emoji-id="${escapeHtml(customEmojiId)}">${escapeHtml(emoji)}</tg-emoji>`,
|
|
33
|
-
userMention: (label, userId) => `<a href="tg://user?id=${userId}">${escapeHtml(label)}</a>`,
|
|
34
|
-
};
|
|
35
|
-
export function splitMessage(text, options = {}) {
|
|
36
|
-
const limit = options.limit ?? TELEGRAM_TEXT_LIMIT;
|
|
37
|
-
if (limit < 1)
|
|
38
|
-
throw new RangeError("limit must be positive");
|
|
39
|
-
if (text.length <= limit)
|
|
40
|
-
return [text];
|
|
41
|
-
const chunks = [];
|
|
42
|
-
let remaining = text;
|
|
43
|
-
while (remaining.length > limit) {
|
|
44
|
-
const window = remaining.slice(0, limit);
|
|
45
|
-
const boundary = Math.max(window.lastIndexOf("\n\n"), window.lastIndexOf("\n"), window.lastIndexOf(" "));
|
|
46
|
-
const cut = boundary > Math.floor(limit * 0.5) ? boundary : limit;
|
|
47
|
-
chunks.push(remaining.slice(0, cut));
|
|
48
|
-
remaining = remaining.slice(cut).replace(/^\s+/, "");
|
|
49
|
-
}
|
|
50
|
-
if (remaining)
|
|
51
|
-
chunks.push(remaining);
|
|
52
|
-
return chunks;
|
|
53
|
-
}
|
|
54
|
-
export function splitCaption(text) { return splitMessage(text, { limit: TELEGRAM_CAPTION_LIMIT }); }
|
|
55
|
-
export function template(templateText, values) { return templateText.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (_match, key) => { const value = key.split(".").reduce((current, part) => current && typeof current === "object" ? current[part] : undefined, values); return value === undefined || value === null ? "" : String(value); }); }
|
|
56
|
-
//# sourceMappingURL=text.js.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CAAC,MAAM,CAAU,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAE,OAAmC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { Bot } from "../core/bot.js";
|
|
3
|
-
export interface WebhookOptions {
|
|
4
|
-
secretToken?: string;
|
|
5
|
-
maxBodyBytes?: number;
|
|
6
|
-
onError?: (error: unknown) => void | Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Telegraf-style webhook replies (default `false`). When enabled, the first
|
|
9
|
-
* outgoing API call while handling an update is answered through the webhook
|
|
10
|
-
* HTTP response instead of a separate request to Telegram — Telegram then
|
|
11
|
-
* executes the method for you. That call resolves with `true`, since Telegram
|
|
12
|
-
* never sends the method result back to a webhook response.
|
|
13
|
-
*/
|
|
14
|
-
webhookReply?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export type WebhookFramework = "express" | "http" | "fastify" | "koa";
|
|
17
|
-
export declare function createWebhookHandler<S extends object>(bot: Bot<S>, options?: WebhookOptions): (request: Request) => Promise<Response>;
|
|
18
|
-
export declare function webhookCallback<S extends object>(bot: Bot<S>, _framework?: WebhookFramework, options?: WebhookOptions): (req: IncomingMessage | Record<string, unknown>, res?: ServerResponse | Record<string, unknown>) => Promise<void>;
|
|
19
|
-
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/webhook/handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAI1C,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AACD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC;AAatE,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,cAAmB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAuBzI;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACX,UAAU,GAAE,gBAA4B,EACxC,OAAO,GAAE,cAAmB,GAC3B,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAkFnH"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { timingSafeEqual } from "node:crypto";
|
|
2
|
-
/** Runs the update, optionally claiming the webhook response for the first API call. */
|
|
3
|
-
async function processWithOptionalReply(bot, update, sink) {
|
|
4
|
-
if (sink === undefined) {
|
|
5
|
-
await bot.handleUpdate(update);
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
await bot.handleUpdate(update, { webhookReply: sink });
|
|
9
|
-
}
|
|
10
|
-
function replyResponse(payload) {
|
|
11
|
-
if (payload !== undefined)
|
|
12
|
-
return new Response(JSON.stringify(payload), { status: 200, headers: { "content-type": "application/json" } });
|
|
13
|
-
return new Response("OK", { status: 200 });
|
|
14
|
-
}
|
|
15
|
-
export function createWebhookHandler(bot, options = {}) {
|
|
16
|
-
const maxBodyBytes = options.maxBodyBytes ?? 1_048_576;
|
|
17
|
-
return async (request) => {
|
|
18
|
-
if (request.method !== "POST")
|
|
19
|
-
return new Response("Method Not Allowed", { status: 405, headers: { allow: "POST" } });
|
|
20
|
-
if (options.secretToken && !secureEqual(request.headers.get("x-telegram-bot-api-secret-token") ?? "", options.secretToken))
|
|
21
|
-
return new Response("Unauthorized", { status: 401 });
|
|
22
|
-
const contentType = request.headers.get("content-type") ?? "";
|
|
23
|
-
if (!/^application\/json(?:\s*;|\s*$)/i.test(contentType))
|
|
24
|
-
return new Response("Unsupported Media Type", { status: 415 });
|
|
25
|
-
const contentLength = Number(request.headers.get("content-length") ?? 0);
|
|
26
|
-
if (contentLength > maxBodyBytes)
|
|
27
|
-
return new Response("Payload Too Large", { status: 413 });
|
|
28
|
-
try {
|
|
29
|
-
const raw = await request.arrayBuffer();
|
|
30
|
-
if (raw.byteLength > maxBodyBytes)
|
|
31
|
-
return new Response("Payload Too Large", { status: 413 });
|
|
32
|
-
const update = JSON.parse(new TextDecoder().decode(raw));
|
|
33
|
-
if (!Number.isInteger(update.update_id))
|
|
34
|
-
return new Response("Bad Request", { status: 400 });
|
|
35
|
-
let replyPayload;
|
|
36
|
-
const sink = options.webhookReply === true ? (payload) => { replyPayload = payload; } : undefined;
|
|
37
|
-
await processWithOptionalReply(bot, update, sink);
|
|
38
|
-
return replyResponse(replyPayload);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
await options.onError?.(error);
|
|
42
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export function webhookCallback(bot, _framework = "express", options = {}) {
|
|
47
|
-
const maxBodyBytes = options.maxBodyBytes ?? 1_048_576;
|
|
48
|
-
return async (req, res) => {
|
|
49
|
-
const rawReq = req;
|
|
50
|
-
const rawRes = res;
|
|
51
|
-
const sendResponse = (status, message, contentType = "text/plain") => {
|
|
52
|
-
if (rawRes && typeof rawRes.writeHead === "function" && typeof rawRes.end === "function") {
|
|
53
|
-
rawRes.writeHead(status, { "Content-Type": contentType });
|
|
54
|
-
rawRes.end(message);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const expressLike = rawRes;
|
|
58
|
-
if (typeof expressLike?.status === "function" && typeof expressLike.send === "function") {
|
|
59
|
-
expressLike.status(status).send(message);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const koaLike = rawRes;
|
|
63
|
-
if (koaLike !== undefined) {
|
|
64
|
-
koaLike.status = status;
|
|
65
|
-
koaLike.body = message;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
if (rawReq.method !== "POST") {
|
|
69
|
-
sendResponse(405, "Method Not Allowed");
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (options.secretToken) {
|
|
73
|
-
if (!secureEqual(readHeader(rawReq, "x-telegram-bot-api-secret-token"), options.secretToken)) {
|
|
74
|
-
sendResponse(401, "Unauthorized");
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
let update;
|
|
80
|
-
if (typeof rawReq.arrayBuffer === "function") {
|
|
81
|
-
// Web-standard Request objects (e.g. Deno, Bun, WinterCG runtimes, or
|
|
82
|
-
// a converted fetch Request) expose the body through arrayBuffer().
|
|
83
|
-
// Checked before `body` because a Request's `body` is a ReadableStream.
|
|
84
|
-
const raw = await rawReq.arrayBuffer();
|
|
85
|
-
if (raw.byteLength > maxBodyBytes) {
|
|
86
|
-
sendResponse(413, "Payload Too Large");
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
update = JSON.parse(new TextDecoder().decode(raw));
|
|
90
|
-
}
|
|
91
|
-
else if (rawReq.body && typeof rawReq.body === "object") {
|
|
92
|
-
update = rawReq.body;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const chunks = [];
|
|
96
|
-
let totalBytes = 0;
|
|
97
|
-
for await (const chunk of rawReq) {
|
|
98
|
-
const buffer = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
99
|
-
totalBytes += buffer.length;
|
|
100
|
-
if (totalBytes > maxBodyBytes) {
|
|
101
|
-
sendResponse(413, "Payload Too Large");
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
chunks.push(buffer);
|
|
105
|
-
}
|
|
106
|
-
const raw = Buffer.concat(chunks).toString("utf8");
|
|
107
|
-
update = JSON.parse(raw);
|
|
108
|
-
}
|
|
109
|
-
if (!Number.isInteger(update?.update_id)) {
|
|
110
|
-
sendResponse(400, "Bad Request");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
let replyPayload;
|
|
114
|
-
const sink = options.webhookReply === true ? (payload) => { replyPayload = payload; } : undefined;
|
|
115
|
-
await processWithOptionalReply(bot, update, sink);
|
|
116
|
-
if (replyPayload !== undefined)
|
|
117
|
-
sendResponse(200, JSON.stringify(replyPayload), "application/json");
|
|
118
|
-
else
|
|
119
|
-
sendResponse(200, "OK");
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
await options.onError?.(error);
|
|
123
|
-
sendResponse(500, "Internal Server Error");
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function readHeader(req, name) {
|
|
128
|
-
const headers = req.headers;
|
|
129
|
-
if (!headers || typeof headers !== "object")
|
|
130
|
-
return "";
|
|
131
|
-
if (typeof headers.get === "function")
|
|
132
|
-
return headers.get(name) ?? "";
|
|
133
|
-
const value = headers[name];
|
|
134
|
-
return Array.isArray(value) ? value[0] ?? "" : value ?? "";
|
|
135
|
-
}
|
|
136
|
-
function secureEqual(left, right) {
|
|
137
|
-
const leftBuffer = Buffer.from(left, "utf8");
|
|
138
|
-
const rightBuffer = Buffer.from(right, "utf8");
|
|
139
|
-
return leftBuffer.length === rightBuffer.length && timingSafeEqual(leftBuffer, rightBuffer);
|
|
140
|
-
}
|
|
141
|
-
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/webhook/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqB9C,wFAAwF;AACxF,KAAK,UAAU,wBAAwB,CAAC,GAAe,EAAE,MAAc,EAAE,IAAkC;IACzG,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAAC,MAAM,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IACnE,MAAM,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,aAAa,CAAC,OAAwC;IAC7D,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAC1I,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAmB,GAAW,EAAE,UAA0B,EAAE;IAC9F,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,SAAS,CAAC;IACvD,OAAO,KAAK,EAAE,OAAgB,EAAqB,EAAE;QACnD,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;YA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AAC9F,CAAC"}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GENERATED_METHODS = exports.TELEGRAM_METHOD_NAMES = exports.TELEGRAM_API_VERSION = void 0;
|
|
4
|
-
/* eslint-disable */
|
|
5
|
-
/** Generated from the official Telegram Bot API documentation. Do not edit manually. */
|
|
6
|
-
exports.TELEGRAM_API_VERSION = "10.2";
|
|
7
|
-
exports.TELEGRAM_METHOD_NAMES = [
|
|
8
|
-
"addStickerToSet",
|
|
9
|
-
"answerCallbackQuery",
|
|
10
|
-
"answerChatJoinRequestQuery",
|
|
11
|
-
"answerGuestQuery",
|
|
12
|
-
"answerInlineQuery",
|
|
13
|
-
"answerPreCheckoutQuery",
|
|
14
|
-
"answerShippingQuery",
|
|
15
|
-
"answerWebAppQuery",
|
|
16
|
-
"approveChatJoinRequest",
|
|
17
|
-
"approveSuggestedPost",
|
|
18
|
-
"banChatMember",
|
|
19
|
-
"banChatSenderChat",
|
|
20
|
-
"close",
|
|
21
|
-
"closeForumTopic",
|
|
22
|
-
"closeGeneralForumTopic",
|
|
23
|
-
"convertGiftToStars",
|
|
24
|
-
"copyMessage",
|
|
25
|
-
"copyMessages",
|
|
26
|
-
"createChatInviteLink",
|
|
27
|
-
"createChatSubscriptionInviteLink",
|
|
28
|
-
"createForumTopic",
|
|
29
|
-
"createInvoiceLink",
|
|
30
|
-
"createNewStickerSet",
|
|
31
|
-
"declineChatJoinRequest",
|
|
32
|
-
"declineSuggestedPost",
|
|
33
|
-
"deleteAllMessageReactions",
|
|
34
|
-
"deleteBusinessMessages",
|
|
35
|
-
"deleteChatPhoto",
|
|
36
|
-
"deleteChatStickerSet",
|
|
37
|
-
"deleteEphemeralMessage",
|
|
38
|
-
"deleteForumTopic",
|
|
39
|
-
"deleteMessage",
|
|
40
|
-
"deleteMessageReaction",
|
|
41
|
-
"deleteMessages",
|
|
42
|
-
"deleteMyCommands",
|
|
43
|
-
"deleteStickerFromSet",
|
|
44
|
-
"deleteStickerSet",
|
|
45
|
-
"deleteStory",
|
|
46
|
-
"deleteWebhook",
|
|
47
|
-
"editChatInviteLink",
|
|
48
|
-
"editChatSubscriptionInviteLink",
|
|
49
|
-
"editEphemeralMessageCaption",
|
|
50
|
-
"editEphemeralMessageMedia",
|
|
51
|
-
"editEphemeralMessageReplyMarkup",
|
|
52
|
-
"editEphemeralMessageText",
|
|
53
|
-
"editForumTopic",
|
|
54
|
-
"editGeneralForumTopic",
|
|
55
|
-
"editMessageCaption",
|
|
56
|
-
"editMessageChecklist",
|
|
57
|
-
"editMessageLiveLocation",
|
|
58
|
-
"editMessageMedia",
|
|
59
|
-
"editMessageReplyMarkup",
|
|
60
|
-
"editMessageText",
|
|
61
|
-
"editStory",
|
|
62
|
-
"editUserStarSubscription",
|
|
63
|
-
"exportChatInviteLink",
|
|
64
|
-
"forwardMessage",
|
|
65
|
-
"forwardMessages",
|
|
66
|
-
"getAvailableGifts",
|
|
67
|
-
"getBusinessAccountGifts",
|
|
68
|
-
"getBusinessAccountStarBalance",
|
|
69
|
-
"getBusinessConnection",
|
|
70
|
-
"getChat",
|
|
71
|
-
"getChatAdministrators",
|
|
72
|
-
"getChatGifts",
|
|
73
|
-
"getChatMember",
|
|
74
|
-
"getChatMemberCount",
|
|
75
|
-
"getChatMenuButton",
|
|
76
|
-
"getCustomEmojiStickers",
|
|
77
|
-
"getFile",
|
|
78
|
-
"getForumTopicIconStickers",
|
|
79
|
-
"getGameHighScores",
|
|
80
|
-
"getManagedBotAccessSettings",
|
|
81
|
-
"getManagedBotToken",
|
|
82
|
-
"getMe",
|
|
83
|
-
"getMyCommands",
|
|
84
|
-
"getMyDefaultAdministratorRights",
|
|
85
|
-
"getMyDescription",
|
|
86
|
-
"getMyName",
|
|
87
|
-
"getMyShortDescription",
|
|
88
|
-
"getMyStarBalance",
|
|
89
|
-
"getStarTransactions",
|
|
90
|
-
"getStickerSet",
|
|
91
|
-
"getUpdates",
|
|
92
|
-
"getUserChatBoosts",
|
|
93
|
-
"getUserGifts",
|
|
94
|
-
"getUserPersonalChatMessages",
|
|
95
|
-
"getUserProfileAudios",
|
|
96
|
-
"getUserProfilePhotos",
|
|
97
|
-
"getWebhookInfo",
|
|
98
|
-
"giftPremiumSubscription",
|
|
99
|
-
"hideGeneralForumTopic",
|
|
100
|
-
"leaveChat",
|
|
101
|
-
"logOut",
|
|
102
|
-
"pinChatMessage",
|
|
103
|
-
"postStory",
|
|
104
|
-
"promoteChatMember",
|
|
105
|
-
"readBusinessMessage",
|
|
106
|
-
"refundStarPayment",
|
|
107
|
-
"removeBusinessAccountProfilePhoto",
|
|
108
|
-
"removeChatVerification",
|
|
109
|
-
"removeMyProfilePhoto",
|
|
110
|
-
"removeUserVerification",
|
|
111
|
-
"reopenForumTopic",
|
|
112
|
-
"reopenGeneralForumTopic",
|
|
113
|
-
"replaceManagedBotToken",
|
|
114
|
-
"replaceStickerInSet",
|
|
115
|
-
"repostStory",
|
|
116
|
-
"restrictChatMember",
|
|
117
|
-
"revokeChatInviteLink",
|
|
118
|
-
"savePreparedInlineMessage",
|
|
119
|
-
"savePreparedKeyboardButton",
|
|
120
|
-
"sendAnimation",
|
|
121
|
-
"sendAudio",
|
|
122
|
-
"sendChatAction",
|
|
123
|
-
"sendChatJoinRequestWebApp",
|
|
124
|
-
"sendChecklist",
|
|
125
|
-
"sendContact",
|
|
126
|
-
"sendDice",
|
|
127
|
-
"sendDocument",
|
|
128
|
-
"sendGame",
|
|
129
|
-
"sendGift",
|
|
130
|
-
"sendInvoice",
|
|
131
|
-
"sendLivePhoto",
|
|
132
|
-
"sendLocation",
|
|
133
|
-
"sendMediaGroup",
|
|
134
|
-
"sendMessage",
|
|
135
|
-
"sendMessageDraft",
|
|
136
|
-
"sendPaidMedia",
|
|
137
|
-
"sendPhoto",
|
|
138
|
-
"sendPoll",
|
|
139
|
-
"sendRichMessage",
|
|
140
|
-
"sendRichMessageDraft",
|
|
141
|
-
"sendSticker",
|
|
142
|
-
"sendVenue",
|
|
143
|
-
"sendVideo",
|
|
144
|
-
"sendVideoNote",
|
|
145
|
-
"sendVoice",
|
|
146
|
-
"setBusinessAccountBio",
|
|
147
|
-
"setBusinessAccountGiftSettings",
|
|
148
|
-
"setBusinessAccountName",
|
|
149
|
-
"setBusinessAccountProfilePhoto",
|
|
150
|
-
"setBusinessAccountUsername",
|
|
151
|
-
"setChatAdministratorCustomTitle",
|
|
152
|
-
"setChatDescription",
|
|
153
|
-
"setChatMemberTag",
|
|
154
|
-
"setChatMenuButton",
|
|
155
|
-
"setChatPermissions",
|
|
156
|
-
"setChatPhoto",
|
|
157
|
-
"setChatStickerSet",
|
|
158
|
-
"setChatTitle",
|
|
159
|
-
"setCustomEmojiStickerSetThumbnail",
|
|
160
|
-
"setGameScore",
|
|
161
|
-
"setManagedBotAccessSettings",
|
|
162
|
-
"setMessageReaction",
|
|
163
|
-
"setMyCommands",
|
|
164
|
-
"setMyDefaultAdministratorRights",
|
|
165
|
-
"setMyDescription",
|
|
166
|
-
"setMyName",
|
|
167
|
-
"setMyProfilePhoto",
|
|
168
|
-
"setMyShortDescription",
|
|
169
|
-
"setPassportDataErrors",
|
|
170
|
-
"setStickerEmojiList",
|
|
171
|
-
"setStickerKeywords",
|
|
172
|
-
"setStickerMaskPosition",
|
|
173
|
-
"setStickerPositionInSet",
|
|
174
|
-
"setStickerSetThumbnail",
|
|
175
|
-
"setStickerSetTitle",
|
|
176
|
-
"setUserEmojiStatus",
|
|
177
|
-
"setWebhook",
|
|
178
|
-
"stopMessageLiveLocation",
|
|
179
|
-
"stopPoll",
|
|
180
|
-
"transferBusinessAccountStars",
|
|
181
|
-
"transferGift",
|
|
182
|
-
"unbanChatMember",
|
|
183
|
-
"unbanChatSenderChat",
|
|
184
|
-
"unhideGeneralForumTopic",
|
|
185
|
-
"unpinAllChatMessages",
|
|
186
|
-
"unpinAllForumTopicMessages",
|
|
187
|
-
"unpinAllGeneralForumTopicMessages",
|
|
188
|
-
"unpinChatMessage",
|
|
189
|
-
"upgradeGift",
|
|
190
|
-
"uploadStickerFile",
|
|
191
|
-
"verifyChat",
|
|
192
|
-
"verifyUser"
|
|
193
|
-
];
|
|
194
|
-
exports.GENERATED_METHODS = Object.freeze(Object.fromEntries(exports.TELEGRAM_METHOD_NAMES.map((name) => [name, name])));
|
package/dist-cjs/package.json
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiClient = void 0;
|
|
4
|
-
const api_js_1 = require("../../generated/api.js");
|
|
5
|
-
const webhook_reply_js_1 = require("../core/webhook-reply.js");
|
|
6
|
-
const errors_js_1 = require("./errors.js");
|
|
7
|
-
class ApiClient {
|
|
8
|
-
methods;
|
|
9
|
-
transport;
|
|
10
|
-
hooks;
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.transport = options.transport;
|
|
13
|
-
this.hooks = options.hooks ?? {};
|
|
14
|
-
const knownMethods = new Set(api_js_1.TELEGRAM_METHOD_NAMES);
|
|
15
|
-
this.methods = new Proxy({}, {
|
|
16
|
-
get: (_target, property) => {
|
|
17
|
-
if (typeof property !== "string")
|
|
18
|
-
return undefined;
|
|
19
|
-
if (property === "then")
|
|
20
|
-
return undefined;
|
|
21
|
-
if (!knownMethods.has(property))
|
|
22
|
-
throw new TypeError(`Unknown Telegram API method: ${property}`);
|
|
23
|
-
return (payload) => this.request(property, payload);
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async call(method, ...args) { return this.request(method, args[0]); }
|
|
28
|
-
async request(method, payload, signal, options) {
|
|
29
|
-
// Webhook reply mode: the first call while handling a webhook update is
|
|
30
|
-
// answered through the webhook HTTP response instead of the transport.
|
|
31
|
-
const webhookReply = (0, webhook_reply_js_1.claimWebhookReply)(method, payload);
|
|
32
|
-
if (webhookReply) {
|
|
33
|
-
const context = { method, payload, startedAt: Date.now() };
|
|
34
|
-
await this.hooks.onRequest?.(context);
|
|
35
|
-
context.durationMs = Date.now() - context.startedAt;
|
|
36
|
-
context.response = webhookReply.data;
|
|
37
|
-
await this.hooks.onResponse?.(context);
|
|
38
|
-
return webhookReply.data.result;
|
|
39
|
-
}
|
|
40
|
-
const context = { method, payload, startedAt: Date.now() };
|
|
41
|
-
await this.hooks.onRequest?.(context);
|
|
42
|
-
try {
|
|
43
|
-
const request = { method };
|
|
44
|
-
if (payload !== undefined)
|
|
45
|
-
request.payload = payload;
|
|
46
|
-
if (signal !== undefined)
|
|
47
|
-
request.signal = signal;
|
|
48
|
-
if (options?.timeoutMs !== undefined)
|
|
49
|
-
request.timeoutMs = options.timeoutMs;
|
|
50
|
-
const response = await this.transport.request(request);
|
|
51
|
-
context.durationMs = Date.now() - context.startedAt;
|
|
52
|
-
context.response = response.data;
|
|
53
|
-
await this.hooks.onResponse?.(context);
|
|
54
|
-
if (!response.data.ok || response.data.result === undefined)
|
|
55
|
-
throw (0, errors_js_1.telegramErrorFromResponse)(response.data, { method, payload, status: response.status });
|
|
56
|
-
return response.data.result;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
context.durationMs = Date.now() - context.startedAt;
|
|
60
|
-
context.error = error;
|
|
61
|
-
await this.hooks.onError?.(context);
|
|
62
|
-
if (error instanceof errors_js_1.TelegramError)
|
|
63
|
-
throw error;
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async raw(method, payload, signal) {
|
|
68
|
-
const request = { method };
|
|
69
|
-
if (payload !== undefined)
|
|
70
|
-
request.payload = payload;
|
|
71
|
-
if (signal !== undefined)
|
|
72
|
-
request.signal = signal;
|
|
73
|
-
const response = await this.transport.request(request);
|
|
74
|
-
if (!response.data.ok)
|
|
75
|
-
throw (0, errors_js_1.telegramErrorFromResponse)(response.data, { method, payload, status: response.status });
|
|
76
|
-
return response.data.result;
|
|
77
|
-
}
|
|
78
|
-
/** Direct download URL for a `file_path` returned by `getFile`; undefined when the transport cannot download files. */
|
|
79
|
-
fileUrl(filePath) {
|
|
80
|
-
return this.transport.fileUrl?.(filePath);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Resolves a `file_id` through `getFile` and downloads the bytes behind the
|
|
84
|
-
* returned `file_path`. Throws a `TelegramError` (kind `validation`) when
|
|
85
|
-
* Telegram returns no `file_path`, and a `TelegramNetworkError` when the
|
|
86
|
-
* download itself fails.
|
|
87
|
-
*/
|
|
88
|
-
async downloadFile(fileId, options = {}) {
|
|
89
|
-
const file = await this.methods.getFile({ file_id: fileId });
|
|
90
|
-
if (!file.file_path) {
|
|
91
|
-
throw new errors_js_1.TelegramError("Telegram returned no file_path for this file; request a fresh one with getFile", { method: "getFile", payload: { file_id: fileId }, kind: "validation" });
|
|
92
|
-
}
|
|
93
|
-
if (!this.transport.download || !this.transport.fileUrl) {
|
|
94
|
-
throw new errors_js_1.TelegramError("The configured transport does not support file downloads", { method: "getFile", payload: { file_id: fileId }, kind: "validation" });
|
|
95
|
-
}
|
|
96
|
-
const bytes = await this.transport.download(file.file_path, options.signal);
|
|
97
|
-
return {
|
|
98
|
-
file,
|
|
99
|
-
bytes,
|
|
100
|
-
filePath: file.file_path,
|
|
101
|
-
url: this.transport.fileUrl(file.file_path),
|
|
102
|
-
fileName: file.file_path.split("/").pop() ?? file.file_path,
|
|
103
|
-
sizeBytes: bytes.byteLength,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.ApiClient = ApiClient;
|