@2byte/tgbot-framework 1.0.3 → 1.0.4

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 +6 -5
  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 -0
  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 +1143 -1113
  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 -35
  28. package/src/libs/TelegramAccountControl.ts +1140 -738
  29. package/src/libs/TgSender.ts +53 -0
  30. package/src/models/Model.ts +67 -0
  31. package/src/models/Proxy.ts +218 -0
  32. package/src/models/TgAccount.ts +362 -0
  33. package/src/models/index.ts +3 -0
  34. package/src/types.ts +191 -188
  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 +23 -19
  39. package/templates/bot/artisan.ts +8 -8
  40. package/templates/bot/bot.ts +82 -79
  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 -0
  45. package/templates/bot/database/migrations/008_tg_accounts.sql +32 -0
  46. package/templates/bot/database/seed.ts +14 -14
  47. package/templates/bot/docs/CLI_SERVICES.md +536 -0
  48. package/templates/bot/docs/INPUT_SYSTEM.md +211 -0
  49. package/templates/bot/docs/SERVICE_EXAMPLES.md +384 -0
  50. package/templates/bot/docs/TASK_SYSTEM.md +156 -0
  51. package/templates/bot/models/Model.ts +7 -0
  52. package/templates/bot/models/index.ts +2 -0
  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/{ExampleServise.ts → ExampleService.ts} +23 -23
