@2byte/tgbot-framework 1.0.2 → 1.0.3

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