chz-telegram-bot 0.0.15 → 0.0.17

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 (126) hide show
  1. package/dist/entities/actionExecutionResult.d.ts +7 -0
  2. package/dist/entities/actionExecutionResult.d.ts.map +1 -0
  3. package/dist/entities/{transactionResult.js → actionExecutionResult.js} +3 -2
  4. package/dist/entities/actions/commandAction.d.ts +4 -4
  5. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  6. package/dist/entities/actions/commandAction.js +12 -11
  7. package/dist/entities/actions/scheduledAction.d.ts +5 -5
  8. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  9. package/dist/entities/actions/scheduledAction.js +10 -9
  10. package/dist/entities/{bot.d.ts → botInstance.d.ts} +5 -5
  11. package/dist/entities/botInstance.d.ts.map +1 -0
  12. package/dist/entities/{bot.js → botInstance.js} +20 -22
  13. package/dist/entities/cachedStateFactory.d.ts +1 -1
  14. package/dist/entities/cachedStateFactory.d.ts.map +1 -1
  15. package/dist/entities/cachedStateFactory.js +2 -1
  16. package/dist/entities/commandTriggerCheckResult.d.ts +1 -1
  17. package/dist/entities/commandTriggerCheckResult.d.ts.map +1 -1
  18. package/dist/entities/commandTriggerCheckResult.js +2 -1
  19. package/dist/entities/context/chatContext.d.ts +7 -5
  20. package/dist/entities/context/chatContext.d.ts.map +1 -1
  21. package/dist/entities/context/chatContext.js +17 -14
  22. package/dist/entities/context/messageContext.d.ts +7 -7
  23. package/dist/entities/context/messageContext.d.ts.map +1 -1
  24. package/dist/entities/context/messageContext.js +19 -21
  25. package/dist/entities/incomingMessage.d.ts +1 -1
  26. package/dist/entities/incomingMessage.d.ts.map +1 -1
  27. package/dist/entities/incomingMessage.js +2 -1
  28. package/dist/entities/responses/imageMessage.d.ts +6 -3
  29. package/dist/entities/responses/imageMessage.d.ts.map +1 -1
  30. package/dist/entities/responses/imageMessage.js +7 -2
  31. package/dist/entities/responses/reaction.d.ts +5 -2
  32. package/dist/entities/responses/reaction.d.ts.map +1 -1
  33. package/dist/entities/responses/reaction.js +6 -2
  34. package/dist/entities/responses/textMessage.d.ts +6 -3
  35. package/dist/entities/responses/textMessage.d.ts.map +1 -1
  36. package/dist/entities/responses/textMessage.js +7 -2
  37. package/dist/entities/responses/unpin.d.ts +10 -0
  38. package/dist/entities/responses/unpin.d.ts.map +1 -0
  39. package/dist/entities/responses/unpin.js +14 -0
  40. package/dist/entities/responses/videoMessage.d.ts +6 -3
  41. package/dist/entities/responses/videoMessage.d.ts.map +1 -1
  42. package/dist/entities/responses/videoMessage.js +7 -2
  43. package/dist/entities/states/actionStateBase.d.ts +3 -2
  44. package/dist/entities/states/actionStateBase.d.ts.map +1 -1
  45. package/dist/entities/states/actionStateBase.js +3 -1
  46. package/dist/entities/taskRecord.d.ts +1 -1
  47. package/dist/entities/taskRecord.d.ts.map +1 -1
  48. package/dist/entities/taskRecord.js +2 -1
  49. package/dist/helpers/builders/commandActionBuilder.d.ts +3 -3
  50. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
  51. package/dist/helpers/builders/commandActionBuilder.js +9 -12
  52. package/dist/helpers/builders/scheduledActionBuilder.d.ts +3 -3
  53. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
  54. package/dist/helpers/builders/scheduledActionBuilder.js +8 -10
  55. package/dist/helpers/noop.d.ts +1 -2
  56. package/dist/helpers/noop.d.ts.map +1 -1
  57. package/dist/helpers/noop.js +2 -1
  58. package/dist/helpers/toArray.d.ts +1 -1
  59. package/dist/helpers/toArray.d.ts.map +1 -1
  60. package/dist/helpers/toArray.js +1 -1
  61. package/dist/main.d.ts +5 -5
  62. package/dist/main.d.ts.map +1 -1
  63. package/dist/main.js +6 -9
  64. package/dist/services/jsonFileStorage.d.ts +6 -5
  65. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  66. package/dist/services/jsonFileStorage.js +10 -1
  67. package/dist/services/logger.d.ts +3 -3
  68. package/dist/services/logger.d.ts.map +1 -1
  69. package/dist/services/logger.js +3 -2
  70. package/dist/services/taskScheduler.d.ts +3 -3
  71. package/dist/services/taskScheduler.d.ts.map +1 -1
  72. package/dist/services/taskScheduler.js +8 -10
  73. package/dist/services/telegramApi.d.ts +20 -15
  74. package/dist/services/telegramApi.d.ts.map +1 -1
  75. package/dist/services/telegramApi.js +50 -43
  76. package/dist/types/actionState.d.ts +2 -1
  77. package/dist/types/actionState.d.ts.map +1 -1
  78. package/dist/types/actionWithState.d.ts +2 -2
  79. package/dist/types/actionWithState.d.ts.map +1 -1
  80. package/dist/types/commandCondition.d.ts +2 -2
  81. package/dist/types/commandCondition.d.ts.map +1 -1
  82. package/dist/types/handlers.d.ts +3 -3
  83. package/dist/types/handlers.d.ts.map +1 -1
  84. package/dist/types/replyMessage.d.ts +1 -1
  85. package/dist/types/replyMessage.d.ts.map +1 -1
  86. package/dist/types/response.d.ts +26 -0
  87. package/dist/types/response.d.ts.map +1 -0
  88. package/dist/types/response.js +10 -0
  89. package/dist/types/storage.d.ts +5 -4
  90. package/dist/types/storage.d.ts.map +1 -1
  91. package/entities/{transactionResult.ts → actionExecutionResult.ts} +2 -2
  92. package/entities/actions/commandAction.ts +10 -10
  93. package/entities/actions/scheduledAction.ts +13 -13
  94. package/entities/{bot.ts → botInstance.ts} +20 -20
  95. package/entities/cachedStateFactory.ts +1 -1
  96. package/entities/commandTriggerCheckResult.ts +1 -1
  97. package/entities/context/chatContext.ts +35 -10
  98. package/entities/context/messageContext.ts +37 -16
  99. package/entities/incomingMessage.ts +1 -1
  100. package/entities/responses/imageMessage.ts +11 -3
  101. package/entities/responses/reaction.ts +8 -2
  102. package/entities/responses/textMessage.ts +11 -3
  103. package/entities/responses/unpin.ts +22 -0
  104. package/entities/responses/videoMessage.ts +11 -3
  105. package/entities/states/actionStateBase.ts +3 -2
  106. package/entities/taskRecord.ts +1 -1
  107. package/helpers/builders/commandActionBuilder.ts +5 -5
  108. package/helpers/builders/scheduledActionBuilder.ts +4 -4
  109. package/helpers/noop.ts +1 -3
  110. package/helpers/toArray.ts +1 -1
  111. package/main.ts +9 -9
  112. package/package.json +1 -1
  113. package/services/jsonFileStorage.ts +21 -6
  114. package/services/logger.ts +2 -2
  115. package/services/taskScheduler.ts +6 -6
  116. package/services/telegramApi.ts +95 -59
  117. package/types/actionState.ts +2 -1
  118. package/types/actionWithState.ts +2 -2
  119. package/types/commandCondition.ts +2 -2
  120. package/types/handlers.ts +3 -3
  121. package/types/response.ts +34 -0
  122. package/types/storage.ts +9 -5
  123. package/dist/entities/bot.d.ts.map +0 -1
  124. package/dist/entities/transactionResult.d.ts +0 -7
  125. package/dist/entities/transactionResult.d.ts.map +0 -1
  126. package/types/replyMessage.ts +0 -7
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const taskRecord_1 = __importDefault(require("../entities/taskRecord"));
3
+ exports.Scheduler = void 0;
4
+ const taskRecord_1 = require("../entities/taskRecord");
7
5
  const timeConvertions_1 = require("../helpers/timeConvertions");
