chz-telegram-bot 0.1.19 → 0.2.0

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 (50) hide show
  1. package/builtin/helpAction.ts +1 -1
  2. package/bun.lock +307 -0
  3. package/dist/builtin/helpAction.js +1 -1
  4. package/dist/dtos/responses/imageMessage.d.ts +5 -4
  5. package/dist/dtos/responses/imageMessage.d.ts.map +1 -1
  6. package/dist/dtos/responses/imageMessage.js +2 -2
  7. package/dist/dtos/responses/textMessage.d.ts +5 -4
  8. package/dist/dtos/responses/textMessage.d.ts.map +1 -1
  9. package/dist/dtos/responses/textMessage.js +2 -2
  10. package/dist/dtos/responses/videoMessage.d.ts +5 -4
  11. package/dist/dtos/responses/videoMessage.d.ts.map +1 -1
  12. package/dist/dtos/responses/videoMessage.js +2 -2
  13. package/dist/entities/botInstance.d.ts +2 -0
  14. package/dist/entities/botInstance.d.ts.map +1 -1
  15. package/dist/entities/botInstance.js +34 -7
  16. package/dist/entities/context/chatContext.d.ts +25 -21
  17. package/dist/entities/context/chatContext.d.ts.map +1 -1
  18. package/dist/entities/context/chatContext.js +32 -38
  19. package/dist/entities/context/messageContext.d.ts +60 -28
  20. package/dist/entities/context/messageContext.d.ts.map +1 -1
  21. package/dist/entities/context/messageContext.js +79 -49
  22. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  23. package/dist/services/jsonFileStorage.js +6 -11
  24. package/dist/services/responseProcessingQueue.d.ts +0 -1
  25. package/dist/services/responseProcessingQueue.d.ts.map +1 -1
  26. package/dist/services/responseProcessingQueue.js +1 -6
  27. package/dist/services/telegramApi.d.ts.map +1 -1
  28. package/dist/services/telegramApi.js +9 -7
  29. package/dist/types/messageTypes.d.ts +1 -0
  30. package/dist/types/messageTypes.d.ts.map +1 -1
  31. package/dist/types/messageTypes.js +15 -14
  32. package/dist/types/replyInfo.d.ts +6 -0
  33. package/dist/types/replyInfo.d.ts.map +1 -0
  34. package/dist/types/replyInfo.js +10 -0
  35. package/dist/types/response.d.ts +3 -2
  36. package/dist/types/response.d.ts.map +1 -1
  37. package/dtos/responses/imageMessage.ts +6 -5
  38. package/dtos/responses/textMessage.ts +6 -5
  39. package/dtos/responses/videoMessage.ts +6 -5
  40. package/entities/botInstance.ts +65 -10
  41. package/entities/context/chatContext.ts +58 -72
  42. package/entities/context/messageContext.ts +133 -88
  43. package/eslint.config.js +0 -1
  44. package/package.json +30 -29
  45. package/services/jsonFileStorage.ts +7 -13
  46. package/services/responseProcessingQueue.ts +2 -8
  47. package/services/telegramApi.ts +11 -9
  48. package/types/messageTypes.ts +15 -13
  49. package/types/replyInfo.ts +9 -0
  50. package/types/response.ts +3 -2
@@ -19,6 +19,7 @@ const traceFactory_1 = require("../helpers/traceFactory");
19
19
  const incomingQuery_1 = require("../dtos/incomingQuery");
20
20
  const inlineQueryContext_1 = require("./context/inlineQueryContext");
21
21
  const helpAction_1 = require("../builtin/helpAction");
