telegram-botbuilder 1.6.5 → 2.0.0
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/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 +678 -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 +59 -15
- 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,35 @@
|
|
|
1
|
+
import type TelegramBot from "node-telegram-bot-api";
|
|
2
|
+
import type { InlineButton, ReplyButton, ReplyKeyboardOptions } from "../types/keyboard.js";
|
|
3
|
+
import type { ButtonRegistry } from "./button_registry.js";
|
|
4
|
+
export interface BuiltInlineKeyboard {
|
|
5
|
+
inline_keyboard: TelegramBot.InlineKeyboardButton[][];
|
|
6
|
+
}
|
|
7
|
+
export interface BuiltReplyKeyboard {
|
|
8
|
+
keyboard: TelegramBot.KeyboardButton[][];
|
|
9
|
+
resize_keyboard: boolean;
|
|
10
|
+
one_time_keyboard: boolean;
|
|
11
|
+
input_field_placeholder?: string;
|
|
12
|
+
selective: boolean;
|
|
13
|
+
is_persistent: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RemoveKeyboard {
|
|
16
|
+
remove_keyboard: true;
|
|
17
|
+
selective?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class KeyboardBuilder {
|
|
20
|
+
private readonly registry;
|
|
21
|
+
constructor(registry: ButtonRegistry);
|
|
22
|
+
/**
|
|
23
|
+
* Build inline keyboard from button definitions
|
|
24
|
+
*/
|
|
25
|
+
build_inline(dialog_id: string, buttons: InlineButton[][], chat_id: number): Promise<BuiltInlineKeyboard>;
|
|
26
|
+
/**
|
|
27
|
+
* Build reply keyboard from button definitions
|
|
28
|
+
*/
|
|
29
|
+
build_reply(dialog_id: string, buttons: ReplyButton[][], chat_id: number, options?: ReplyKeyboardOptions): Promise<BuiltReplyKeyboard>;
|
|
30
|
+
/**
|
|
31
|
+
* Create remove keyboard markup
|
|
32
|
+
*/
|
|
33
|
+
build_remove(selective?: boolean): RemoveKeyboard;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=keyboard_builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard_builder.d.ts","sourceRoot":"","sources":["../../src/core/keyboard_builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,WAAW,CAAC,oBAAoB,EAAE,EAAE,CAAC;CACvD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,WAAW,CAAC,cAAc,EAAE,EAAE,CAAC;IACzC,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;gBAE9B,QAAQ,EAAE,cAAc;IAIpC;;OAEG;IACG,YAAY,CAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EAAE,EAAE,EACzB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC;IAmC/B;;OAEG;IACG,WAAW,CACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EAAE,EAAE,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,kBAAkB,CAAC;IA8C9B;;OAEG;IACH,YAAY,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,cAAc;CAMlD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { resolve_inline_button, resolve_reply_button } from "../utils/resolvers.js";
|
|
2
|
+
export class KeyboardBuilder {
|
|
3
|
+
registry;
|
|
4
|
+
constructor(registry) {
|
|
5
|
+
this.registry = registry;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Build inline keyboard from button definitions
|
|
9
|
+
*/
|
|
10
|
+
async build_inline(dialog_id, buttons, chat_id) {
|
|
11
|
+
const keyboard = [];
|
|
12
|
+
let button_index = 0;
|
|
13
|
+
for (const row of buttons) {
|
|
14
|
+
const keyboard_row = [];
|
|
15
|
+
for (const button of row) {
|
|
16
|
+
const resolved = await resolve_inline_button(button, chat_id);
|
|
17
|
+
const hash = this.registry.register_inline(dialog_id, button, button_index);
|
|
18
|
+
const kb_button = {
|
|
19
|
+
text: resolved.text,
|
|
20
|
+
};
|
|
21
|
+
if (resolved.url) {
|
|
22
|
+
kb_button.url = resolved.url;
|
|
23
|
+
}
|
|
24
|
+
else if (resolved.web_app) {
|
|
25
|
+
kb_button.web_app = { url: resolved.web_app };
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
kb_button.callback_data = hash;
|
|
29
|
+
}
|
|
30
|
+
keyboard_row.push(kb_button);
|
|
31
|
+
button_index++;
|
|
32
|
+
}
|
|
33
|
+
if (keyboard_row.length > 0) {
|
|
34
|
+
keyboard.push(keyboard_row);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { inline_keyboard: keyboard };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build reply keyboard from button definitions
|
|
41
|
+
*/
|
|
42
|
+
async build_reply(dialog_id, buttons, chat_id, options) {
|
|
43
|
+
const keyboard = [];
|
|
44
|
+
for (const row of buttons) {
|
|
45
|
+
const keyboard_row = [];
|
|
46
|
+
for (const button of row) {
|
|
47
|
+
const resolved = await resolve_reply_button(button, chat_id);
|
|
48
|
+
// Register for action lookup
|
|
49
|
+
this.registry.register_reply(dialog_id, button, resolved.text);
|
|
50
|
+
const kb_button = {
|
|
51
|
+
text: resolved.text,
|
|
52
|
+
};
|
|
53
|
+
if (button.request_contact) {
|
|
54
|
+
kb_button.request_contact = true;
|
|
55
|
+
}
|
|
56
|
+
if (button.request_location) {
|
|
57
|
+
kb_button.request_location = true;
|
|
58
|
+
}
|
|
59
|
+
if (button.request_poll) {
|
|
60
|
+
kb_button.request_poll = { type: button.request_poll.type };
|
|
61
|
+
}
|
|
62
|
+
keyboard_row.push(kb_button);
|
|
63
|
+
}
|
|
64
|
+
if (keyboard_row.length > 0) {
|
|
65
|
+
keyboard.push(keyboard_row);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
keyboard,
|
|
70
|
+
resize_keyboard: options?.resize_keyboard ?? true,
|
|
71
|
+
one_time_keyboard: options?.one_time_keyboard ?? false,
|
|
72
|
+
input_field_placeholder: options?.input_field_placeholder,
|
|
73
|
+
selective: options?.selective ?? false,
|
|
74
|
+
is_persistent: options?.is_persistent ?? false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create remove keyboard markup
|
|
79
|
+
*/
|
|
80
|
+
build_remove(selective) {
|
|
81
|
+
return {
|
|
82
|
+
remove_keyboard: true,
|
|
83
|
+
selective,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=keyboard_builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard_builder.js","sourceRoot":"","sources":["../../src/core/keyboard_builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAqBpF,MAAM,OAAO,eAAe;IACT,QAAQ,CAAiB;IAE1C,YAAY,QAAwB;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAChB,SAAiB,EACjB,OAAyB,EACzB,OAAe;QAEf,MAAM,QAAQ,GAAyC,EAAE,CAAC;QAC1D,IAAI,YAAY,GAAG,CAAC,CAAC;QAErB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,YAAY,GAAuC,EAAE,CAAC;YAE5D,KAAK,MAAM,MAAM,IAAI,GAAG,EAAE,CAAC;gBACzB,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;gBAE5E,MAAM,SAAS,GAAqC;oBAClD,IAAI,EAAE,QAAQ,CAAC,IAAI;iBACpB,CAAC;gBAEF,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;oBACjB,SAAS,CAAC,GAAG,GAAG,QAAQ,CAAC,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,CAAC;gBACpC,CAAC;gBAED,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;oBACxB,SAAS,CAAC,YAAY,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,IAAgB,EAAE,CAAC;gBAC1E,CAAC;gBAED,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;YAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,OAAO;YACL,QAAQ;YACR,eAAe,EAAE,OAAO,EAAE,eAAe,IAAI,IAAI;YACjD,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,IAAI,KAAK;YACtD,uBAAuB,EAAE,OAAO,EAAE,uBAAuB;YACzD,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,KAAK;YACtC,aAAa,EAAE,OAAO,EAAE,aAAa,IAAI,KAAK;SAC/C,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,SAAmB;QAC9B,OAAO;YACL,eAAe,EAAE,IAAI;YACrB,SAAS;SACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Middleware, MiddlewareContext } from "../types/middleware.js";
|
|
2
|
+
import type { Logger } from "../utils/logger.js";
|
|
3
|
+
export declare class MiddlewareChain {
|
|
4
|
+
private readonly middlewares;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(logger: Logger);
|
|
7
|
+
/**
|
|
8
|
+
* Add middleware to the chain
|
|
9
|
+
*/
|
|
10
|
+
use(middleware: Middleware): void;
|
|
11
|
+
/**
|
|
12
|
+
* Execute the middleware chain
|
|
13
|
+
* Returns true if chain completed (reached final handler)
|
|
14
|
+
*/
|
|
15
|
+
execute(context: MiddlewareContext, final_handler: () => Promise<void>): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Get number of registered middlewares
|
|
18
|
+
*/
|
|
19
|
+
get count(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Clear all middlewares
|
|
22
|
+
*/
|
|
23
|
+
clear(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=middleware_chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware_chain.d.ts","sourceRoot":"","sources":["../../src/core/middleware_chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAkB,MAAM,wBAAwB,CAAC;AAC5F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM;IAI1B;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAIjC;;;OAGG;IACG,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IA0B/F;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class MiddlewareChain {
|
|
2
|
+
middlewares = [];
|
|
3
|
+
logger;
|
|
4
|
+
constructor(logger) {
|
|
5
|
+
this.logger = logger;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Add middleware to the chain
|
|
9
|
+
*/
|
|
10
|
+
use(middleware) {
|
|
11
|
+
this.middlewares.push(middleware);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Execute the middleware chain
|
|
15
|
+
* Returns true if chain completed (reached final handler)
|
|
16
|
+
*/
|
|
17
|
+
async execute(context, final_handler) {
|
|
18
|
+
let index = 0;
|
|
19
|
+
let completed = false;
|
|
20
|
+
const next = async () => {
|
|
21
|
+
if (index < this.middlewares.length) {
|
|
22
|
+
const middleware = this.middlewares[index];
|
|
23
|
+
index++;
|
|
24
|
+
try {
|
|
25
|
+
await middleware(context, next);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.logger.error(`Middleware error:`, error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// End of chain, execute final handler
|
|
34
|
+
await final_handler();
|
|
35
|
+
completed = true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
await next();
|
|
39
|
+
return completed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get number of registered middlewares
|
|
43
|
+
*/
|
|
44
|
+
get count() {
|
|
45
|
+
return this.middlewares.length;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Clear all middlewares
|
|
49
|
+
*/
|
|
50
|
+
clear() {
|
|
51
|
+
this.middlewares.length = 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=middleware_chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware_chain.js","sourceRoot":"","sources":["../../src/core/middleware_chain.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,eAAe;IACT,WAAW,GAAiB,EAAE,CAAC;IAC/B,MAAM,CAAS;IAEhC,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,UAAsB;QACxB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,OAA0B,EAAE,aAAkC;QAC1E,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,MAAM,IAAI,GAAmB,KAAK,IAAI,EAAE;YACtC,IAAI,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;gBACpC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAC3C,KAAK,EAAE,CAAC;gBAER,IAAI,CAAC;oBACH,MAAM,UAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;gBACnC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;oBAC9C,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,MAAM,aAAa,EAAE,CAAC;gBACtB,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,IAAI,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Schema } from "../types/schema.js";
|
|
2
|
+
import type { Command } from "../types/dialog.js";
|
|
3
|
+
import type { InternalSchema, InternalDialog } from "../types/internal.js";
|
|
4
|
+
import type { Logger } from "../utils/logger.js";
|
|
5
|
+
export declare class SchemaCompiler {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(logger: Logger);
|
|
8
|
+
/**
|
|
9
|
+
* Compile raw schema into internal format
|
|
10
|
+
*/
|
|
11
|
+
compile(raw_schema: Schema, should_validate: boolean): InternalSchema;
|
|
12
|
+
/**
|
|
13
|
+
* Compile a single dialog
|
|
14
|
+
*/
|
|
15
|
+
private compile_dialog;
|
|
16
|
+
/**
|
|
17
|
+
* Get dialog by ID
|
|
18
|
+
*/
|
|
19
|
+
static get_dialog(schema: InternalSchema, dialog_id: string): InternalDialog | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Get command by name
|
|
22
|
+
*/
|
|
23
|
+
static get_command(schema: InternalSchema, command_name: string): Command | undefined;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=schema_compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_compiler.d.ts","sourceRoot":"","sources":["../../src/core/schema_compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM;IAI1B;;OAEG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAG,cAAc;IAsCrE;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIxF;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;CAGtF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { validate_schema } from "../validation/schema_validator.js";
|
|
2
|
+
export class SchemaCompiler {
|
|
3
|
+
logger;
|
|
4
|
+
constructor(logger) {
|
|
5
|
+
this.logger = logger;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Compile raw schema into internal format
|
|
9
|
+
*/
|
|
10
|
+
compile(raw_schema, should_validate) {
|
|
11
|
+
// Validate if requested
|
|
12
|
+
if (should_validate) {
|
|
13
|
+
this.logger.debug("Validating schema...");
|
|
14
|
+
validate_schema(raw_schema);
|
|
15
|
+
this.logger.debug("Schema validation passed");
|
|
16
|
+
}
|
|
17
|
+
// Build dialog map
|
|
18
|
+
const dialogs = new Map();
|
|
19
|
+
for (const dialog of raw_schema.dialogs) {
|
|
20
|
+
dialogs.set(dialog.id, this.compile_dialog(dialog));
|
|
21
|
+
}
|
|
22
|
+
// Build command map
|
|
23
|
+
const commands = new Map();
|
|
24
|
+
if (raw_schema.commands) {
|
|
25
|
+
for (const command of raw_schema.commands) {
|
|
26
|
+
commands.set(command.name.toLowerCase(), command);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.logger.info(`Schema compiled: ${dialogs.size} dialogs, ${commands.size} commands`);
|
|
30
|
+
return {
|
|
31
|
+
start_dialog: raw_schema.start_dialog,
|
|
32
|
+
dialogs,
|
|
33
|
+
commands,
|
|
34
|
+
inline_buttons: new Map(), // Populated dynamically
|
|
35
|
+
reply_buttons: new Map(), // Populated dynamically
|
|
36
|
+
error_dialog: raw_schema.error_dialog,
|
|
37
|
+
fallback_action: raw_schema.fallback_action,
|
|
38
|
+
reply_fallback_action: raw_schema.reply_fallback_action,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Compile a single dialog
|
|
43
|
+
*/
|
|
44
|
+
compile_dialog(dialog) {
|
|
45
|
+
return {
|
|
46
|
+
...dialog,
|
|
47
|
+
// Internal fields added during runtime
|
|
48
|
+
_compiled_inline_buttons: undefined,
|
|
49
|
+
_compiled_reply_buttons: undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get dialog by ID
|
|
54
|
+
*/
|
|
55
|
+
static get_dialog(schema, dialog_id) {
|
|
56
|
+
return schema.dialogs.get(dialog_id);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get command by name
|
|
60
|
+
*/
|
|
61
|
+
static get_command(schema, command_name) {
|
|
62
|
+
return schema.commands.get(command_name.toLowerCase());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=schema_compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_compiler.js","sourceRoot":"","sources":["../../src/core/schema_compiler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,MAAM,OAAO,cAAc;IACR,MAAM,CAAS;IAEhC,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,UAAkB,EAAE,eAAwB;QAClD,wBAAwB;QACxB,IAAI,eAAe,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,eAAe,CAAC,UAAU,CAAC,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAChD,CAAC;QAED,mBAAmB;QACnB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;QAClD,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,oBAAoB;QACpB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;QAC5C,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBAC1C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,oBAAoB,OAAO,CAAC,IAAI,aAAa,QAAQ,CAAC,IAAI,WAAW,CACtE,CAAC;QAEF,OAAO;YACL,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,OAAO;YACP,QAAQ;YACR,cAAc,EAAE,IAAI,GAAG,EAAE,EAAE,wBAAwB;YACnD,aAAa,EAAE,IAAI,GAAG,EAAE,EAAG,wBAAwB;YACnD,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,qBAAqB,EAAE,UAAU,CAAC,qBAAqB;SACxD,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,MAAc;QACnC,OAAO;YACL,GAAG,MAAM;YACT,uCAAuC;YACvC,wBAAwB,EAAE,SAAS;YACnC,uBAAuB,EAAE,SAAS;SACnC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAsB,EAAE,SAAiB;QACzD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAsB,EAAE,YAAoB;QAC7D,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class BotError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly chat_id?: number;
|
|
4
|
+
readonly details?: Record<string, unknown>;
|
|
5
|
+
constructor(message: string, code: string, chat_id?: number, details?: Record<string, unknown>);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=bot_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot_error.d.ts","sourceRoot":"","sources":["../../src/errors/bot_error.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGhD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAapC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class BotError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
chat_id;
|
|
4
|
+
details;
|
|
5
|
+
constructor(message, code, chat_id, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "BotError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.chat_id = chat_id;
|
|
10
|
+
this.details = details;
|
|
11
|
+
// Maintains proper stack trace for where our error was thrown (only in V8)
|
|
12
|
+
if (Error.captureStackTrace) {
|
|
13
|
+
Error.captureStackTrace(this, BotError);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=bot_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot_error.js","sourceRoot":"","sources":["../../src/errors/bot_error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjB,IAAI,CAAS;IACb,OAAO,CAAU;IACjB,OAAO,CAA2B;IAElD,YACE,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,OAAiC;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,2EAA2E;QAC3E,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export declare class DialogError extends BotError {
|
|
3
|
+
readonly dialog_id?: string;
|
|
4
|
+
constructor(message: string, dialog_id?: string, chat_id?: number, details?: Record<string, unknown>);
|
|
5
|
+
}
|
|
6
|
+
export declare class DialogNotFoundError extends DialogError {
|
|
7
|
+
constructor(dialog_id: string, chat_id?: number);
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidDialogError extends DialogError {
|
|
10
|
+
constructor(dialog_id: string, reason: string);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=dialog_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog_error.d.ts","sourceRoot":"","sources":["../../src/errors/dialog_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,qBAAa,WAAY,SAAQ,QAAQ;IACvC,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMpC;AAED,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAIhD;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAI9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export class DialogError extends BotError {
|
|
3
|
+
dialog_id;
|
|
4
|
+
constructor(message, dialog_id, chat_id, details) {
|
|
5
|
+
super(message, "DIALOG_ERROR", chat_id, details);
|
|
6
|
+
this.name = "DialogError";
|
|
7
|
+
this.dialog_id = dialog_id;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class DialogNotFoundError extends DialogError {
|
|
11
|
+
constructor(dialog_id, chat_id) {
|
|
12
|
+
super(`Dialog not found: "${dialog_id}"`, dialog_id, chat_id);
|
|
13
|
+
this.name = "DialogNotFoundError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class InvalidDialogError extends DialogError {
|
|
17
|
+
constructor(dialog_id, reason) {
|
|
18
|
+
super(`Invalid dialog "${dialog_id}": ${reason}`, dialog_id);
|
|
19
|
+
this.name = "InvalidDialogError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=dialog_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog_error.js","sourceRoot":"","sources":["../../src/errors/dialog_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,OAAO,WAAY,SAAQ,QAAQ;IACvB,SAAS,CAAU;IAEnC,YACE,OAAe,EACf,SAAkB,EAClB,OAAgB,EAChB,OAAiC;QAEjC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,SAAiB,EAAE,OAAgB;QAC7C,KAAK,CAAC,sBAAsB,SAAS,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,YAAY,SAAiB,EAAE,MAAc;QAC3C,KAAK,CAAC,mBAAmB,SAAS,MAAM,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BotError } from "./bot_error.js";
|
|
2
|
+
export { DialogError, DialogNotFoundError, InvalidDialogError } from "./dialog_error.js";
|
|
3
|
+
export { ValidationError, SchemaValidationError, InputValidationError, type ValidationIssue, } from "./validation_error.js";
|
|
4
|
+
export { TelegramError } from "./telegram_error.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BotError } from "./bot_error.js";
|
|
2
|
+
export { DialogError, DialogNotFoundError, InvalidDialogError } from "./dialog_error.js";
|
|
3
|
+
export { ValidationError, SchemaValidationError, InputValidationError, } from "./validation_error.js";
|
|
4
|
+
export { TelegramError } from "./telegram_error.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export declare class TelegramError extends BotError {
|
|
3
|
+
readonly telegram_error_code?: number;
|
|
4
|
+
readonly telegram_description?: string;
|
|
5
|
+
constructor(message: string, chat_id?: number, telegram_error_code?: number, telegram_description?: string);
|
|
6
|
+
static from_error(error: unknown, chat_id?: number): TelegramError;
|
|
7
|
+
is_message_not_modified(): boolean;
|
|
8
|
+
is_message_not_found(): boolean;
|
|
9
|
+
is_blocked_by_user(): boolean;
|
|
10
|
+
is_chat_not_found(): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=telegram_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram_error.d.ts","sourceRoot":"","sources":["../../src/errors/telegram_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,qBAAa,aAAc,SAAQ,QAAQ;IACzC,SAAgB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7C,SAAgB,oBAAoB,CAAC,EAAE,MAAM,CAAC;gBAG5C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,MAAM,EAC5B,oBAAoB,CAAC,EAAE,MAAM;WAWjB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,aAAa;IAalE,uBAAuB,IAAI,OAAO;IAIlC,oBAAoB,IAAI,OAAO;IAK/B,kBAAkB,IAAI,OAAO;IAK7B,iBAAiB,IAAI,OAAO;CAGpC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export class TelegramError extends BotError {
|
|
3
|
+
telegram_error_code;
|
|
4
|
+
telegram_description;
|
|
5
|
+
constructor(message, chat_id, telegram_error_code, telegram_description) {
|
|
6
|
+
super(message, "TELEGRAM_ERROR", chat_id, {
|
|
7
|
+
telegram_error_code,
|
|
8
|
+
telegram_description,
|
|
9
|
+
});
|
|
10
|
+
this.name = "TelegramError";
|
|
11
|
+
this.telegram_error_code = telegram_error_code;
|
|
12
|
+
this.telegram_description = telegram_description;
|
|
13
|
+
}
|
|
14
|
+
static from_error(error, chat_id) {
|
|
15
|
+
if (error instanceof TelegramError) {
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
const err = error;
|
|
19
|
+
const message = err.message || "Unknown Telegram error";
|
|
20
|
+
const code = err.code;
|
|
21
|
+
const description = err.response?.body?.description;
|
|
22
|
+
return new TelegramError(message, chat_id, code, description);
|
|
23
|
+
}
|
|
24
|
+
is_message_not_modified() {
|
|
25
|
+
return this.message.includes("message is not modified");
|
|
26
|
+
}
|
|
27
|
+
is_message_not_found() {
|
|
28
|
+
return this.message.includes("message to edit not found") ||
|
|
29
|
+
this.message.includes("message to delete not found");
|
|
30
|
+
}
|
|
31
|
+
is_blocked_by_user() {
|
|
32
|
+
return this.message.includes("bot was blocked by the user") ||
|
|
33
|
+
this.message.includes("user is deactivated");
|
|
34
|
+
}
|
|
35
|
+
is_chat_not_found() {
|
|
36
|
+
return this.message.includes("chat not found");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=telegram_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram_error.js","sourceRoot":"","sources":["../../src/errors/telegram_error.ts"],"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AAC;YACpD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IACtD,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export interface ValidationIssue {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class ValidationError extends BotError {
|
|
7
|
+
readonly issues: ValidationIssue[];
|
|
8
|
+
constructor(message: string, issues?: ValidationIssue[]);
|
|
9
|
+
format(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare class SchemaValidationError extends ValidationError {
|
|
12
|
+
constructor(issues: ValidationIssue[]);
|
|
13
|
+
}
|
|
14
|
+
export declare class InputValidationError extends ValidationError {
|
|
15
|
+
readonly chat_id: number;
|
|
16
|
+
readonly input: string;
|
|
17
|
+
constructor(chat_id: number, input: string, message: string);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=validation_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation_error.d.ts","sourceRoot":"","sources":["../../src/errors/validation_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;gBAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,eAAe,EAAO;IAMpD,MAAM,IAAI,MAAM;CAWxB;AAED,qBAAa,qBAAsB,SAAQ,eAAe;gBAC5C,MAAM,EAAE,eAAe,EAAE;CAItC;AAED,qBAAa,oBAAqB,SAAQ,eAAe;IACvD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM5D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BotError } from "./bot_error.js";
|
|
2
|
+
export class ValidationError extends BotError {
|
|
3
|
+
issues;
|
|
4
|
+
constructor(message, issues = []) {
|
|
5
|
+
super(message, "VALIDATION_ERROR");
|
|
6
|
+
this.name = "ValidationError";
|
|
7
|
+
this.issues = issues;
|
|
8
|
+
}
|
|
9
|
+
format() {
|
|
10
|
+
if (this.issues.length === 0) {
|
|
11
|
+
return this.message;
|
|
12
|
+
}
|
|
13
|
+
const issue_list = this.issues
|
|
14
|
+
.map((issue) => ` - ${issue.path}: ${issue.message}`)
|
|
15
|
+
.join("\n");
|
|
16
|
+
return `${this.message}\n${issue_list}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class SchemaValidationError extends ValidationError {
|
|
20
|
+
constructor(issues) {
|
|
21
|
+
super("Schema validation failed", issues);
|
|
22
|
+
this.name = "SchemaValidationError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class InputValidationError extends ValidationError {
|
|
26
|
+
chat_id;
|
|
27
|
+
input;
|
|
28
|
+
constructor(chat_id, input, message) {
|
|
29
|
+
super(message, [{ path: "input", message }]);
|
|
30
|
+
this.name = "InputValidationError";
|
|
31
|
+
this.chat_id = chat_id;
|
|
32
|
+
this.input = input;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=validation_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation_error.js","sourceRoot":"","sources":["../../src/errors/validation_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C,MAAM,OAAO,eAAgB,SAAQ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export { BotBuilder } from "./core/bot_builder.js";
|
|
2
|
+
export { go_to, go_to_start, emit, call, call_with_context, wait_for_text, wait_for_file, wait_for_photo, notify, notify_dynamic, sequence, when, delay, when_data, set_data, delete_data, } from "./actions/index.js";
|
|
3
|
+
export type { LogLevel, CustomLogger, LoggerConfig, BotConfig, Action, ActionContext, DialogAction, DialogActionContext, CallbackFunction, InputType, WaitForInputOptions, WaitResult, FileWaitResult, InlineButton, ReplyButton, ReplyKeyboardOptions, ButtonSource, TextSource, ImageSource, Dialog, Command, Schema, UpdateType, MiddlewareContext, MiddlewareNext, Middleware, UserState, } from "./types/index.js";
|
|
4
|
+
export { BotError, DialogError, DialogNotFoundError, InvalidDialogError, ValidationError, SchemaValidationError, InputValidationError, TelegramError, } from "./errors/index.js";
|
|
5
|
+
export { Logger } from "./utils/logger.js";
|
|
6
|
+
export { validate_schema, is_valid_schema } from "./validation/index.js";
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EACL,KAAK,EACL,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,MAAM,EACN,cAAc,EACd,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EAEV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EAET,MAAM,EACN,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,cAAc,EAEd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,YAAY,EAEZ,UAAU,EACV,WAAW,EACX,MAAM,EACN,OAAO,EAEP,MAAM,EAEN,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,UAAU,EAEV,SAAS,GACV,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./bot-service"), exports);
|
|
18
|
-
__exportStar(require("./bot-struct"), exports);
|
|
1
|
+
// Main class
|
|
2
|
+
export { BotBuilder } from "./core/bot_builder.js";
|
|
3
|
+
// Actions
|
|
4
|
+
export { go_to, go_to_start, emit, call, call_with_context, wait_for_text, wait_for_file, wait_for_photo, notify, notify_dynamic, sequence, when, delay, when_data, set_data, delete_data, } from "./actions/index.js";
|
|
5
|
+
// Errors
|
|
6
|
+
export { BotError, DialogError, DialogNotFoundError, InvalidDialogError, ValidationError, SchemaValidationError, InputValidationError, TelegramError, } from "./errors/index.js";
|
|
7
|
+
// Utilities (advanced usage)
|
|
8
|
+
export { Logger } from "./utils/logger.js";
|
|
9
|
+
export { validate_schema, is_valid_schema } from "./validation/index.js";
|
|
19
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,UAAU;AACV,OAAO,EACL,KAAK,EACL,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,MAAM,EACN,cAAc,EACd,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAwC5B,SAAS;AACT,OAAO,EACL,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,6BAA6B;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|