8
- const logger_1 = __importDefault(require("./logger"));
6
+ const logger_1 = require("./logger");
9
7
  class TaskScheduler {
10
8
  constructor() {
11
9
  this.activeTasks = [];
@@ -18,20 +16,20 @@ class TaskScheduler {
18
16
  createTask(name, action, interval, executeRightAway, ownerName) {
19
17
  executeRightAway = executeRightAway ?? false;
20
18
  const taskId = setInterval(action, interval);
21
- const task = new taskRecord_1.default(name, taskId, interval);
19
+ const task = new taskRecord_1.TaskRecord(name, taskId, interval);
22
20
  if (executeRightAway) {
23
21
  setTimeout(action, (0, timeConvertions_1.secondsToMilliseconds)(1));
24
22
  }
25
- logger_1.default.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created task [${taskId}]${name}, that will run every ${interval}ms.`);
23
+ logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created task [${taskId}]${name}, that will run every ${interval}ms.`);
26
24
  this.activeTasks.push(task);
27
25
  }
28
26
  createOnetimeTask(name, action, delay, ownerName) {
29
27
  const actionWrapper = () => {
30
- logger_1.default.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Executing delayed oneshot [${taskId}]${name}`);
28
+ logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Executing delayed oneshot [${taskId}]${name}`);
31
29
  action();
32
30
  };
33
31
  const taskId = setTimeout(actionWrapper, delay);
34
- logger_1.default.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created oneshot task [${taskId}]${name}, that will run in ${delay}ms.`);
32
+ logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created oneshot task [${taskId}]${name}, that will run in ${delay}ms.`);
35
33
  }
