@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
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { WebAppInfo } from "./markup.js";
|
|
2
|
-
/** This object represents the bot's name. */
|
|
3
|
-
export interface BotName {
|
|
4
|
-
/** The bot's name */
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
7
|
-
/** This object represents the bot's description. */
|
|
8
|
-
export interface BotDescription {
|
|
9
|
-
/** The bot's description */
|
|
10
|
-
description: string;
|
|
11
|
-
}
|
|
12
|
-
/** This object represents the bot's short description. */
|
|
13
|
-
export interface BotShortDescription {
|
|
14
|
-
/** The bot's short description */
|
|
15
|
-
short_description: string;
|
|
16
|
-
}
|
|
17
|
-
/** This object describes the bot's menu button in a private chat. It should be one of
|
|
18
|
-
- MenuButtonCommands
|
|
19
|
-
- MenuButtonWebApp
|
|
20
|
-
- MenuButtonDefault
|
|
21
|
-
|
|
22
|
-
If a menu button other than MenuButtonDefault is set for a private chat, then it is applied in the chat. Otherwise the default menu button is applied. By default, the menu button opens the list of bot commands. */
|
|
23
|
-
export type MenuButton = MenuButtonCommands | MenuButtonWebApp | MenuButtonDefault;
|
|
24
|
-
/** Represents a menu button, which opens the bot's list of commands. */
|
|
25
|
-
export interface MenuButtonCommands {
|
|
26
|
-
/** Type of the button, must be commands */
|
|
27
|
-
type: "commands";
|
|
28
|
-
}
|
|
29
|
-
/** Represents a menu button, which launches a Web App. */
|
|
30
|
-
export interface MenuButtonWebApp {
|
|
31
|
-
/** Button type, must be web_app */
|
|
32
|
-
type: "web_app";
|
|
33
|
-
/** Text on the button */
|
|
34
|
-
text: string;
|
|
35
|
-
/** Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Alternatively, a t.me link to a Web App can be specified in the object instead of the Web App's URL, in which case the Web App will be opened as if the user pressed the link. */
|
|
36
|
-
web_app: WebAppInfo;
|
|
37
|
-
}
|
|
38
|
-
/** Describes that no specific value for the menu button was set. */
|
|
39
|
-
export interface MenuButtonDefault {
|
|
40
|
-
/** Type of the button, must be default */
|
|
41
|
-
type: "default";
|
|
42
|
-
}
|
|
43
|
-
/** This object represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported:
|
|
44
|
-
- BotCommandScopeDefault
|
|
45
|
-
- BotCommandScopeAllPrivateChats
|
|
46
|
-
- BotCommandScopeAllGroupChats
|
|
47
|
-
- BotCommandScopeAllChatAdministrators
|
|
48
|
-
- BotCommandScopeChat
|
|
49
|
-
- BotCommandScopeChatAdministrators
|
|
50
|
-
- BotCommandScopeChatMember
|
|
51
|
-
|
|
52
|
-
## Determining list of commands
|
|
53
|
-
|
|
54
|
-
The following algorithm is used to determine the list of commands for a particular user viewing the bot menu. The first list of commands which is set is returned:
|
|
55
|
-
|
|
56
|
-
### Commands in the chat with the bot
|
|
57
|
-
- botCommandScopeChat + language_code
|
|
58
|
-
- botCommandScopeChat
|
|
59
|
-
- botCommandScopeAllPrivateChats + language_code
|
|
60
|
-
- botCommandScopeAllPrivateChats
|
|
61
|
-
- botCommandScopeDefault + language_code
|
|
62
|
-
- botCommandScopeDefault
|
|
63
|
-
|
|
64
|
-
### Commands in group and supergroup chats
|
|
65
|
-
- botCommandScopeChatMember + language_code
|
|
66
|
-
- botCommandScopeChatMember
|
|
67
|
-
- botCommandScopeChatAdministrators + language_code (administrators only)
|
|
68
|
-
- botCommandScopeChatAdministrators (administrators only)
|
|
69
|
-
- botCommandScopeChat + language_code
|
|
70
|
-
- botCommandScopeChat
|
|
71
|
-
- botCommandScopeAllChatAdministrators + language_code (administrators only)
|
|
72
|
-
- botCommandScopeAllChatAdministrators (administrators only)
|
|
73
|
-
- botCommandScopeAllGroupChats + language_code
|
|
74
|
-
- botCommandScopeAllGroupChats
|
|
75
|
-
- botCommandScopeDefault + language_code
|
|
76
|
-
- botCommandScopeDefault */
|
|
77
|
-
export type BotCommandScope = BotCommandScopeDefault | BotCommandScopeAllPrivateChats | BotCommandScopeAllGroupChats | BotCommandScopeAllChatAdministrators | BotCommandScopeChat | BotCommandScopeChatAdministrators | BotCommandScopeChatMember;
|
|
78
|
-
/** Represents the default scope of bot commands. Default commands are used if no commands with a narrower scope are specified for the user. */
|
|
79
|
-
export interface BotCommandScopeDefault {
|
|
80
|
-
/** Scope type, must be default */
|
|
81
|
-
type: "default";
|
|
82
|
-
}
|
|
83
|
-
/** Represents the scope of bot commands, covering all private chats. */
|
|
84
|
-
export interface BotCommandScopeAllPrivateChats {
|
|
85
|
-
/** Scope type, must be all_private_chats */
|
|
86
|
-
type: "all_private_chats";
|
|
87
|
-
}
|
|
88
|
-
/** Represents the scope of bot commands, covering all group and supergroup chats. */
|
|
89
|
-
export interface BotCommandScopeAllGroupChats {
|
|
90
|
-
/** Scope type, must be all_group_chats */
|
|
91
|
-
type: "all_group_chats";
|
|
92
|
-
}
|
|
93
|
-
/** Represents the scope of bot commands, covering all group and supergroup chat administrators. */
|
|
94
|
-
export interface BotCommandScopeAllChatAdministrators {
|
|
95
|
-
/** Scope type, must be all_chat_administrators */
|
|
96
|
-
type: "all_chat_administrators";
|
|
97
|
-
}
|
|
98
|
-
/** Represents the scope of bot commands, covering a specific chat. */
|
|
99
|
-
export interface BotCommandScopeChat {
|
|
100
|
-
/** Scope type, must be chat */
|
|
101
|
-
type: "chat";
|
|
102
|
-
/** Unique identifier for the target chat or username of the target supergroup in the format `@username`. Channel direct messages chats and channel chats aren't supported. */
|
|
103
|
-
chat_id: number | string;
|
|
104
|
-
}
|
|
105
|
-
/** Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat. */
|
|
106
|
-
export interface BotCommandScopeChatAdministrators {
|
|
107
|
-
/** Scope type, must be chat_administrators */
|
|
108
|
-
type: "chat_administrators";
|
|
109
|
-
/** Unique identifier for the target chat or username of the target supergroup in the format `@username`. Channel direct messages chats and channel chats aren't supported. */
|
|
110
|
-
chat_id: number | string;
|
|
111
|
-
}
|
|
112
|
-
/** Represents the scope of bot commands, covering a specific member of a group or supergroup chat. */
|
|
113
|
-
export interface BotCommandScopeChatMember {
|
|
114
|
-
/** Scope type, must be chat_member */
|
|
115
|
-
type: "chat_member";
|
|
116
|
-
/** Unique identifier for the target chat or username of the target supergroup in the format `@username`. Channel direct messages chats and channel chats aren't supported. */
|
|
117
|
-
chat_id: number | string;
|
|
118
|
-
/** Unique identifier of the target user */
|
|
119
|
-
user_id: number;
|
|
120
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { ReactionType } from "./message.js";
|
|
2
|
-
/** Describes the position of a clickable area within a story. */
|
|
3
|
-
export interface StoryAreaPosition {
|
|
4
|
-
/** The abscissa of the area's center, as a percentage of the media width */
|
|
5
|
-
x_percentage: number;
|
|
6
|
-
/** The ordinate of the area's center, as a percentage of the media height */
|
|
7
|
-
y_percentage: number;
|
|
8
|
-
/** The width of the area's rectangle, as a percentage of the media width */
|
|
9
|
-
width_percentage: number;
|
|
10
|
-
/** The height of the area's rectangle, as a percentage of the media height */
|
|
11
|
-
height_percentage: number;
|
|
12
|
-
/** The clockwise rotation angle of the rectangle, in degrees; 0-360 */
|
|
13
|
-
rotation_angle: number;
|
|
14
|
-
/** The radius of the rectangle corner rounding, as a percentage of the media width */
|
|
15
|
-
corner_radius_percentage: number;
|
|
16
|
-
}
|
|
17
|
-
/** Describes the physical address of a location. */
|
|
18
|
-
export interface LocationAddress {
|
|
19
|
-
/** The two-letter ISO 3166-1 alpha-2 country code of the country where the location is located */
|
|
20
|
-
country_code: string;
|
|
21
|
-
/** State of the location */
|
|
22
|
-
state?: string;
|
|
23
|
-
/** City of the location */
|
|
24
|
-
city?: string;
|
|
25
|
-
/** Street address of the location */
|
|
26
|
-
street?: string;
|
|
27
|
-
}
|
|
28
|
-
/** Describes the type of a clickable area on a story. Currently, it can be one of
|
|
29
|
-
|
|
30
|
-
- StoryAreaTypeLocation
|
|
31
|
-
- StoryAreaTypeSuggestedReaction
|
|
32
|
-
- StoryAreaTypeLink
|
|
33
|
-
- StoryAreaTypeWeather
|
|
34
|
-
- StoryAreaTypeUniqueGift */
|
|
35
|
-
export type StoryAreaType = StoryAreaTypeLocation | StoryAreaTypeSuggestedReaction | StoryAreaTypeLink | StoryAreaTypeWeather | StoryAreaTypeUniqueGift;
|
|
36
|
-
/** Describes a story area pointing to a location. Currently, a story can have up to 10 location areas. */
|
|
37
|
-
export interface StoryAreaTypeLocation {
|
|
38
|
-
/** Type of the area, always “location” */
|
|
39
|
-
type: "location";
|
|
40
|
-
/** Location latitude in degrees */
|
|
41
|
-
latitude: number;
|
|
42
|
-
/** Location longitude in degrees */
|
|
43
|
-
longitude: number;
|
|
44
|
-
/** Address of the location */
|
|
45
|
-
address?: LocationAddress;
|
|
46
|
-
}
|
|
47
|
-
/** Describes a story area pointing to a suggested reaction. Currently, a story can have up to 5 suggested reaction areas. */
|
|
48
|
-
export interface StoryAreaTypeSuggestedReaction {
|
|
49
|
-
/** Type of the area, always “suggested_reaction” */
|
|
50
|
-
type: "suggested_reaction";
|
|
51
|
-
/** Type of the reaction */
|
|
52
|
-
reaction_type: ReactionType;
|
|
53
|
-
/** Pass True if the reaction area has a dark background */
|
|
54
|
-
is_dark?: boolean;
|
|
55
|
-
/** Pass True if reaction area corner is flipped */
|
|
56
|
-
is_flipped?: boolean;
|
|
57
|
-
}
|
|
58
|
-
/** Describes a story area pointing to an HTTP or tg:// link. Currently, a story can have up to 3 link areas. */
|
|
59
|
-
export interface StoryAreaTypeLink {
|
|
60
|
-
/** Type of the area, always “link” */
|
|
61
|
-
type: "link";
|
|
62
|
-
/** HTTP or tg:// URL to be opened when the area is clicked */
|
|
63
|
-
url: string;
|
|
64
|
-
}
|
|
65
|
-
/** Describes a story area containing weather information. Currently, a story can have up to 3 weather areas. */
|
|
66
|
-
export interface StoryAreaTypeWeather {
|
|
67
|
-
/** Type of the area, always “weather” */
|
|
68
|
-
type: "weather";
|
|
69
|
-
/** Temperature, in degree Celsius */
|
|
70
|
-
temperature: number;
|
|
71
|
-
/** Emoji representing the weather */
|
|
72
|
-
emoji: string;
|
|
73
|
-
/** A color of the area background in the ARGB format */
|
|
74
|
-
background_color: number;
|
|
75
|
-
}
|
|
76
|
-
/** Describes a story area pointing to a unique gift. Currently, a story can have at most 1 unique gift area. */
|
|
77
|
-
export interface StoryAreaTypeUniqueGift {
|
|
78
|
-
/** Type of the area, always “unique_gift” */
|
|
79
|
-
type: "unique_gift";
|
|
80
|
-
/** Unique name of the gift */
|
|
81
|
-
name: string;
|
|
82
|
-
}
|
|
83
|
-
/** Describes a clickable area on a story media. */
|
|
84
|
-
export interface StoryArea {
|
|
85
|
-
/** Position of the area */
|
|
86
|
-
position: StoryAreaPosition;
|
|
87
|
-
/** Type of the area */
|
|
88
|
-
type: StoryAreaType;
|
|
89
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { ChosenInlineResult, InlineQuery } from "./inline.js";
|
|
2
|
-
import type { BotSubscriptionUpdated, BusinessConnection, BusinessMessagesDeleted, Chat, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, ChatMemberUpdated, ManagedBotUpdated, User } from "./manage.js";
|
|
3
|
-
import type { CallbackQuery } from "./markup.js";
|
|
4
|
-
import type { Message, MessageReactionCountUpdated, MessageReactionUpdated, Poll, PollAnswer } from "./message.js";
|
|
5
|
-
import type { PaidMediaPurchased, PreCheckoutQuery, ShippingQuery } from "./payment.js";
|
|
6
|
-
/** Internal namespace used to make some message types more accurate */
|
|
7
|
-
export declare namespace Update {
|
|
8
|
-
/** Internal type holding properties that message updates in private chats share. */
|
|
9
|
-
interface Private {
|
|
10
|
-
chat: Chat.PrivateChat;
|
|
11
|
-
}
|
|
12
|
-
/** Internal type holding properties that message updates in channels share. */
|
|
13
|
-
interface Channel {
|
|
14
|
-
chat: Chat.ChannelChat;
|
|
15
|
-
}
|
|
16
|
-
/** Internal type holding properties that message updates outside of channels share. */
|
|
17
|
-
interface NonChannel {
|
|
18
|
-
chat: Exclude<Chat, Chat.ChannelChat>;
|
|
19
|
-
from: User;
|
|
20
|
-
}
|
|
21
|
-
/** Internal type holding properties that updates about edited messages share. */
|
|
22
|
-
interface Edited {
|
|
23
|
-
/** Date the message was last edited in Unix time */
|
|
24
|
-
edit_date: number;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/** This object represents an incoming update.
|
|
28
|
-
At most one of the optional fields can be present in any given update. */
|
|
29
|
-
export interface Update {
|
|
30
|
-
/** The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This identifier becomes especially handy if you're using webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially. */
|
|
31
|
-
update_id: number;
|
|
32
|
-
/** New incoming message of any kind - text, photo, sticker, etc. */
|
|
33
|
-
message?: Message & Update.NonChannel;
|
|
34
|
-
/** New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot. */
|
|
35
|
-
edited_message?: Message & Update.Edited & Update.NonChannel;
|
|
36
|
-
/** New incoming channel post of any kind - text, photo, sticker, etc. */
|
|
37
|
-
channel_post?: Message & Update.Channel;
|
|
38
|
-
/** New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot. */
|
|
39
|
-
edited_channel_post?: Message & Update.Edited & Update.Channel;
|
|
40
|
-
/** The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot */
|
|
41
|
-
business_connection?: BusinessConnection;
|
|
42
|
-
/** New message from a connected business account */
|
|
43
|
-
business_message?: Message & Update.Private;
|
|
44
|
-
/** New version of a message from a connected business account */
|
|
45
|
-
edited_business_message?: Message & Update.Edited & Update.Private;
|
|
46
|
-
/** Messages were deleted from a connected business account */
|
|
47
|
-
deleted_business_messages?: BusinessMessagesDeleted;
|
|
48
|
-
/** New guest message. The bot can use the field Message.guest_query_id and the method answerGuestQuery to send a message in response. */
|
|
49
|
-
guest_message?: Message & Update.NonChannel;
|
|
50
|
-
/** A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify "message_reaction" in the list of allowed_updates to receive these updates. The update isn't received for reactions set by bots. */
|
|
51
|
-
message_reaction?: MessageReactionUpdated;
|
|
52
|
-
/** Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify "message_reaction_count" in the list of allowed_updates to receive these updates. The updates are grouped and can be sent with delay up to a few minutes. */
|
|
53
|
-
message_reaction_count?: MessageReactionCountUpdated;
|
|
54
|
-
/** New incoming inline query */
|
|
55
|
-
inline_query?: InlineQuery;
|
|
56
|
-
/** The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot. */
|
|
57
|
-
chosen_inline_result?: ChosenInlineResult;
|
|
58
|
-
/** New incoming callback query */
|
|
59
|
-
callback_query?: CallbackQuery;
|
|
60
|
-
/** New incoming shipping query. Only for invoices with flexible price. */
|
|
61
|
-
shipping_query?: ShippingQuery;
|
|
62
|
-
/** New incoming pre-checkout query. Contains full information about checkout. */
|
|
63
|
-
pre_checkout_query?: PreCheckoutQuery;
|
|
64
|
-
/** A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat */
|
|
65
|
-
purchased_paid_media?: PaidMediaPurchased;
|
|
66
|
-
/** New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot. */
|
|
67
|
-
poll?: Poll;
|
|
68
|
-
/** A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. */
|
|
69
|
-
poll_answer?: PollAnswer;
|
|
70
|
-
/** The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user. */
|
|
71
|
-
my_chat_member?: ChatMemberUpdated;
|
|
72
|
-
/** A chat member's status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates. */
|
|
73
|
-
chat_member?: ChatMemberUpdated;
|
|
74
|
-
/** A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates. */
|
|
75
|
-
chat_join_request?: ChatJoinRequest;
|
|
76
|
-
/** A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates. */
|
|
77
|
-
chat_boost?: ChatBoostUpdated;
|
|
78
|
-
/** A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates. */
|
|
79
|
-
removed_chat_boost?: ChatBoostRemoved;
|
|
80
|
-
/** A new bot was created to be managed by the bot, or token or owner of a managed bot was changed */
|
|
81
|
-
managed_bot?: ManagedBotUpdated;
|
|
82
|
-
/** User payment subscription has changed */
|
|
83
|
-
subscription?: BotSubscriptionUpdated;
|
|
84
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FetchTransport = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const consumers_1 = require("node:stream/consumers");
|
|
7
|
-
const errors_js_1 = require("./errors.js");
|
|
8
|
-
class FetchTransport {
|
|
9
|
-
baseUrl;
|
|
10
|
-
fetchImpl;
|
|
11
|
-
timeoutMs;
|
|
12
|
-
retries;
|
|
13
|
-
backoffMs;
|
|
14
|
-
maxBackoffMs;
|
|
15
|
-
jitter;
|
|
16
|
-
headers;
|
|
17
|
-
floodGate;
|
|
18
|
-
/** Timestamp (ms) until which Telegram asked us to stop sending. */
|
|
19
|
-
floodUntil = 0;
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
this.baseUrl = (options.baseUrl ?? "https://api.telegram.org").replace(/\/$/, "");
|
|
22
|
-
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
23
|
-
if (!this.fetchImpl)
|
|
24
|
-
throw new Error("A fetch implementation is required.");
|
|
25
|
-
this.timeoutMs = options.timeoutMs ?? 30_000;
|
|
26
|
-
this.retries = options.retries ?? 2;
|
|
27
|
-
this.backoffMs = options.backoffMs ?? 250;
|
|
28
|
-
this.maxBackoffMs = options.maxBackoffMs ?? 8_000;
|
|
29
|
-
this.jitter = options.jitter ?? 0.2;
|
|
30
|
-
this.headers = options.headers ?? {};
|
|
31
|
-
this.floodGate = options.floodGate ?? true;
|
|
32
|
-
}
|
|
33
|
-
/** Waits out the remainder of a Telegram-ordered flood window, if any. */
|
|
34
|
-
async waitForFloodWindow() {
|
|
35
|
-
if (!this.floodGate)
|
|
36
|
-
return;
|
|
37
|
-
const waitMs = this.floodUntil - Date.now();
|
|
38
|
-
if (waitMs > 0)
|
|
39
|
-
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
40
|
-
}
|
|
41
|
-
/** Extends the flood window when Telegram answers 429 or sends retry_after. */
|
|
42
|
-
recordFloodWindow(data) {
|
|
43
|
-
if (!this.floodGate)
|
|
44
|
-
return;
|
|
45
|
-
if (data.ok || (data.error_code !== 429 && data.parameters?.retry_after === undefined))
|
|
46
|
-
return;
|
|
47
|
-
const retryAfterMs = Math.max(0, (data.parameters?.retry_after ?? 0) * 1000);
|
|
48
|
-
this.floodUntil = Math.max(this.floodUntil, Date.now() + retryAfterMs);
|
|
49
|
-
}
|
|
50
|
-
/** Direct-download URL for a `file_path` from `getFile` (`/bot<token>` → `/file/bot<token>`). */
|
|
51
|
-
fileUrl(filePath) {
|
|
52
|
-
const downloadBase = /\/bot[^/]+$/.test(this.baseUrl) ? this.baseUrl.replace(/\/bot([^/]+)$/, "/file/bot$1") : this.baseUrl;
|
|
53
|
-
return `${downloadBase}/${filePath}`;
|
|
54
|
-
}
|
|
55
|
-
/** Downloads the raw bytes behind a `file_path` from `getFile` (Telegram caps downloads at 20 MB). */
|
|
56
|
-
async download(filePath, signal) {
|
|
57
|
-
const controller = new AbortController();
|
|
58
|
-
const timeout = setTimeout(() => controller.abort(new Error("File download timed out")), Math.max(this.timeoutMs, 120_000));
|
|
59
|
-
const onAbort = () => controller.abort(signal?.reason);
|
|
60
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
61
|
-
try {
|
|
62
|
-
const response = await this.fetchImpl(this.fileUrl(filePath), { method: "GET", signal: controller.signal });
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
const bodyText = await response.text().catch(() => "");
|
|
65
|
-
throw new errors_js_1.TelegramNetworkError(`Failed to download ${filePath}: HTTP ${response.status} ${response.statusText || "request failed"}`, { method: "getFile", payload: { file_path: filePath }, status: response.status, cause: bodyText.slice(0, 512) });
|
|
66
|
-
}
|
|
67
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
if (error instanceof errors_js_1.TelegramNetworkError)
|
|
71
|
-
throw error;
|
|
72
|
-
if (signal?.aborted)
|
|
73
|
-
throw error;
|
|
74
|
-
throw new errors_js_1.TelegramNetworkError(`Failed to download ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { method: "getFile", payload: { file_path: filePath }, cause: error });
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
clearTimeout(timeout);
|
|
78
|
-
signal?.removeEventListener("abort", onAbort);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async request({ method, payload = {}, signal, timeoutMs }) {
|
|
82
|
-
const effectiveTimeoutMs = timeoutMs ?? this.timeoutMs;
|
|
83
|
-
const hasUpload = await containsUpload(payload);
|
|
84
|
-
let body;
|
|
85
|
-
const headers = new Headers(this.headers);
|
|
86
|
-
if (hasUpload) {
|
|
87
|
-
const form = new FormData();
|
|
88
|
-
for (const [key, value] of Object.entries(payload))
|
|
89
|
-
await appendFormValue(form, key, value);
|
|
90
|
-
body = form;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
headers.set("content-type", "application/json; charset=utf-8");
|
|
94
|
-
body = JSON.stringify(payload);
|
|
95
|
-
}
|
|
96
|
-
let attempt = 0;
|
|
97
|
-
while (true) {
|
|
98
|
-
await this.waitForFloodWindow();
|
|
99
|
-
let responseStatus;
|
|
100
|
-
const controller = new AbortController();
|
|
101
|
-
const timeout = setTimeout(() => controller.abort(new Error(`Request timed out after ${effectiveTimeoutMs}ms`)), effectiveTimeoutMs);
|
|
102
|
-
const onAbort = () => controller.abort(signal?.reason);
|
|
103
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
104
|
-
try {
|
|
105
|
-
const normalizedMethod = method.replace(/^\//, "");
|
|
106
|
-
const response = await this.fetchImpl(`${this.baseUrl}/${normalizedMethod}`, {
|
|
107
|
-
method: "POST",
|
|
108
|
-
headers,
|
|
109
|
-
body,
|
|
110
|
-
signal: controller.signal,
|
|
111
|
-
});
|
|
112
|
-
responseStatus = response.status;
|
|
113
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
114
|
-
if (contentType.length > 0 && !/json/i.test(contentType)) {
|
|
115
|
-
const bodyText = await response.text();
|
|
116
|
-
const error = new errors_js_1.TelegramNetworkError(`HTTP ${response.status} ${response.statusText || "request failed"} returned a non-JSON response`, { method, payload, status: response.status, cause: bodyText.slice(0, 512) });
|
|
117
|
-
if (isRetryableStatus(response.status) && attempt < this.retries) {
|
|
118
|
-
await waitBeforeRetry(attempt, this.backoffMs, this.maxBackoffMs, this.jitter);
|
|
119
|
-
attempt += 1;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
const data = await response.json();
|
|
125
|
-
this.recordFloodWindow(data);
|
|
126
|
-
if (!data.ok && isRetryableResponse(response.status, data) && attempt < this.retries) {
|
|
127
|
-
const retryAfterMs = data.parameters?.retry_after === undefined ? undefined : Math.max(0, data.parameters.retry_after * 1000);
|
|
128
|
-
await waitBeforeRetry(attempt, this.backoffMs, this.maxBackoffMs, this.jitter, retryAfterMs);
|
|
129
|
-
attempt += 1;
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
return { status: response.status, headers: response.headers, data };
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (signal?.aborted)
|
|
136
|
-
throw error;
|
|
137
|
-
if (error instanceof errors_js_1.TelegramNetworkError && error.status !== undefined) {
|
|
138
|
-
if (isRetryableStatus(error.status) && attempt < this.retries) {
|
|
139
|
-
await waitBeforeRetry(attempt, this.backoffMs, this.maxBackoffMs, this.jitter);
|
|
140
|
-
attempt += 1;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
if (responseStatus !== undefined && error instanceof SyntaxError) {
|
|
146
|
-
const parseError = new errors_js_1.TelegramNetworkError(`HTTP ${responseStatus} ${responseStatus >= 500 ? "server" : "request"} returned invalid JSON`, { method, payload, status: responseStatus, cause: error });
|
|
147
|
-
if (isRetryableStatus(responseStatus) && attempt < this.retries) {
|
|
148
|
-
await waitBeforeRetry(attempt, this.backoffMs, this.maxBackoffMs, this.jitter);
|
|
149
|
-
attempt += 1;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
throw parseError;
|
|
153
|
-
}
|
|
154
|
-
if (attempt >= this.retries || !isRetryableNetworkError(error)) {
|
|
155
|
-
throw new errors_js_1.TelegramNetworkError(error instanceof Error ? error.message : "Network request failed", { method, payload, cause: error });
|
|
156
|
-
}
|
|
157
|
-
await waitBeforeRetry(attempt, this.backoffMs, this.maxBackoffMs, this.jitter);
|
|
158
|
-
attempt += 1;
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
clearTimeout(timeout);
|
|
162
|
-
signal?.removeEventListener("abort", onAbort);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.FetchTransport = FetchTransport;
|
|
168
|
-
function isRetryableStatus(status) { return status >= 500 || status === 429; }
|
|
169
|
-
function isRetryableResponse(status, data) { return isRetryableStatus(status) || data.error_code === 429; }
|
|
170
|
-
async function waitBeforeRetry(attempt, backoffMs, maxBackoffMs, jitter, retryAfterMs) {
|
|
171
|
-
const exponential = Math.min(maxBackoffMs, backoffMs * 2 ** attempt);
|
|
172
|
-
const spread = exponential * jitter;
|
|
173
|
-
const jittered = Math.max(0, exponential - spread + Math.random() * spread * 2);
|
|
174
|
-
await new Promise((resolveDelay) => setTimeout(resolveDelay, Math.max(jittered, retryAfterMs ?? 0)));
|
|
175
|
-
}
|
|
176
|
-
function isRetryableNetworkError(error) {
|
|
177
|
-
if (!(error instanceof Error))
|
|
178
|
-
return true;
|
|
179
|
-
return error.name === "AbortError" || /network|fetch|socket|timeout|temporar/i.test(error.message);
|
|
180
|
-
}
|
|
181
|
-
async function containsUpload(value) {
|
|
182
|
-
if (value instanceof Uint8Array || value instanceof ArrayBuffer || value instanceof Blob)
|
|
183
|
-
return true;
|
|
184
|
-
if (value instanceof ReadableStream)
|
|
185
|
-
return true;
|
|
186
|
-
if (typeof value === "string")
|
|
187
|
-
return false;
|
|
188
|
-
if (value && typeof value === "object" && "source" in value) {
|
|
189
|
-
const source = value.source;
|
|
190
|
-
// A path-like string source means the transport reads the file from disk
|
|
191
|
-
// and must switch to multipart — a plain string source is just a file_id.
|
|
192
|
-
if (typeof source === "string" && ((0, node_path_1.isAbsolute)(source) || source.startsWith("./") || source.startsWith("../")))
|
|
193
|
-
return true;
|
|
194
|
-
return containsUpload(source);
|
|
195
|
-
}
|
|
196
|
-
if (typeof value?.pipe === "function")
|
|
197
|
-
return true;
|
|
198
|
-
if (Array.isArray(value)) {
|
|
199
|
-
for (const item of value)
|
|
200
|
-
if (await containsUpload(item))
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
else if (value && typeof value === "object") {
|
|
204
|
-
for (const item of Object.values(value))
|
|
205
|
-
if (await containsUpload(item))
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
/** Converts a Node.js or web ReadableStream to a Blob by draining it. */
|
|
211
|
-
async function streamToBlob(stream) {
|
|
212
|
-
if (stream instanceof ReadableStream)
|
|
213
|
-
return new Blob([await new Response(stream).arrayBuffer()]);
|
|
214
|
-
const bytes = await (0, consumers_1.buffer)(stream);
|
|
215
|
-
return new Blob([bytes]);
|
|
216
|
-
}
|
|
217
|
-
async function appendFormValue(form, key, value) {
|
|
218
|
-
if (value === undefined || value === null)
|
|
219
|
-
return;
|
|
220
|
-
if (value instanceof Uint8Array) {
|
|
221
|
-
form.append(key, new Blob([value]));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (value instanceof ArrayBuffer) {
|
|
225
|
-
form.append(key, new Blob([value]));
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (value instanceof Blob) {
|
|
229
|
-
form.append(key, value);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (value instanceof ReadableStream || typeof value?.pipe === "function") {
|
|
233
|
-
form.append(key, await streamToBlob(value));
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (value && typeof value === "object" && "source" in value) {
|
|
237
|
-
const upload = value;
|
|
238
|
-
if (typeof upload.source === "string" && ((0, node_path_1.isAbsolute)(upload.source) || upload.source.startsWith("./") || upload.source.startsWith("../"))) {
|
|
239
|
-
const filePath = (0, node_path_1.resolve)(upload.source);
|
|
240
|
-
const bytes = await (0, promises_1.readFile)(filePath);
|
|
241
|
-
form.append(key, new Blob([bytes]), upload.filename ?? (0, node_path_1.basename)(filePath));
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
if (upload.filename !== undefined && upload.source instanceof Uint8Array) {
|
|
245
|
-
form.append(key, new Blob([upload.source]), upload.filename);
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
if (upload.filename !== undefined && upload.source instanceof Blob) {
|
|
249
|
-
form.append(key, upload.source, upload.filename);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
if (upload.filename !== undefined && upload.source instanceof ArrayBuffer) {
|
|
253
|
-
form.append(key, new Blob([upload.source]), upload.filename);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
return appendFormValue(form, key, upload.source);
|
|
257
|
-
}
|
|
258
|
-
if (typeof value === "string") {
|
|
259
|
-
form.append(key, value);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
263
|
-
form.append(key, String(value));
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
form.append(key, JSON.stringify(value));
|
|
267
|
-
}
|