chz-telegram-bot 0.3.10 → 0.3.12

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 (127) hide show
  1. package/builtin/helpAction.ts +1 -1
  2. package/dist/builtin/helpAction.js +1 -1
  3. package/dist/dtos/chatInfo.js +4 -0
  4. package/dist/dtos/commandTriggerCheckResult.js +3 -0
  5. package/dist/dtos/incomingMessage.js +9 -1
  6. package/dist/dtos/incomingQuery.js +5 -0
  7. package/dist/dtos/replyInfo.js +2 -0
  8. package/dist/dtos/responses/delay.js +6 -2
  9. package/dist/dtos/responses/imageMessage.js +10 -4
  10. package/dist/dtos/responses/inlineQueryResponse.js +6 -2
  11. package/dist/dtos/responses/reaction.js +7 -2
  12. package/dist/dtos/responses/textMessage.js +10 -3
  13. package/dist/dtos/responses/unpin.js +6 -2
  14. package/dist/dtos/responses/videoMessage.js +10 -4
  15. package/dist/entities/actions/commandAction.d.ts +4 -1
  16. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  17. package/dist/entities/actions/commandAction.js +46 -17
  18. package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
  19. package/dist/entities/actions/inlineQueryAction.js +8 -1
  20. package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
  21. package/dist/entities/actions/replyCaptureAction.js +8 -1
  22. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  23. package/dist/entities/actions/scheduledAction.js +13 -14
  24. package/dist/entities/botInstance.js +6 -1
  25. package/dist/entities/cachedStateFactory.js +2 -0
  26. package/dist/entities/context/baseContext.js +14 -2
  27. package/dist/entities/context/chatContext.d.ts +0 -3
  28. package/dist/entities/context/chatContext.d.ts.map +1 -1
  29. package/dist/entities/context/chatContext.js +38 -41
  30. package/dist/entities/context/inlineQueryContext.d.ts +0 -3
  31. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
  32. package/dist/entities/context/inlineQueryContext.js +12 -6
  33. package/dist/entities/context/messageContext.d.ts +0 -3
  34. package/dist/entities/context/messageContext.d.ts.map +1 -1
  35. package/dist/entities/context/messageContext.js +77 -68
  36. package/dist/entities/context/replyContext.d.ts +0 -3
  37. package/dist/entities/context/replyContext.d.ts.map +1 -1
  38. package/dist/entities/context/replyContext.js +90 -65
  39. package/dist/entities/states/actionStateBase.js +2 -4
  40. package/dist/entities/taskRecord.js +3 -0
  41. package/dist/helpers/builders/commandActionBuilder.d.ts +3 -0
  42. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
  43. package/dist/helpers/builders/commandActionBuilder.js +18 -9
  44. package/dist/helpers/builders/inlineQueryActionBuilder.js +7 -6
  45. package/dist/helpers/builders/scheduledActionBuilder.js +7 -5
  46. package/dist/helpers/mapUtils.d.ts +3 -0
  47. package/dist/helpers/mapUtils.d.ts.map +1 -0
  48. package/dist/helpers/mapUtils.js +17 -0
  49. package/dist/helpers/noop.d.ts +3 -4
  50. package/dist/helpers/noop.d.ts.map +1 -1
  51. package/dist/helpers/noop.js +2 -1
  52. package/dist/helpers/traceFactory.d.ts +1 -1
  53. package/dist/helpers/traceFactory.d.ts.map +1 -1
  54. package/dist/main.js +1 -3
  55. package/dist/services/actionProcessingService.d.ts.map +1 -1
  56. package/dist/services/actionProcessingService.js +15 -3
  57. package/dist/services/actionProcessors/baseProcessor.d.ts +1 -3
  58. package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -1
  59. package/dist/services/actionProcessors/baseProcessor.js +6 -2
  60. package/dist/services/actionProcessors/commandActionProcessor.d.ts +0 -4
  61. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  62. package/dist/services/actionProcessors/commandActionProcessor.js +10 -13
  63. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +0 -4
  64. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
  65. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +4 -6
  66. package/dist/services/actionProcessors/scheduledActionProcessor.js +6 -4
  67. package/dist/services/jsonFileStorage.d.ts +4 -3
  68. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  69. package/dist/services/jsonFileStorage.js +22 -14
  70. package/dist/services/jsonLogger.d.ts +1 -1
  71. package/dist/services/jsonLogger.d.ts.map +1 -1
  72. package/dist/services/jsonLogger.js +9 -3
  73. package/dist/services/nodeTimeoutScheduler.d.ts +2 -2
  74. package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -1
  75. package/dist/services/nodeTimeoutScheduler.js +6 -5
  76. package/dist/services/responseProcessingQueue.d.ts.map +1 -1
  77. package/dist/services/responseProcessingQueue.js +9 -7
  78. package/dist/services/telegramApi.d.ts.map +1 -1
  79. package/dist/services/telegramApi.js +17 -8
  80. package/dist/types/commandTrigger.d.ts +1 -2
  81. package/dist/types/commandTrigger.d.ts.map +1 -1
  82. package/dist/types/handlers.d.ts +1 -1
  83. package/dist/types/handlers.d.ts.map +1 -1
  84. package/dist/types/logger.d.ts +2 -2
  85. package/dist/types/logger.d.ts.map +1 -1
  86. package/dist/types/scheduler.d.ts +2 -2
  87. package/dist/types/scheduler.d.ts.map +1 -1
  88. package/dist/types/storage.d.ts +2 -2
  89. package/dist/types/storage.d.ts.map +1 -1
  90. package/dist/types/timeValues.d.ts +3 -3
  91. package/dist/types/timeValues.d.ts.map +1 -1
  92. package/dist/types/trace.d.ts +1 -1
  93. package/dist/types/trace.d.ts.map +1 -1
  94. package/dtos/incomingMessage.ts +1 -1
  95. package/entities/actions/commandAction.ts +55 -28
  96. package/entities/actions/inlineQueryAction.ts +5 -1
  97. package/entities/actions/replyCaptureAction.ts +5 -1
  98. package/entities/actions/scheduledAction.ts +11 -13
  99. package/entities/botInstance.ts +7 -7
  100. package/entities/context/chatContext.ts +0 -6
  101. package/entities/context/inlineQueryContext.ts +0 -6
  102. package/entities/context/messageContext.ts +0 -6
  103. package/entities/context/replyContext.ts +18 -15
  104. package/eslint.config.js +26 -1
  105. package/helpers/builders/commandActionBuilder.ts +10 -0
  106. package/helpers/mapUtils.ts +15 -0
  107. package/helpers/noop.ts +4 -4
  108. package/helpers/traceFactory.ts +2 -2
  109. package/package.json +1 -1
  110. package/services/actionProcessingService.ts +8 -4
  111. package/services/actionProcessors/baseProcessor.ts +5 -8
  112. package/services/actionProcessors/commandActionProcessor.ts +5 -17
  113. package/services/actionProcessors/inlineQueryActionProcessor.ts +5 -15
  114. package/services/actionProcessors/scheduledActionProcessor.ts +4 -4
  115. package/services/jsonFileStorage.ts +39 -21
  116. package/services/jsonLogger.ts +12 -8
  117. package/services/nodeTimeoutScheduler.ts +6 -6
  118. package/services/responseProcessingQueue.ts +9 -4
  119. package/services/telegramApi.ts +7 -5
  120. package/tsconfig.json +1 -1
  121. package/types/commandTrigger.ts +1 -3
  122. package/types/handlers.ts +1 -1
  123. package/types/logger.ts +3 -6
  124. package/types/scheduler.ts +2 -2
  125. package/types/storage.ts +2 -2
  126. package/types/timeValues.ts +3 -3
  127. package/types/trace.ts +3 -1