22
+ const messageTypes_1 = require("../types/messageTypes");
22
23
  class BotInstance {
23
24
  constructor(options) {
24
25
  const actions = [
@@ -110,18 +111,23 @@ class BotInstance {
110
111
  }
111
112
  initializeMessageProcessing(verboseLoggingForIncomingMessage) {
112
113
  if (this.commands.length > 0) {
114
+ const triggersToBeProcessed = new Set(this.commands
115
+ .flatMap((x) => x.triggers)
116
+ .map((x) => typeof x == 'string'
117
+ ? x.startsWith(messageTypes_1.INTERNAL_MESSAGE_TYPE_PREFIX)
118
+ ? x
119
+ : messageTypes_1.MessageType.Text
120
+ : messageTypes_1.MessageType.Text));
113
121
  this.telegraf.on('message', async (ctx) => {
114
122
  const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.name);
115
- const messageContent = msg.text || `<non-text message: ${msg.type}>`;
116
- const messageFromName = msg.from?.first_name ?? 'Unknown';
117
- const messageFromId = msg.from?.id ?? 'Unknown';
118
123
  if (verboseLoggingForIncomingMessage) {
119
124
  this.logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatInfo.name, ctx.update.message);
120
125
  }
121
126
  else {
122
- this.logger.logWithTraceId(this.name, msg.traceId, msg.chatInfo.name, `${messageFromName} (${messageFromId}): ${messageContent}`);
127
+ this.logger.logWithTraceId(this.name, msg.traceId, msg.chatInfo.name, `${msg.from?.first_name ?? 'Unknown'} (${msg.from?.id ?? 'Unknown'}): ${msg.text || `<non-text message: ${msg.type}>`}`);
123
128
  }
124
- await this.processMessage(msg);
129
+ if (triggersToBeProcessed.has(msg.type))
130
+ await this.processMessage(msg);
125
131
  });
126
132
  }
127
133
  }
@@ -131,11 +137,32 @@ class BotInstance {
131
137
  await this.storage.close();
132
138
  this.telegraf.stop(code);
133
139
  }
140
+ initializeMessageContext(ctx, action, message) {
141
+ ctx.messageId = message.message_id;
142
+ ctx.messageText = message.text ?? '';
143
+ ctx.messageType = message.type;
144
+ ctx.fromUserId = message.from?.id;
145
+ ctx.fromUserName =
146
+ (message.from?.first_name ?? 'Unknown user') +
147
+ (message.from?.last_name ? ` ${message.from.last_name}` : '');
148
+ ctx.messageUpdateObject = message.updateObject;
149
+ ctx.matchResults = [];
150
+ ctx.startCooldown = true;
151
+ this.initializeChatContext(ctx, action, message.chatInfo, message.traceId);
152
+ }
153
+ initializeChatContext(ctx, action, chatInfo, traceId) {
154
+ ctx.responses = [];
155
+ ctx.isInitialized = true;
156
+ ctx.botName = this.name;
157
+ ctx.action = action;
158
+ ctx.chatInfo = chatInfo;
159
+ ctx.traceId = traceId;
160
+ }
134
161
  async runScheduled() {
135
162
  const ctx = new chatContext_1.ChatContext(this.storage, this.logger, this.scheduler);
136
163
  for (const [chatName, chatId] of Object.entries(this.chats)) {
137
164
  for (const scheduledAction of this.scheduled) {
138
- ctx.initializeChatContext(this.name, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), (0, traceFactory_1.createTrace)(scheduledAction, this.name, `${scheduledAction.key}-${chatId}`));
165
+ this.initializeChatContext(ctx, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), (0, traceFactory_1.createTrace)(scheduledAction, this.name, `${scheduledAction.key}-${chatId}`));
139
166
  try {
140
167
  const responses = await scheduledAction.exec(ctx);
141
168
  this.api.enqueueBatchedResponses(responses);
@@ -151,7 +178,7 @@ class BotInstance {
151
178
  async processMessage(msg) {
152
179
  const ctx = new messageContext_1.MessageContext(this.storage, this.logger, this.scheduler);
153
180
  for (const commandAction of this.commands) {
154
- ctx.initializeMessageContext(this.name, commandAction, msg);
181
+ this.initializeMessageContext(ctx, commandAction, msg);
155
182
  try {
156
183
  const responses = await commandAction.exec(ctx);
157
184
  this.api.enqueueBatchedResponses(responses);
@@ -12,7 +12,7 @@ import { TraceId } from '../../types/trace';
12
12
  * Context of action executed in chat.
13
13
  */
14
14
  export declare class ChatContext<TActionState extends IActionState> {
15
- protected action: IActionWithState<TActionState>;
15
+ action: IActionWithState<TActionState>;
16
16
  /** Storage client instance for the bot executing this action. */
17
17
  readonly storage: IStorageClient;
18
18
  /** Logger instance for the bot executing this action */
@@ -29,28 +29,32 @@ export declare class ChatContext<TActionState extends IActionState> {
29
29
  responses: BotResponse[];
30
30
  isInitialized: boolean;
31
31
  constructor(storage: IStorageClient, logger: ILogger, scheduler: IScheduler);
32
- initializeChatContext(botName: string, action: IActionWithState<TActionState>, chatInfo: ChatInfo, traceId: TraceId): this;
33
32
  /**
34
- * Sends text message to chat after action execution is finished.
35
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
36
- * @param text Message contents.
37
- * @param options Message sending option.
38
- */
39
- sendTextToChat(text: string, options?: TextMessageSendingOptions): void;
40
- /**
41
- * Sends image message to chat after action execution is finished.
42
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
43
- * @param name Message contents.
44
- * @param options Message sending option.
45
- */
46
- sendImageToChat(name: string, options?: MessageSendingOptions): void;
47
- /**
48
- * Sends video/gif message to chat after action execution is finished.
49
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
50
- * @param name Message contents.
51
- * @param options Message sending option.
33
+ * Collection of actions that send something to chat as a standalone message.
52
34
  */
53
- sendVideoToChat(name: string, options?: MessageSendingOptions): void;
35
+ send: {
36
+ /**
37
+ * Sends text message to chat after action execution is finished.
38
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
39
+ * @param text Message contents.
40
+ * @param options Message sending option.
41
+ */
42
+ text: (text: string, options?: TextMessageSendingOptions) => void;
43
+ /**
44
+ * Sends image message to chat after action execution is finished.
45
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
46
+ * @param name Message contents.
47
+ * @param options Message sending option.
48
+ */
49
+ image: (name: string, options?: MessageSendingOptions) => void;
50
+ /**
51
+ * Sends video/gif message to chat after action execution is finished.
52
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
53
+ * @param name Message contents.
54
+ * @param options Message sending option.
55
+ */
56
+ video: (name: string, options?: MessageSendingOptions) => void;
57
+ };
54
58
  /**
55
59
  * Unpins message after action execution is finished.
56
60
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
@@ -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,4BAA4B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,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KG;sBACW,MAAM,YAAY,qBAAqB;QAarD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;MAYvD;IAEF;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;IAW9B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,YAAY;CAK3B"}
@@ -15,48 +15,42 @@ class ChatContext {
15
15
  /** Ordered collection of responses to be processed */
16
16
  this.responses = [];
17
17
  this.isInitialized = false;
18
+ /**
19
+ * Collection of actions that send something to chat as a standalone message.
20
+ */
21
+ this.send = {
22
+ /**
23
+ * Sends text message to chat after action execution is finished.
24
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
25
+ * @param text Message contents.
26
+ * @param options Message sending option.
27
+ */
28
+ text: (text, options) => {
29
+ this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, undefined, options));
30
+ },
31
+ /**
32
+ * Sends image message to chat after action execution is finished.
33
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
34
+ * @param name Message contents.
35
+ * @param options Message sending option.
36
+ */
37
+ image: (name, options) => {
38
+ this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, undefined, options));
39
+ },
40
+ /**
41
+ * Sends video/gif message to chat after action execution is finished.
42
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
43
+ * @param name Message contents.
44
+ * @param options Message sending option.
45
+ */
46
+ video: (name, options) => {
47
+ this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, undefined, options));
48
+ }
49
+ };
18
50
  this.storage = storage;
19
51
  this.logger = logger;
20
52
  this.scheduler = scheduler;
21
53
  }
22
- initializeChatContext(botName, action, chatInfo, traceId) {
23
- this.botName = botName;
24
- this.action = action;
25
- this.chatInfo = chatInfo;
26
- this.traceId = traceId;
27
- this.isInitialized = true;
28
- this.responses = [];
29
- return this;
30
- }
31
- /**
32
- * Sends text message to chat after action execution is finished.
33
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
34
- * @param text Message contents.
35
- * @param options Message sending option.
36
- */
37
- sendTextToChat(text, options) {
38
- this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, undefined, this.traceId, this.action, options));
39
- }
40
- /**
41
- * Sends image message to chat after action execution is finished.
42
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
43
- * @param name Message contents.
44
- * @param options Message sending option.
45
- */
46
- sendImageToChat(name, options) {
47
- const filePath = `./content/${name}.png`;
48
- this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
49
- }
50
- /**
51
- * Sends video/gif message to chat after action execution is finished.
52
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
53
- * @param name Message contents.
54
- * @param options Message sending option.
55
- */
56
- sendVideoToChat(name, options) {
57
- const filePath = `./content/${name}.mp4`;
58
- this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
59
- }
60
54
  /**
61
55
  * Unpins message after action execution is finished.
62
56
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
@@ -2,9 +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 '../../dtos/incomingMessage';
6
5
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
7
- import { IActionWithState } from '../../types/statefulAction';
8
6
  import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
9
7
  import { ILogger } from '../../types/logger';
10
8
  import { IScheduler } from '../../types/scheduler';
@@ -29,7 +27,9 @@ export declare class MessageContext<TActionState extends IActionState> extends C
29
27
  /** Message object recieved from Telegram */
