chz-telegram-bot 0.0.50 → 0.0.51

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 (87) hide show
  1. package/dist/dtos/actionExecutionResult.d.ts +7 -0
  2. package/dist/dtos/actionExecutionResult.d.ts.map +1 -0
  3. package/dist/dtos/actionExecutionResult.js +10 -0
  4. package/dist/dtos/chatInfo.d.ts +8 -0
  5. package/dist/dtos/chatInfo.d.ts.map +1 -0
  6. package/dist/dtos/chatInfo.js +10 -0
  7. package/dist/dtos/commandTriggerCheckResult.d.ts +10 -0
  8. package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -0
  9. package/dist/dtos/commandTriggerCheckResult.js +23 -0
  10. package/dist/dtos/incomingMessage.d.ts +14 -0
  11. package/dist/dtos/incomingMessage.d.ts.map +1 -0
  12. package/dist/dtos/incomingMessage.js +44 -0
  13. package/dist/dtos/responses/delay.d.ts +14 -0
  14. package/dist/dtos/responses/delay.d.ts.map +1 -0
  15. package/dist/dtos/responses/delay.js +14 -0
  16. package/dist/dtos/responses/imageMessage.d.ts +18 -0
  17. package/dist/dtos/responses/imageMessage.d.ts.map +1 -0
  18. package/dist/dtos/responses/imageMessage.js +17 -0
  19. package/dist/dtos/responses/reaction.d.ts +15 -0
  20. package/dist/dtos/responses/reaction.d.ts.map +1 -0
  21. package/dist/dtos/responses/reaction.js +15 -0
  22. package/dist/dtos/responses/textMessage.d.ts +17 -0
  23. package/dist/dtos/responses/textMessage.d.ts.map +1 -0
  24. package/dist/dtos/responses/textMessage.js +17 -0
  25. package/dist/dtos/responses/unpin.d.ts +13 -0
  26. package/dist/dtos/responses/unpin.d.ts.map +1 -0
  27. package/dist/dtos/responses/unpin.js +14 -0
  28. package/dist/dtos/responses/videoMessage.d.ts +18 -0
  29. package/dist/dtos/responses/videoMessage.d.ts.map +1 -0
  30. package/dist/dtos/responses/videoMessage.js +17 -0
  31. package/dist/entities/actions/commandAction.d.ts +10 -10
  32. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  33. package/dist/entities/actions/commandAction.js +6 -6
  34. package/dist/entities/actions/scheduledAction.d.ts +10 -10
  35. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  36. package/dist/entities/actions/scheduledAction.js +5 -5
  37. package/dist/entities/botInstance.d.ts +7 -7
  38. package/dist/entities/botInstance.d.ts.map +1 -1
  39. package/dist/entities/botInstance.js +8 -7
  40. package/dist/entities/cachedStateFactory.d.ts +2 -2
  41. package/dist/entities/cachedStateFactory.d.ts.map +1 -1
  42. package/dist/entities/context/chatContext.d.ts +4 -5
  43. package/dist/entities/context/chatContext.d.ts.map +1 -1
  44. package/dist/entities/context/chatContext.js +12 -13
  45. package/dist/entities/context/messageContext.d.ts +1 -1
  46. package/dist/entities/context/messageContext.d.ts.map +1 -1
  47. package/dist/entities/context/messageContext.js +10 -10
  48. package/dist/entities/taskRecord.d.ts +3 -3
  49. package/dist/entities/taskRecord.d.ts.map +1 -1
  50. package/dist/services/jsonFileStorage.d.ts +5 -5
  51. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  52. package/dist/services/taskScheduler.d.ts +1 -1
  53. package/dist/services/taskScheduler.d.ts.map +1 -1
  54. package/dist/services/telegramApi.d.ts +5 -14
  55. package/dist/services/telegramApi.d.ts.map +1 -1
  56. package/dist/services/telegramApi.js +10 -18
  57. package/dist/types/actionWithState.d.ts +2 -2
  58. package/dist/types/actionWithState.d.ts.map +1 -1
  59. package/dist/types/response.d.ts +15 -14
  60. package/dist/types/response.d.ts.map +1 -1
  61. package/dist/types/storage.d.ts +1 -1
  62. package/dist/types/storage.d.ts.map +1 -1
  63. package/{entities → dtos}/actionExecutionResult.ts +2 -2
  64. package/dtos/chatInfo.ts +11 -0
  65. package/{entities → dtos}/incomingMessage.ts +8 -7
  66. package/{entities → dtos}/responses/delay.ts +8 -7
  67. package/{entities → dtos}/responses/imageMessage.ts +11 -10
  68. package/{entities → dtos}/responses/reaction.ts +9 -8
  69. package/{entities → dtos}/responses/textMessage.ts +11 -10
  70. package/{entities → dtos}/responses/unpin.ts +8 -7
  71. package/{entities → dtos}/responses/videoMessage.ts +11 -10
  72. package/entities/actions/commandAction.ts +18 -17
  73. package/entities/actions/scheduledAction.ts +16 -16
  74. package/entities/botInstance.ts +26 -15
  75. package/entities/cachedStateFactory.ts +2 -2
  76. package/entities/context/chatContext.ts +20 -18
  77. package/entities/context/messageContext.ts +11 -12
  78. package/entities/taskRecord.ts +3 -3
  79. package/package.json +1 -1
  80. package/services/jsonFileStorage.ts +5 -5
  81. package/services/taskScheduler.ts +1 -1
  82. package/services/telegramApi.ts +16 -58
  83. package/types/actionWithState.ts +2 -2
  84. package/types/response.ts +15 -14
  85. package/types/storage.ts +1 -1
  86. package/helpers/inverseRecord.ts +0 -7
  87. /package/{entities → dtos}/commandTriggerCheckResult.ts +0 -0