36
34
  }
37
- exports.default = new TaskScheduler();
35
+ exports.Scheduler = new TaskScheduler();
@@ -1,27 +1,32 @@
1
- import MessageContext from '../entities/context/messageContext';
2
- import ChatContext from '../entities/context/chatContext';
3
- import { Telegraf } from 'telegraf';
4
- import IReplyMessage from '../types/replyMessage';
5
- import IncomingMessage from '../entities/incomingMessage';
6
- import Reaction from '../entities/responses/reaction';
1
+ import { ChatContext } from '../entities/context/chatContext';
2
+ import { MessageContext } from '../entities/context/messageContext';
7
3
  import { IStorageClient } from '../types/storage';
8
- export default class TelegramApiService {
4
+ import { Reaction } from '../entities/responses/reaction';
5
+ import { IncomingMessage } from '../entities/incomingMessage';
6
+ import { BotResponse } from '../types/response';
7
+ import { UnpinResponse } from '../entities/responses/unpin';
8
+ import { TextMessage } from '../entities/responses/textMessage';
9
+ import { VideoMessage } from '../entities/responses/videoMessage';
10
+ import { ImageMessage } from '../entities/responses/imageMessage';
11
+ import { Telegram } from 'telegraf/typings/telegram';
12
+ export declare class TelegramApiService {
9
13
  botName: string;
10
- telegraf: Telegraf;
14
+ telegram: Telegram;
11
15
  chats: Map<number, string>;
12
- messageQueue: Array<IReplyMessage<unknown> | Reaction>;
16
+ messageQueue: Array<BotResponse>;
13
17
  storage: IStorageClient;
14
- constructor(botName: string, telegraf: Telegraf, storage: IStorageClient, chats: Map<string, number>);
18
+ constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Map<string, number>);
15
19
  private dequeueResponse;
20
+ private pinIfShould;
16
21
  private processResponse;
17
- private enqueueResponse;
18
- private enqueueReaction;
22
+ private enqueue;
19
23
  private getInteractions;
20
- createContextForMessage(incomingMessage: IncomingMessage): MessageContext<import("../types/actionState").default>;
21
- createContextForChat(chatId: number, scheduledName: string): ChatContext;
24
+ createContextForMessage(incomingMessage: IncomingMessage, commandKey: string): MessageContext<import("..").IActionState>;
25
+ createContextForChat(chatId: number, scheduledKey: string): ChatContext;
22
26
  }
23
27
  export interface IBotApiInteractions {
24
- respond: <TType>(response: IReplyMessage<TType>) => void;
28
+ respond: (response: TextMessage | VideoMessage | ImageMessage) => void;
25
29
  react: (reaction: Reaction) => void;
30
+ unpin: (unpinMessage: UnpinResponse) => void;
26
31
  }
27
32
  //# sourceMappingURL=telegramApi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAM1D,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D,OAAO,QAAQ,MAAM,gCAAgC,CAAC;AAGtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAM;IAC5D,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;YAkBhB,eAAe;YAkBf,eAAe;IAgE7B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAOvB,uBAAuB,CAAC,eAAe,EAAE,eAAe;IAoBxD,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAU7D;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IACzD,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;CACvC"}