30
28
  messageUpdateObject: TelegrafContextMessage;
31
29
  constructor(storage: IStorageClient, logger: ILogger, scheduler: IScheduler);
32
- initializeMessageContext(botName: string, action: IActionWithState<TActionState>, message: IncomingMessage): this;
30
+ private replyWithText;
31
+ private replyWithImage;
32
+ private replyWithVideo;
33
33
  /**
34
34
  * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
35
35
  * @param commandName Name of an action to load state of.
@@ -37,31 +37,63 @@ export declare class MessageContext<TActionState extends IActionState> extends C
37
37
  */
38
38
  loadStateOf<TAnotherActionState extends IActionState>(commandName: string): Promise<TAnotherActionState>;
39
39
  /**
40
- * Reply with text message to message that triggered this action after action execution is finished.
41
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
42
- * @param text Message contents.
43
- * @param options Message sending option.
40
+ * Collection of actions that can be done as a reply to a message that triggered this action
44
41
  */
45
- replyWithText(text: string, options?: TextMessageSendingOptions): void;
46
- /**
47
- * Reply with image message to message that triggered this action after action execution is finished.
48
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
49
- * @param text Message contents.
50
- * @param options Message sending option.
51
- */
52
- replyWithImage(name: string, options?: MessageSendingOptions): void;
53
- /**
54
- * Reply with video/gif message to message that triggered this action after action execution is finished.
55
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
56
- * @param text Message contents.
57
- * @param options Message sending option.
58
- */
59
- replyWithVideo(name: string, options?: MessageSendingOptions): void;
60
- /**
61
- * React to the message that triggered this action after action execution is finished.
62
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
63
- * @param emoji Telegram emoji to react with.
64
- */
65
- react(emoji: TelegramEmoji): void;
42
+ reply: {
43
+ /**
44
+ * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
45
+ * If regex is matched, first match will be quoted
46
+ */
47
+ andQuote: {
48
+ /**
49
+ * Reply with text message to message that triggered this action after action execution is finished.
50
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
51
+ * @param text Message contents.
52
+ * @param options Message sending option.
53
+ */
54
+ withText: (text: string, options?: TextMessageSendingOptions) => void;
55
+ /**
56
+ * Reply with image message to message that triggered this action after action execution is finished.
57
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
58
+ * @param text Message contents.
59
+ * @param options Message sending option.
60
+ */
61
+ withImage: (name: string, options?: MessageSendingOptions) => void;
62
+ /**
63
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
64
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
65
+ * @param text Message contents.
66
+ * @param options Message sending option.
67
+ */
68
+ withVideo: (name: string, options?: MessageSendingOptions) => void;
69
+ };
70
+ /**
71
+ * Reply with text message to message that triggered this action after action execution is finished.
72
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
73
+ * @param text Message contents.
74
+ * @param options Message sending option.
75
+ */
76
+ withText: (text: string, options?: TextMessageSendingOptions) => void;
77
+ /**
78
+ * Reply with image message to message that triggered this action after action execution is finished.
79
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
80
+ * @param text Message contents.
81
+ * @param options Message sending option.
82
+ */
83
+ withImage: (name: string, options?: MessageSendingOptions) => void;
84
+ /**
85
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
86
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
87
+ * @param text Message contents.
88
+ * @param options Message sending option.
89
+ */
90
+ withVideo: (name: string, options?: MessageSendingOptions) => void;
91
+ /**
92
+ * React to the message that triggered this action after action execution is finished.
93
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
94
+ * @param emoji Telegram emoji to react with.
95
+ */
96
+ withReaction: (emoji: TelegramEmoji) => void;
97
+ };
66
98
  }