@@ -10,10 +10,11 @@ const jsonFileStorage_1 = require("../services/jsonFileStorage");
10
10
  const telegramApi_1 = require("../services/telegramApi");
11
11
  const logger_1 = require("../services/logger");
12
12
  const taskScheduler_1 = require("../services/taskScheduler");
13
- const incomingMessage_1 = require("./incomingMessage");
13
+ const incomingMessage_1 = require("../dtos/incomingMessage");
14
14
  const moment_1 = __importDefault(require("moment"));
15
15
  const chatContext_1 = require("./context/chatContext");
16
16
  const messageContext_1 = require("./context/messageContext");
17
+ const chatInfo_1 = require("../dtos/chatInfo");
17
18
  class BotInstance {
18
19
  constructor(options) {
19
20
  this.name = options.name;
@@ -26,7 +27,7 @@ class BotInstance {
26
27
  this.storage =
27
28
  options.storageClient ??
28
29
  new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
29
- this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
30
+ this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage);
30
31
  this.initializeMessageProcessing(options.verboseLoggingForIncomingMessage ?? false);
31
32
  this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
32
33
  this.storage.saveMetadata(actions, this.name);
@@ -61,10 +62,10 @@ class BotInstance {
61
62
  const messageFromName = msg.from?.first_name ?? 'Unknown';
62
63
  const messageFromId = msg.from?.id ?? 'Unknown';
63
64
  if (verboseLoggingForIncomingMessage) {
64
- logger_1.Logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatName, ctx.update.message);
65
+ logger_1.Logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatInfo.name, ctx.update.message);
65
66
  }
66
67
  else {
67
- logger_1.Logger.logWithTraceId(this.name, msg.traceId, msg.chatName, `${messageFromName} (${messageFromId}): ${messageContent}`);
68
+ logger_1.Logger.logWithTraceId(this.name, msg.traceId, msg.chatInfo.name, `${messageFromName} (${messageFromId}): ${messageContent}`);
68
69
  }
69
70
  await this.processMessage(msg);
70
71
  });
