@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.
- package/README.md +300 -300
- package/bin/2byte-cli.ts +97 -84
- package/package.json +6 -2
- package/src/cli/CreateBotCommand.ts +181 -181
- package/src/cli/GenerateCommand.ts +195 -111
- package/src/cli/InitCommand.ts +107 -107
- package/src/console/migrate.ts +82 -82
- package/src/core/ApiService.ts +21 -0
- package/src/core/ApiServiceManager.ts +63 -0
- package/src/core/App.ts +1113 -1042
- package/src/core/BotArtisan.ts +79 -79
- package/src/core/BotMigration.ts +30 -30
- package/src/core/BotSeeder.ts +66 -66
- package/src/core/Model.ts +84 -84
- package/src/core/utils.ts +2 -2
- package/src/illumination/Artisan.ts +149 -149
- package/src/illumination/InlineKeyboard.ts +61 -60
- package/src/illumination/Message2Byte.ts +255 -254
- package/src/illumination/Message2ByteLiveProgressive.ts +278 -278
- package/src/illumination/Message2bytePool.ts +107 -107
- package/src/illumination/Migration.ts +186 -186
- package/src/illumination/RunSectionRoute.ts +85 -85
- package/src/illumination/Section.ts +410 -410
- package/src/illumination/SectionComponent.ts +64 -64
- package/src/illumination/Telegraf2byteContext.ts +32 -32
- package/src/index.ts +35 -33
- package/src/libs/TelegramAccountControl.ts +738 -738
- package/src/types.ts +188 -186
- package/src/user/UserModel.ts +297 -288
- package/src/user/UserStore.ts +119 -119
- package/src/workflow/services/MassSendApiService.ts +80 -0
- package/templates/bot/.env.example +18 -17
- package/templates/bot/artisan.ts +8 -8
- package/templates/bot/bot.ts +79 -77
- package/templates/bot/database/dbConnector.ts +4 -4
- package/templates/bot/database/migrate.ts +9 -9
- package/templates/bot/database/migrations/001_create_users.sql +18 -18
- package/templates/bot/database/seed.ts +14 -14
- package/templates/bot/package.json +30 -30
- package/templates/bot/sectionList.ts +9 -7
- package/templates/bot/sections/ExampleInputSection.ts +85 -0
- package/templates/bot/sections/ExampleLiveTaskerSection.ts +60 -0
- package/templates/bot/sections/HomeSection.ts +63 -63
- 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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
};
|