@@ -12,47 +12,6 @@ const baseContext_1 = require("./baseContext");
12
12
  * Context of action executed in chat.
13
13
  */
14
14
  class ChatContext extends baseContext_1.BaseContext {
15
- constructor(storage, scheduler) {
16
- super(storage, scheduler);
17
- /**
18
- * Collection of actions that send something to chat as a standalone message.
19
- */
20
- this.send = {
21
- /**
22
- * Sends text message to chat after action execution is finished.
23
- * 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.
24
- * @param text Message contents.
25
- * @param options Message sending option.
26
- */
27
- text: (text, options) => {
28
- const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, undefined, options);
29
- this.responses.push(response);
30
- return this.createCaptureController(response);
31
- },
32
- /**
33
- * Sends image message to chat after action execution is finished.
34
- * 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.
35
- * @param name Message contents.
36
- * @param options Message sending option.
37
- */
38
- image: (name, options) => {
39
- const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, undefined, options);
40
- this.responses.push(response);
41
- return this.createCaptureController(response);
42
- },
43
- /**
44
- * Sends video/gif 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
- video: (name, options) => {
50
- const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, undefined, options);
51
- this.responses.push(response);
52
- return this.createCaptureController(response);
53
- }
54
- };
55
- }
56
15
  createCaptureController(response) {
57
16
  return {
58
17
  captureReplies: (trigger, handler, abortController) => {
@@ -65,6 +24,44 @@ class ChatContext extends baseContext_1.BaseContext {
65
24
  }
66
25
  };
67
26
  }
27
+ /**
28
+ * Collection of actions that send something to chat as a standalone message.
29
+ */
30
+ send = {
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
+ text: (text, options) => {
38
+ const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, undefined, options);
39
+ this.responses.push(response);
40
+ return this.createCaptureController(response);
41
+ },
42
+ /**
43
+ * Sends image message to chat after action execution is finished.
44
+ * 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.
45
+ * @param name Message contents.
46
+ * @param options Message sending option.
47
+ */
48
+ image: (name, options) => {
49
+ const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, undefined, options);
50
+ this.responses.push(response);
51
+ return this.createCaptureController(response);
52
+ },
53
+ /**
54
+ * Sends video/gif message to chat 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 name Message contents.
57
+ * @param options Message sending option.
58
+ */
59
+ video: (name, options) => {
60
+ const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, undefined, options);
61
+ this.responses.push(response);
62
+ return this.createCaptureController(response);
63
+ }
64
+ };
68
65
  /**
69
66
  * Unpins message after action execution is finished.
70
67
  * 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,7 +1,5 @@
1
1
  import { InlineQueryResult } from 'telegraf/types';
2
2
  import { BotResponse } from '../../types/response';
3
- import { IScheduler } from '../../types/scheduler';
4
- import { IStorageClient } from '../../types/storage';
5
3
  import { InlineQueryAction } from '../actions/inlineQueryAction';
6
4
  import { BaseContext } from './baseContext';
7
5
  export declare class InlineQueryContext extends BaseContext<InlineQueryAction> {
@@ -19,7 +17,6 @@ export declare class InlineQueryContext extends BaseContext<InlineQueryAction> {
19
17
  queryId: string;
20
18
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
21
19
  matchResults: RegExpMatchArray[];
22
- constructor(storage: IStorageClient, scheduler: IScheduler);
23
20
  /**
24
21
  * This result will be shown to user as a response to inline query.
25
22
  * @param queryResult Inline query result to be shown to user.
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,kBAAmB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;IAClE,YAAY,EAAE,iBAAiB,EAAE,CAAM;IACvC;;;OAGG;IACH,WAAW,EAAG,WAAW,CAAC;IAE1B,uDAAuD;IACvD,IAAI,SAAS,IAAI,WAAW,EAAE,CAS7B;IACD,wBAAwB;IACxB,SAAS,EAAG,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,EAAG,MAAM,CAAC;IACjB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;gBAE1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,iBAAiB;CAGvD"}
1
+ {"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,kBAAmB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;IAClE,YAAY,EAAE,iBAAiB,EAAE,CAAM;IACvC;;;OAGG;IACH,WAAW,EAAG,WAAW,CAAC;IAE1B,uDAAuD;IACvD,IAAI,SAAS,IAAI,WAAW,EAAE,CAS7B;IACD,wBAAwB;IACxB,SAAS,EAAG,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,EAAG,MAAM,CAAC;IACjB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IAEtC;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,iBAAiB;CAGvD"}
@@ -4,18 +4,24 @@ exports.InlineQueryContext = void 0;
4
4
  const inlineQueryResponse_1 = require("../../dtos/responses/inlineQueryResponse");
5
5
  const baseContext_1 = require("./baseContext");
6
6
  class InlineQueryContext extends baseContext_1.BaseContext {
7
+ queryResults = [];
8
+ /**
9
+ * Abort signal to be utilized in query handler.
10
+ * Signal will be aborted if new query comes from the same user.
11
+ */
12
+ abortSignal;
7
13
  /** Ordered collection of responses to be processed */
