@2byte/tgbot-framework 1.0.12 → 1.0.13

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 (60) hide show
  1. package/README.md +300 -300
  2. package/bin/2byte-cli.ts +97 -97
  3. package/package.json +55 -55
  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 +1242 -1178
  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 +79 -79
  19. package/src/illumination/Message2Byte.ts +256 -256
  20. package/src/illumination/Message2ByteLiveProgressive.ts +278 -278
  21. package/src/illumination/Message2bytePool.ts +113 -113
  22. package/src/illumination/Migration.ts +186 -186
  23. package/src/illumination/RunSectionRoute.ts +109 -95
  24. package/src/illumination/Section.ts +429 -420
  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 +198 -191
  35. package/src/user/UserModel.ts +297 -297
  36. package/src/user/UserStore.ts +119 -119
  37. package/src/workflow/services/MassSendApiService.ts +83 -83
  38. package/templates/bot/.env.example +33 -33
  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/MASS_SEND_SERVICE.md +327 -327
  50. package/templates/bot/docs/SERVICE_EXAMPLES.md +384 -384
  51. package/templates/bot/docs/TASK_SYSTEM.md +156 -156
  52. package/templates/bot/models/Model.ts +8 -8
  53. package/templates/bot/models/index.ts +1 -1
  54. package/templates/bot/package.json +30 -30
  55. package/templates/bot/sectionList.ts +9 -9
  56. package/templates/bot/sections/ExampleInputSection.ts +85 -85
  57. package/templates/bot/sections/ExampleLiveTaskerSection.ts +60 -60
  58. package/templates/bot/sections/HomeSection.ts +63 -63
  59. package/templates/bot/tsconfig.json +16 -16
  60. package/templates/bot/workflow/services/ExampleService.ts +23 -23