@@ -79,7 +80,7 @@ class BotInstance {
79
80
  const ctx = new chatContext_1.ChatContext();
80
81
  for (const [chatName, chatId] of Object.entries(this.chats)) {
81
82
  for (const scheduledAction of this.scheduled) {
82
- this.api.initializeContextForChat(ctx, chatId, scheduledAction);
83
+ ctx.initializeChatContext(this.name, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
83
84
  try {
84
85
  const responses = await scheduledAction.exec(ctx);
85
86
  this.api.enqueueBatchedResponses(responses);
@@ -94,13 +95,13 @@ class BotInstance {
94
95
  async processMessage(msg) {
95
96
  const ctx = new messageContext_1.MessageContext();
96
97
  for (const commandAction of this.commands) {
97
- this.api.initializeContextForMessage(ctx, msg, commandAction);
98
+ ctx.initializeMessageContext(this.name, commandAction, msg, this.storage);
98
99
  try {
99
100
  const responses = await commandAction.exec(ctx);
100
101
  this.api.enqueueBatchedResponses(responses);
101
102
  }
102
103
  catch (error) {
103
- logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, error, ctx);
104
+ logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatInfo.name, error, ctx);
104
105
  }
105
106
  }
106
107
  await this.api.flushResponses();
@@ -1,7 +1,7 @@
1
1
  import { Hours } from '../types/timeValues';
2
2
  export declare class CachedStateFactory {
3
- getValue: () => Promise<unknown>;
4
- invalidationTimeoutInHours: Hours;
3
+ readonly getValue: () => Promise<unknown>;
4
+ readonly invalidationTimeoutInHours: Hours;
5
5
  constructor(itemFactory: () => Promise<unknown>, invalidationTimeout: Hours);
6
6
  }
7
7
  //# sourceMappingURL=cachedStateFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cachedStateFactory.d.ts","sourceRoot":"","sources":["../../entities/cachedStateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,kBAAkB;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,0BAA0B,EAAE,KAAK,CAAC;gBAG9B,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,mBAAmB,EAAE,KAAK;CAKjC"}
1
+ {"version":3,"file":"cachedStateFactory.d.ts","sourceRoot":"","sources":["../../entities/cachedStateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,kBAAkB;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,0BAA0B,EAAE,KAAK,CAAC;gBAGvC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,mBAAmB,EAAE,KAAK;CAKjC"}
@@ -4,6 +4,7 @@ import { IActionWithState } from '../../types/actionWithState';
4
4
  import { IActionState } from '../../types/actionState';
5
5
  import { BotResponse } from '../../types/response';
6
6
  import { Milliseconds } from '../../types/timeValues';
7
+ import { ChatInfo } from '../../dtos/chatInfo';
7
8
  /**
8
9
  * Context of action executed in chat.
9
10
  */
@@ -14,17 +15,15 @@ export declare class ChatContext<TActionState extends IActionState> {
14
15
  traceId: number | string;
15
16
  /** Name of a bot that executes this action. */
16
17
  botName: string;
17
- /** Id of a chat that action is executed in. */
18
- chatId: number;
19
- /** Name of a chat that action is executed in. */
20
- chatName: string;
18
+ /** Chat information. */
19
+ chatInfo: ChatInfo;
21
20
  /** Storage client instance for this bot. */
22
21
  storage: IStorageClient;
23
22
  /** Ordered collection of responses to be processed */
24
23
  responses: BotResponse[];
25
24
  isInitialized: boolean;
26
25
  constructor();
27
- initializeChatContext(botName: string, action: IActionWithState<TActionState>, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient): this;
26
+ initializeChatContext(botName: string, action: IActionWithState<TActionState>, chatInfo: ChatInfo, traceId: number | string, storage: IStorageClient): this;
28
27
  /**
29
28
  * Manually update the state of an action.
30
29
  * @param stateUpdateAction Function that will modify state.
@@ -1 +1 @@
1
- {"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY,SAAS,YAAY;IACtD,SAAS,CAAC,MAAM,EAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAClD,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,sCAAsC;IACtC,OAAO,EAAG,MAAM,GAAG,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,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatContext = void 0;
4
4
  const path_1 = require("path");
5
- const imageMessage_1 = require("../responses/imageMessage");
6
- const textMessage_1 = require("../responses/textMessage");
7
- const videoMessage_1 = require("../responses/videoMessage");
8
- const unpin_1 = require("../responses/unpin");
9
- const delay_1 = require("../responses/delay");
5
+ const imageMessage_1 = require("../../dtos/responses/imageMessage");
6
+ const textMessage_1 = require("../../dtos/responses/textMessage");
7
+ const videoMessage_1 = require("../../dtos/responses/videoMessage");
8
+ const unpin_1 = require("../../dtos/responses/unpin");
9
+ const delay_1 = require("../../dtos/responses/delay");
10
10
  /**
11
11
  * Context of action executed in chat.
12
12
  */
@@ -17,11 +17,10 @@ class ChatContext {
17
17
  this.responses = [];
18
18
  this.isInitialized = false;
19
19
  }
20
- initializeChatContext(botName, action, chatId, chatName, traceId, storage) {
20
+ initializeChatContext(botName, action, chatInfo, traceId, storage) {
21
21
  this.botName = botName;
22
22
  this.action = action;
23
- this.chatId = chatId;
24
- this.chatName = chatName;
23
+ this.chatInfo = chatInfo;
25
24
  this.traceId = traceId;
26
25
  this.storage = storage;
27
26
  this.updateActions = [];
@@ -43,7 +42,7 @@ class ChatContext {
43
42
  * @param options Message sending option.
44
43
  */
45
44
  sendTextToChat(text, options) {
46
- this.responses.push(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.action, options));
45
+ this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, undefined, this.traceId, this.action, options));
47
46
  }
48
47
  /**
49
48
  * Sends image message to chat after action execution is finished.
@@ -53,7 +52,7 @@ class ChatContext {
53
52
  */
54
53
  sendImageToChat(name, options) {
55
54
  const filePath = `./content/${name}.png`;
56
- this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
55
+ this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
57
56
  }
58
57
  /**
59
58
  * Sends video/gif message to chat after action execution is finished.
@@ -63,7 +62,7 @@ class ChatContext {
63
62
  */
64
63
  sendVideoToChat(name, options) {
65
64
  const filePath = `./content/${name}.mp4`;
66
- this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
65
+ this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
67
66
  }
68
67
  /**
69
68
  * Unpins message after action execution is finished.
@@ -71,14 +70,14 @@ class ChatContext {
71
70
  * @param messageId Message id.
72
71
  */
73
72
  unpinMessage(messageId) {
74
- this.responses.push(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.action));
73
+ this.responses.push(new unpin_1.UnpinResponse(messageId, this.chatInfo, this.traceId, this.action));
75
74
  }
76
75
  /**
77
76
  * Delays next response by specified amount of time.
78
77
  * @param delay Delay in milliseconds.
79
78
  */
80
79
  delayNextResponse(delay) {
81
- this.responses.push(new delay_1.DelayResponse(delay, this.chatId, this.traceId, this.action));
80
+ this.responses.push(new delay_1.DelayResponse(delay, this.chatInfo, this.traceId, this.action));
82
81
  }
83
82
  }
84
83
  exports.ChatContext = ChatContext;
@@ -2,7 +2,7 @@ import { TelegramEmoji } from 'telegraf/types';
2
2
  import { IStorageClient } from '../../types/storage';
3
3
  import { IActionState } from '../../types/actionState';
4
4
  import { ChatContext } from './chatContext';
5
- import { IncomingMessage } from '../incomingMessage';
5
+ import { IncomingMessage } from '../../dtos/incomingMessage';
6
6
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
7
7
  import { IActionWithState } from '../../types/actionWithState';
8
8
  import { MessageTypeValue } from '../../types/messageTypes';
@@ -1 +1 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EA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AE,cAAc;IAsB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MessageContext = void 0;
4
4
  const path_1 = require("path");
5
- const imageMessage_1 = require("../responses/imageMessage");
6
- const reaction_1 = require("../responses/reaction");
7
- const textMessage_1 = require("../responses/textMessage");
8
- const videoMessage_1 = require("../responses/videoMessage");
5
+ const imageMessage_1 = require("../../dtos/responses/imageMessage");
6
+ const reaction_1 = require("../../dtos/responses/reaction");
7
+ const textMessage_1 = require("../../dtos/responses/textMessage");
8
+ const videoMessage_1 = require("../../dtos/responses/videoMessage");
9
9
  const actionStateBase_1 = require("../states/actionStateBase");
10
10
  const chatContext_1 = require("./chatContext");
11
11
  /**
@@ -29,7 +29,7 @@ class MessageContext extends chatContext_1.ChatContext {
29
29
  (message.from?.last_name ? ` ${message.from.last_name}` : '');
30
30
  this.matchResults = [];
31
31
  this.startCooldown = true;
32
- return this.initializeChatContext(botName, action, message.chat.id, message.chatName, message.traceId, storage);
32
+ return this.initializeChatContext(botName, action, message.chatInfo, message.traceId, storage);
33
33
  }
34
34
  /**
35
35
  * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
@@ -39,7 +39,7 @@ class MessageContext extends chatContext_1.ChatContext {
39
39
  async loadStateOf(commandName) {
40
40
  const storageKey = `command:${commandName.replace('.', '-')}`;
41
41
  const allStates = await this.storage.load(storageKey);
42
- const stateForChat = allStates[this.chatId];
42
+ const stateForChat = allStates[this.chatInfo.id];
43
43
  if (!stateForChat) {
44
44
  return new actionStateBase_1.ActionStateBase();
45
45
  }
@@ -52,7 +52,7 @@ class MessageContext extends chatContext_1.ChatContext {
52
52
  * @param options Message sending option.
53
53
  */
54
54
  replyWithText(text, options) {
55
- this.responses.push(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.action, options));
55
+ this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, this.messageId, this.traceId, this.action, options));
56
56
  }
57
57
  /**
58
58
  * Reply with image message to message that triggered this action after action execution is finished.
@@ -62,7 +62,7 @@ class MessageContext extends chatContext_1.ChatContext {
62
62
  */
63
63
  replyWithImage(name, options) {
64
64
  const filePath = `./content/${name}.png`;
65
- this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
65
+ this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
66
66
  }
67
67
  /**
68
68
  * Reply with video/gif message to message that triggered this action after action execution is finished.
@@ -72,7 +72,7 @@ class MessageContext extends chatContext_1.ChatContext {
72
72
  */
73
73
  replyWithVideo(name, options) {
74
74
  const filePath = `./content/${name}.mp4`;
75
- this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
75
+ this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
76
76
  }
77
77
  /**
78
78
  * React to the message that triggered this action after action execution is finished.
@@ -80,7 +80,7 @@ class MessageContext extends chatContext_1.ChatContext {
80
80
  * @param emoji Telegram emoji to react with.
81
81
  */
82
82
  react(emoji) {
83
- this.responses.push(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.action));
83
+ this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
84
84
  }
85
85
  }