67
99
  //# sourceMappingURL=messageContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,4BAA4B,CAAC;AACzE,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC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CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;gBAGzC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,UAAU;IAKzB,OAAO,CAAC,aAAa;IAsBrB,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,cAAc;IAsBtB;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BACc,MAAM,YAAY,yBAAyB;YAE5D;;;;;eAKG;8BACe,MAAM,YAAY,qBAAqB;YAGzD;;;;;eAKG;8BACe,MAAM,YAAY,qBAAqB;;QAI7D;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -8,6 +8,7 @@ const textMessage_1 = require("../../dtos/responses/textMessage");
8
8
  const videoMessage_1 = require("../../dtos/responses/videoMessage");
9
9
  const actionStateBase_1 = require("../states/actionStateBase");
10
10
  const chatContext_1 = require("./chatContext");
11
+ const replyInfo_1 = require("../../types/replyInfo");
11
12
  /**
12
13
  * Context of action executed in chat, in response to a message
13
14
  */
@@ -18,19 +19,85 @@ class MessageContext extends chatContext_1.ChatContext {
18
19
  this.matchResults = [];
19
20
  /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
20
21
  this.startCooldown = true;
22
+ /**
23
+ * Collection of actions that can be done as a reply to a message that triggered this action
24
+ */
25
+ this.reply = {
26
+ /**
27
+ * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
28
+ * If regex is matched, first match will be quoted
29
+ */
30
+ andQuote: {
31
+ /**
32
+ * Reply with text message to message that triggered this action after action execution is finished.
33
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
34
+ * @param text Message contents.
35
+ * @param options Message sending option.
36
+ */
37
+ withText: (text, options) => this.replyWithText(text, true, options),
38
+ /**
39
+ * Reply with image message to message that triggered this action after action execution is finished.
40
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
41
+ * @param text Message contents.
42
+ * @param options Message sending option.
43
+ */
44
+ withImage: (name, options) => this.replyWithImage(name, true, options),
45
+ /**
46
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
47
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
48
+ * @param text Message contents.
49
+ * @param options Message sending option.
50
+ */
51
+ withVideo: (name, options) => this.replyWithVideo(name, true, options)
52
+ },
53
+ /**
54
+ * Reply with text message to message that triggered this action after action execution is finished.
55
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
56
+ * @param text Message contents.
57
+ * @param options Message sending option.
58
+ */
59
+ withText: (text, options) => this.replyWithText(text, false, options),
60
+ /**
61
+ * Reply with image message to message that triggered this action after action execution is finished.
62
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
63
+ * @param text Message contents.
64
+ * @param options Message sending option.
65
+ */
66
+ withImage: (name, options) => this.replyWithImage(name, false, options),
67
+ /**
68
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
69
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
70
+ * @param text Message contents.
71
+ * @param options Message sending option.
72
+ */
73
+ withVideo: (name, options) => this.replyWithVideo(name, false, options),
74
+ /**
75
+ * React to the message that triggered this action after action execution is finished.
76
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
77
+ * @param emoji Telegram emoji to react with.
78
+ */
79
+ withReaction: (emoji) => {
80
+ this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
81
+ }
82
+ };
21
83
  }