@@ -1,60 +1,60 @@
1
- import { Section } from "@2byte/tgbot-framework";
2
- import { SectionOptions } from "@2byte/tgbot-framework";
3
- import { InlineKeyboard } from "@2byte/tgbot-framework";
4
-
5
- export default class ExampleLiveTaskerSection extends Section {
6
- static command = "examplelivetasker";
7
- static description = "ExampleLiveTasker section";
8
- static actionRoutes = {
9
- "exampleLiveTasker.index": "index",
10
- "exampleLiveTasker.runTasker": "runTasker",
11
- };
12
-
13
- public sectionId = "ExampleLiveTasker";
14
- private mainInlineKeyboard: InlineKeyboard;
15
-
16
- constructor(options: SectionOptions) {
17
- super(options);
18
-
19
- this.mainInlineKeyboard = this.makeInlineKeyboard().addFootFixedButtons(this.btnHome);
20
- }
21
-
22
- public async up(): Promise<void> {}
23
- public async down(): Promise<void> {}
24
- public async setup(): Promise<void> {}
25
- public async unsetup(): Promise<void> {}
26
-
27
- async index() {
28
- const message = `
29
- 👋 Welcome to ExampleLiveTasker Section
30
- `;
31
-
32
- await this.message(message)
33
- .inlineKeyboard(this.mainInlineKeyboard.append(
34
- this.makeInlineButton('➕ Example Live Tasker', 'exampleLiveTasker.runTasker')
35
- ))
36
- .send();
37
- }
38
-
39
- async runTasker() {
40
- const msgPool = this.createUpdatePoolMessage("Starting tasker...");
41
-
42
- await msgPool.send();
43
-
44
- const msgProgressive = msgPool.liveProgressive();
45
-
46
- await msgProgressive.setBaseMessage("Tasker in progress:").send();
47
-
48
- for (let i = 1; i <= 5; i++) {
49
- await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate a task taking time
50
- await msgProgressive.appendItem(i, `Task ${i} running`).send();
51
- await msgProgressive.sleepProgressBar(2000).send();
52
- await msgProgressive.changeItem(i, `Task ${i} changed`).send();
53
- await msgProgressive.setItemStatusCompleted(i).send();
54
- }
55
-
56
- await msgProgressive.stopSleepProgress();
57
- const res = await msgPool.append("\n\nAll tasks completed!").send();
58
- console.log("Final message sent:", res);
59
- }
60
- }
1
+ import { Section } from "@2byte/tgbot-framework";
2
+ import { SectionOptions } from "@2byte/tgbot-framework";
3
+ import { InlineKeyboard } from "@2byte/tgbot-framework";
4
+
5
+ export default class ExampleLiveTaskerSection extends Section {
6
+ static command = "examplelivetasker";
7
+ static description = "ExampleLiveTasker section";
8
+ static actionRoutes = {
9
+ "exampleLiveTasker.index": "index",
10
+ "exampleLiveTasker.runTasker": "runTasker",
11
+ };
12
+
13
+ public sectionId = "ExampleLiveTasker";
14
+ private mainInlineKeyboard: InlineKeyboard;
15
+
16
+ constructor(options: SectionOptions) {
17
+ super(options);
18
+
19
+ this.mainInlineKeyboard = this.makeInlineKeyboard().addFootFixedButtons(this.btnHome);
20
+ }
21
+
22
+ public async up(): Promise<void> {}
23
+ public async down(): Promise<void> {}
24
+ public async setup(): Promise<void> {}
25
+ public async unsetup(): Promise<void> {}
26
+
27
+ async index() {
28
+ const message = `
29
+ 👋 Welcome to ExampleLiveTasker Section
30
+ `;
31
+
32
+ await this.message(message)
33
+ .inlineKeyboard(this.mainInlineKeyboard.append(
34
+ this.makeInlineButton('➕ Example Live Tasker', 'exampleLiveTasker.runTasker')
35
+ ))
36
+ .send();
37
+ }
38
+
39
+ async runTasker() {
40
+ const msgPool = this.createUpdatePoolMessage("Starting tasker...");
41
+
42
+ await msgPool.send();
43
+
44
+ const msgProgressive = msgPool.liveProgressive();
45
+
46
+ await msgProgressive.setBaseMessage("Tasker in progress:").send();
47
+
48
+ for (let i = 1; i <= 5; i++) {
49
+ await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate a task taking time
50
+ await msgProgressive.appendItem(i, `Task ${i} running`).send();
51
+ await msgProgressive.sleepProgressBar(2000).send();
52
+ await msgProgressive.changeItem(i, `Task ${i} changed`).send();
53
+ await msgProgressive.setItemStatusCompleted(i).send();
54
+ }
55
+
56
+ await msgProgressive.stopSleepProgress();
57
+ const res = await msgPool.append("\n\nAll tasks completed!").send();
58
+ console.log("Final message sent:", res);
59
+ }
60
+ }
@@ -1,63 +1,63 @@
1
- import { Section, SectionOptions, InlineKeyboard } from "@2byte/tgbot-framework";
2
-
3
- export default class HomeSection extends Section {
4
- static command = "start";
5
- static description = "Example Bot Home section";
6
- static actionRoutes = {
7
- "home.index": "index",
8
- "home.help": "help",
9
- };
10
-
11
- public sectionId = "home";
12
- private mainInlineKeyboard: InlineKeyboard;
13
-
14
- constructor(options: SectionOptions) {
15
- super(options);
16
-
17
- this.mainInlineKeyboard = this.makeInlineKeyboard().addFootFixedButtons(this.btnHome);
18
- }
19
-
20
- public async up(): Promise<void> {}
21
- public async down(): Promise<void> {}
22
- public async setup(): Promise<void> {}
23
- public async unsetup(): Promise<void> {}
24
-
25
- async index() {
26
- const message = `
27
- 🏠 **Example Bot**
28
-
29
- Добро пожаловать в Example бот!
30
- Это стартовая секция, созданная с помощью 2byte framework.
31
-
32
- Выберите действие:
33
- `;
34
-
35
- await this.message(message)
36
- .markdown()
37
- .inlineKeyboard(
38
- this.mainInlineKeyboard
39
- .append(this.makeInlineButton("ℹ️ Помощь", "home.help"))
40
- .append(this.makeInlineButton("➕ Example Input", "exampleInput.index"))
41
- .append(this.makeInlineButton("🚀 Example Live Tasker", "exampleLiveTasker.index"))
42
- )
43
- .send();
44
- }
45
-
46
- async help() {
47
- const message = `
48
- ℹ️ **Помощь**
49
-
50
- Это бот, созданный с помощью 2byte Telegram Bot Framework.
51
-
52
- Доступные команды:
53
- • /start - Главное меню
54
-
55
- Для разработчиков:
56
- • bun run artisan make:section <name> - Создать секцию
57
- • bun run migrate - Выполнить миграции
58
- • bun run seed - Заполнить данными
59
- `;
60
-
61
- await this.message(message).inlineKeyboard(this.mainInlineKeyboard).markdown().send();
62
- }
63
- }
1
+ import { Section, SectionOptions, InlineKeyboard } from "@2byte/tgbot-framework";
2
+
3
+ export default class HomeSection extends Section {
4
+ static command = "start";
5
+ static description = "Example Bot Home section";
6
+ static actionRoutes = {
7
+ "home.index": "index",
8
+ "home.help": "help",
9
+ };
10
+
11
+ public sectionId = "home";
12
+ private mainInlineKeyboard: InlineKeyboard;
13
+
14
+ constructor(options: SectionOptions) {
15
+ super(options);
16
+
17
+ this.mainInlineKeyboard = this.makeInlineKeyboard().addFootFixedButtons(this.btnHome);
18
+ }
19
+
20
+ public async up(): Promise<void> {}
21
+ public async down(): Promise<void> {}
22
+ public async setup(): Promise<void> {}
23
+ public async unsetup(): Promise<void> {}
24
+
25
+ async index() {
26
+ const message = `
27
+ 🏠 **Example Bot**
28
+
29
+ Добро пожаловать в Example бот!
30
+ Это стартовая секция, созданная с помощью 2byte framework.
31
+
32
+ Выберите действие:
33
+ `;
34
+
35
+ await this.message(message)
36
+ .markdown()
37
+ .inlineKeyboard(
38
+ this.mainInlineKeyboard
39
+ .append(this.makeInlineButton("ℹ️ Помощь", "home.help"))
40
+ .append(this.makeInlineButton("➕ Example Input", "exampleInput.index"))
41
+ .append(this.makeInlineButton("🚀 Example Live Tasker", "exampleLiveTasker.index"))
42
+ )
43
+ .send();
44
+ }
45
+
46
+ async help() {
47
+ const message = `
48
+ ℹ️ **Помощь**
49
+
50
+ Это бот, созданный с помощью 2byte Telegram Bot Framework.
51
+
52
+ Доступные команды:
53
+ • /start - Главное меню
54
+
55
+ Для разработчиков:
56
+ • bun run artisan make:section <name> - Создать секцию
57
+ • bun run migrate - Выполнить миграции
58
+ • bun run seed - Заполнить данными
59
+ `;
60
+
61
+ await this.message(message).inlineKeyboard(this.mainInlineKeyboard).markdown().send();
62
+ }
63
+ }
@@ -1,17 +1,17 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ES2022",
5
- "lib": ["ES2022"],
6
- "moduleResolution": "bundler",
7
- "types": ["bun-types"],
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "allowSyntheticDefaultImports": true
14
- },
15
- "include": ["*.ts"],
16
- "exclude": ["node_modules", "dist", "packed"]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "types": ["bun-types"],
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "allowSyntheticDefaultImports": true
14
+ },
15
+ "include": ["*.ts"],
16
+ "exclude": ["node_modules", "dist", "packed"]
17
17
  }
