@2byte/tgbot-framework 1.0.5 → 1.0.7

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.
Files changed (58) hide show
  1. package/README.md +300 -300
  2. package/bin/2byte-cli.ts +97 -97
  3. package/package.json +54 -54
  4. package/src/cli/CreateBotCommand.ts +181 -181
  5. package/src/cli/GenerateCommand.ts +195 -195
  6. package/src/cli/InitCommand.ts +107 -107
  7. package/src/cli/TgAccountManager.ts +50 -50
  8. package/src/console/migrate.ts +82 -82
  9. package/src/core/ApiService.ts +20 -20
  10. package/src/core/ApiServiceManager.ts +63 -63
  11. package/src/core/App.ts +1157 -1143
  12. package/src/core/BotArtisan.ts +79 -79
  13. package/src/core/BotMigration.ts +30 -30
  14. package/src/core/BotSeeder.ts +66 -66
  15. package/src/core/Model.ts +84 -84
  16. package/src/core/utils.ts +2 -2
  17. package/src/illumination/Artisan.ts +149 -149
  18. package/src/illumination/InlineKeyboard.ts +61 -61
  19. package/src/illumination/Message2Byte.ts +255 -255
  20. package/src/illumination/Message2ByteLiveProgressive.ts +278 -278
  21. package/src/illumination/Message2bytePool.ts +107 -107
  22. package/src/illumination/Migration.ts +186 -186
  23. package/src/illumination/RunSectionRoute.ts +85 -85
  24. package/src/illumination/Section.ts +410 -410
  25. package/src/illumination/SectionComponent.ts +64 -64
  26. package/src/illumination/Telegraf2byteContext.ts +32 -32
  27. package/src/index.ts +42 -42
  28. package/src/libs/TelegramAccountControl.ts +1140 -1140
  29. package/src/libs/TgSender.ts +53 -53
  30. package/src/models/Model.ts +67 -67
  31. package/src/models/Proxy.ts +217 -217
  32. package/src/models/TgAccount.ts +362 -362
  33. package/src/models/index.ts +2 -2
  34. package/src/types.ts +191 -191
  35. package/src/user/UserModel.ts +297 -297
  36. package/src/user/UserStore.ts +119 -119
  37. package/src/workflow/services/MassSendApiService.ts +80 -80
  38. package/templates/bot/.env.example +34 -23
  39. package/templates/bot/artisan.ts +8 -8
  40. package/templates/bot/bot.ts +82 -82
  41. package/templates/bot/database/dbConnector.ts +4 -4
  42. package/templates/bot/database/migrate.ts +9 -9
  43. package/templates/bot/database/migrations/001_create_users.sql +18 -18
  44. package/templates/bot/database/migrations/007_proxy.sql +27 -27
  45. package/templates/bot/database/migrations/008_tg_accounts.sql +32 -32
  46. package/templates/bot/database/seed.ts +14 -14
  47. package/templates/bot/docs/CLI_SERVICES.md +536 -536
  48. package/templates/bot/docs/INPUT_SYSTEM.md +211 -211
  49. package/templates/bot/docs/SERVICE_EXAMPLES.md +384 -384
  50. package/templates/bot/docs/TASK_SYSTEM.md +156 -156
  51. package/templates/bot/models/Model.ts +7 -7
  52. package/templates/bot/models/index.ts +1 -1
  53. package/templates/bot/package.json +30 -30
  54. package/templates/bot/sectionList.ts +9 -9
  55. package/templates/bot/sections/ExampleInputSection.ts +85 -85
  56. package/templates/bot/sections/ExampleLiveTaskerSection.ts +60 -60
  57. package/templates/bot/sections/HomeSection.ts +63 -63
  58. package/templates/bot/workflow/services/ExampleService.ts +23 -23
@@ -1,3 +1,3 @@
1
- export * from './Model';
2
- export * from './TgAccount';
1
+ export * from './Model';
2
+ export * from './TgAccount';
3
3
  export * from './Proxy';