22
- initializeMessageContext(botName, action, message) {
23
- this.messageId = message.message_id;
24
- this.messageText = message.text ?? '';
25
- this.messageType = message.type;
26
- this.fromUserId = message.from?.id;
27
- this.fromUserName =
28
- (message.from?.first_name ?? 'Unknown user') +
29
- (message.from?.last_name ? ` ${message.from.last_name}` : '');
30
- this.messageUpdateObject = message.updateObject;
31
- this.matchResults = [];
32
- this.startCooldown = true;
33
- return this.initializeChatContext(botName, action, message.chatInfo, message.traceId);
84
+ replyWithText(text, quote, options) {
85
+ const quotedPart = this.matchResults.length != 0
86
+ ? this.matchResults[0][1]
87
+ : this.messageText;
88
+ this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options));
89
+ }
90
+ replyWithImage(name, quote, options) {
91
+ const quotedPart = this.matchResults.length != 0
92
+ ? this.matchResults[0][1]
93
+ : this.messageText;
94
+ this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options));
95
+ }
96
+ replyWithVideo(name, quote, options) {
97
+ const quotedPart = this.matchResults.length != 0
98
+ ? this.matchResults[0][1]
99
+ : this.messageText;
100
+ this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options));
34
101
  }
35
102
  /**
36
103
  * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
@@ -46,42 +113,5 @@ class MessageContext extends chatContext_1.ChatContext {
46
113
  }
47
114
  return stateForChat;
48
115
  }
49
- /**
50
- * Reply with text message to message that triggered this action after action execution is finished.
51
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
52
- * @param text Message contents.
53
- * @param options Message sending option.
54
- */
55
- replyWithText(text, options) {
56
- this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, this.messageId, this.traceId, this.action, options));
57
- }
58
- /**
59
- * Reply with image message to message that triggered this action after action execution is finished.
60
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
61
- * @param text Message contents.
62
- * @param options Message sending option.
63
- */
64
- replyWithImage(name, options) {
65
- const filePath = `./content/${name}.png`;
66
- this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
67
- }
68
- /**
69
- * Reply with video/gif message to message that triggered this action after action execution is finished.
70
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
71
- * @param text Message contents.
72
- * @param options Message sending option.
73
- */
74
- replyWithVideo(name, options) {
75
- const filePath = `./content/${name}.mp4`;
76
- this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
77
- }
78
- /**
79
- * React to the message that triggered this action after action execution is finished.
80
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
81
- * @param emoji Telegram emoji to react with.
82
- */
83
- react(emoji) {
84
- this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
85
- }
86
116
  }