@@ -1,24 +1,24 @@
1
- import { App } from "@2byte/tgbot-framework";
2
- import { ApiService } from "@2byte/tgbot-framework";
3
-
4
- export default class ExampleService extends ApiService {
5
-
6
- constructor(
7
- protected app: App,
8
- public name: string = "ExampleService"
9
- ) {
10
- super(app, name);
11
- }
12
-
13
- public async setup(): Promise<void> {
14
- return Promise.resolve();
15
- }
16
-
17
- public async unsetup(): Promise<void> {
18
- return Promise.resolve();
19
- }
20
-
21
- public async run(): Promise<void> {
22
- return Promise.resolve();
23
- }
1
+ import { App } from "@2byte/tgbot-framework";
2
+ import { ApiService } from "@2byte/tgbot-framework";
3
+
4
+ export default class ExampleService extends ApiService {
5
+
6
+ constructor(
7
+ protected app: App,
8
+ public name: string = "ExampleService"
9
+ ) {
10
+ super(app, name);
11
+ }
12
+
13
+ public async setup(): Promise<void> {
14
+ return Promise.resolve();
15
+ }
16
+
17
+ public async unsetup(): Promise<void> {
18
+ return Promise.resolve();
19
+ }
20
+
21
+ public async run(): Promise<void> {
22
+ return Promise.resolve();
23
+ }
24
24
  }