1
+ {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,qBAAa,kBAAkB;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,CAAM;IACtC,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;YAkBhB,eAAe;YAkBf,WAAW;YAqBX,eAAe;IA2E7B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,eAAe;IAQvB,uBAAuB,CACnB,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,MAAM;IAsBtB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAW5D;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,KAAK,IAAI,CAAC;IACvE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD"}
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const messageContext_1 = __importDefault(require("../entities/context/messageContext"));
7
- const chatContext_1 = __importDefault(require("../entities/context/chatContext"));
8
- const imageMessage_1 = __importDefault(require("../entities/responses/imageMessage"));
9
- const textMessage_1 = __importDefault(require("../entities/responses/textMessage"));
10
- const videoMessage_1 = __importDefault(require("../entities/responses/videoMessage"));
11
- const taskScheduler_1 = __importDefault(require("./taskScheduler"));
12
- const logger_1 = __importDefault(require("./logger"));
3
+ exports.TelegramApiService = void 0;
4
+ const chatContext_1 = require("../entities/context/chatContext");
5
+ const messageContext_1 = require("../entities/context/messageContext");
13
6
  const reverseMap_1 = require("../helpers/reverseMap");
7
+ const taskScheduler_1 = require("./taskScheduler");
8
+ const logger_1 = require("./logger");
14
9
  class TelegramApiService {
15
- constructor(botName, telegraf, storage, chats) {
10
+ constructor(botName, telegram, storage, chats) {
16
11
  this.messageQueue = [];
17
- this.telegraf = telegraf;
12
+ this.telegram = telegram;
18
13
  this.botName = botName;
19
14
  this.chats = (0, reverseMap_1.reverseMap)(chats);
20
15
  this.storage = storage;
21
- taskScheduler_1.default.createTask('MessageSending', () => {
16
+ taskScheduler_1.Scheduler.createTask('MessageSending', () => {
22
17
  this.dequeueResponse();
23
18
  }, 100, false, this.botName);
24
19
  }
@@ -30,66 +25,78 @@ class TelegramApiService {
30
25
  await this.processResponse(message);
31
26
  }
32
27
  catch (error) {
33
- logger_1.default.errorWithTraceId(this.botName, message.traceId, this.chats.get(message.chatId), error, message);
28
+ logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats.get(message.chatId), error, message);
34
29
  }
35
30
  }
36
- async processResponse(response) {
37
- if ('emoji' in response) {
38
- this.telegraf.telegram.setMessageReaction(response.chatId, response.messageId, [
39
- {
40
- type: 'emoji',
41
- emoji: response.emoji
42
- }
43
- ], true);
44
- return;
31
+ async pinIfShould(response, sentMessage) {
32
+ if (response.shouldPin) {
33
+ await this.telegram.pinChatMessage(response.chatId, sentMessage.message_id, { disable_notification: true });
34
+ await this.storage.updateStateFor(response.sourceActionKey, response.chatId, async (state) => {
35
+ state.pinnedMessages.push(sentMessage.message_id);
36
+ });
45
37
  }
46
- switch (response.constructor) {
47
- case textMessage_1.default:
48
- await this.telegraf.telegram.sendMessage(response.chatId, response.content, {
38
+ }
39
+ async processResponse(response) {
40
+ let sentMessage;
41
+ switch (response.kind) {
42
+ case 'text':
43
+ sentMessage = await this.telegram.sendMessage(response.chatId, response.content, {
49
44
  reply_to_message_id: response.replyId,
50
45
  parse_mode: 'MarkdownV2',
51
46
  disable_web_page_preview: response.disableWebPreview
52
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
48
  });
49
+ await this.pinIfShould(response, sentMessage);
54
50
  break;
55
- case imageMessage_1.default:
56
- await this.telegraf.telegram.sendPhoto(response.chatId, response.content, response.replyId
51
+ case 'image':
52
+ sentMessage = await this.telegram.sendPhoto(response.chatId, response.content, response.replyId
57
53
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
54
  { reply_to_message_id: response.replyId }
59
55
  : undefined);
56
+ await this.pinIfShould(response, sentMessage);
60
57
  break;
61
- case videoMessage_1.default:
62
- await this.telegraf.telegram.sendVideo(response.chatId, response.content, response.replyId
58
+ case 'video':
59
+ sentMessage = await this.telegram.sendVideo(response.chatId, response.content, response.replyId
63
60
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
61
  { reply_to_message_id: response.replyId }
65
62
  : undefined);
63
+ await this.pinIfShould(response, sentMessage);
66
64
  break;
67
- default:
68
- logger_1.default.errorWithTraceId(this.botName, response.traceId, this.chats.get(response.chatId), `Unknown message type: ${response.constructor}`, response);
65
+ case 'react':
66
+ await this.telegram.setMessageReaction(response.chatId, response.messageId, [
67
+ {
68
+ type: 'emoji',
69
+ emoji: response.emoji
70
+ }
71
+ ], true);
72
+ return;
73
+ case 'unpin':
74
+ await this.telegram.unpinChatMessage(response.chatId, response.messageId);
75
+ await this.storage.updateStateFor(response.sourceActionKey, response.chatId, async (state) => {
76
+ state.pinnedMessages = state.pinnedMessages.filter((x) => x != response.messageId);
77
+ });
69
78
  break;
70
79
  }
71
80
  }
72
- enqueueResponse(response) {
73
- this.messageQueue.push(response);
74
- }
75
- enqueueReaction(reaction) {
81
+ enqueue(reaction) {
76
82
  this.messageQueue.push(reaction);
77
83
  }
78
84
  getInteractions() {
79
85
  return {
80
- react: (reaction) => this.enqueueReaction(reaction),
81
- respond: (response) => this.enqueueResponse(response)
86
+ react: (reaction) => this.enqueue(reaction),
87
+ respond: (response) => this.enqueue(response),
88
+ unpin: (unpinMessage) => this.enqueue(unpinMessage)
82
89
  };
83
90
  }
84
- createContextForMessage(incomingMessage) {
91
+ createContextForMessage(incomingMessage, commandKey) {
85
92
  const firstName = incomingMessage.from?.first_name ?? 'Unknown user';
86
93
  const lastName = incomingMessage.from?.last_name
87
94
  ? ` ${incomingMessage.from?.last_name}`
88
95
  : '';
89
- return new messageContext_1.default(this.botName, this.getInteractions(), incomingMessage.chat.id, incomingMessage.chatName, incomingMessage.message_id, incomingMessage.text, incomingMessage.from?.id, incomingMessage.traceId, firstName + lastName, this.storage);
96
+ return new messageContext_1.MessageContext(this.botName, commandKey, this.getInteractions(), incomingMessage.chat.id, incomingMessage.chatName, incomingMessage.message_id, incomingMessage.text, incomingMessage.from?.id, incomingMessage.traceId, firstName + lastName, this.storage);
90
97
  }
91
- createContextForChat(chatId, scheduledName) {
92
- return new chatContext_1.default(this.botName, this.getInteractions(), chatId, this.chats.get(chatId), `Scheduled:${scheduledName}:${chatId}`, this.storage);
98
+ createContextForChat(chatId, scheduledKey) {
99
+ return new chatContext_1.ChatContext(this.botName, scheduledKey, this.getInteractions(), chatId, this.chats.get(chatId), `Scheduled:${scheduledKey}:${chatId}`, this.storage);
93
100
  }
94
101
  }
95
- exports.default = TelegramApiService;
102
+ exports.TelegramApiService = TelegramApiService;
@@ -1,4 +1,5 @@
1
- export default interface IActionState {
1
+ export interface IActionState {
2
2
  lastExecutedDate: number;
3
+ pinnedMessages: number[];
3
4
  }
4
5
  //# sourceMappingURL=actionState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actionState.d.ts","sourceRoot":"","sources":["../../types/actionState.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,YAAY;IACjC,gBAAgB,EAAE,MAAM,CAAC;CAC5B"}
1
+ {"version":3,"file":"actionState.d.ts","sourceRoot":"","sources":["../../types/actionState.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
@@ -1,5 +1,5 @@
1
- import IActionState from './actionState';
2
- export default interface IActionWithState {
1
+ import { IActionState } from './actionState';
2
+ export interface IActionWithState {
3
3
  key: string;
4
4
  stateConstructor: () => IActionState;
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACxC"}
1
+ {"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACxC"}
@@ -1,4 +1,4 @@
1
- import MessageContext from '../entities/context/messageContext';
2
- import IActionState from './actionState';
1
+ import { MessageContext } from '../entities/context/messageContext';
2
+ import { IActionState } from './actionState';
3
3
  export type CommandCondition<TActionState extends IActionState> = (ctx: MessageContext<TActionState>) => Promise<boolean>;
4
4
  //# sourceMappingURL=commandCondition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandCondition.d.ts","sourceRoot":"","sources":["../../types/commandCondition.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI,CAC9D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,KAChC,OAAO,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"commandCondition.d.ts","sourceRoot":"","sources":["../../types/commandCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI,CAC9D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,KAChC,OAAO,CAAC,OAAO,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
- import ChatContext from '../entities/context/chatContext';
2
- import MessageContext from '../entities/context/messageContext';
3
- import IActionState from './actionState';
1
+ import { ChatContext } from '../entities/context/chatContext';
2
+ import { MessageContext } from '../entities/context/messageContext';
3
+ import { IActionState } from './actionState';
4
4
  import { CachedValueAccessor } from './cachedValueAccessor';
5
5
  export type CommandHandler<TActionState extends IActionState> = (ctx: MessageContext<TActionState>, state: TActionState) => Promise<void>;
6
6
  export type ScheduledHandler = (ctx: ChatContext, getCached: CachedValueAccessor) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../types/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAC1D,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,YAAY,IAAI,CAC5D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,EACjC,KAAK,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,gBAAgB,GAAG,CAC3B,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,mBAAmB,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../types/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,YAAY,IAAI,CAC5D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,EACjC,KAAK,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,gBAAgB,GAAG,CAC3B,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,mBAAmB,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- export default interface IReplyMessage<TType> {
1
+ export interface IReplyMessage<TType> {
2
2
  content: TType;
3
3
  chatId: number;
4
4
  replyId: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"replyMessage.d.ts","sourceRoot":"","sources":["../../types/replyMessage.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC,KAAK;IACxC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC9B"}
1
+ {"version":3,"file":"replyMessage.d.ts","sourceRoot":"","sources":["../../types/replyMessage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,KAAK;IAChC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC9B"}
@@ -0,0 +1,26 @@
1
+ import { ImageMessage } from '../entities/responses/imageMessage';
2
+ import { Reaction } from '../entities/responses/reaction';
3
+ import { TextMessage } from '../entities/responses/textMessage';
4
+ import { UnpinResponse } from '../entities/responses/unpin';
5
+ import { VideoMessage } from '../entities/responses/videoMessage';
6
+ export declare const BotResponseTypes: {
7
+ readonly unpin: "unpin";
8
+ readonly text: "text";
9
+ readonly image: "image";
10
+ readonly video: "video";
11
+ readonly react: "react";
12
+ };
13
+ export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | ImageMessage;
14
+ export interface IChatResponse {
15
+ kind: keyof typeof BotResponseTypes;
16
+ chatId: number;
17
+ traceId: number | string;
18
+ sourceActionKey: string;
19
+ }
20
+ export interface IReplyMessage<TType> extends IChatResponse {
21
+ content: TType;
22
+ replyId: number | undefined;
23
+ disableWebPreview: boolean;
24
+ shouldPin: boolean;
25
+ }
26
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX,MAAM,MAAM,WAAW,GACjB,aAAa,GACb,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,YAAY,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,OAAO,gBAAgB,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,aAAa;IACvD,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACtB"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BotResponseTypes = void 0;
4
+ exports.BotResponseTypes = {
5
+ unpin: 'unpin',
6
+ text: 'text',
7
+ image: 'image',
8
+ video: 'video',
9
+ react: 'react'
10
+ };
@@ -1,11 +1,12 @@
1
- import TransactionResult from '../entities/transactionResult';
2
- import IActionState from './actionState';
3
- import IActionWithState from './actionWithState';
1
+ import { ActionExecutionResult } from '../entities/actionExecutionResult';
2
+ import { IActionState } from './actionState';
3
+ import { IActionWithState } from './actionWithState';
4
4
  export interface IStorageClient {
5
+ updateStateFor<TActionState extends IActionState>(sourceActionKey: string, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
5
6
  close(): Promise<void>;
6
7
  load<TActionState extends IActionState>(key: string): Promise<Record<number, TActionState>>;
7
8
  saveMetadata(actions: IActionWithState[], botName: string): Promise<void>;
8
9
  getActionState<TActionState extends IActionState>(entity: IActionWithState, chatId: number): Promise<TActionState>;
9
- saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult: TransactionResult): Promise<void>;
10
+ saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult: ActionExecutionResult): Promise<void>;
10
11
  }
11
12
  //# sourceMappingURL=storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,cAAc;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,YAAY,SAAS,YAAY,EAClC,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,yBAAyB,CACrB,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,iBAAiB,GACrC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,YAAY,SAAS,YAAY,EAClC,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,yBAAyB,CACrB,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB,GACzC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
@@ -1,6 +1,6 @@
1
- import IActionState from '../types/actionState';
1
+ import { IActionState } from '../types/actionState';
2
2
 
3
- export default class TransactionResult {
3
+ export class ActionExecutionResult {
4
4
  data: IActionState;
5
5
  shouldUpdate: boolean;
6
6
 
@@ -1,17 +1,17 @@
1
- import ActionExecutionResult from '../transactionResult';
2
1
  import moment from 'moment';
3
- import logger from '../../services/logger';
4
- import MessageContext from '../context/messageContext';
5
- import IActionWithState from '../../types/actionWithState';
6
- import toArray from '../../helpers/toArray';
7
- import IActionState from '../../types/actionState';
8
- import CommandTriggerCheckResult from '../commandTriggerCheckResult';
9
2
  import { CommandHandler } from '../../types/handlers';
10
3
  import { CommandCondition } from '../../types/commandCondition';
11
4
  import { Seconds } from '../../types/timeValues';
12
5
  import { secondsToMilliseconds } from '../../helpers/timeConvertions';
13
-
14
- export default class CommandAction<TActionState extends IActionState>
6
+ import { toArray } from '../../helpers/toArray';
7
+ import { IActionState } from '../../types/actionState';
8
+ import { IActionWithState } from '../../types/actionWithState';
9
+ import { CommandTriggerCheckResult } from '../commandTriggerCheckResult';
10
+ import { MessageContext } from '../context/messageContext';
11
+ import { Logger } from '../../services/logger';
12
+ import { ActionExecutionResult } from '../actionExecutionResult';
13
+
14
+ export class CommandAction<TActionState extends IActionState>
15
15
  implements IActionWithState
16
16
  {
17
17
  triggers: (string | RegExp)[];
@@ -70,7 +70,7 @@ export default class CommandAction<TActionState extends IActionState>
70
70
 
71
71
  if (!shouldTrigger) return;
72
72
 
73
- logger.logWithTraceId(
73
+ Logger.logWithTraceId(
74
74
  ctx.botName,
75
75
  ctx.traceId,
76
76
  ctx.chatName,
@@ -1,18 +1,18 @@
1
- import TransactionResult from '../transactionResult';
2
1
  import moment from 'moment';
3
- import logger from '../../services/logger';
4
- import taskScheduler from '../../services/taskScheduler';
5
2
  import { Sema as Semaphore } from 'async-sema';
6
- import ChatContext from '../context/chatContext';
7
- import IActionWithState from '../../types/actionWithState';
8
- import ActionStateBase from '../states/actionStateBase';
9
- import IActionState from '../../types/actionState';
10
3
  import { ScheduledHandler } from '../../types/handlers';
11
- import CachedStateFactory from '../cachedStateFactory';
12
4
  import { hoursToMilliseconds } from '../../helpers/timeConvertions';
13
5
  import { HoursOfDay } from '../../types/timeValues';
14
-
15
- export default class ScheduledAction implements IActionWithState {
6
+ import { IActionState } from '../../types/actionState';
7
+ import { IActionWithState } from '../../types/actionWithState';
8
+ import { CachedStateFactory } from '../cachedStateFactory';
9
+ import { ChatContext } from '../context/chatContext';
10
+ import { ActionStateBase } from '../states/actionStateBase';
11
+ import { ActionExecutionResult } from '../actionExecutionResult';
12
+ import { Logger } from '../../services/logger';
13
+ import { Scheduler } from '../../services/taskScheduler';
14
+
15
+ export class ScheduledAction implements IActionWithState {
16
16
  static semaphore = new Semaphore(1);
17
17
 
18
18
  name: string;
@@ -50,7 +50,7 @@ export default class ScheduledAction implements IActionWithState {
50
50
  const isAllowedToTrigger = this.shouldTrigger(state);
51
51
 
52
52
  if (isAllowedToTrigger) {
53
- logger.logWithTraceId(
53
+ Logger.logWithTraceId(
54
54
  ctx.botName,
55
55
  ctx.traceId,
56
56
  ctx.chatName,
@@ -66,7 +66,7 @@ export default class ScheduledAction implements IActionWithState {
66
66
  await ctx.storage.saveActionExecutionResult(
67
67
  this,
68
68
  ctx.chatId,
69
- new TransactionResult(state, isAllowedToTrigger)
69
+ new ActionExecutionResult(state, isAllowedToTrigger)
70
70
  );
71
71
  }
72
72
  }
@@ -93,7 +93,7 @@ export default class ScheduledAction implements IActionWithState {
93
93
 
94
94
  this.cachedState.set(key, value);
95
95
 
96
- taskScheduler.createOnetimeTask(
96
+ Scheduler.createOnetimeTask(
97
97
  `Drop cached value [${this.name} : ${key}]`,
98
98
  () => this.cachedState.delete(key),
99
99
  hoursToMilliseconds(
@@ -1,20 +1,20 @@
1
1
  import { Telegraf } from 'telegraf';
2
- import TelegramApiService from '../services/telegramApi';
3
- import IncomingMessage from './incomingMessage';
4
- import taskScheduler from '../services/taskScheduler';
5
- import logger from '../services/logger';
6
- import CommandAction from './actions/commandAction';
7
- import ScheduledAction from './actions/scheduledAction';
8
- import IActionState from '../types/actionState';
9
2
  import {
10
3
  hoursToMilliseconds,
11
4
  secondsToMilliseconds
12
5
  } from '../helpers/timeConvertions';
13
6
  import { Hours, Seconds } from '../types/timeValues';
14
- import JsonFileStorage from '../services/jsonFileStorage';
15
7
  import { IStorageClient } from '../types/storage';
16
-
17
- export default class Bot {
8
+ import { JsonFileStorage } from '../services/jsonFileStorage';
9
+ import { TelegramApiService } from '../services/telegramApi';
10
+ import { IActionState } from '../types/actionState';
11
+ import { CommandAction } from './actions/commandAction';
12
+ import { ScheduledAction } from './actions/scheduledAction';
13
+ import { Logger } from '../services/logger';
14
+ import { Scheduler } from '../services/taskScheduler';
15
+ import { IncomingMessage } from './incomingMessage';
16
+
17
+ export class BotInstance {
18
18
  name: string;
19
19
  private api: TelegramApiService;
20
20
  private telegraf: Telegraf;
@@ -38,7 +38,7 @@ export default class Bot {
38
38
  this.scheduled = options.scheduled;
39
39
  this.chats = options.chats;
40
40
 
41
- logger.logWithTraceId(
41
+ Logger.logWithTraceId(
42
42
  this.name,
43
43
  `System:Bot-${this.name}-Start`,
44
44
  'System',
@@ -50,7 +50,7 @@ export default class Bot {
50
50
  new JsonFileStorage(options.name, options.storagePath);
51
51
  this.api = new TelegramApiService(
52
52
  this.name,
53
- this.telegraf,
53
+ this.telegraf.telegram,
54
54
  this.storage,
55
55
  this.chats
56
56
  );
@@ -61,7 +61,7 @@ export default class Bot {
61
61
 
62
62
  const messageFromName = msg.from?.first_name ?? 'Unknown';
63
63
  const messageFromId = msg.from?.id ?? 'Unknown';
64
- logger.logWithTraceId(
64
+ Logger.logWithTraceId(
65
65
  this.name,
66
66
  msg.traceId,
67
67
  msg.chatName,
@@ -75,7 +75,7 @@ export default class Bot {
75
75
 
76
76
  this.telegraf.launch();
77
77
 
78
- taskScheduler.createTask(
78
+ Scheduler.createTask(
79
79
  'MessageProcessing',
80
80
  async () => {
81
81
  while (this.messageQueue.length > 0) {
@@ -87,7 +87,7 @@ export default class Bot {
87
87
  this.name
88
88
  );
89
89
 
90
- taskScheduler.createTask(
90
+ Scheduler.createTask(
91
91
  'ScheduledProcessing',
92
92
  async () => {
93
93
  await this.runScheduled();
@@ -104,7 +104,7 @@ export default class Bot {
104
104
  }
105
105
 
106
106
  async stop(code: string) {
107
- logger.logWithTraceId(
107
+ Logger.logWithTraceId(
108
108
  this.name,
109
109
  `System:Bot-${this.name}-Stop`,
110
110
  'System',
@@ -118,13 +118,13 @@ export default class Bot {
118
118
  private async runScheduled() {
119
119
  for (const [chatName, chatId] of this.chats.entries()) {
120
120
  for (const trig of this.scheduled) {
121
- const ctx = this.api.createContextForChat(chatId, trig.name);
121
+ const ctx = this.api.createContextForChat(chatId, trig.key);
122
122
 
123
123
  try {
124
124
  await trig.exec(ctx);
125
125
  } catch (error) {
126
126
  console.dir(error);
127
- logger.errorWithTraceId(
127
+ Logger.errorWithTraceId(
128
128
  ctx.botName,
129
129
  ctx.traceId,
130
130
  chatName,
@@ -140,12 +140,12 @@ export default class Bot {
140
140
  const msg = this.messageQueue.pop()!;
141
141
 
142
142
  for (const cmd of this.commands) {
143
- const ctx = this.api.createContextForMessage(msg);
143
+ const ctx = this.api.createContextForMessage(msg, cmd.key);
144
144
 
145
145
  try {
146
146
  await cmd.exec(ctx);
147
147
  } catch (error) {
148
- logger.errorWithTraceId(
148
+ Logger.errorWithTraceId(
149
149
  ctx.botName,
150
150
  ctx.traceId,
151
151
  ctx.chatName,
@@ -1,6 +1,6 @@
1
1
  import { Hours } from '../types/timeValues';
2
2
 
3
- export default class CachedStateFactory {
3
+ export class CachedStateFactory {
4
4
  getValue: () => Promise<unknown>;
5
5
  invalidationTimeoutInHours: Hours;
6
6
 
@@ -1,4 +1,4 @@
1
- export default class CommandTriggerCheckResult {
1
+ export class CommandTriggerCheckResult {
2
2
  static get DontTriggerAndSkipCooldown() {
3
3
  return new CommandTriggerCheckResult(false, [], true);
4
4
  }