telegram-botbuilder 1.6.6 → 2.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 +81 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +453 -0
- package/README.md +403 -0
- package/lib/actions/callback_action.d.ts +14 -0
- package/lib/actions/callback_action.d.ts.map +1 -0
- package/lib/actions/callback_action.js +25 -0
- package/lib/actions/callback_action.js.map +1 -0
- package/lib/actions/change_dialog.d.ts +10 -0
- package/lib/actions/change_dialog.d.ts.map +1 -0
- package/lib/actions/change_dialog.js +17 -0
- package/lib/actions/change_dialog.js.map +1 -0
- package/lib/actions/control_flow.d.ts +26 -0
- package/lib/actions/control_flow.d.ts.map +1 -0
- package/lib/actions/control_flow.js +61 -0
- package/lib/actions/control_flow.js.map +1 -0
- package/lib/actions/index.d.ts +6 -0
- package/lib/actions/index.d.ts.map +1 -0
- package/lib/actions/index.js +11 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/actions/send_message.d.ts +16 -0
- package/lib/actions/send_message.d.ts.map +1 -0
- package/lib/actions/send_message.js +32 -0
- package/lib/actions/send_message.js.map +1 -0
- package/lib/actions/wait_for_input.d.ts +14 -0
- package/lib/actions/wait_for_input.d.ts.map +1 -0
- package/lib/actions/wait_for_input.js +54 -0
- package/lib/actions/wait_for_input.js.map +1 -0
- package/lib/core/bot_builder.d.ts +145 -0
- package/lib/core/bot_builder.d.ts.map +1 -0
- package/lib/core/bot_builder.js +689 -0
- package/lib/core/bot_builder.js.map +1 -0
- package/lib/core/button_registry.d.ts +39 -0
- package/lib/core/button_registry.d.ts.map +1 -0
- package/lib/core/button_registry.js +84 -0
- package/lib/core/button_registry.js.map +1 -0
- package/lib/core/dialog_manager.d.ts +71 -0
- package/lib/core/dialog_manager.d.ts.map +1 -0
- package/lib/core/dialog_manager.js +146 -0
- package/lib/core/dialog_manager.js.map +1 -0
- package/lib/core/index.d.ts +8 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/index.js +8 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/input_manager.d.ts +49 -0
- package/lib/core/input_manager.d.ts.map +1 -0
- package/lib/core/input_manager.js +129 -0
- package/lib/core/input_manager.js.map +1 -0
- package/lib/core/keyboard_builder.d.ts +35 -0
- package/lib/core/keyboard_builder.d.ts.map +1 -0
- package/lib/core/keyboard_builder.js +87 -0
- package/lib/core/keyboard_builder.js.map +1 -0
- package/lib/core/middleware_chain.d.ts +25 -0
- package/lib/core/middleware_chain.d.ts.map +1 -0
- package/lib/core/middleware_chain.js +54 -0
- package/lib/core/middleware_chain.js.map +1 -0
- package/lib/core/schema_compiler.d.ts +25 -0
- package/lib/core/schema_compiler.d.ts.map +1 -0
- package/lib/core/schema_compiler.js +65 -0
- package/lib/core/schema_compiler.js.map +1 -0
- package/lib/errors/bot_error.d.ts +7 -0
- package/lib/errors/bot_error.d.ts.map +1 -0
- package/lib/errors/bot_error.js +17 -0
- package/lib/errors/bot_error.js.map +1 -0
- package/lib/errors/dialog_error.d.ts +12 -0
- package/lib/errors/dialog_error.d.ts.map +1 -0
- package/lib/errors/dialog_error.js +22 -0
- package/lib/errors/dialog_error.js.map +1 -0
- package/lib/errors/index.d.ts +5 -0
- package/lib/errors/index.d.ts.map +1 -0
- package/lib/errors/index.js +5 -0
- package/lib/errors/index.js.map +1 -0
- package/lib/errors/telegram_error.d.ts +12 -0
- package/lib/errors/telegram_error.d.ts.map +1 -0
- package/lib/errors/telegram_error.js +39 -0
- package/lib/errors/telegram_error.js.map +1 -0
- package/lib/errors/validation_error.d.ts +19 -0
- package/lib/errors/validation_error.d.ts.map +1 -0
- package/lib/errors/validation_error.js +35 -0
- package/lib/errors/validation_error.js.map +1 -0
- package/lib/index.d.ts +6 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -18
- package/lib/index.js.map +1 -1
- package/lib/types/action.d.ts +58 -0
- package/lib/types/action.d.ts.map +1 -0
- package/lib/types/action.js +2 -0
- package/lib/types/action.js.map +1 -0
- package/lib/types/config.d.ts +36 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +12 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/dialog.d.ts +39 -0
- package/lib/types/dialog.d.ts.map +1 -0
- package/lib/types/dialog.js +2 -0
- package/lib/types/dialog.js.map +1 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/internal.d.ts +58 -0
- package/lib/types/internal.d.ts.map +1 -0
- package/lib/types/internal.js +11 -0
- package/lib/types/internal.js.map +1 -0
- package/lib/types/keyboard.d.ts +41 -0
- package/lib/types/keyboard.d.ts.map +1 -0
- package/lib/types/keyboard.js +2 -0
- package/lib/types/keyboard.js.map +1 -0
- package/lib/types/middleware.d.ts +24 -0
- package/lib/types/middleware.d.ts.map +1 -0
- package/lib/types/middleware.js +2 -0
- package/lib/types/middleware.js.map +1 -0
- package/lib/types/schema.d.ts +17 -0
- package/lib/types/schema.d.ts.map +1 -0
- package/lib/types/schema.js +2 -0
- package/lib/types/schema.js.map +1 -0
- package/lib/utils/constants.d.ts +33 -0
- package/lib/utils/constants.d.ts.map +1 -0
- package/lib/utils/constants.js +33 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/deep_copy.d.ts +6 -0
- package/lib/utils/deep_copy.d.ts.map +1 -0
- package/lib/utils/deep_copy.js +45 -0
- package/lib/utils/deep_copy.js.map +1 -0
- package/lib/utils/hash.d.ts +17 -0
- package/lib/utils/hash.d.ts.map +1 -0
- package/lib/utils/hash.js +50 -0
- package/lib/utils/hash.js.map +1 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +7 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger.d.ts +17 -0
- package/lib/utils/logger.d.ts.map +1 -0
- package/lib/utils/logger.js +91 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/resolvers.d.ts +29 -0
- package/lib/utils/resolvers.d.ts.map +1 -0
- package/lib/utils/resolvers.js +60 -0
- package/lib/utils/resolvers.js.map +1 -0
- package/lib/utils/type_guards.d.ts +22 -0
- package/lib/utils/type_guards.d.ts.map +1 -0
- package/lib/utils/type_guards.js +38 -0
- package/lib/utils/type_guards.js.map +1 -0
- package/lib/validation/index.d.ts +2 -0
- package/lib/validation/index.d.ts.map +1 -0
- package/lib/validation/index.js +2 -0
- package/lib/validation/index.js.map +1 -0
- package/lib/validation/schema_validator.d.ts +11 -0
- package/lib/validation/schema_validator.d.ts.map +1 -0
- package/lib/validation/schema_validator.js +156 -0
- package/lib/validation/schema_validator.js.map +1 -0
- package/package.json +65 -21
- package/lib/bot-service.d.ts +0 -27
- package/lib/bot-service.d.ts.map +0 -1
- package/lib/bot-service.js +0 -326
- package/lib/bot-service.js.map +0 -1
- package/lib/bot-struct.d.ts +0 -58
- package/lib/bot-struct.d.ts.map +0 -1
- package/lib/bot-struct.js +0 -3
- package/lib/bot-struct.js.map +0 -1
- package/readme.md +0 -54
- package/src/bot-service.ts +0 -289
- package/src/bot-struct.ts +0 -59
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -108
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type TelegramBot from "node-telegram-bot-api";
|
|
2
|
+
import type { BotBuilder } from "../core/bot_builder.js";
|
|
3
|
+
export interface ActionContext {
|
|
4
|
+
/** Chat ID */
|
|
5
|
+
chat_id: number;
|
|
6
|
+
/** Bot instance */
|
|
7
|
+
bot: BotBuilder;
|
|
8
|
+
/** Additional arguments passed to action */
|
|
9
|
+
args?: unknown[];
|
|
10
|
+
/** Raw message (if available) */
|
|
11
|
+
message?: TelegramBot.Message;
|
|
12
|
+
/** Raw callback query (if available) */
|
|
13
|
+
callback_query?: TelegramBot.CallbackQuery;
|
|
14
|
+
/** Matched command arguments (for command actions) */
|
|
15
|
+
command_args?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DialogActionContext extends ActionContext {
|
|
18
|
+
/** Previous dialog ID (for on_enter) or new dialog ID (for on_leave) */
|
|
19
|
+
other_dialog_id: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export type Action = (context: ActionContext) => void | Promise<void>;
|
|
22
|
+
export type DialogAction = (context: DialogActionContext) => void | Promise<void>;
|
|
23
|
+
export type CallbackFunction = (chat_id: number, ...args: unknown[]) => void | Promise<void>;
|
|
24
|
+
export type InputType = "text" | "document" | "photo" | "video" | "audio" | "voice" | "contact" | "location";
|
|
25
|
+
export interface WaitForInputOptions {
|
|
26
|
+
/** Timeout in milliseconds (default: from config) */
|
|
27
|
+
timeout?: number;
|
|
28
|
+
/** Allowed input types (default: depends on wait function) */
|
|
29
|
+
input_types?: InputType[];
|
|
30
|
+
/** Validation function - return true if valid, string for error message */
|
|
31
|
+
validator?: (input: string) => boolean | string | Promise<boolean | string>;
|
|
32
|
+
/** Message to show on validation failure */
|
|
33
|
+
validation_error_message?: string;
|
|
34
|
+
/** Message to show on timeout */
|
|
35
|
+
timeout_message?: string;
|
|
36
|
+
/** Cancel keywords (default: ["/cancel"]) */
|
|
37
|
+
cancel_keywords?: string[];
|
|
38
|
+
/** Message to show on cancel */
|
|
39
|
+
cancel_message?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface WaitResult<T = string> {
|
|
42
|
+
success: boolean;
|
|
43
|
+
value?: T;
|
|
44
|
+
cancelled?: boolean;
|
|
45
|
+
timed_out?: boolean;
|
|
46
|
+
error?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface FileWaitResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
file_id?: string;
|
|
51
|
+
file_content?: string;
|
|
52
|
+
file_name?: string;
|
|
53
|
+
mime_type?: string;
|
|
54
|
+
cancelled?: boolean;
|
|
55
|
+
timed_out?: boolean;
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=action.d.ts.map
|
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,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;IAE1B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;IAE5E,4CAA4C;IAC5C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC,iCAAiC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,gCAAgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,MAAM;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/types/action.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type TelegramBot from "node-telegram-bot-api";
|
|
2
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
3
|
+
export interface CustomLogger {
|
|
4
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
7
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface LoggerConfig {
|
|
10
|
+
/** Log level (default: "info") */
|
|
11
|
+
level?: LogLevel;
|
|
12
|
+
/** Custom logger implementation */
|
|
13
|
+
custom_logger?: CustomLogger;
|
|
14
|
+
}
|
|
15
|
+
export interface BotConfig {
|
|
16
|
+
/** Telegram bot token */
|
|
17
|
+
token: string;
|
|
18
|
+
/** node-telegram-bot-api options */
|
|
19
|
+
telegram_options?: TelegramBot.ConstructorOptions;
|
|
20
|
+
/** Enable /start command handling (default: true) */
|
|
21
|
+
enable_start_command?: boolean;
|
|
22
|
+
/** Parse mode for messages (default: "HTML") */
|
|
23
|
+
default_parse_mode?: "HTML" | "Markdown" | "MarkdownV2";
|
|
24
|
+
/** Logger configuration */
|
|
25
|
+
logger?: LoggerConfig;
|
|
26
|
+
/** Enable schema validation on startup (default: true) */
|
|
27
|
+
validate_schema?: boolean;
|
|
28
|
+
/** Auto-delete user messages in dialogs (default: true) */
|
|
29
|
+
auto_delete_user_messages?: boolean;
|
|
30
|
+
/** Timeout for waiting input in ms (default: 300000 = 5 min) */
|
|
31
|
+
default_input_timeout?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare const DEFAULT_CONFIG: Required<Omit<BotConfig, "token" | "telegram_options" | "logger">> & {
|
|
34
|
+
logger: Required<LoggerConfig>;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE,MAAM,WAAW,YAA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
+
export const DEFAULT_CONFIG = {
|
|
2
|
+
enable_start_command: true,
|
|
3
|
+
default_parse_mode: "HTML",
|
|
4
|
+
validate_schema: true,
|
|
5
|
+
auto_delete_user_messages: true,
|
|
6
|
+
default_input_timeout: 300000,
|
|
7
|
+
logger: {
|
|
8
|
+
level: "info",
|
|
9
|
+
custom_logger: undefined,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AA4CA,MAAM,CAAC,MAAM,cAAc,GAEvB;IACF,oBAAoB,EAAE,IAAI;IAC1B,kBAAkB,EAAE,MAAM;IAC1B,eAAe,EAAE,IAAI;IACrB,yBAAyB,EAAE,IAAI;IAC/B,qBAAqB,EAAE,MAAM;IAC7B,MAAM,EAAE;QACN,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,SAAU;KAC1B;CACF,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Action, DialogAction } from "./action.js";
|
|
2
|
+
import type { InlineButton, ReplyButton, ButtonSource, ReplyKeyboardOptions } from "./keyboard.js";
|
|
3
|
+
export type TextSource = string | ((chat_id: number) => string | Promise<string>);
|
|
4
|
+
export type ImageSource = string | string[] | ((chat_id: number) => string | string[] | undefined | Promise<string | string[] | undefined>);
|
|
5
|
+
export interface Dialog {
|
|
6
|
+
/** Unique dialog identifier */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Dialog text content (supports HTML by default) */
|
|
9
|
+
text?: TextSource;
|
|
10
|
+
/** Inline keyboard buttons (under the message) */
|
|
11
|
+
inline_buttons?: ButtonSource<InlineButton>;
|
|
12
|
+
/** Reply keyboard buttons (main keyboard) */
|
|
13
|
+
reply_buttons?: ButtonSource<ReplyButton>;
|
|
14
|
+
/** Reply keyboard options */
|
|
15
|
+
reply_keyboard_options?: ReplyKeyboardOptions;
|
|
16
|
+
/** Remove reply keyboard when entering this dialog */
|
|
17
|
+
remove_reply_keyboard?: boolean;
|
|
18
|
+
/** Images/photos to display */
|
|
19
|
+
images?: ImageSource;
|
|
20
|
+
/** Called when user enters this dialog */
|
|
21
|
+
on_enter?: DialogAction;
|
|
22
|
+
/** Called when user leaves this dialog */
|
|
23
|
+
on_leave?: DialogAction;
|
|
24
|
+
/** Disable web page preview for links (default: false) */
|
|
25
|
+
disable_web_page_preview?: boolean;
|
|
26
|
+
/** Protect content from forwarding/saving (default: false) */
|
|
27
|
+
protect_content?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface Command {
|
|
30
|
+
/** Command name without slash (e.g., "help", "settings") */
|
|
31
|
+
name: string;
|
|
32
|
+
/** Command description for BotFather */
|
|
33
|
+
description?: string;
|
|
34
|
+
/** Action(s) to execute */
|
|
35
|
+
action?: Action | Action[];
|
|
36
|
+
}
|
|
37
|
+
export type { InlineButton, ReplyButton, ButtonSource, ReplyKeyboardOptions } from "./keyboard.js";
|
|
38
|
+
export type { Action, DialogAction, ActionContext, DialogActionContext } from "./action.js";
|
|
39
|
+
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/types/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEnG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAElF,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,MAAM,EAAE,GACR,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,EAAE,G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|
1
|
+
export type { LogLevel, CustomLogger, LoggerConfig, BotConfig, } from "./config.js";
|
|
2
|
+
export { DEFAULT_CONFIG } from "./config.js";
|
|
3
|
+
export type { Action, ActionContext, DialogAction, DialogActionContext, CallbackFunction, InputType, WaitForInputOptions, WaitResult, FileWaitResult, } from "./action.js";
|
|
4
|
+
export type { InlineButton, ReplyButton, ReplyKeyboardOptions, ButtonSource, } from "./keyboard.js";
|
|
5
|
+
export type { TextSource, ImageSource, Dialog, Command, } from "./dialog.js";
|
|
6
|
+
export type { Schema } from "./schema.js";
|
|
7
|
+
export type { UpdateType, MiddlewareContext, MiddlewareNext, Middleware, } from "./middleware.js";
|
|
8
|
+
export type { MessageType, UserState, RegisteredInlineButton, RegisteredReplyButton, InternalDialog, InternalSchema, PendingInput, } from "./internal.js";
|
|
9
|
+
export { DEFAULT_USER_STATE } from "./internal.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EACV,MAAM,EACN,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,YAAY,GACb,MAAM,eAAe,CAAC;AAGvB,YAAY,EACV,UAAU,EACV,WAAW,EACX,MAAM,EACN,OAAO,GACR,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,UAAU,GACX,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,WAAW,EACX,SAAS,EACT,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAoD7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Dialog, InlineButton, ReplyButton } from "./dialog.js";
|
|
2
|
+
export type MessageType = "text" | "photo" | "media_group";
|
|
3
|
+
export interface UserState {
|
|
4
|
+
/** Current dialog ID */
|
|
5
|
+
current_dialog_id: string;
|
|
6
|
+
/** Last bot message ID (for editing) */
|
|
7
|
+
last_bot_message_id: number;
|
|
8
|
+
/** Type of last message sent */
|
|
9
|
+
last_message_type: MessageType;
|
|
10
|
+
/** Whether bot is waiting for user input */
|
|
11
|
+
waiting_for_input: boolean;
|
|
12
|
+
/** Unique ID for current input wait */
|
|
13
|
+
input_wait_id: string;
|
|
14
|
+
/** Types of input being waited for */
|
|
15
|
+
input_wait_types: string[];
|
|
16
|
+
/** Whether reply keyboard is currently shown */
|
|
17
|
+
reply_keyboard_active: boolean;
|
|
18
|
+
/** Custom user data storage */
|
|
19
|
+
custom_data: Record<string, unknown>;
|
|
20
|
+
/** Last activity timestamp */
|
|
21
|
+
last_activity: number;
|
|
22
|
+
}
|
|
23
|
+
export interface RegisteredInlineButton {
|
|
24
|
+
hash: string;
|
|
25
|
+
dialog_id: string;
|
|
26
|
+
button: InlineButton;
|
|
27
|
+
}
|
|
28
|
+
export interface RegisteredReplyButton {
|
|
29
|
+
text: string;
|
|
30
|
+
dialog_id: string;
|
|
31
|
+
button: ReplyButton;
|
|
32
|
+
}
|
|
33
|
+
export interface InternalDialog extends Dialog {
|
|
34
|
+
_compiled_inline_buttons?: RegisteredInlineButton[][];
|
|
35
|
+
_compiled_reply_buttons?: RegisteredReplyButton[][];
|
|
36
|
+
}
|
|
37
|
+
export interface InternalSchema {
|
|
38
|
+
start_dialog: string;
|
|
39
|
+
dialogs: Map<string, InternalDialog>;
|
|
40
|
+
commands: Map<string, import("./dialog.js").Command>;
|
|
41
|
+
inline_buttons: Map<string, RegisteredInlineButton>;
|
|
42
|
+
reply_buttons: Map<string, RegisteredReplyButton[]>;
|
|
43
|
+
error_dialog?: string;
|
|
44
|
+
fallback_action?: import("./action.js").Action;
|
|
45
|
+
reply_fallback_action?: import("./action.js").Action;
|
|
46
|
+
}
|
|
47
|
+
export interface PendingInput {
|
|
48
|
+
wait_id: string;
|
|
49
|
+
chat_id: number;
|
|
50
|
+
resolve: (result: unknown) => void;
|
|
51
|
+
reject: (error: Error) => void;
|
|
52
|
+
timeout_handle?: ReturnType<typeof setTimeout>;
|
|
53
|
+
input_types: string[];
|
|
54
|
+
validator?: (input: string) => boolean | string | Promise<boolean | string>;
|
|
55
|
+
cancel_keywords: string[];
|
|
56
|
+
}
|
|
57
|
+
export declare const DEFAULT_USER_STATE: Omit<UserState, "current_dialog_id">;
|
|
58
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;AAE3D,MAAM,WAAW,SAAS;IACxB,wBAAwB;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAE1B,wCAAwC;IACxC,mBAAmB,EAAE,MAAM,CAAC;IAE5B,gCAAgC;IAChC,i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AAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAC/C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;IAC5E,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,eAAO,MAAM,kBAAkB,EAAE,IAAI,CAAC,SAAS,EAAE,mBAAmB,CASnE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const DEFAULT_USER_STATE = {
|
|
2
|
+
last_bot_message_id: -1,
|
|
3
|
+
last_message_type: "text",
|
|
4
|
+
waiting_for_input: false,
|
|
5
|
+
input_wait_id: "",
|
|
6
|
+
input_wait_types: [],
|
|
7
|
+
reply_keyboard_active: false,
|
|
8
|
+
custom_data: {},
|
|
9
|
+
last_activity: Date.now(),
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/types/internal.ts"],"names":[],"mappings":"AAwEA,MAAM,CAAC,MAAM,kBAAkB,GAAyC;IACtE,mBAAmB,EAAE,CAAC,CAAC;IACvB,iBAAiB,EAAE,MAAM;IACzB,iBAAiB,EAAE,KAAK;IACxB,aAAa,EAAE,EAAE;IACjB,gBAAgB,EAAE,EAAE;IACpB,qBAAqB,EAAE,KAAK;IAC5B,WAAW,EAAE,EAAE;IACf,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE;CAC1B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Action, TextSource } from "./dialog.js";
|
|
2
|
+
export interface InlineButton {
|
|
3
|
+
/** Button label */
|
|
4
|
+
text: TextSource;
|
|
5
|
+
/** Action(s) to execute on click */
|
|
6
|
+
action?: Action | Action[];
|
|
7
|
+
/** URL to open (mutually exclusive with action) */
|
|
8
|
+
url?: TextSource;
|
|
9
|
+
/** Mini app / Web app URL */
|
|
10
|
+
web_app?: TextSource;
|
|
11
|
+
/** Callback data override (auto-generated if not set) */
|
|
12
|
+
callback_data?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ReplyButton {
|
|
15
|
+
/** Button label */
|
|
16
|
+
text: TextSource;
|
|
17
|
+
/** Action(s) to execute when this text is received */
|
|
18
|
+
action?: Action | Action[];
|
|
19
|
+
/** Request contact from user */
|
|
20
|
+
request_contact?: boolean;
|
|
21
|
+
/** Request location from user */
|
|
22
|
+
request_location?: boolean;
|
|
23
|
+
/** Request poll from user */
|
|
24
|
+
request_poll?: {
|
|
25
|
+
type?: "quiz" | "regular";
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface ReplyKeyboardOptions {
|
|
29
|
+
/** Resize keyboard to fit buttons (default: true) */
|
|
30
|
+
resize_keyboard?: boolean;
|
|
31
|
+
/** Hide keyboard after button press (default: false) */
|
|
32
|
+
one_time_keyboard?: boolean;
|
|
33
|
+
/** Placeholder text in input field */
|
|
34
|
+
input_field_placeholder?: string;
|
|
35
|
+
/** Show only to specific users in groups (default: false) */
|
|
36
|
+
selective?: boolean;
|
|
37
|
+
/** Keep keyboard persistent (default: false) */
|
|
38
|
+
is_persistent?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type ButtonSource<T> = T[][] | ((chat_id: number) => T[][] | Promise<T[][]>);
|
|
41
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/types/keybo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
|
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../../src/types/keyboard.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type TelegramBot from "node-telegram-bot-api";
|
|
2
|
+
import type { BotBuilder } from "../core/bot_builder.js";
|
|
3
|
+
export type UpdateType = "message" | "callback_query" | "command" | "document" | "photo" | "contact" | "location";
|
|
4
|
+
export interface MiddlewareContext {
|
|
5
|
+
/** Chat ID */
|
|
6
|
+
chat_id: number;
|
|
7
|
+
/** Bot instance */
|
|
8
|
+
bot: BotBuilder;
|
|
9
|
+
/** Original message (if applicable) */
|
|
10
|
+
message?: TelegramBot.Message;
|
|
11
|
+
/** Callback query (if applicable) */
|
|
12
|
+
callback_query?: TelegramBot.CallbackQuery;
|
|
13
|
+
/** Type of update being processed */
|
|
14
|
+
update_type: UpdateType;
|
|
15
|
+
/** User ID */
|
|
16
|
+
user_id: number;
|
|
17
|
+
/** Username (if available) */
|
|
18
|
+
username?: string;
|
|
19
|
+
/** Raw update timestamp */
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
export type MiddlewareNext = () => Promise<void>;
|
|
23
|
+
export type Middleware = (context: MiddlewareContext, next: MiddlewareNext) => void | Promise<void>;
|
|
24
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/types/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAElH,MAAM,WAAW,iBAAiB;IAChC,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAEhB,mBAAmB;IACnB,GAAG,EAAE,UAAU,CAAC;IAEhB,uCAAuC;IACvC,OAAO,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC;IAE9B,qCAAqC;IACrC,cAAc,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC;IAE3C,qCAAqC;IACrC,WAAW,EAAE,UAAU,CAAC;IAExB,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAEhB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjD,MAAM,MAAM,UAAU,GAAG,CACvB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,cAAc,KACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/types/middleware.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Action } from "./action.js";
|
|
2
|
+
import type { Dialog, Command } from "./dialog.js";
|
|
3
|
+
export interface Schema {
|
|
4
|
+
/** Starting dialog ID */
|
|
5
|
+
start_dialog: string;
|
|
6
|
+
/** All dialogs */
|
|
7
|
+
dialogs: Dialog[];
|
|
8
|
+
/** Bot commands (will be registered with BotFather format) */
|
|
9
|
+
commands?: Command[];
|
|
10
|
+
/** Global error dialog ID (shown on unhandled errors) */
|
|
11
|
+
error_dialog?: string;
|
|
12
|
+
/** Global fallback handler for unmatched messages */
|
|
13
|
+
fallback_action?: Action;
|
|
14
|
+
/** Fallback for unmatched reply keyboard buttons */
|
|
15
|
+
reply_fallback_action?: Action;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,MAAM;IACrB,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IAErB,kBAAkB;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IAErB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,qDAAqD;IACrD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,oDAAoD;IACpD,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Error messages for consistent messaging */
|
|
2
|
+
export declare const ERROR_MESSAGES: {
|
|
3
|
+
readonly DIALOG_NOT_FOUND: (id: string) => string;
|
|
4
|
+
readonly BUTTON_NOT_FOUND: (hash: string) => string;
|
|
5
|
+
readonly SCHEMA_INVALID: "Invalid schema provided";
|
|
6
|
+
readonly START_DIALOG_MISSING: "start_dialog must reference an existing dialog";
|
|
7
|
+
readonly NO_DIALOGS: "Schema must contain at least one dialog";
|
|
8
|
+
readonly DUPLICATE_DIALOG_ID: (id: string) => string;
|
|
9
|
+
readonly DUPLICATE_COMMAND: (name: string) => string;
|
|
10
|
+
readonly INPUT_TIMEOUT: "Input timeout - operation cancelled";
|
|
11
|
+
readonly INPUT_CANCELLED: "Operation cancelled";
|
|
12
|
+
readonly VALIDATION_FAILED: (reason: string) => string;
|
|
13
|
+
};
|
|
14
|
+
/** Telegram API error substrings for detection */
|
|
15
|
+
export declare const TELEGRAM_ERRORS: {
|
|
16
|
+
readonly MESSAGE_NOT_MODIFIED: "message is not modified";
|
|
17
|
+
readonly MESSAGE_NOT_FOUND: "message to edit not found";
|
|
18
|
+
readonly MESSAGE_DELETE_NOT_FOUND: "message to delete not found";
|
|
19
|
+
readonly BOT_BLOCKED: "bot was blocked by the user";
|
|
20
|
+
readonly USER_DEACTIVATED: "user is deactivated";
|
|
21
|
+
readonly CHAT_NOT_FOUND: "chat not found";
|
|
22
|
+
readonly QUERY_TOO_OLD: "query is too old";
|
|
23
|
+
};
|
|
24
|
+
/** Default values */
|
|
25
|
+
export declare const DEFAULTS: {
|
|
26
|
+
readonly PARSE_MODE: "HTML";
|
|
27
|
+
readonly INPUT_TIMEOUT_MS: 300000;
|
|
28
|
+
readonly CANCEL_KEYWORDS: readonly ["/cancel"];
|
|
29
|
+
readonly MAX_CALLBACK_DATA_LENGTH: 64;
|
|
30
|
+
readonly MAX_MESSAGE_LENGTH: 4096;
|
|
31
|
+
readonly MAX_CAPTION_LENGTH: 1024;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,eAAO,MAAM,cAAc;oCACF,MAAM;sCACJ,MAAM;;;;uCAIL,MAAM;uCACN,MAAM;;;yCAGJ,MAAM;CAC1B,CAAC;AAEX,kDAAkD;AAClD,eAAO,MAAM,eAAe;;;;;;;;CAQlB,CAAC;AAEX,qBAAqB;AACrB,eAAO,MAAM,QAAQ;;;;;;;CAOX,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Error messages for consistent messaging */
|
|
2
|
+
export const ERROR_MESSAGES = {
|
|
3
|
+
DIALOG_NOT_FOUND: (id) => `Dialog "${id}" not found`,
|
|
4
|
+
BUTTON_NOT_FOUND: (hash) => `Button with hash "${hash}" not found`,
|
|
5
|
+
SCHEMA_INVALID: "Invalid schema provided",
|
|
6
|
+
START_DIALOG_MISSING: "start_dialog must reference an existing dialog",
|
|
7
|
+
NO_DIALOGS: "Schema must contain at least one dialog",
|
|
8
|
+
DUPLICATE_DIALOG_ID: (id) => `Duplicate dialog ID: "${id}"`,
|
|
9
|
+
DUPLICATE_COMMAND: (name) => `Duplicate command: "/${name}"`,
|
|
10
|
+
INPUT_TIMEOUT: "Input timeout - operation cancelled",
|
|
11
|
+
INPUT_CANCELLED: "Operation cancelled",
|
|
12
|
+
VALIDATION_FAILED: (reason) => `Validation failed: ${reason}`,
|
|
13
|
+
};
|
|
14
|
+
/** Telegram API error substrings for detection */
|
|
15
|
+
export const TELEGRAM_ERRORS = {
|
|
16
|
+
MESSAGE_NOT_MODIFIED: "message is not modified",
|
|
17
|
+
MESSAGE_NOT_FOUND: "message to edit not found",
|
|
18
|
+
MESSAGE_DELETE_NOT_FOUND: "message to delete not found",
|
|
19
|
+
BOT_BLOCKED: "bot was blocked by the user",
|
|
20
|
+
USER_DEACTIVATED: "user is deactivated",
|
|
21
|
+
CHAT_NOT_FOUND: "chat not found",
|
|
22
|
+
QUERY_TOO_OLD: "query is too old",
|
|
23
|
+
};
|
|
24
|
+
/** Default values */
|
|
25
|
+
export const DEFAULTS = {
|
|
26
|
+
PARSE_MODE: "HTML",
|
|
27
|
+
INPUT_TIMEOUT_MS: 300000, // 5 minutes
|
|
28
|
+
CANCEL_KEYWORDS: ["/cancel"],
|
|
29
|
+
MAX_CALLBACK_DATA_LENGTH: 64,
|
|
30
|
+
MAX_MESSAGE_LENGTH: 4096,
|
|
31
|
+
MAX_CAPTION_LENGTH: 1024,
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG;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+1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep copy an object, preserving functions by reference.
|
|
3
|
+
* Functions cannot be cloned, so they remain as references.
|
|
4
|
+
*/
|
|
5
|
+
export function deep_copy(obj) {
|
|
6
|
+
if (obj === null || obj === undefined) {
|
|
7
|
+
return obj;
|
|
8
|
+
}
|
|
9
|
+
if (typeof obj === "function") {
|
|
10
|
+
return obj; // Functions cannot be cloned
|
|
11
|
+
}
|
|
12
|
+
if (typeof obj !== "object") {
|
|
13
|
+
return obj; // Primitives
|
|
14
|
+
}
|
|
15
|
+
if (obj instanceof Date) {
|
|
16
|
+
return new Date(obj.getTime());
|
|
17
|
+
}
|
|
18
|
+
if (obj instanceof RegExp) {
|
|
19
|
+
return new RegExp(obj.source, obj.flags);
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(obj)) {
|
|
22
|
+
return obj.map((item) => deep_copy(item));
|
|
23
|
+
}
|
|
24
|
+
if (obj instanceof Map) {
|
|
25
|
+
const copy = new Map();
|
|
26
|
+
obj.forEach((value, key) => {
|
|
27
|
+
copy.set(deep_copy(key), deep_copy(value));
|
|
28
|
+
});
|
|
29
|
+
return copy;
|
|
30
|
+
}
|
|
31
|
+
if (obj instanceof Set) {
|
|
32
|
+
const copy = new Set();
|
|
33
|
+
obj.forEach((value) => {
|
|
34
|
+
copy.add(deep_copy(value));
|
|
35
|
+
});
|
|
36
|
+
return copy;
|
|
37
|
+
}
|
|
38
|
+
// Plain object
|
|
39
|
+
const copy = {};
|
|
40
|
+
for (const key of Object.keys(obj)) {
|
|
41
|
+
copy[key] = deep_copy(obj[key]);
|
|
42
|
+
}
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=deep_copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep_copy.js","sourceRoot":"","sources":["../../src/utils/deep_copy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAI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C,KAAK,CAAC,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,OAAO,IAAS,CAAC;IACnB,CAAC;IAED,eAAe;IACf,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAE,GAA+B,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface HashableButton {
|
|
2
|
+
text?: string | ((...args: unknown[]) => unknown);
|
|
3
|
+
action?: unknown;
|
|
4
|
+
url?: string | ((...args: unknown[]) => unknown);
|
|
5
|
+
web_app?: string | ((...args: unknown[]) => unknown);
|
|
6
|
+
callback_data?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generate a deterministic hash for a button based on its properties.
|
|
10
|
+
* Used for matching callback_data to buttons.
|
|
11
|
+
*/
|
|
12
|
+
export declare function hash_button(dialog_id: string, button: HashableButton, index?: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique ID for input waiting
|
|
15
|
+
*/
|
|
16
|
+
export declare function generate_wait_id(): string;
|
|
17
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CA4C7F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a deterministic hash for a button based on its properties.
|
|
4
|
+
* Used for matching callback_data to buttons.
|
|
5
|
+
*/
|
|
6
|
+
export function hash_button(dialog_id, button, index) {
|
|
7
|
+
// If callback_data is explicitly set, use it
|
|
8
|
+
if (button.callback_data) {
|
|
9
|
+
return button.callback_data;
|
|
10
|
+
}
|
|
11
|
+
const hash_input = {
|
|
12
|
+
dialog_id,
|
|
13
|
+
};
|
|
14
|
+
// Include text if it's a string
|
|
15
|
+
if (typeof button.text === "string") {
|
|
16
|
+
hash_input.text = button.text;
|
|
17
|
+
}
|
|
18
|
+
// Include url if it's a string
|
|
19
|
+
if (typeof button.url === "string") {
|
|
20
|
+
hash_input.url = button.url;
|
|
21
|
+
}
|
|
22
|
+
// Include web_app if it's a string
|
|
23
|
+
if (typeof button.web_app === "string") {
|
|
24
|
+
hash_input.web_app = button.web_app;
|
|
25
|
+
}
|
|
26
|
+
// Include index for uniqueness when other properties are dynamic
|
|
27
|
+
if (index !== undefined) {
|
|
28
|
+
hash_input.index = index;
|
|
29
|
+
}
|
|
30
|
+
// Include action reference for uniqueness
|
|
31
|
+
if (button.action) {
|
|
32
|
+
if (typeof button.action === "function") {
|
|
33
|
+
hash_input.action_name = button.action.name || "anonymous";
|
|
34
|
+
}
|
|
35
|
+
else if (Array.isArray(button.action)) {
|
|
36
|
+
hash_input.action_count = button.action.length;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const json = JSON.stringify(hash_input, Object.keys(hash_input).sort());
|
|
40
|
+
const hash = createHash("sha256").update(json).digest("hex");
|
|
41
|
+
// Return first 16 chars - enough for uniqueness, fits callback_data limit
|
|
42
|
+
return hash.substring(0, 16);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate a unique ID for input waiting
|
|
46
|
+
*/
|
|
47
|
+
export function generate_wait_id() {
|
|
48
|
+
return crypto.randomUUID();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=hash.js.map
|