86
86
  exports.MessageContext = MessageContext;
@@ -1,8 +1,8 @@
1
1
  import { Milliseconds } from '../types/timeValues';
2
2
  export declare class TaskRecord {
3
- name: string;
4
- taskId: NodeJS.Timeout;
5
- interval: Milliseconds;
3
+ readonly name: string;
4
+ readonly taskId: NodeJS.Timeout;
5
+ readonly interval: Milliseconds;
6
6
  constructor(name: string, taskId: NodeJS.Timeout, interval: Milliseconds);
7
7
  }
8
8
  //# sourceMappingURL=taskRecord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;CAK3E"}
1
+ {"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;gBAEpB,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;CAK3E"}
@@ -1,12 +1,12 @@
1
1
  import { IStorageClient } from '../types/storage';
2
- import { ActionExecutionResult } from '../entities/actionExecutionResult';
2
+ import { ActionExecutionResult } from '../dtos/actionExecutionResult';
3
3
  import { IActionState } from '../types/actionState';
4
4
  import { IActionWithState, ActionKey } from '../types/actionWithState';
5
5
  export declare class JsonFileStorage implements IStorageClient {
6
- private locks;
7
- private cache;
8
- private storagePath;
9
- private botName;
6
+ private readonly locks;
7
+ private readonly cache;
8
+ private readonly storagePath;
9
+ private readonly botName;
10
10
  constructor(botName: string, actions: IActionWithState<IActionState>[], path?: string);
11
11
  private lock;
12
12
  private loadInternal;
@@ -1 +1 @@
1
- {"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEvE,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAGpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,MAAM;YAiBH,IAAI;YAgBJ,YAAY;YAqBZ,IAAI;IAgBlB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,SAAS;IAMtD,YAAY,CACd,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,OAAO,EAAE,MAAM;IAWb,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM;IAYZ,yB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,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM;IAYZ,yBAAyB,CAAC,YAAY,SAAS,YAAY,EAC7D,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAYpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAcrD"}
@@ -1,7 +1,7 @@
1
1
  import { TaskRecord } from '../entities/taskRecord';
2
2
  import { Milliseconds } from '../types/timeValues';
3
3
  declare class TaskScheduler {
4
- activeTasks: TaskRecord[];
4
+ readonly activeTasks: TaskRecord[];
5
5
  stopAll(): void;
6
6
  createTask(name: string, action: () => void, interval: Milliseconds, executeRightAway: boolean, ownerName: string): void;
7
7
  createOnetimeTask(name: string, action: () => void, delay: Milliseconds, ownerName: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,cAAM,aAAa;IACf,WAAW,EAAE,UAAU,EAAE,CAAM;IAE/B,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IAmBrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CAoBxB;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC"}
1
+ {"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,cAAM,aAAa;IACf,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAM;IAExC,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IAmBrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CAoBxB;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC"}
@@ -1,25 +1,16 @@
1
- import { ChatContext } from '../entities/context/chatContext';
2
- import { MessageContext } from '../entities/context/messageContext';
3
1
  import { IStorageClient } from '../types/storage';
4
- import { IncomingMessage } from '../entities/incomingMessage';
5
2
  import { BotResponse } from '../types/response';
6
3
  import { Telegram } from 'telegraf/typings/telegram';
7
- import { ScheduledAction } from '../entities/actions/scheduledAction';
8
- import { IActionState } from '../types/actionState';
9
- import { CommandAction } from '../entities/actions/commandAction';
10
4
  export declare class TelegramApiService {
11
5
  isFlushing: boolean;
12
- messageQueue: BotResponse[];
13
- botName: string;
14
- telegram: Telegram;
15
- chats: Record<number, string>;
16
- storage: IStorageClient;
17
- constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Record<string, number>);
6
+ readonly messageQueue: BotResponse[];
7
+ readonly botName: string;
8
+ readonly telegram: Telegram;
9
+ readonly storage: IStorageClient;
10
+ constructor(botName: string, telegram: Telegram, storage: IStorageClient);
18
11
  enqueueBatchedResponses(responses: BotResponse[]): void;
19
12
  flushResponses(): Promise<void>;
20
13
  private pinIfShould;
21
14
  private processResponse;
22
- initializeContextForMessage<TActionState extends IActionState>(ctx: MessageContext<TActionState>, incomingMessage: IncomingMessage, command: CommandAction<TActionState>): MessageContext<TActionState>;
23
- initializeContextForChat<TActionState extends IActionState>(ctx: ChatContext<TActionState>, chatId: number, scheduledAction: ScheduledAction<TActionState>): ChatContext<TActionState>;
24
15
  }
25
16
  //# sourceMappingURL=telegramApi.d.ts.map
@@ -1 +1 @@
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;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAIlE,qBAAa,kBAAkB;IAC3B,UAAU,UAAS;IACnB,YAAY,EAAE,WAAW,EAAE,CAAM;IAEjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQjC,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAM1C,cAAc;YA2BN,WAAW;YAqBX,eAAe;IA+E7B,2BAA2B,CAAC,YAAY,SAAS,YAAY,EACzD,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,EACjC,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC;IAUxC,wBAAwB,CAAC,YAAY,SAAS,YAAY,EACtD,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,eAAe,CAAC,YAAY,CAAC;CAWrD"}
1
+ {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAMrD,qBAAa,kBAAkB;IAC3B,UAAU,UAAS;IACnB,QAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,CAAM;IAE1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc;IAMxE,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAM1C,cAAc;YA2BN,WAAW;YAqBX,eAAe;CA8EhC"}
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TelegramApiService = void 0;
4
- const inverseRecord_1 = require("../helpers/inverseRecord");
5
4
  const logger_1 = require("./logger");
6
5
  const promises_1 = require("timers/promises");
7
6
  const TELEGRAM_RATELIMIT_DELAY = 35;
8
7
  class TelegramApiService {
9
- constructor(botName, telegram, storage, chats) {
8
+ constructor(botName, telegram, storage) {
10
9
  this.isFlushing = false;
11
10
  this.messageQueue = [];
12
11
  this.telegram = telegram;
13
12
  this.botName = botName;
14
- this.chats = (0, inverseRecord_1.inverseRecord)(chats);
15
13
  this.storage = storage;
16
14
  }
17
15
  enqueueBatchedResponses(responses) {
@@ -32,15 +30,15 @@ class TelegramApiService {
32
30
  await (0, promises_1.setTimeout)(TELEGRAM_RATELIMIT_DELAY);
33
31
  }
34
32
  catch (error) {
35
- logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats[message.chatId], error, message);
33
+ logger_1.Logger.errorWithTraceId(this.botName, message.traceId, message.chatInfo.name, error, message);
36
34
  }
37
35
  }
38
36
  this.isFlushing = false;
39
37
  }
40
38
  async pinIfShould(response, sentMessage) {
41
39
  if (response.shouldPin) {
42
- await this.telegram.pinChatMessage(response.chatId, sentMessage.message_id, { disable_notification: true });
43
- await this.storage.updateStateFor(response.action, response.chatId, async (state) => {
40
+ await this.telegram.pinChatMessage(response.chatInfo.id, sentMessage.message_id, { disable_notification: true });
41
+ await this.storage.updateStateFor(response.action, response.chatInfo.id, async (state) => {
44
42
  state.pinnedMessages.push(sentMessage.message_id);
45
43
  });
46
44
  }
@@ -49,7 +47,7 @@ class TelegramApiService {
49
47
  let sentMessage;
50
48
  switch (response.kind) {
51
49
  case 'text':
52
- sentMessage = await this.telegram.sendMessage(response.chatId, response.content, {
50
+ sentMessage = await this.telegram.sendMessage(response.chatInfo.id, response.content, {
53
51
  reply_to_message_id: response.replyId,
54
52
  parse_mode: 'MarkdownV2',
55
53
  disable_web_page_preview: response.disableWebPreview
@@ -58,21 +56,21 @@ class TelegramApiService {
58
56
  await this.pinIfShould(response, sentMessage);
59
57
  break;
60
58
  case 'image':
61
- sentMessage = await this.telegram.sendPhoto(response.chatId, response.content, response.replyId
59
+ sentMessage = await this.telegram.sendPhoto(response.chatInfo.id, response.content, response.replyId
62
60
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
61
  { reply_to_message_id: response.replyId }
64
62
  : undefined);
65
63
  await this.pinIfShould(response, sentMessage);
66
64
  break;
67
65
  case 'video':
68
- sentMessage = await this.telegram.sendVideo(response.chatId, response.content, response.replyId
66
+ sentMessage = await this.telegram.sendVideo(response.chatInfo.id, response.content, response.replyId
69
67
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
68
  { reply_to_message_id: response.replyId }
71
69
  : undefined);
72
70
  await this.pinIfShould(response, sentMessage);
73
71
  break;
74
72
  case 'react':
75
- await this.telegram.setMessageReaction(response.chatId, response.messageId, [
73
+ await this.telegram.setMessageReaction(response.chatInfo.id, response.messageId, [
76
74
  {
77
75
  type: 'emoji',
78
76
  emoji: response.emoji
@@ -80,8 +78,8 @@ class TelegramApiService {
80
78
  ], true);
81
79
  return;
82
80
  case 'unpin':
83
- await this.telegram.unpinChatMessage(response.chatId, response.messageId);
84
- await this.storage.updateStateFor(response.action, response.chatId, async (state) => {
81
+ await this.telegram.unpinChatMessage(response.chatInfo.id, response.messageId);
82
+ await this.storage.updateStateFor(response.action, response.chatInfo.id, async (state) => {
85
83
  state.pinnedMessages = state.pinnedMessages.filter((x) => x != response.messageId);
86
84
  });
87
85
  break;
@@ -91,11 +89,5 @@ class TelegramApiService {
91
89
  }
92
90
  }
93
91
  }
94
- initializeContextForMessage(ctx, incomingMessage, command) {
95
- return ctx.initializeMessageContext(this.botName, command, incomingMessage, this.storage);
96
- }
97
- initializeContextForChat(ctx, chatId, scheduledAction) {
98
- return ctx.initializeChatContext(this.botName, scheduledAction, chatId, this.chats[chatId], `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
99
- }
100
92
  }
101
93
  exports.TelegramApiService = TelegramApiService;
@@ -3,7 +3,7 @@ export type ActionKey = string & {
3
3
  __brand: 'actionKey';
4
4
  };
5
5
  export interface IActionWithState<TActionState extends IActionState> {
6
- key: ActionKey;
7
- stateConstructor: () => TActionState;
6
+ readonly key: ActionKey;
7
+ readonly stateConstructor: () => TActionState;
8
8
  }
9
9
  //# sourceMappingURL=actionWithState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY;IAC/D,GAAG,EAAE,SAAS,CAAC;IACf,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,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY;IAC/D,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACjD"}
@@ -1,9 +1,10 @@
1
- import { DelayResponse } from '../entities/responses/delay';
2
- import { ImageMessage } from '../entities/responses/imageMessage';
3
- import { Reaction } from '../entities/responses/reaction';
4
- import { TextMessage } from '../entities/responses/textMessage';
5
- import { UnpinResponse } from '../entities/responses/unpin';
6
- import { VideoMessage } from '../entities/responses/videoMessage';
1
+ import { ChatInfo } from '../dtos/chatInfo';
2
+ import { DelayResponse } from '../dtos/responses/delay';
3
+ import { ImageMessage } from '../dtos/responses/imageMessage';
4
+ import { Reaction } from '../dtos/responses/reaction';
5
+ import { TextMessage } from '../dtos/responses/textMessage';
6
+ import { UnpinResponse } from '../dtos/responses/unpin';
7
+ import { VideoMessage } from '../dtos/responses/videoMessage';
7
8
  import { IActionState } from './actionState';
8
9
  import { IActionWithState } from './actionWithState';
9
10
  export declare const BotResponseTypes: {
@@ -16,15 +17,15 @@ export declare const BotResponseTypes: {
16
17
  };
17
18
  export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | DelayResponse | ImageMessage;
18
19
  export interface IChatResponse {
19
- kind: keyof typeof BotResponseTypes;
20
- chatId: number;
21
- traceId: number | string;
22
- action: IActionWithState<IActionState>;
20
+ readonly kind: keyof typeof BotResponseTypes;
21
+ readonly chatInfo: ChatInfo;
22
+ readonly traceId: number | string;
23
+ readonly action: IActionWithState<IActionState>;
23
24
  }
24
25
  export interface IReplyMessage<TType> extends IChatResponse {
25
- content: TType;
26
- replyId: number | undefined;
27
- disableWebPreview: boolean;
28
- shouldPin: boolean;
26
+ readonly content: TType;
27
+ readonly replyId: number | undefined;
28
+ readonly disableWebPreview: boolean;
29
+ readonly shouldPin: boolean;
29
30
  }
30
31
  //# sourceMappingURL=response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,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;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAEX,MAAM,MAAM,WAAW,GACjB,aAAa,GACb,QAAQ,GACR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,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,aAAa;IACvD,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC/B"}
@@ -1,4 +1,4 @@
1
- import { ActionExecutionResult } from '../entities/actionExecutionResult';
1
+ import { ActionExecutionResult } from '../dtos/actionExecutionResult';
2
2
  import { IActionState } from './actionState';
3
3
  import { ActionKey, IActionWithState } from './actionWithState';
4
4
  export interface IStorageClient {
@@ -1 +1 @@
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,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,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,SAAS,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CA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,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,yBAAyB,CAAC,YAAY,SAAS,YAAY,EACvD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB,CAAC,YAAY,CAAC,GACvD,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
@@ -1,8 +1,8 @@
1
1
  import { IActionState } from '../types/actionState';
2
2
 
3
3
  export class ActionExecutionResult<TActionState extends IActionState> {
4
- data: TActionState;
5
- shouldUpdate: boolean;
4
+ readonly data: TActionState;
5
+ readonly shouldUpdate: boolean;
6
6
 
7
7
  constructor(data: TActionState, shouldUpdate: boolean) {
8
8
  this.data = data;
@@ -0,0 +1,11 @@
1
+ export class ChatInfo {
2
+ /** Id of a chat that action is executed in. */
3
+ readonly id: number;
4
+ /** Name of a chat that action is executed in. */
5
+ readonly name: string;
6
+
7
+ constructor(chatId: number, chatName: string) {
8
+ this.id = chatId;
9
+ this.name = chatName;
10
+ }
11
+ }
@@ -1,13 +1,13 @@
1
- import { Chat, Message, Update, User } from 'telegraf/types';
1
+ import { Message, Update, User } from 'telegraf/types';
2
2
  import { randomInt } from 'crypto';
3
3
  import { MessageType, MessageTypeValue } from '../types/messageTypes';
4
+ import { ChatInfo } from './chatInfo';
4
5
 
5
6
  export class IncomingMessage {
6
7
  message_id: number;
7
- chat: Chat;
8
+ chatInfo: ChatInfo;
8
9
  from: User | undefined;
9
10
  text: string;
10
- chatName: string;
11
11
  type: MessageTypeValue;
12
12
  traceId = randomInt(10000, 99999);
13
13
 
@@ -31,13 +31,14 @@ export class IncomingMessage {
31
31
 
32
32
  constructor(ctxMessage: Update.New & (Update.NonChannel & Message)) {
33
33
  this.message_id = ctxMessage.message_id;
34
- this.chat = ctxMessage.chat;
35
34
  this.from = ctxMessage.from;
36
35
  this.text = 'text' in ctxMessage ? ctxMessage.text : '';
37
- this.type = this.detectMessageType(ctxMessage);
38
- this.chatName =
36
+ this.chatInfo = new ChatInfo(
37
+ ctxMessage.chat.id,
39
38
  'title' in ctxMessage.chat
40
39
  ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
41
- : 'DM';
40
+ : 'DM'
41
+ );
42
+ this.type = this.detectMessageType(ctxMessage);
42
43
  }
43
44
  }