package/src/types.ts CHANGED
@@ -1,192 +1,192 @@
1
- import { Telegraf, Context } from 'telegraf';
2
- import { Section } from './illumination/Section';
3
- import { UserStore } from './user/UserStore';
4
- import { Telegraf2byteContext } from './illumination/Telegraf2byteContext';
5
- import { RunSectionRoute } from './illumination/RunSectionRoute';
6
-
7
- export interface AppConfig {
8
- accessPublic: boolean;
9
- apiUrl: string | null;
10
- envConfig: EnvVars;
11
- botToken: string | null;
12
- telegrafConfigLaunch: Record<string, any> | null;
13
- settings: Record<string, any> | null;
14
- userStorage: UserStore | null;
15
- builderPromises: Promise<any>[];
16
- sections: SectionList;
17
- components: Record<string, string>;
18
- debug: boolean;
19
- devHotReloadSections: boolean;
20
- telegrafLog: boolean;
21
- mainMenuKeyboard: any[][];
22
- hears: Record<string, string>;
23
- terminateSigInt: boolean;
24
- terminateSigTerm: boolean;
25
- keepSectionInstances: boolean;
26
- botCwd: string;
27
- }
28
-
29
- export interface SectionOptions {
30
- ctx: Telegraf2byteContext;
31
- bot: Telegraf<Telegraf2byteContext>;
32
- app: any; // App instance,
33
- route: RunSectionRoute;
34
- }
35
-
36
- export interface RunnedSection {
37
- instance: Section;
38
- route: RunSectionRoute;
39
- }
40
-
41
- export interface UserAttributes {
42
- id?: number;
43
- user_refid?: number;
44
- tg_id: number;
45
- tg_username: string;
46
- tg_first_name: string;
47
- tg_last_name?: string;
48
- role: 'user' | 'admin';
49
- is_banned_by_user?: boolean;
50
- is_banned_by_admin?: boolean;
51
- bunned_reason?: string;
52
- language: string;
53
- updated_at: string;
54
- created_at: string;
55
- [key: string]: any;
56
- }
57
-
58
- export interface FileValidationOptions {
59
- allowedTypes?: string[]; // ['image/jpeg', 'image/png', 'application/pdf']
60
- maxSize?: number; // в байтах
61
- minSize?: number; // в байтах
62
- }
63
-
64
- export interface RequestInputOptions {
65
- validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
66
- errorMessage?: string;
67
- allowCancel?: boolean; // по умолчанию true
68
- cancelButtonText?: string; // текст кнопки отмены
69
- cancelAction?: string; // действие при отмене
70
- fileValidation?: FileValidationOptions; // опции для валидации файлов
71
- runSection?: RunSectionRoute;
72
- }
73
-
74
- export interface UserSession {
75
- previousSection?: RunnedSection;
76
- awaitingInput?: {
77
- key: string;
78
- validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
79
- errorMessage: string;
80
- allowCancel: boolean;
81
- cancelButtonText?: string;
82
- cancelAction?: string;
83
- fileValidation?: FileValidationOptions;
84
- runSection?: RunSectionRoute;
85
- retryCount?: number; // счетчик попыток
86
- };
87
- awaitingInputPromise?: {
88
- key: string;
89
- validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
90
- errorMessage: string;
91
- allowCancel: boolean;
92
- cancelButtonText?: string;
93
- cancelAction?: string;
94
- fileValidation?: FileValidationOptions;
95
- retryCount?: number;
96
- resolve: (value: string | any) => void;
97
- reject: (reason?: any) => void;
98
- };
99
- [key: string]: any;
100
- }
101
-
102
- export interface UserRegistrationData {
103
- user_refid?: number;
104
- tg_id: number;
105
- tg_username: string;
106
- tg_first_name: string;
107
- tg_last_name?: string;
108
- role: 'user' | 'admin';
109
- language: string;
110
- }
111
-
112
- export interface ComponentOptions {
113
- ctx: Telegraf2byteContext;
114
- app: any; // App instance
115
- section: Section;
116
- }
117
-
118
- export interface UserServiceAttributes {
119
- lastActive: Date;
120
- lastMessageIds: number[];
121
- }
122
-
123
- export interface UserAwaitingReply {
124
- answer: any;
125
- validator: ((text: string) => Promise<boolean>) | null;
126
- is_rejected: boolean;
127
- run: [Section, string] | null;
128
- type?: any;
129
- }
130
-
131
- export interface RunSectionRouteParams {
132
- section: string | null;
133
- method: string | null;
134
- methodArgs: any[] | null;
135
- callbackParams: URLSearchParams;
136
- runAsCallcackQuery: boolean;
137
- actionPath: string | null;
138
- hearsKey: string | null;
139
- }
140
-
141
- export type SectionEnabledList = string[]
142
-
143
- export interface SectionEntityConfig {
144
- pathModule?: string;
145
- }
146
-
147
- export interface SectionList {
148
- [key: string]: SectionEntityConfig;
149
- }
150
-
151
- export interface EnvVars {
152
- BOT_TOKEN?: string;
153
- BOT_API_URL?: string;
154
- BOT_HOOK_DOMAIN?: string;
155
- BOT_HOOK_PORT?: string;
156
- BOT_HOOK_SECRET_TOKEN?: string;
157
- BOT_DEV_HOT_RELOAD_SECTIONS?: string;
158
- BOT_ACCESS?: 'private' | 'public';
159
- BOT_ACCESS_KEYS?: string; // comma separated access keys
160
- ACCESS_USERNAMES?: string; // comma separated usernames
161
- BOT_APP_API_PORT?: number;
162
- TG_APP_ID?: string;
163
- TG_APP_HASH?: string;
164
- [key: string]: string | number |undefined;
165
- }
166
-
167
- export type ModelPaginateParams = {
168
- route: string;
169
- routeParams?: Record<string, any>;
170
- page: number;
171
- limit: number;
172
- whereSql: string;
173
- whereParams?: any[];
174
- };
175
-
176
- export type PaginateResult = {
177
- items: any[];
178
- paginateButtons: any[][];
179
- total: number;
180
- totalPages: number;
181
- hasPreviousPage: boolean;
182
- hasNextPage: boolean;
183
- currentPage: number;
184
- };
185
-
186
- export type MakeManualPaginateButtonsParams = {
187
- callbackDataAction: string;
188
- paramsQuery: Record<string, any>;
189
- currentPage: number | string;
190
- totalRecords: number;
191
- perPage: number;
1
+ import { Telegraf, Context } from 'telegraf';
2
+ import { Section } from './illumination/Section';
3
+ import { UserStore } from './user/UserStore';
4
+ import { Telegraf2byteContext } from './illumination/Telegraf2byteContext';
5
+ import { RunSectionRoute } from './illumination/RunSectionRoute';
6
+
7
+ export interface AppConfig {
8
+ accessPublic: boolean;
9
+ apiUrl: string | null;
10
+ envConfig: EnvVars;
11
+ botToken: string | null;
12
+ telegrafConfigLaunch: Record<string, any> | null;
13
+ settings: Record<string, any> | null;
14
+ userStorage: UserStore | null;
15
+ builderPromises: Promise<any>[];
16
+ sections: SectionList;
17
+ components: Record<string, string>;
18
+ debug: boolean;
19
+ devHotReloadSections: boolean;
20
+ telegrafLog: boolean;
21
+ mainMenuKeyboard: any[][];
22
+ hears: Record<string, string>;
23
+ terminateSigInt: boolean;
24
+ terminateSigTerm: boolean;
25
+ keepSectionInstances: boolean;
26
+ botCwd: string;
27
+ }
28
+
29
+ export interface SectionOptions {
30
+ ctx: Telegraf2byteContext;
31
+ bot: Telegraf<Telegraf2byteContext>;
32
+ app: any; // App instance,
33
+ route: RunSectionRoute;
34
+ }
35
+
36
+ export interface RunnedSection {
37
+ instance: Section;
38
+ route: RunSectionRoute;
39
+ }
40
+
41
+ export interface UserAttributes {
42
+ id?: number;
43
+ user_refid?: number;
44
+ tg_id: number;
45
+ tg_username: string;
46
+ tg_first_name: string;
47
+ tg_last_name?: string;
48
+ role: 'user' | 'admin';
49
+ is_banned_by_user?: boolean;
50
+ is_banned_by_admin?: boolean;
51
+ bunned_reason?: string;
52
+ language: string;
53
+ updated_at: string;
54
+ created_at: string;
55
+ [key: string]: any;
56
+ }
57
+
58
+ export interface FileValidationOptions {
59
+ allowedTypes?: string[]; // ['image/jpeg', 'image/png', 'application/pdf']
60
+ maxSize?: number; // в байтах
61
+ minSize?: number; // в байтах
62
+ }
63
+
64
+ export interface RequestInputOptions {
65
+ validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
66
+ errorMessage?: string;
67
+ allowCancel?: boolean; // по умолчанию true
68
+ cancelButtonText?: string; // текст кнопки отмены
69
+ cancelAction?: string; // действие при отмене
70
+ fileValidation?: FileValidationOptions; // опции для валидации файлов
71
+ runSection?: RunSectionRoute;
72
+ }
73
+
74
+ export interface UserSession {
75
+ previousSection?: RunnedSection;
76
+ awaitingInput?: {
77
+ key: string;
78
+ validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
79
+ errorMessage: string;
80
+ allowCancel: boolean;
81
+ cancelButtonText?: string;
82
+ cancelAction?: string;
83
+ fileValidation?: FileValidationOptions;
84
+ runSection?: RunSectionRoute;
85
+ retryCount?: number; // счетчик попыток
86
+ };
87
+ awaitingInputPromise?: {
88
+ key: string;
89
+ validator?: 'number' | 'phone' | 'code' | 'file' | ((value: string | any) => boolean | Promise<boolean>);
90
+ errorMessage: string;
91
+ allowCancel: boolean;
92
+ cancelButtonText?: string;
93
+ cancelAction?: string;
94
+ fileValidation?: FileValidationOptions;
95
+ retryCount?: number;
96
+ resolve: (value: string | any) => void;
97
+ reject: (reason?: any) => void;
98
+ };
99
+ [key: string]: any;
100
+ }
101
+
102
+ export interface UserRegistrationData {
103
+ user_refid?: number;
104
+ tg_id: number;
105
+ tg_username: string;
106
+ tg_first_name: string;
107
+ tg_last_name?: string;
108
+ role: 'user' | 'admin';
109
+ language: string;
110
+ }
111
+
112
+ export interface ComponentOptions {
113
+ ctx: Telegraf2byteContext;
114
+ app: any; // App instance
115
+ section: Section;
116
+ }
117
+
118
+ export interface UserServiceAttributes {
119
+ lastActive: Date;
120
+ lastMessageIds: number[];
121
+ }
122
+
123
+ export interface UserAwaitingReply {
124
+ answer: any;
125
+ validator: ((text: string) => Promise<boolean>) | null;
126
+ is_rejected: boolean;
127
+ run: [Section, string] | null;
128
+ type?: any;
129
+ }
130
+
131
+ export interface RunSectionRouteParams {
132
+ section: string | null;
133
+ method: string | null;
134
+ methodArgs: any[] | null;
135
+ callbackParams: URLSearchParams;
136
+ runAsCallcackQuery: boolean;
137
+ actionPath: string | null;
138
+ hearsKey: string | null;
139
+ }
140
+
141
+ export type SectionEnabledList = string[]
142
+
143
+ export interface SectionEntityConfig {
144
+ pathModule?: string;
145
+ }
146
+
147
+ export interface SectionList {
148
+ [key: string]: SectionEntityConfig;
149
+ }
150
+
151
+ export interface EnvVars {
152
+ BOT_TOKEN?: string;
153
+ BOT_API_URL?: string;
154
+ BOT_HOOK_DOMAIN?: string;
155
+ BOT_HOOK_PORT?: string;
156
+ BOT_HOOK_SECRET_TOKEN?: string;
157
+ BOT_DEV_HOT_RELOAD_SECTIONS?: string;
158
+ BOT_ACCESS?: 'private' | 'public';
159
+ BOT_ACCESS_KEYS?: string; // comma separated access keys
160
+ ACCESS_USERNAMES?: string; // comma separated usernames
161
+ BOT_APP_API_PORT?: number;
162
+ TG_APP_ID?: string;
163
+ TG_APP_HASH?: string;
164
+ [key: string]: string | number |undefined;
165
+ }
166
+
167
+ export type ModelPaginateParams = {
168
+ route: string;
169
+ routeParams?: Record<string, any>;
170
+ page: number;
171
+ limit: number;
172
+ whereSql: string;
173
+ whereParams?: any[];
174
+ };
175
+
176
+ export type PaginateResult = {
177
+ items: any[];
178
+ paginateButtons: any[][];
179
+ total: number;
180
+ totalPages: number;
181
+ hasPreviousPage: boolean;
182
+ hasNextPage: boolean;
183
+ currentPage: number;
184
+ };
185
+
186
+ export type MakeManualPaginateButtonsParams = {
187
+ callbackDataAction: string;
188
+ paramsQuery: Record<string, any>;
189
+ currentPage: number | string;
190
+ totalRecords: number;
191
+ perPage: number;
192
192
  };