@@ -1,64 +1,64 @@
1
- import { TelegrafContextCustom } from './Telegraf2byteContext';
2
- import { Section } from './Section';
3
- import { ComponentOptions } from '../types';
4
-
5
- export class SectionComponent {
6
- static readonly TYPE_SYNC = 'sync';
7
- static readonly TYPE_PENDINGS = 'pendings';
8
- static readonly STATUS_PROCESSED = 'processed';
9
- static readonly STATUS_PENDING = 'pending';
10
-
11
- protected _ctx: TelegrafContextCustom;
12
- protected _app: any; // App instance
13
- protected _section: Section;
14
-
15
- protected _type: string = SectionComponent.TYPE_SYNC;
16
- protected _status: string = SectionComponent.STATUS_PROCESSED;
17
-
18
- protected _name: string = 'SectionComponent';
19
- protected _actions: Record<string, string> = {};
20
- protected _isCallbackQuery: boolean = true;
21
-
22
- constructor(options: ComponentOptions) {
23
- this._ctx = options.ctx;
24
- this._app = options.app;
25
- this._section = options.section;
26
- }
27
-
28
- static init(options: ComponentOptions): SectionComponent {
29
- return new this(options);
30
- }
31
-
32
- async default(): Promise<{ text: string, [key: string]: any }> {
33
- return { text: 'Section component' };
34
- }
35
-
36
- async run(): Promise<any> {
37
- // this._app.registerComponent(this);
38
-
39
- switch (this._type) {
40
- case SectionComponent.TYPE_PENDINGS:
41
- break;
42
-
43
- default:
44
- return this.default();
45
- }
46
- return this;
47
- }
48
-
49
- get name(): string {
50
- return this._name;
51
- }
52
-
53
- get actions(): Record<string, string> {
54
- return this._actions;
55
- }
56
-
57
- get type(): string {
58
- return this._type;
59
- }
60
-
61
- get status(): string {
62
- return this._status;
63
- }
64
- }
1
+ import { TelegrafContextCustom } from './Telegraf2byteContext';
2
+ import { Section } from './Section';
3
+ import { ComponentOptions } from '../types';
4
+
5
+ export class SectionComponent {
6
+ static readonly TYPE_SYNC = 'sync';
7
+ static readonly TYPE_PENDINGS = 'pendings';
8
+ static readonly STATUS_PROCESSED = 'processed';
9
+ static readonly STATUS_PENDING = 'pending';
10
+
11
+ protected _ctx: TelegrafContextCustom;
12
+ protected _app: any; // App instance
13
+ protected _section: Section;
14
+
15
+ protected _type: string = SectionComponent.TYPE_SYNC;
16
+ protected _status: string = SectionComponent.STATUS_PROCESSED;
17
+
18
+ protected _name: string = 'SectionComponent';
19
+ protected _actions: Record<string, string> = {};
20
+ protected _isCallbackQuery: boolean = true;
21
+
22
+ constructor(options: ComponentOptions) {
23
+ this._ctx = options.ctx;
24
+ this._app = options.app;
25
+ this._section = options.section;
26
+ }
27
+
28
+ static init(options: ComponentOptions): SectionComponent {
29
+ return new this(options);
30
+ }
31
+
32
+ async default(): Promise<{ text: string, [key: string]: any }> {
33
+ return { text: 'Section component' };
34
+ }
35
+
36
+ async run(): Promise<any> {
37
+ // this._app.registerComponent(this);
38
+
39
+ switch (this._type) {
40
+ case SectionComponent.TYPE_PENDINGS:
41
+ break;
42
+
43
+ default:
44
+ return this.default();
45
+ }
46
+ return this;
47
+ }
48
+
49
+ get name(): string {
50
+ return this._name;
51
+ }
52
+
53
+ get actions(): Record<string, string> {
54
+ return this._actions;
55
+ }
56
+
57
+ get type(): string {
58
+ return this._type;
59
+ }
60
+
61
+ get status(): string {
62
+ return this._status;
63
+ }
64
+ }
@@ -1,33 +1,33 @@
1
- import { Context } from 'telegraf';
2
- import { UserModel } from '../user/UserModel';
3
- import { UserStore } from '../user/UserStore';
4
- import { UserSession } from '../types';
5
-
6
- export interface ITelegraf2byteContextExtraMethods {
7
- deleteLastMessage(): Promise<void>;
8
- }
9
-
10
- export interface Telegraf2byteContext extends Context, ITelegraf2byteContextExtraMethods {
11
- user: UserModel;
12
- userStorage: UserStore;
13
- userSession: UserSession;
14
- // msgId?: number;
15
- }
16
-
17
- export const Telegraf2byteContextExtraMethods = {
18
- async deleteLastMessage(this: Telegraf2byteContext): Promise<void> {
19
- const lastMessageId = this.user.lastMessageId;
20
- if (lastMessageId) {
21
- try {
22
-
23
- console.log('Deleting last message with ID:', lastMessageId);
24
-
25
- await this.deleteMessage(lastMessageId);
26
-
27
- this.user.removeMessageId(lastMessageId);
28
- } catch (error) {
29
- console.error('Failed to delete last message:', error)
30
- };
31
- }
32
- },
1
+ import { Context } from 'telegraf';
2
+ import { UserModel } from '../user/UserModel';
3
+ import { UserStore } from '../user/UserStore';
4
+ import { UserSession } from '../types';
5
+
6
+ export interface ITelegraf2byteContextExtraMethods {
7
+ deleteLastMessage(): Promise<void>;
8
+ }
9
+
10
+ export interface Telegraf2byteContext extends Context, ITelegraf2byteContextExtraMethods {
11
+ user: UserModel;
12
+ userStorage: UserStore;
13
+ userSession: UserSession;
14
+ // msgId?: number;
15
+ }
16
+
17
+ export const Telegraf2byteContextExtraMethods = {
18
+ async deleteLastMessage(this: Telegraf2byteContext): Promise<void> {
19
+ const lastMessageId = this.user.lastMessageId;
20
+ if (lastMessageId) {
21
+ try {
22
+
23
+ console.log('Deleting last message with ID:', lastMessageId);
24
+
25
+ await this.deleteMessage(lastMessageId);
26
+
27
+ this.user.removeMessageId(lastMessageId);
28
+ } catch (error) {
29
+ console.error('Failed to delete last message:', error)
30
+ };
31
+ }
32
+ },
33
33
  };
package/src/index.ts CHANGED
@@ -1,35 +1,42 @@
1
- // Core classes
2
- export { App } from './core/App';
3
- export { ApiService } from './core/ApiService';
4
- export { ApiServiceManager } from './core/ApiServiceManager';
5
- export { BotArtisan } from './core/BotArtisan';
6
- export { BotMigration } from './core/BotMigration';
7
- export { BotSeeder } from './core/BotSeeder';
8
-
9
- // Framework classes
10
- export { Section } from './illumination/Section';
11
- export { Artisan } from './illumination/Artisan';
12
- export { Migration } from './illumination/Migration';
13
- export { InlineKeyboard } from './illumination/InlineKeyboard';
14
- export { default as Message2Byte } from './illumination/Message2Byte';
15
- export { RunSectionRoute } from './illumination/RunSectionRoute';
16
- export { SectionComponent } from './illumination/SectionComponent';
17
- export type { Telegraf2byteContext } from './illumination/Telegraf2byteContext';
18
-
19
- // Console utilities
20
- export { setupMigrations } from './console/migrate';
21
-
22
- // Types
23
- export * from './types';
24
-
25
- // CLI Commands (for internal use)
26
- export { CreateBotCommand } from './cli/CreateBotCommand';
27
- export { InitCommand } from './cli/InitCommand';
28
- export { GenerateCommand } from './cli/GenerateCommand';
29
-
30
- // User exports
31
- export { UserModel } from './user/UserModel';
32
- export { UserStore } from './user/UserStore';
33
-
34
- // Type exports
35
- export * from './types';
1
+ // Core classes
2
+ export { App } from './core/App';
3
+ export { ApiService } from './core/ApiService';
4
+ export { ApiServiceManager } from './core/ApiServiceManager';
5
+ export { BotArtisan } from './core/BotArtisan';
6
+ export { BotMigration } from './core/BotMigration';
7
+ export { BotSeeder } from './core/BotSeeder';
8
+
9
+ // Framework classes
10
+ export { Section } from './illumination/Section';
11
+ export { Artisan } from './illumination/Artisan';
12
+ export { Migration } from './illumination/Migration';
13
+ export { InlineKeyboard } from './illumination/InlineKeyboard';
14
+ export { default as Message2Byte } from './illumination/Message2Byte';
15
+ export { RunSectionRoute } from './illumination/RunSectionRoute';
16
+ export { SectionComponent } from './illumination/SectionComponent';
17
+ export type { Telegraf2byteContext } from './illumination/Telegraf2byteContext';
18
+
19
+ // Console utilities
20
+ export { setupMigrations } from './console/migrate';
21
+
22
+ // Types
23
+ export * from './types';
24
+
25
+ // CLI Commands (for internal use)
26
+ export { CreateBotCommand } from './cli/CreateBotCommand';
27
+ export { InitCommand } from './cli/InitCommand';
28
+ export { GenerateCommand } from './cli/GenerateCommand';
29
+ export { manualAdderTgAccount } from './cli/TgAccountManager';
30
+
31
+ // Model exports
32
+ export * from './models';
33
+
34
+ // User exports
35
+ export { UserModel } from './user/UserModel';
36
+ export { UserStore } from './user/UserStore';
37
+
38
+ export * from './libs/TelegramAccountControl';
39
+ export { TgSender } from './libs/TgSender';
40
+
41
+ // Type exports
42
+ export * from './types';