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 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,MAAsB,EAAE,KAAc;IACnF,6CAA6C;IAC7C,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,MAAM,UAAU,GAA4B;QAC1C,SAAS;KACV,CAAC;IAEF,gCAAgC;IAChC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CA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,UAAU,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Logger, SILENT_LOGGER } from "./logger.js";
|
|
2
|
+
export { hash_button, generate_wait_id } from "./hash.js";
|
|
3
|
+
export { deep_copy } from "./deep_copy.js";
|
|
4
|
+
export { is_message, is_callback_query, has_text, has_document, has_photo, has_contact, has_location, is_text_source_function, is_button_source_function, is_image_source_function, } from "./type_guards.js";
|
|
5
|
+
export { ERROR_MESSAGES, TELEGRAM_ERRORS, DEFAULTS } from "./constants.js";
|
|
6
|
+
export { resolve_text, resolve_images, resolve_buttons, resolve_inline_button, resolve_reply_button, } from "./resolvers.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Logger, SILENT_LOGGER } from "./logger.js";
|
|
2
|
+
export { hash_button, generate_wait_id } from "./hash.js";
|
|
3
|
+
export { deep_copy } from "./deep_copy.js";
|
|
4
|
+
export { is_message, is_callback_query, has_text, has_document, has_photo, has_contact, has_location, is_text_source_function, is_button_source_function, is_image_source_function, } from "./type_guards.js";
|
|
5
|
+
export { ERROR_MESSAGES, TELEGRAM_ERRORS, DEFAULTS } from "./constants.js";
|
|
6
|
+
export { resolve_text, resolve_images, resolve_buttons, resolve_inline_button, resolve_reply_button, } from "./resolvers.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LoggerConfig } from "../types/config.js";
|
|
2
|
+
export declare class Logger {
|
|
3
|
+
private readonly level;
|
|
4
|
+
private readonly custom;
|
|
5
|
+
private readonly use_colors;
|
|
6
|
+
constructor(config?: LoggerConfig);
|
|
7
|
+
private format_message;
|
|
8
|
+
debug(message: string, ...args: unknown[]): void;
|
|
9
|
+
info(message: string, ...args: unknown[]): void;
|
|
10
|
+
warn(message: string, ...args: unknown[]): void;
|
|
11
|
+
error(message: string, ...args: unknown[]): void;
|
|
12
|
+
/** Create a child logger with a prefix */
|
|
13
|
+
child(prefix: string): Logger;
|
|
14
|
+
}
|
|
15
|
+
/** Global silent logger for disabled logging */
|
|
16
|
+
export declare const SILENT_LOGGER: Logger;
|
|
17
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAoB/E,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;gBAEzB,MAAM,CAAC,EAAE,YAAY;IAMjC,OAAO,CAAC,cAAc;IAYtB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAUhD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAU/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAU/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAUhD,0CAA0C;IAC1C,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAc9B;AAED,gDAAgD;AAChD,eAAO,MAAM,aAAa,QAAkC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const LOG_LEVELS = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
info: 1,
|
|
4
|
+
warn: 2,
|
|
5
|
+
error: 3,
|
|
6
|
+
silent: 4,
|
|
7
|
+
};
|
|
8
|
+
const LEVEL_COLORS = {
|
|
9
|
+
debug: "\x1b[36m", // cyan
|
|
10
|
+
info: "\x1b[32m", // green
|
|
11
|
+
warn: "\x1b[33m", // yellow
|
|
12
|
+
error: "\x1b[31m", // red
|
|
13
|
+
silent: "",
|
|
14
|
+
};
|
|
15
|
+
const RESET_COLOR = "\x1b[0m";
|
|
16
|
+
export class Logger {
|
|
17
|
+
level;
|
|
18
|
+
custom;
|
|
19
|
+
use_colors;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.level = LOG_LEVELS[config?.level ?? "info"];
|
|
22
|
+
this.custom = config?.custom_logger;
|
|
23
|
+
this.use_colors = process.stdout.isTTY ?? false;
|
|
24
|
+
}
|
|
25
|
+
format_message(level, message) {
|
|
26
|
+
const timestamp = new Date().toISOString();
|
|
27
|
+
const level_upper = level.toUpperCase().padEnd(5);
|
|
28
|
+
if (this.use_colors) {
|
|
29
|
+
const color = LEVEL_COLORS[level];
|
|
30
|
+
return `${color}[${timestamp}] [${level_upper}]${RESET_COLOR} ${message}`;
|
|
31
|
+
}
|
|
32
|
+
return `[${timestamp}] [${level_upper}] ${message}`;
|
|
33
|
+
}
|
|
34
|
+
debug(message, ...args) {
|
|
35
|
+
if (this.level > LOG_LEVELS.debug)
|
|
36
|
+
return;
|
|
37
|
+
if (this.custom) {
|
|
38
|
+
this.custom.debug(message, ...args);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.debug(this.format_message("debug", message), ...args);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
info(message, ...args) {
|
|
45
|
+
if (this.level > LOG_LEVELS.info)
|
|
46
|
+
return;
|
|
47
|
+
if (this.custom) {
|
|
48
|
+
this.custom.info(message, ...args);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.info(this.format_message("info", message), ...args);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
warn(message, ...args) {
|
|
55
|
+
if (this.level > LOG_LEVELS.warn)
|
|
56
|
+
return;
|
|
57
|
+
if (this.custom) {
|
|
58
|
+
this.custom.warn(message, ...args);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.warn(this.format_message("warn", message), ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
error(message, ...args) {
|
|
65
|
+
if (this.level > LOG_LEVELS.error)
|
|
66
|
+
return;
|
|
67
|
+
if (this.custom) {
|
|
68
|
+
this.custom.error(message, ...args);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.error(this.format_message("error", message), ...args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Create a child logger with a prefix */
|
|
75
|
+
child(prefix) {
|
|
76
|
+
const parent = this;
|
|
77
|
+
const prefixed_logger = {
|
|
78
|
+
debug: (msg, ...args) => parent.debug(`[${prefix}] ${msg}`, ...args),
|
|
79
|
+
info: (msg, ...args) => parent.info(`[${prefix}] ${msg}`, ...args),
|
|
80
|
+
warn: (msg, ...args) => parent.warn(`[${prefix}] ${msg}`, ...args),
|
|
81
|
+
error: (msg, ...args) => parent.error(`[${prefix}] ${msg}`, ...args),
|
|
82
|
+
};
|
|
83
|
+
return new Logger({
|
|
84
|
+
level: Object.entries(LOG_LEVELS).find(([_, v]) => v === this.level)?.[0],
|
|
85
|
+
custom_logger: prefixed_logger,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Global silent logger for disabled logging */
|
|
90
|
+
export const SILENT_LOGGER = new Logger({ level: "silent" });
|
|
91
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAA6B;IAC3C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AAEF,MAAM,YAAY,GAA6B;IAC7C,KAAK,EAAE,UAA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ton } from "../types/keyboard.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a TextSource to a string value
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolve_text(source: TextSource | undefined, chat_id: number): Promise<string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Resolve an ImageSource to string or string[]
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolve_images(source: ImageSource | undefined, chat_id: number): Promise<string | string[] | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve ButtonSource to a 2D array of buttons
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolve_buttons<T extends InlineButton | ReplyButton>(source: ButtonSource<T> | undefined, chat_id: number): Promise<T[][] | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve all dynamic properties of an InlineButton
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolve_inline_button(button: InlineButton, chat_id: number): Promise<{
|
|
19
|
+
text: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
web_app?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve all dynamic properties of a ReplyButton
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolve_reply_button(button: ReplyButton, chat_id: number): Promise<{
|
|
27
|
+
text: string;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/utils/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGtE;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU/G;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAUxC;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,CAAC,SAAS,YAAY,GAAG,WAAW,EACxE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,EACnC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,SAAS,CAAC,CAU5B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAU3D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAM3B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { is_text_source_function, is_button_source_function, is_image_source_function } from "./type_guards.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a TextSource to a string value
|
|
4
|
+
*/
|
|
5
|
+
export async function resolve_text(source, chat_id) {
|
|
6
|
+
if (source === undefined) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
if (is_text_source_function(source)) {
|
|
10
|
+
return await source(chat_id);
|
|
11
|
+
}
|
|
12
|
+
return source;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve an ImageSource to string or string[]
|
|
16
|
+
*/
|
|
17
|
+
export async function resolve_images(source, chat_id) {
|
|
18
|
+
if (source === undefined) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (is_image_source_function(source)) {
|
|
22
|
+
return await source(chat_id);
|
|
23
|
+
}
|
|
24
|
+
return source;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve ButtonSource to a 2D array of buttons
|
|
28
|
+
*/
|
|
29
|
+
export async function resolve_buttons(source, chat_id) {
|
|
30
|
+
if (source === undefined) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (is_button_source_function(source)) {
|
|
34
|
+
return await source(chat_id);
|
|
35
|
+
}
|
|
36
|
+
return source;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Resolve all dynamic properties of an InlineButton
|
|
40
|
+
*/
|
|
41
|
+
export async function resolve_inline_button(button, chat_id) {
|
|
42
|
+
const text = await resolve_text(button.text, chat_id);
|
|
43
|
+
const url = await resolve_text(button.url, chat_id);
|
|
44
|
+
const web_app = await resolve_text(button.web_app, chat_id);
|
|
45
|
+
return {
|
|
46
|
+
text: text ?? "",
|
|
47
|
+
url,
|
|
48
|
+
web_app,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve all dynamic properties of a ReplyButton
|
|
53
|
+
*/
|
|
54
|
+
export async function resolve_reply_button(button, chat_id) {
|
|
55
|
+
const text = await resolve_text(button.text, chat_id);
|
|
56
|
+
return {
|
|
57
|
+
text: text ?? "",
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=resolvers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.js","sourceRoot":"","sources":["../../src/utils/resolvers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAEhH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAA8B,EAAE,OAAe;IAChF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO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B,CACxC,MAAmB,EACnB,OAAe;IAEf,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,IAAI,IAAI,EAAE;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type TelegramBot from "node-telegram-bot-api";
|
|
2
|
+
export declare function is_message(update: unknown): update is TelegramBot.Message;
|
|
3
|
+
export declare function is_callback_query(update: unknown): update is TelegramBot.CallbackQuery;
|
|
4
|
+
export declare function has_text(message: TelegramBot.Message): message is TelegramBot.Message & {
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function has_document(message: TelegramBot.Message): message is TelegramBot.Message & {
|
|
8
|
+
document: TelegramBot.Document;
|
|
9
|
+
};
|
|
10
|
+
export declare function has_photo(message: TelegramBot.Message): message is TelegramBot.Message & {
|
|
11
|
+
photo: TelegramBot.PhotoSize[];
|
|
12
|
+
};
|
|
13
|
+
export declare function has_contact(message: TelegramBot.Message): message is TelegramBot.Message & {
|
|
14
|
+
contact: TelegramBot.Contact;
|
|
15
|
+
};
|
|
16
|
+
export declare function has_location(message: TelegramBot.Message): message is TelegramBot.Message & {
|
|
17
|
+
location: TelegramBot.Location;
|
|
18
|
+
};
|
|
19
|
+
export declare function is_text_source_function(source: unknown): source is (chat_id: number) => string | Promise<string>;
|
|
20
|
+
export declare function is_button_source_function<T>(source: unknown): source is (chat_id: number) => T[][] | Promise<T[][]>;
|
|
21
|
+
export declare function is_image_source_function(source: unknown): source is (chat_id: number) => string | string[] | undefined | Promise<string | string[] | undefined>;
|
|
22
|
+
//# sourceMappingURL=type_guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type_guards.d.ts","sourceRoot":"","sources":["../../src/utils/type_guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAC;AAErD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AC,CAEvD;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAEvG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function is_message(update) {
|
|
2
|
+
return (typeof update === "object" &&
|
|
3
|
+
update !== null &&
|
|
4
|
+
"chat" in update &&
|
|
5
|
+
"message_id" in update);
|
|
6
|
+
}
|
|
7
|
+
export function is_callback_query(update) {
|
|
8
|
+
return (typeof update === "object" &&
|
|
9
|
+
update !== null &&
|
|
10
|
+
"id" in update &&
|
|
11
|
+
"from" in update &&
|
|
12
|
+
!("chat" in update && "message_id" in update && !("message" in update)));
|
|
13
|
+
}
|
|
14
|
+
export function has_text(message) {
|
|
15
|
+
return typeof message.text === "string";
|
|
16
|
+
}
|
|
17
|
+
export function has_document(message) {
|
|
18
|
+
return message.document !== undefined;
|
|
19
|
+
}
|
|
20
|
+
export function has_photo(message) {
|
|
21
|
+
return Array.isArray(message.photo) && message.photo.length > 0;
|
|
22
|
+
}
|
|
23
|
+
export function has_contact(message) {
|
|
24
|
+
return message.contact !== undefined;
|
|
25
|
+
}
|
|
26
|
+
export function has_location(message) {
|
|
27
|
+
return message.location !== undefined;
|
|
28
|
+
}
|
|
29
|
+
export function is_text_source_function(source) {
|
|
30
|
+
return typeof source === "function";
|
|
31
|
+
}
|
|
32
|
+
export function is_button_source_function(source) {
|
|
33
|
+
return typeof source === "function";
|
|
34
|
+
}
|
|
35
|
+
export function is_image_source_function(source) {
|
|
36
|
+
return typeof source === "function";
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=type_guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type_guards.js","sourceRoot":"","sources":["../../src/utils/type_guards.ts"],"names":[],"mappings":"AAEA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;IAEf,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Schema } from "../types/schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validate a schema and return the validated schema
|
|
4
|
+
* @throws SchemaValidationError if validation fails
|
|
5
|
+
*/
|
|
6
|
+
export declare function validate_schema(schema: unknown): Schema;
|
|
7
|
+
/**
|
|
8
|
+
* Check if schema is valid without throwing
|
|
9
|
+
*/
|
|
10
|
+
export declare function is_valid_schema(schema: unknown): schema is Schema;
|
|
11
|
+
//# sourceMappingURL=schema_validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_validator.d.ts","sourceRoot":"","sources":["../../src/validation/schema_validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAkGjD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAkEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAOjE"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SchemaValidationError } from "../errors/validation_error.js";
|
|
3
|
+
// Text source can be string or function
|
|
4
|
+
const text_source_schema = z.union([
|
|
5
|
+
z.string(),
|
|
6
|
+
z.function(),
|
|
7
|
+
]);
|
|
8
|
+
// Image source
|
|
9
|
+
const image_source_schema = z.union([
|
|
10
|
+
z.string(),
|
|
11
|
+
z.array(z.string()),
|
|
12
|
+
z.function(),
|
|
13
|
+
]);
|
|
14
|
+
// Inline button
|
|
15
|
+
const inline_button_schema = z.object({
|
|
16
|
+
text: text_source_schema,
|
|
17
|
+
action: z.union([z.function(), z.array(z.function())]).optional(),
|
|
18
|
+
url: text_source_schema.optional(),
|
|
19
|
+
web_app: text_source_schema.optional(),
|
|
20
|
+
callback_data: z.string().max(64).optional(),
|
|
21
|
+
}).refine((btn) => !(btn.action && btn.url), { message: "Button cannot have both 'action' and 'url'" }).refine((btn) => !(btn.action && btn.web_app), { message: "Button cannot have both 'action' and 'web_app'" });
|
|
22
|
+
// Reply button
|
|
23
|
+
const reply_button_schema = z.object({
|
|
24
|
+
text: text_source_schema,
|
|
25
|
+
action: z.union([z.function(), z.array(z.function())]).optional(),
|
|
26
|
+
request_contact: z.boolean().optional(),
|
|
27
|
+
request_location: z.boolean().optional(),
|
|
28
|
+
request_poll: z.object({
|
|
29
|
+
type: z.enum(["quiz", "regular"]).optional(),
|
|
30
|
+
}).optional(),
|
|
31
|
+
});
|
|
32
|
+
// Button source (array or function)
|
|
33
|
+
const inline_button_source_schema = z.union([
|
|
34
|
+
z.array(z.array(inline_button_schema)),
|
|
35
|
+
z.function(),
|
|
36
|
+
]);
|
|
37
|
+
const reply_button_source_schema = z.union([
|
|
38
|
+
z.array(z.array(reply_button_schema)),
|
|
39
|
+
z.function(),
|
|
40
|
+
]);
|
|
41
|
+
// Reply keyboard options
|
|
42
|
+
const reply_keyboard_options_schema = z.object({
|
|
43
|
+
resize_keyboard: z.boolean().optional(),
|
|
44
|
+
one_time_keyboard: z.boolean().optional(),
|
|
45
|
+
input_field_placeholder: z.string().max(64).optional(),
|
|
46
|
+
selective: z.boolean().optional(),
|
|
47
|
+
is_persistent: z.boolean().optional(),
|
|
48
|
+
}).optional();
|
|
49
|
+
// Dialog
|
|
50
|
+
const dialog_schema = z.object({
|
|
51
|
+
id: z.string().min(1, "Dialog ID cannot be empty"),
|
|
52
|
+
text: text_source_schema.optional(),
|
|
53
|
+
inline_buttons: inline_button_source_schema.optional(),
|
|
54
|
+
reply_buttons: reply_button_source_schema.optional(),
|
|
55
|
+
reply_keyboard_options: reply_keyboard_options_schema,
|
|
56
|
+
remove_reply_keyboard: z.boolean().optional(),
|
|
57
|
+
images: image_source_schema.optional(),
|
|
58
|
+
on_enter: z.function().optional(),
|
|
59
|
+
on_leave: z.function().optional(),
|
|
60
|
+
disable_web_page_preview: z.boolean().optional(),
|
|
61
|
+
protect_content: z.boolean().optional(),
|
|
62
|
+
});
|
|
63
|
+
// Command
|
|
64
|
+
const command_schema = z.object({
|
|
65
|
+
name: z.string()
|
|
66
|
+
.min(1, "Command name cannot be empty")
|
|
67
|
+
.max(32, "Command name too long (max 32 chars)")
|
|
68
|
+
.regex(/^[a-z0-9_]+$/, "Command name must be lowercase alphanumeric with underscores"),
|
|
69
|
+
description: z.string().max(256).optional(),
|
|
70
|
+
action: z.union([z.function(), z.array(z.function())]).optional(),
|
|
71
|
+
});
|
|
72
|
+
// Full schema
|
|
73
|
+
const schema_validator = z.object({
|
|
74
|
+
start_dialog: z.string().min(1, "start_dialog is required"),
|
|
75
|
+
dialogs: z.array(dialog_schema).min(1, "At least one dialog is required"),
|
|
76
|
+
commands: z.array(command_schema).optional(),
|
|
77
|
+
error_dialog: z.string().optional(),
|
|
78
|
+
fallback_action: z.function().optional(),
|
|
79
|
+
reply_fallback_action: z.function().optional(),
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Validate a schema and return the validated schema
|
|
83
|
+
* @throws SchemaValidationError if validation fails
|
|
84
|
+
*/
|
|
85
|
+
export function validate_schema(schema) {
|
|
86
|
+
const result = schema_validator.safeParse(schema);
|
|
87
|
+
if (!result.success) {
|
|
88
|
+
const issues = result.error.issues.map((issue) => ({
|
|
89
|
+
path: issue.path.join("."),
|
|
90
|
+
message: issue.message,
|
|
91
|
+
}));
|
|
92
|
+
throw new SchemaValidationError(issues);
|
|
93
|
+
}
|
|
94
|
+
const validated = result.data;
|
|
95
|
+
// Additional validation: check start_dialog exists
|
|
96
|
+
const dialog_ids = new Set(validated.dialogs.map((d) => d.id));
|
|
97
|
+
if (!dialog_ids.has(validated.start_dialog)) {
|
|
98
|
+
throw new SchemaValidationError([
|
|
99
|
+
{
|
|
100
|
+
path: "start_dialog",
|
|
101
|
+
message: `start_dialog "${validated.start_dialog}" does not reference an existing dialog`,
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
// Check error_dialog exists if specified
|
|
106
|
+
if (validated.error_dialog && !dialog_ids.has(validated.error_dialog)) {
|
|
107
|
+
throw new SchemaValidationError([
|
|
108
|
+
{
|
|
109
|
+
path: "error_dialog",
|
|
110
|
+
message: `error_dialog "${validated.error_dialog}" does not reference an existing dialog`,
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
// Check for duplicate dialog IDs
|
|
115
|
+
const seen_ids = new Set();
|
|
116
|
+
for (const dialog of validated.dialogs) {
|
|
117
|
+
if (seen_ids.has(dialog.id)) {
|
|
118
|
+
throw new SchemaValidationError([
|
|
119
|
+
{
|
|
120
|
+
path: `dialogs`,
|
|
121
|
+
message: `Duplicate dialog ID: "${dialog.id}"`,
|
|
122
|
+
},
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
seen_ids.add(dialog.id);
|
|
126
|
+
}
|
|
127
|
+
// Check for duplicate command names
|
|
128
|
+
if (validated.commands) {
|
|
129
|
+
const seen_commands = new Set();
|
|
130
|
+
for (const command of validated.commands) {
|
|
131
|
+
if (seen_commands.has(command.name)) {
|
|
132
|
+
throw new SchemaValidationError([
|
|
133
|
+
{
|
|
134
|
+
path: `commands`,
|
|
135
|
+
message: `Duplicate command name: "/${command.name}"`,
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
seen_commands.add(command.name);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return validated;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if schema is valid without throwing
|
|
146
|
+
*/
|
|
147
|
+
export function is_valid_schema(schema) {
|
|
148
|
+
try {
|
|
149
|
+
validate_schema(schema);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=schema_validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_validator.js","sourceRoot":"","sources":["../../src/validation/schema_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,wCAAwC;AACxC,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC;IACjC,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,QAAQ,EAAE;CACb,CAAC,CAAC;AAEH,eAAe;AACf,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC;IAClC,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACnB,CAAC,CAAC,QAAQ,EAAE;CACb,CAAC,CAAC;AAEH,gBAAgB;AAChB,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACjE,GAAG,EAAE,kBAAkB,CAAC,QAAQ,EAAE;IAClC,OA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
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "telegram-botbuilder",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Declarative dialog-based Telegram bot framework for Node.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"README.md",
|
|
17
|
+
"CHANGELOG.md",
|
|
18
|
+
"MIGRATION.md"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"clean": "rm -rf lib",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"telegram",
|
|
31
|
+
"bot",
|
|
32
|
+
"telegram-bot",
|
|
33
|
+
"botbuilder",
|
|
34
|
+
"dialog",
|
|
35
|
+
"declarative",
|
|
36
|
+
"typescript"
|
|
37
|
+
],
|
|
38
|
+
"author": "zxcpadik",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/zxcpadik/telegram-botbuilder.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/zxcpadik/telegram-botbuilder/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/zxcpadik/telegram-botbuilder#readme",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"node-telegram-bot-api": "^0.67.0",
|
|
50
|
+
"zod": "^3.23.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"@types/node-telegram-bot-api": "^0.64.13",
|
|
55
|
+
"typescript": "^5.6.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"typescript": ">=5.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"typescript": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/lib/bot-service.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import TelegramBot from 'node-telegram-bot-api';
|
|
2
|
-
import { Schema, Action, BotBuilderMiddleware, CallbackActionFunc, Dialog } from './bot-struct';
|
|
3
|
-
import EventEmitter from 'events';
|
|
4
|
-
export declare class BotBuilder {
|
|
5
|
-
_bot: TelegramBot;
|
|
6
|
-
private _schema;
|
|
7
|
-
ActionSystem: EventEmitter;
|
|
8
|
-
private _userdialogs;
|
|
9
|
-
private _middleware;
|
|
10
|
-
private _mwbreak;
|
|
11
|
-
use(func: BotBuilderMiddleware): void;
|
|
12
|
-
private _mwba;
|
|
13
|
-
private _runmw;
|
|
14
|
-
private _hashbtn;
|
|
15
|
-
constructor(schema: Schema, token: string, options?: TelegramBot.ConstructorOptions);
|
|
16
|
-
private _getDialog;
|
|
17
|
-
private _getButton;
|
|
18
|
-
private _getButtonID;
|
|
19
|
-
private _activateButton;
|
|
20
|
-
ChangeDialog(chat: number, id: string | Dialog, message_id?: number): Promise<void>;
|
|
21
|
-
AttachDataWait(chat: number, descriptor: string): void;
|
|
22
|
-
Message(chat: number, content: string): Promise<TelegramBot.Message>;
|
|
23
|
-
}
|
|
24
|
-
export declare function ChangeDialog(id: string): Action;
|
|
25
|
-
export declare function CallbackAction(descriptor: string | CallbackActionFunc, ...args: any[]): Action;
|
|
26
|
-
export declare function WaitForData(descriptor: string | CallbackActionFunc): Action;
|
|
27
|
-
//# sourceMappingURL=bot-service.d.ts.map
|