8
14
  get responses() {
9
15
  return [
10
16
  new inlineQueryResponse_1.InlineQueryResponse(this.queryResults, this.queryId, this.traceId, this.action)
11
17
  ];
12
18
  }
13
- constructor(storage, scheduler) {
14
- super(storage, scheduler);
15
- this.queryResults = [];
16
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
17
- this.matchResults = [];
18
- }
19
+ /** Inline query text */
20
+ queryText;
21
+ /** Internal query id */
22
+ queryId;
23
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
24
+ matchResults = [];
19
25
  /**
20
26
  * This result will be shown to user as a response to inline query.
21
27
  * @param queryResult Inline query result to be shown to user.
@@ -1,10 +1,8 @@
1
1
  import { TelegramEmoji } from 'telegraf/types';
2
- import { IStorageClient } from '../../types/storage';
3
2
  import { IActionState } from '../../types/actionState';
4
3
  import { ChatContext } from './chatContext';
5
4
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
6
5
  import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
7
- import { IScheduler } from '../../types/scheduler';
8
6
  import { CommandAction } from '../actions/commandAction';
9
7
  /**
10
8
  * Context of action executed in chat, in response to a message
@@ -26,7 +24,6 @@ export declare class MessageContext<TActionState extends IActionState> extends C
26
24
  messageType: MessageTypeValue;
27
25
  /** Message object recieved from Telegram */