87
117
  exports.MessageContext = MessageContext;
@@ -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,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEtE,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;IAClE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,MAAM;YAiBH,IAAI;YAcJ,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,yBAAyB,CAAC,YAAY,SAAS,YAAY,EAC7D,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY;IAWjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MA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AAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAcrD"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonFileStorage = void 0;
4
4
  const fs_1 = require("fs");
5
- const path_1 = require("path");
6
5
  const promises_1 = require("fs/promises");
7
6
  const async_sema_1 = require("async-sema");
8
7
  class JsonFileStorage {
@@ -35,10 +34,10 @@ class JsonFileStorage {
35
34
  async loadInternal(key) {
36
35
  if (!this.cache.has(key)) {
37
36
  const targetPath = this.buidPathFromKey(key);
38
- if (!(0, fs_1.existsSync)(targetPath)) {
39
- return {};
40
- }
41
- const fileContent = await (0, promises_1.readFile)(targetPath, 'utf8');
37
+ const fileContent = await (0, promises_1.readFile)(targetPath, {
38
+ encoding: 'utf-8',
39
+ flag: 'a+'
40
+ });
42
41
  if (fileContent) {
43
42
  const data = JSON.parse(fileContent);
44
43
  this.cache.set(key, data);
@@ -49,10 +48,6 @@ class JsonFileStorage {
49
48
  async save(data, key) {
50
49
  this.cache.set(key, data);
51
50
  const targetPath = this.buidPathFromKey(key);
52
- const folderName = (0, path_1.dirname)(targetPath);
53
- if (!(0, fs_1.existsSync)(folderName)) {
54
- await (0, promises_1.mkdir)(folderName, { recursive: true });
55
- }
56
51
  await (0, promises_1.writeFile)(targetPath, JSON.stringify(data), { flag: 'w+' });
57
52
  }
58
53
  buidPathFromKey(key) {
@@ -60,7 +55,7 @@ class JsonFileStorage {
60
55
  }
61
56
  async load(key) {
62
57
  return await this.lock(key, async () => {
63
- return this.loadInternal(key);
58
+ return await this.loadInternal(key);
64
59
  });
65
60
  }
66
61
  async saveMetadata(actions, botName) {
@@ -76,7 +71,7 @@ class JsonFileStorage {
76
71
  });
77
72
  }
78
73
  async saveActionExecutionResult(action, chatId, state) {
79
- await this.lock(action.key, async () => {
74
+ return await this.lock(action.key, async () => {
80
75
  const data = await this.loadInternal(action.key);
81
76
  data[chatId] = state;
82
77
  await this.save(data, action.key);
@@ -7,6 +7,5 @@ export declare class ResponseProcessingQueue {
7
7
  isFlushing: boolean;
8
8
  enqueue(item: QueueItem): void;
9
9
  flushReadyItems(): Promise<void>;
10
- private peek;
11
10
  }
12
11
  //# sourceMappingURL=responseProcessingQueue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responseProcessingQueue.d.ts","sourceRoot":"","sources":["../../services/responseProcessingQueue.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAAC;AAIF,qBAAa,uBAAuB;IAChC,KAAK,EAAE,SAAS,EAAE,CAAM;IACxB,UAAU,UAAS;IAEnB,OAAO,CAAC,IAAI,EAAE,SAAS;IAmBjB,eAAe;IAoBrB,OAAO,CAAC,IAAI;CAGf"}
1
+ {"version":3,"file":"responseProcessingQueue.d.ts","sourceRoot":"","sources":["../../services/responseProcessingQueue.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAAC;AAIF,qBAAa,uBAAuB;IAChC,KAAK,EAAE,SAAS,EAAE,CAAM;IACxB,UAAU,UAAS;IAEnB,OAAO,CAAC,IAAI,EAAE,SAAS;IAmBjB,eAAe;CAiBxB"}
@@ -26,10 +26,8 @@ class ResponseProcessingQueue {
26
26
  return;
27
27
  this.isFlushing = true;
28
28
  while (this.items.length) {
29
- if (Date.now() >= this.peek().priority) {
29
+ if (Date.now() >= this.items[0].priority) {
30
30
  const item = this.items.shift();
31
- if (!item)
32
- return;
33
31
  await item.callback();
34
32
  }
35
33
  else {
@@ -38,8 +36,5 @@ class ResponseProcessingQueue {
38
36
  }
39
37
  this.isFlushing = false;
40
38
  }
41
- peek() {
42
- return this.items[0];
43
- }
44
39
  }
45
40
  exports.ResponseProcessingQueue = ResponseProcessingQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG7B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO;IAQnB,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IA8BhD,cAAc;YAIA,WAAW;YAqBX,eAAe;CAmFhC"}
1
+ {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QA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