28
26
  messageUpdateObject: TelegrafContextMessage;
29
- constructor(storage: IStorageClient, scheduler: IScheduler);
30
27
  private getQuotePart;
31
28
  private replyWithText;
32
29
  private replyWithImage;
@@ -1 +1 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CA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IAqBtB,OAAO,CAAC,cAAc;IAqBtB;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAEvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAGnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -12,74 +12,22 @@ const replyInfo_1 = require("../../dtos/replyInfo");
12
12
  * Context of action executed in chat, in response to a message
13
13
  */
14
14
  class MessageContext extends chatContext_1.ChatContext {
15
- constructor(storage, scheduler) {
16
- super(storage, scheduler);
17
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
18
- this.matchResults = [];
19
- /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
20
- this.startCooldown = true;
21
- /**
22
- * Collection of actions that can be done as a reply to a message that triggered this action
23
- */
24
- this.reply = {
25
- /**
26
- * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
27
- * If regex is matched, first match will be quoted
28
- */
29
- andQuote: {
30
- /**
31
- * Reply with text message to message that triggered this action after action execution is finished.
32
- * 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.
33
- * @param text Message contents.
34
- * @param options Message sending option.
35
- */
36
- withText: (text, quote, options) => this.replyWithText(text, quote ?? true, options),
37
- /**
38
- * Reply with image message to message that triggered this action after action execution is finished.
39
- * 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.
40
- * @param text Message contents.
41
- * @param options Message sending option.
42
- */
43
- withImage: (name, quote, options) => this.replyWithImage(name, quote ?? true, options),
44
- /**
45
- * Reply with video/gif message to message that triggered this action after action execution is finished.
46
- * 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.
47
- * @param text Message contents.
48
- * @param options Message sending option.
49
- */
50
- withVideo: (name, quote, options) => this.replyWithVideo(name, quote ?? true, options)
51
- },
52
- /**
53
- * Reply with text message to message that triggered this action after action execution is finished.
54
- * 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.
55
- * @param text Message contents.
56
- * @param options Message sending option.
57
- */
58
- withText: (text, options) => this.replyWithText(text, false, options),
59
- /**
60
- * Reply with image message to message that triggered this action after action execution is finished.
61
- * 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.
62
- * @param text Message contents.
63
- * @param options Message sending option.
64
- */
65
- withImage: (name, options) => this.replyWithImage(name, false, options),
66
- /**
67
- * Reply with video/gif message to message that triggered this action after action execution is finished.
68
- * 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.
69
- * @param text Message contents.
70
- * @param options Message sending option.
71
- */
72
- withVideo: (name, options) => this.replyWithVideo(name, false, options),
73
- /**
74
- * React to the message that triggered this action after action execution is finished.
75
- * 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.
76
- * @param emoji Telegram emoji to react with.
77
- */
78
- withReaction: (emoji) => {
79
- this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
80
- }
81
- };
82
- }
15
+ /** Id of a message that triggered this action. */
16
+ messageId;
17
+ /** Text of a message that triggered this action. */
18
+ messageText;
19
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
20
+ matchResults = [];
21
+ /** Id of a user that sent a message that triggered this action. */
22
+ fromUserId;
23
+ /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
24
+ startCooldown = true;
25
+ /** Name of a user that sent a message that triggered this action. */
26
+ fromUserName;
27
+ /** Type of message being received */
28
+ messageType;
29
+ /** Message object recieved from Telegram */
30
+ messageUpdateObject;
83
31
  getQuotePart(quote) {
84
32
  return typeof quote == 'boolean'
85
33
  ? this.matchResults.length != 0
@@ -105,5 +53,66 @@ class MessageContext extends chatContext_1.ChatContext {
105
53
  this.responses.push(response);
106
54
  return this.createCaptureController(response);
107
55
  }
56
+ /**
57
+ * Collection of actions that can be done as a reply to a message that triggered this action
58
+ */
59
+ reply = {
60
+ /**
61
+ * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
62
+ * If regex is matched, first match will be quoted
63
+ */
64
+ andQuote: {
65
+ /**
66
+ * Reply with text message to message that triggered this action after action execution is finished.
67
+ * 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.
68
+ * @param text Message contents.
69
+ * @param options Message sending option.
70
+ */
71
+ withText: (text, quote, options) => this.replyWithText(text, quote ?? true, options),
72
+ /**
73
+ * Reply with image message to message that triggered this action after action execution is finished.
74
+ * 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.
75
+ * @param text Message contents.
76
+ * @param options Message sending option.
77
+ */
78
+ withImage: (name, quote, options) => this.replyWithImage(name, quote ?? true, options),
79
+ /**
80
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
81
+ * 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.
82
+ * @param text Message contents.
83
+ * @param options Message sending option.
84
+ */
85
+ withVideo: (name, quote, options) => this.replyWithVideo(name, quote ?? true, options)
86
+ },
87
+ /**
88
+ * Reply with text message to message that triggered this action after action execution is finished.
89
+ * 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.
90
+ * @param text Message contents.
91
+ * @param options Message sending option.
92
+ */
93
+ withText: (text, options) => this.replyWithText(text, false, options),
94
+ /**
95
+ * Reply with image message to message that triggered this action after action execution is finished.
96
+ * 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.
97
+ * @param text Message contents.
98
+ * @param options Message sending option.
99
+ */
100
+ withImage: (name, options) => this.replyWithImage(name, false, options),
101
+ /**
102
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
103
+ * 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.
104
+ * @param text Message contents.
105
+ * @param options Message sending option.
106
+ */
107
+ withVideo: (name, options) => this.replyWithVideo(name, false, options),
108
+ /**
109
+ * React to the message that triggered this action after action execution is finished.
110
+ * 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.
111
+ * @param emoji Telegram emoji to react with.
112
+ */
113
+ withReaction: (emoji) => {
114
+ this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
115
+ }
116
+ };
108
117
  }
109
118
  exports.MessageContext = MessageContext;
@@ -2,8 +2,6 @@ import { TelegramEmoji } from 'telegraf/types';
2
2
  import { IActionState } from '../../types/actionState';
3
3
  import { TextMessageSendingOptions, MessageSendingOptions } from '../../types/messageSendingOptions';
4
4
  import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
5
- import { IScheduler } from '../../types/scheduler';
6
- import { IStorageClient } from '../../types/storage';
7
5
  import { ReplyCaptureAction } from '../actions/replyCaptureAction';
8
6
  import { BaseContext } from './baseContext';
9
7
  export declare class ReplyContext<TParentActionState extends IActionState> extends BaseContext<ReplyCaptureAction<TParentActionState>> {
@@ -24,7 +22,6 @@ export declare class ReplyContext<TParentActionState extends IActionState> exten
24
22
  /** Message object recieved from Telegram */
25
23
  messageUpdateObject: TelegrafContextMessage;
26
24
  isInitialized: boolean;
27
- constructor(storage: IStorageClient, scheduler: IScheduler);
28
25
  private getQuotePart;
29
26
  private replyWithText;
30
27
  private replyWithImage;
@@ -1 +1 @@
1
- {"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM/C,OA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IAmBrB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,cAAc;IAmBtB;;OAEG;IACH,WAAW;IAIX;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAIvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAKnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAMvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAG5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAIzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAIzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -9,71 +9,23 @@ const videoMessage_1 = require("../../dtos/responses/videoMessage");
9
9
  const path_1 = require("path");
10
10
  const baseContext_1 = require("./baseContext");
11
11
  class ReplyContext extends baseContext_1.BaseContext {
12
- constructor(storage, scheduler) {
13
- super(storage, scheduler);
14
- this.isInitialized = false;
15
- /**
16
- * Collection of actions that can be done as a reply to a message that triggered this action
17
- */
18
- this.reply = {
19
- /**
20
- * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
21
- * If regex is matched, first match will be quoted
22
- */
23
- andQuote: {
24
- /**
25
- * Reply with text message to message that triggered this action after action execution is finished.
26
- * 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.
27
- * @param text Message contents.
28
- * @param options Message sending option.
29
- */
30
- withText: (text, quote, options) => this.replyWithText(text, quote ?? true, options),
31
- /**
32
- * Reply with image 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
- withImage: (name, quote, options) => this.replyWithImage(name, quote ?? true, options),
38
- /**
39
- * Reply with video/gif 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
- withVideo: (name, quote, options) => this.replyWithVideo(name, quote ?? true, options)
45
- },
46
- /**
47
- * Reply with text 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
- withText: (text, options) => this.replyWithText(text, false, options),
53
- /**
54
- * Reply with image 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
- withImage: (name, options) => this.replyWithImage(name, false, options),
60
- /**
61
- * Reply with video/gif 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
- withVideo: (name, options) => this.replyWithVideo(name, false, options),
67
- /**
68
- * React to the 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 emoji Telegram emoji to react with.
71
- */
72
- withReaction: (emoji) => {
73
- this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
74
- }
75
- };
76
- }
12
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
13
+ matchResults;
14
+ /** Id of a message that triggered this action. */
15
+ replyMessageId;
16
+ /** Id of a message that triggered this action. */
17
+ messageId;
18
+ /** Type of message being received */
19
+ messageType;
20
+ /** Text of a message that triggered this action. */
21
+ messageText;
22
+ /** Id of a user that sent a message that triggered this action. */
23
+ fromUserId;
24
+ /** Name of a user that sent a message that triggered this action. */
25
+ fromUserName;
26
+ /** Message object recieved from Telegram */
27
+ messageUpdateObject;
28
+ isInitialized = false;
77
29
  getQuotePart(quote) {
78
30
  return typeof quote == 'boolean'
79
31
  ? this.matchResults.length != 0
@@ -102,5 +54,78 @@ class ReplyContext extends baseContext_1.BaseContext {
102
54
  stopCapture() {
103
55
  this.action.abortController.abort();
104
56
  }
57
+ /**
58
+ * Collection of actions that can be done as a reply to a message that triggered this action
59
+ */
60
+ reply = {
61
+ /**
62
+ * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
63
+ * If regex is matched, first match will be quoted
64
+ */
65
+ andQuote: {
66
+ /**
67
+ * Reply with text message to message that triggered this action after action execution is finished.
68
+ * 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.
69
+ * @param text Message contents.
70
+ * @param options Message sending option.
71
+ */
72
+ withText: (text, quote, options) => {
73
+ this.replyWithText(text, quote ?? true, options);
74
+ },
75
+ /**
76
+ * Reply with image message to message that triggered this action after action execution is finished.
77
+ * 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.
78
+ * @param text Message contents.
79
+ * @param options Message sending option.
80
+ */
81
+ withImage: (name, quote, options) => {
82
+ this.replyWithImage(name, quote ?? true, options);
83
+ },
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, quote, options) => {
91
+ this.replyWithVideo(name, quote ?? true, options);
92
+ }
93
+ },
94
+ /**
95
+ * Reply with text message to message that triggered this action after action execution is finished.
96
+ * 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.
97
+ * @param text Message contents.
98
+ * @param options Message sending option.
99
+ */
100
+ withText: (text, options) => {
101
+ this.replyWithText(text, false, options);
102
+ },
103
+ /**
104
+ * Reply with image message to message that triggered this action after action execution is finished.
105
+ * 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.
106
+ * @param text Message contents.
107
+ * @param options Message sending option.
108
+ */
109
+ withImage: (name, options) => {
110
+ this.replyWithImage(name, false, options);
111
+ },
112
+ /**
113
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
114
+ * 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.
115
+ * @param text Message contents.
116
+ * @param options Message sending option.
117
+ */
118
+ withVideo: (name, options) => {
119
+ this.replyWithVideo(name, false, options);
120
+ },
121
+ /**
122
+ * React to the message that triggered this action after action execution is finished.
123
+ * 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.
124
+ * @param emoji Telegram emoji to react with.
125
+ */
126
+ withReaction: (emoji) => {
127
+ this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
128
+ }
129
+ };
105
130
  }
106
131
  exports.ReplyContext = ReplyContext;
@@ -2,9 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActionStateBase = void 0;
4
4
  class ActionStateBase {
5
- constructor() {
6
- this.pinnedMessages = [];
7
- this.lastExecutedDate = 0;
8
- }
5
+ pinnedMessages = [];
6
+ lastExecutedDate = 0;
9
7
  }
10
8
  exports.ActionStateBase = ActionStateBase;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskRecord = void 0;
4
4
  class TaskRecord {
5
+ name;
6
+ taskId;
7
+ interval;
5
8
  constructor(name, taskId, interval) {
6
9
  this.name = name;
7
10
  this.taskId = taskId;
@@ -19,6 +19,7 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
19
19
  stateConstructor: () => TActionState;
20
20
  handler: CommandHandler<TActionState>;
21
21
  condition: CommandCondition<TActionState>;
22
+ maxAllowedSimultaniousExecutions: number;
22
23
  /**
23
24
  * Builder for `CommandAction` with state represented by `TActionState`
24
25
  * @param name Action name, will be used for logging and storage
@@ -47,6 +48,8 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
47
48
  withHelp(readmeFactory: (botName: string) => string): this;
48
49
  /** If called during building, action is marked as disabled and never checked. */
49
50
  disabled(): this;
51
+ /** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
52
+ ratelimit(maxAllowedSimultaniousExecutions: number): this;
50
53
  /** Sets action cooldown.
51
54
  * @param seconds Cooldown in seconds.
52
55
  */
@@ -1 +1 @@
1
- {"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAM;IAEhD,MAAM,UAAQ;IACd,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAQ;IAC3D,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IAEtD;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,g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hD,MAAM,UAAQ;IACd,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAQ;IAC3D,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IACtD,gCAAgC,EAAE,MAAM,CAAK;IAE7C;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D;;;;;OAKG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE;IAM7C;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;IAM1B;;OAEG;IACH,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAMnD,iFAAiF;IACjF,QAAQ;IAMR,qHAAqH;IACrH,SAAS,CAAC,gCAAgC,EAAE,MAAM;IAOlD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,oBAAoB;IACpB,KAAK;CAeR;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACpF;;OAEG;gBACS,IAAI,EAAE,MAAM;CAG3B"}
@@ -9,20 +9,23 @@ const noop_1 = require("../noop");
9
9
  * Builder for `CommandAction` with state represented by `TActionState`
10
10
  */
11
11
  class CommandActionBuilderWithState {
12
+ name;
13
+ trigger = [];
14
+ active = true;
15
+ readmeFactory = null;
16
+ cooldownSeconds = 0;
17
+ blacklist = [];
18
+ allowedUsers = [];
19
+ stateConstructor;
20
+ handler = noop_1.Noop.call;
21
+ condition = noop_1.Noop.true;
22
+ maxAllowedSimultaniousExecutions = 0;
12
23
  /**
13
24
  * Builder for `CommandAction` with state represented by `TActionState`
14
25
  * @param name Action name, will be used for logging and storage
15
26
  * @param stateConstructor Function that creates default state object
16
27
  */
17
28
  constructor(name, stateConstructor) {
18
- this.trigger = [];
19
- this.active = true;
20
- this.readmeFactory = null;
21
- this.cooldownSeconds = 0;
22
- this.blacklist = [];
23
- this.allowedUsers = [];
24
- this.handler = noop_1.Noop.call;
25
- this.condition = noop_1.Noop.true;
26
29
  this.name = name;
27
30
  this.stateConstructor = stateConstructor;
28
31
  }
@@ -66,6 +69,12 @@ class CommandActionBuilderWithState {
66
69
  this.active = false;
67
70
  return this;
68
71
  }
72
+ /** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
73
+ ratelimit(maxAllowedSimultaniousExecutions) {
74
+ this.maxAllowedSimultaniousExecutions =
75
+ maxAllowedSimultaniousExecutions;
76
+ return this;
77
+ }
69
78
  /** Sets action cooldown.
70
79
  * @param seconds Cooldown in seconds.
71
80
  */
@@ -83,7 +92,7 @@ class CommandActionBuilderWithState {
83
92
  }
84
93
  /** Builds action */
85
94
  build() {
86
- return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
95
+ return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
87
96
  }
88
97
  }
89
98
  exports.CommandActionBuilderWithState = CommandActionBuilderWithState;