chz-telegram-bot 0.3.7 → 0.3.9

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 (52) hide show
  1. package/dist/entities/botInstance.d.ts.map +1 -1
  2. package/dist/entities/botInstance.js +0 -1
  3. package/dist/entities/context/baseContext.d.ts +35 -0
  4. package/dist/entities/context/baseContext.d.ts.map +1 -0
  5. package/dist/entities/context/baseContext.js +32 -0
  6. package/dist/entities/context/chatContext.d.ts +4 -27
  7. package/dist/entities/context/chatContext.d.ts.map +1 -1
  8. package/dist/entities/context/chatContext.js +3 -19
  9. package/dist/entities/context/inlineQueryContext.d.ts +2 -15
  10. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
  11. package/dist/entities/context/inlineQueryContext.js +3 -4
  12. package/dist/entities/context/messageContext.d.ts +2 -1
  13. package/dist/entities/context/messageContext.d.ts.map +1 -1
  14. package/dist/entities/context/replyContext.d.ts +2 -20
  15. package/dist/entities/context/replyContext.d.ts.map +1 -1
  16. package/dist/entities/context/replyContext.js +3 -5
  17. package/dist/services/actionProcessingService.d.ts.map +1 -1
  18. package/dist/services/actionProcessingService.js +4 -2
  19. package/dist/services/actionProcessors/baseProcessor.d.ts +20 -0
  20. package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -0
  21. package/dist/services/actionProcessors/baseProcessor.js +29 -0
  22. package/dist/services/actionProcessors/commandActionProcessor.d.ts +2 -7
  23. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  24. package/dist/services/actionProcessors/commandActionProcessor.js +12 -27
  25. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +2 -7
  26. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
  27. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +6 -15
  28. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +2 -6
  29. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -1
  30. package/dist/services/actionProcessors/scheduledActionProcessor.js +5 -14
  31. package/dist/services/jsonFileStorage.d.ts +5 -4
  32. package/dist/services/jsonFileStorage.d.ts.map +1 -1
  33. package/dist/services/jsonFileStorage.js +40 -29
  34. package/dist/types/action.d.ts +3 -0
  35. package/dist/types/action.d.ts.map +1 -1
  36. package/dist/types/storage.d.ts +1 -1
  37. package/dist/types/storage.d.ts.map +1 -1
  38. package/entities/botInstance.ts +0 -2
  39. package/entities/context/baseContext.ts +58 -0
  40. package/entities/context/chatContext.ts +8 -45
  41. package/entities/context/inlineQueryContext.ts +3 -20
  42. package/entities/context/messageContext.ts +2 -1
  43. package/entities/context/replyContext.ts +5 -25
  44. package/package.json +1 -1
  45. package/services/actionProcessingService.ts +9 -5
  46. package/services/actionProcessors/baseProcessor.ts +60 -0
  47. package/services/actionProcessors/commandActionProcessor.ts +19 -42
  48. package/services/actionProcessors/inlineQueryActionProcessor.ts +16 -32
  49. package/services/actionProcessors/scheduledActionProcessor.ts +7 -23
  50. package/services/jsonFileStorage.ts +57 -41
  51. package/types/action.ts +3 -0
  52. package/types/storage.ts +1 -2
@@ -1 +1 @@
1
- {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ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C,IAAI,CAAC,IAAI,EAAE,MAAM;CAY1B"}
@@ -21,7 +21,6 @@ class BotInstance {
21
21
  options.services?.storageClient ??
22
22
  new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
23
23
  this.actionProcessingService = new actionProcessingService_1.ActionProcessingService(this.name, options.chats, this.storage, this.scheduler, this.logger);
24
- this.storage.saveMetadata(actions, this.name);
25
24
  }
26
25
  async start(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage) {
27
26
  this.actionProcessingService.initialize(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage);
@@ -0,0 +1,35 @@
1
+ import { ChatInfo } from '../../dtos/chatInfo';
2
+ import { IAction, IActionWithState } from '../../types/action';
3
+ import { IActionState } from '../../types/actionState';
4
+ import { IScopedLogger } from '../../types/logger';
5
+ import { BotResponse } from '../../types/response';
6
+ import { IScheduler } from '../../types/scheduler';
7
+ import { IStorageClient } from '../../types/storage';
8
+ import { TraceId } from '../../types/trace';
9
+ export declare abstract class BaseContext<TAction extends IAction> {
10
+ isInitialized: boolean;
11
+ private _responses;
12
+ action: TAction;
13
+ /** Storage client instance for the bot executing this action. */
14
+ readonly storage: IStorageClient;
15
+ /** Scheduler instance for the bot executing this action */
16
+ readonly scheduler: IScheduler;
17
+ logger: IScopedLogger;
18
+ /** Trace id of a action execution. */
19
+ traceId: TraceId;
20
+ /** Name of a bot that executes this action. */
21
+ botName: string;
22
+ /** Chat information. */
23
+ chatInfo: ChatInfo;
24
+ /** Ordered collection of responses to be processed */
25
+ get responses(): BotResponse[];
26
+ set responses(value: BotResponse[]);
27
+ constructor(storage: IStorageClient, scheduler: IScheduler);
28
+ /**
29
+ * Loads state of another action for current chat.
30
+ * @param action Action to load state of.
31
+ * @template TAnotherActionState - Type of a state that is used by another action.
32
+ */
33
+ loadStateOf<TAnotherActionState extends IActionState>(action: IActionWithState<TAnotherActionState>): Promise<Readonly<TAnotherActionState>>;
34
+ }
35
+ //# sourceMappingURL=baseContext.d.ts.map
@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2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseContext = void 0;
4
+ class BaseContext {
5
+ /** Ordered collection of responses to be processed */
6
+ get responses() {
7
+ return this._responses;
8
+ }
9
+ set responses(value) {
10
+ this._responses = value;
11
+ }
12
+ constructor(storage, scheduler) {
13
+ this.isInitialized = false;
14
+ this._responses = [];
15
+ this.storage = storage;
16
+ this.scheduler = scheduler;
17
+ }
18
+ /**
19
+ * Loads state of another action for current chat.
20
+ * @param action Action to load state of.
21
+ * @template TAnotherActionState - Type of a state that is used by another action.
22
+ */
23
+ async loadStateOf(action) {
24
+ const allStates = await this.storage.load(action.key);
25
+ const stateForChat = allStates[this.chatInfo.id];
26
+ if (!stateForChat) {
27
+ return Object.freeze(action.stateConstructor());
28
+ }
29
+ return Object.freeze(stateForChat);
30
+ }
31
+ }
32
+ exports.BaseContext = BaseContext;
@@ -2,41 +2,18 @@ import { IStorageClient } from '../../types/storage';
2
2
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
3
3
  import { IActionWithState } from '../../types/action';
4
4
  import { IActionState } from '../../types/actionState';
5
- import { BotResponse, IReplyResponse } from '../../types/response';
5
+ import { IReplyResponse } from '../../types/response';
6
6
  import { Milliseconds } from '../../types/timeValues';
7
- import { ChatInfo } from '../../dtos/chatInfo';
8
- import { IScopedLogger } from '../../types/logger';
9
7
  import { IScheduler } from '../../types/scheduler';
10
- import { TraceId } from '../../types/trace';
11
8
  import { ICaptureController } from '../../types/capture';
9
+ import { BaseContext } from './baseContext';
10
+ import { ScheduledAction } from '../actions/scheduledAction';
12
11
  /**
13
12
  * Context of action executed in chat.
14
13
  */
15
- export declare class ChatContext<TActionState extends IActionState> {
16
- action: IActionWithState<TActionState>;
17
- /** Storage client instance for the bot executing this action. */
18
- readonly storage: IStorageClient;
19
- /** Logger instance for the bot executing this action */
20
- /** Scheduler instance for the bot executing this action */
21
- readonly scheduler: IScheduler;
22
- logger: IScopedLogger;
23
- /** Trace id of a action execution. */
24
- traceId: TraceId;
25
- /** Name of a bot that executes this action. */
26
- botName: string;
27
- /** Chat information. */
28
- chatInfo: ChatInfo;
29
- /** Ordered collection of responses to be processed */
30
- responses: BotResponse[];
31
- isInitialized: boolean;
14
+ export declare class ChatContext<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> extends BaseContext<TAction> {
32
15
  constructor(storage: IStorageClient, scheduler: IScheduler);
33
16
  protected createCaptureController(response: IReplyResponse): ICaptureController;
34
- /**
35
- * Loads state of another action for current chat.
36
- * @param action Action to load state of.
37
- * @template TAnotherActionState - Type of a state that is used by another action.
38
- */
39
- loadStateOf<TAnotherActionState extends IActionState>(action: IActionWithState<TAnotherActionState>): Promise<Readonly<TAnotherActionState>>;
40
17
  /**
41
18
  * Collection of actions that send something to chat as a standalone message.
42
19
  */
@@ -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,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAIzD;;GAEG;AACH,qB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,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,qBAAa,WAAW,CACpB,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAChF,SAAQ,WAAW,CAAC,OAAO,CAAC;gBACd,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;OAEG;IACH,IAAI;QACA;;;;;WAKG;qBACU,MAAM,YAAY,yBAAyB;QAexD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;QAerD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;MAcvD;IAEF;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;IAW9B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,YAAY;CAK3B"}
@@ -7,14 +7,13 @@ const textMessage_1 = require("../../dtos/responses/textMessage");
7
7
  const videoMessage_1 = require("../../dtos/responses/videoMessage");
8
8
  const unpin_1 = require("../../dtos/responses/unpin");
9
9
  const delay_1 = require("../../dtos/responses/delay");
10
+ const baseContext_1 = require("./baseContext");
10
11
  /**
11
12
  * Context of action executed in chat.
12
13
  */
13
- class ChatContext {
14
+ class ChatContext extends baseContext_1.BaseContext {
14
15
  constructor(storage, scheduler) {
15
- /** Ordered collection of responses to be processed */
16
- this.responses = [];
17
- this.isInitialized = false;
16
+ super(storage, scheduler);
18
17
  /**
19
18
  * Collection of actions that send something to chat as a standalone message.
20
19
  */
@@ -53,8 +52,6 @@ class ChatContext {
53
52
  return this.createCaptureController(response);
54
53
  }
55
54
  };
56
- this.storage = storage;
57
- this.scheduler = scheduler;
58
55
  }
59
56
  createCaptureController(response) {
60
57
  return {
@@ -68,19 +65,6 @@ class ChatContext {
68
65
  }
69
66
  };
70
67
  }
71
- /**
72
- * Loads state of another action for current chat.
73
- * @param action Action to load state of.
74
- * @template TAnotherActionState - Type of a state that is used by another action.
75
- */
76
- async loadStateOf(action) {
77
- const allStates = await this.storage.load(action.key);
78
- const stateForChat = allStates[this.chatInfo.id];
79
- if (!stateForChat) {
80
- return Object.freeze(action.stateConstructor());
81
- }
82
- return Object.freeze(stateForChat);
83
- }
84
68
  /**
85
69
  * Unpins message after action execution is finished.
86
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.
@@ -1,23 +1,11 @@
1
1
  import { InlineQueryResult } from 'telegraf/types';
2
- import { IScopedLogger } from '../../types/logger';
3
2
  import { BotResponse } from '../../types/response';
4
3
  import { IScheduler } from '../../types/scheduler';
5
4
  import { IStorageClient } from '../../types/storage';
6
- import { TraceId } from '../../types/trace';
7
5
  import { InlineQueryAction } from '../actions/inlineQueryAction';
8
- export declare class InlineQueryContext {
9
- action: InlineQueryAction;
6
+ import { BaseContext } from './baseContext';
7
+ export declare class InlineQueryContext extends BaseContext<InlineQueryAction> {
10
8
  queryResults: InlineQueryResult[];
11
- /** Storage client instance for the bot executing this action. */
12
- readonly storage: IStorageClient;
13
- /** Scheduler instance for the bot executing this action */
14
- readonly scheduler: IScheduler;
15
- /** Logger instance for the bot executing this action */
16
- logger: IScopedLogger;
17
- /** Trace id of a action execution. */
18
- traceId: TraceId;
19
- /** Name of a bot that executes this action. */
20
- botName: string;
21
9
  /**
22
10
  * Abort signal to be utilized in query handler.
23
11
  * Signal will be aborted if new query comes from the same user.
@@ -31,7 +19,6 @@ export declare class InlineQueryContext {
31
19
  queryId: string;
32
20
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
33
21
  matchResults: RegExpMatchArray[];
34
- isInitialized: boolean;
35
22
  constructor(storage: IStorageClient, scheduler: IScheduler);
36
23
  /**
37
24
  * This result will be shown to user as a response to inline query.
@@ -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,aAAa,EAAE,MAAM,oBAAoB,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,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,qBAAa,kBAAkB;IAC3B,MAAM,EAAG,iBAAiB,CAAC;IAC3B,YAAY,EAAE,iBAAiB,EAAE,CAAM;IAEvC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAE/B,wDAAwD;IACxD,MAAM,EAAG,aAAa,CAAC;IACvB,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB;;;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,aAAa,UAAS;gBAEV,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAK1D;;;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,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"}
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InlineQueryContext = void 0;
4
4
  const inlineQueryResponse_1 = require("../../dtos/responses/inlineQueryResponse");
5
- class InlineQueryContext {
5
+ const baseContext_1 = require("./baseContext");
6
+ class InlineQueryContext extends baseContext_1.BaseContext {
6
7
  /** Ordered collection of responses to be processed */
7
8
  get responses() {
8
9
  return [
@@ -10,12 +11,10 @@ class InlineQueryContext {
10
11
  ];
11
12
  }
12
13
  constructor(storage, scheduler) {
14
+ super(storage, scheduler);
13
15
  this.queryResults = [];
14
16
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
15
17
  this.matchResults = [];
16
- this.isInitialized = false;
17
- this.storage = storage;
18
- this.scheduler = scheduler;
19
18
  }
20
19
  /**
21
20
  * This result will be shown to user as a response to inline query.
@@ -5,10 +5,11 @@ import { ChatContext } from './chatContext';
5
5
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
6
6
  import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
7
7
  import { IScheduler } from '../../types/scheduler';
8
+ import { CommandAction } from '../actions/commandAction';
8
9
  /**
9
10
  * Context of action executed in chat, in response to a message
10
11
  */
11
- export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState> {
12
+ export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState, CommandAction<TActionState>> {
12
13
  /** Id of a message that triggered this action. */
13
14
  messageId: number;
14
15
  /** Text of a message that triggered this action. */
@@ -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;AAKvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;GAEG;AACH,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D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -1,30 +1,12 @@
1
1
  import { TelegramEmoji } from 'telegraf/types';
2
- import { ChatInfo } from '../../dtos/chatInfo';
3
2
  import { IActionState } from '../../types/actionState';
4
- import { IScopedLogger } from '../../types/logger';
5
3
  import { TextMessageSendingOptions, MessageSendingOptions } from '../../types/messageSendingOptions';
6
4
  import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
7
- import { BotResponse } from '../../types/response';
8
5
  import { IScheduler } from '../../types/scheduler';
9
6
  import { IStorageClient } from '../../types/storage';
10
- import { TraceId } from '../../types/trace';
11
7
  import { ReplyCaptureAction } from '../actions/replyCaptureAction';
12
- export declare class ReplyContext<TParentActionState extends IActionState> {
13
- action: ReplyCaptureAction<TParentActionState>;
14
- /** Storage client instance for the bot executing this action. */
15
- readonly storage: IStorageClient;
16
- /** Scheduler instance for the bot executing this action */
17
- readonly scheduler: IScheduler;
18
- /** Trace id of a action execution. */
19
- traceId: TraceId;
20
- /** Name of a bot that executes this action. */
21
- botName: string;
22
- /** Logger instance for the bot executing this action */
23
- logger: IScopedLogger;
24
- /** Ordered collection of responses to be processed */
25
- responses: BotResponse[];
26
- /** Chat information. */
27
- chatInfo: ChatInfo;
8
+ import { BaseContext } from './baseContext';
9
+ export declare class ReplyContext<TParentActionState extends IActionState> extends BaseContext<ReplyCaptureAction<TParentActionState>> {
28
10
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
29
11
  matchResults: RegExpExecArray[];
30
12
  /** Id of a message that triggered this action. */
@@ -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;AAC/C,OAAO,EAAE,QAAQ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M,eAAe,CAAC;AAE5C,qBAAa,YAAY,CACrB,kBAAkB,SAAS,YAAY,CACzC,SAAQ,WAAW,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACzD,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC;IACjC,kDAAkD;IAClD,cAAc,EAAG,MAAM,GAAG,SAAS,CAAC;IACpC,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;IAE7C,aAAa,UAAS;gBAEV,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;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;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"}
@@ -7,10 +7,10 @@ const reaction_1 = require("../../dtos/responses/reaction");
7
7
  const textMessage_1 = require("../../dtos/responses/textMessage");
8
8
  const videoMessage_1 = require("../../dtos/responses/videoMessage");
9
9
  const path_1 = require("path");
10
- class ReplyContext {
10
+ const baseContext_1 = require("./baseContext");
11
+ class ReplyContext extends baseContext_1.BaseContext {
11
12
  constructor(storage, scheduler) {
12
- /** Ordered collection of responses to be processed */
13
- this.responses = [];
13
+ super(storage, scheduler);
14
14
  this.isInitialized = false;
15
15
  /**
16
16
  * Collection of actions that can be done as a reply to a message that triggered this action
@@ -73,8 +73,6 @@ class ReplyContext {
73
73
  this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
74
74
  }
75
75
  };
76
- this.storage = storage;
77
- this.scheduler = scheduler;
78
76
  }
79
77
  getQuotePart(quote) {
80
78
  return typeof quote == 'boolean'
@@ -1 +1 @@
1
- {"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAMtE,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CA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CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAY;gBAGxB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IA4Bb,UAAU,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO,EACzB,gCAAgC,CAAC,EAAE,OAAO;IAsD9C,IAAI,CAAC,IAAI,EAAE,MAAM;CAGpB"}
@@ -21,16 +21,18 @@ class ActionProcessingService {
21
21
  this.telegraf = new telegraf_1.Telegraf(token);
22
22
  const api = new telegramApi_1.TelegramApiService(this.botName, this.telegraf.telegram, this.storage, this.logger, (capture, id, chatInfo, traceId) => this.commandProcessor.captureRegistrationCallback(capture, id, chatInfo, traceId));
23
23
  const botInfo = await this.telegraf.telegram.getMe();
24
- this.commandProcessor.initialize(api, this.telegraf, actions.commands.length > 0
24
+ const commandActions = actions.commands.length > 0
25
25
  ? [
26
26
  (0, helpAction_1.buildHelpCommand)(actions.commands
27
27
  .map((x) => x.readmeFactory(botInfo.username))
28
28
  .filter((x) => !!x), botInfo.username),
29
29
  ...actions.commands
30
30
  ]
31
- : [], verboseLoggingForIncomingMessage ?? false);
31
+ : [];
32
+ this.commandProcessor.initialize(api, this.telegraf, commandActions, verboseLoggingForIncomingMessage ?? false);
32
33
  this.inlineQueryProcessor.initialize(api, this.telegraf, actions.inlineQueries, 300);
33
34
  this.scheduledProcessor.initialize(api, actions.scheduled, scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
35
+ this.storage.saveMetadata([...actions.scheduled, ...commandActions]);
34
36
  this.telegraf.launch();
35
37
  }
36
38
  stop(code) {
@@ -0,0 +1,20 @@
1
+ import { Telegraf } from 'telegraf';
2
+ import { ILogger } from '../../types/logger';
3
+ import { IScheduler } from '../../types/scheduler';
4
+ import { IStorageClient } from '../../types/storage';
5
+ import { TelegramApiService } from '../telegramApi';
6
+ import { IAction } from '../../types/action';
7
+ import { BaseContext } from '../../entities/context/baseContext';
8
+ export declare abstract class BaseActionProcessor {
9
+ protected readonly storage: IStorageClient;
10
+ protected readonly scheduler: IScheduler;
11
+ protected readonly logger: ILogger;
12
+ protected readonly botName: string;
13
+ protected api: TelegramApiService;
14
+ protected telegraf: Telegraf;
15
+ constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
16
+ private defaultErrorHandler;
17
+ initializeDependencies(api: TelegramApiService, telegraf: Telegraf): void;
18
+ executeAction<TAction extends IAction, TActionContext extends BaseContext<TAction>>(action: TAction, ctx: TActionContext, errorHandler?: (error: Error, ctx: TActionContext) => void): Promise<void>;
19
+ }
20
+ //# sourceMappingURL=baseProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/baseProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,8BAAsB,mBAAmB;IACrC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEnC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAG,kBAAkB,CAAC;IACnC,SAAS,CAAC,QAAQ,EAAG,QAAQ,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IASnB,OAAO,CAAC,mBAAmB;IAO3B,sBAAsB,CAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ;IAK5D,aAAa,CACf,OAAO,SAAS,OAAO,EACvB,cAAc,SAAS,WAAW,CAAC,OAAO,CAAC,EAE3C,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,cAAc,EACnB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;CAUjE"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseActionProcessor = void 0;
4
+ class BaseActionProcessor {
5
+ constructor(botName, storage, scheduler, logger) {
6
+ this.storage = storage;
7
+ this.scheduler = scheduler;
8
+ this.logger = logger;
9
+ this.botName = botName;
10
+ }
11
+ defaultErrorHandler(error, ctx) {
12
+ ctx.logger.errorWithTraceId(error, ctx);
13
+ }
14
+ initializeDependencies(api, telegraf) {
15
+ this.api = api;
16
+ this.telegraf = telegraf;
17
+ }
18
+ async executeAction(action, ctx, errorHandler) {
19
+ try {
20
+ const responses = await action.exec(ctx);
21
+ this.api.enqueueBatchedResponses(responses);
22
+ ctx.isInitialized = false;
23
+ }
24
+ catch (error) {
25
+ (errorHandler ?? this.defaultErrorHandler)(error, ctx);
26
+ }
27
+ }
28
+ }
29
+ exports.BaseActionProcessor = BaseActionProcessor;
@@ -8,14 +8,9 @@ import { TelegramApiService } from '../telegramApi';
8
8
  import { IReplyCapture } from '../../types/capture';
9
9
  import { TraceId } from '../../types/trace';
10
10
  import { ChatInfo } from '../../dtos/chatInfo';
11
- export declare class CommandActionProcessor {
12
- private readonly storage;
13
- private readonly scheduler;
14
- private readonly logger;
15
- private readonly botName;
11
+ import { BaseActionProcessor } from './baseProcessor';
12
+ export declare class CommandActionProcessor extends BaseActionProcessor {
16
13
  private readonly replyCaptures;
17
- private api;
18
- private telegraf;
19
14
  private commands;
20
15
  constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
21
16
  initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean): void;
@@ -1 +1 @@
1
- {"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAKrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAO/C,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,C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,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IAExE,OAAO,CAAC,QAAQ,CAKd;gBAGE,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAKnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO;IAyD7C,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YA+BN,cAAc;IAiC5B,OAAO,CAAC,6BAA6B;IA6BrC,OAAO,CAAC,wBAAwB;CA8BnC"}
@@ -7,21 +7,18 @@ const messageContext_1 = require("../../entities/context/messageContext");
7
7
  const replyContext_1 = require("../../entities/context/replyContext");
8
8
  const messageTypes_1 = require("../../types/messageTypes");
9
9
  const objectFromEntries_1 = require("../../helpers/objectFromEntries");
10
- class CommandActionProcessor {
10
+ const baseProcessor_1 = require("./baseProcessor");
11
+ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
11
12
  constructor(botName, storage, scheduler, logger) {
13
+ super(botName, storage, scheduler, logger);
14
+ this.replyCaptures = [];
12
15
  this.commands = (0, objectFromEntries_1.typeSafeObjectFromEntries)(Object.values(messageTypes_1.MessageType).map((x) => [
13
16
  x,
14
17
  []
15
18
  ]));
16
- this.storage = storage;
17
- this.scheduler = scheduler;
18
- this.logger = logger;
19
- this.botName = botName;
20
- this.replyCaptures = [];
21
19
  }
22
20
  initialize(api, telegraf, commands, verboseLoggingForIncomingMessage) {
23
- this.api = api;
24
- this.telegraf = telegraf;
21
+ this.initializeDependencies(api, telegraf);
25
22
  for (const msgType of Object.values(messageTypes_1.MessageType)) {
26
23
  if (msgType == messageTypes_1.MessageType.Text) {
27
24
  this.commands[msgType] = commands.filter((cmd) => cmd.triggers.find((x) => typeof x != 'string') !=
@@ -64,29 +61,17 @@ class CommandActionProcessor {
64
61
  const ctx = new messageContext_1.MessageContext(this.storage, this.scheduler);
65
62
  const commandsToCheck = new Set(this.commands[msg.type]);
66
63
  if (msg.type != messageTypes_1.MessageType.Text && msg.text != '') {
67
- this.commands[messageTypes_1.MessageType.Text].map((x) => commandsToCheck.add(x));
64
+ this.commands[messageTypes_1.MessageType.Text].forEach((x) => commandsToCheck.add(x));
68
65
  }
69
66
  for (const commandAction of commandsToCheck) {
70
67
  this.initializeMessageContext(ctx, commandAction, msg);
71
- try {
72
- const responses = await commandAction.exec(ctx);
73
- this.api.enqueueBatchedResponses(responses);
74
- ctx.isInitialized = false;
75
- }
76
- catch (error) {
77
- ctx.logger.errorWithTraceId(error, ctx);
78
- }
68
+ this.executeAction(commandAction, ctx);
79
69
  }
80
- const replyCtx = new replyContext_1.ReplyContext(this.storage, this.scheduler);
81
- for (const replyAction of this.replyCaptures) {
82
- this.initializeReplyCaptureContext(replyCtx, replyAction, msg);
83
- try {
84
- const responses = await replyAction.exec(replyCtx);
85
- this.api.enqueueBatchedResponses(responses);
86
- replyCtx.isInitialized = false;
87
- }
88
- catch (error) {
89
- replyCtx.logger.errorWithTraceId(error, replyCtx);
70
+ if (this.replyCaptures.length != 0) {
71
+ const replyCtx = new replyContext_1.ReplyContext(this.storage, this.scheduler);
72
+ for (const replyAction of this.replyCaptures) {
73
+ this.initializeReplyCaptureContext(replyCtx, replyAction, msg);
74
+ this.executeAction(replyAction, replyCtx);
90
75
  }
91
76
  }
92
77
  this.api.flushResponses();
@@ -5,13 +5,8 @@ import { IScheduler } from '../../types/scheduler';
5
5
  import { IStorageClient } from '../../types/storage';
6
6
  import { Milliseconds } from '../../types/timeValues';
7
7
  import { TelegramApiService } from '../telegramApi';
8
- export declare class InlineQueryActionProcessor {
9
- private readonly storage;
10
- private readonly scheduler;
11
- private readonly logger;
12
- private readonly botName;
13
- private api;
14
- private telegraf;
8
+ import { BaseActionProcessor } from './baseProcessor';
9
+ export declare class InlineQueryActionProcessor extends BaseActionProcessor {
15
10
  private inlineQueries;
16
11
  constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
17
12
  initialize(api: TelegramApiService, telegraf: Telegraf, inlineQueries: InlineQueryAction[], period: Milliseconds): void;
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,qBAAa,0BAA0B;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,aAAa,CAAuB;gBAGxC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IASnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IA0GxB,OAAO,CAAC,4BAA4B;CAqBvC"}
1
+ {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,0BAA2B,SAAQ,mBAAmB;IAC/D,OAAO,CAAC,aAAa,CAAuB;gBAGxC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAKnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IAqGxB,OAAO,CAAC,4BAA4B;CAqBvC"}
@@ -4,16 +4,13 @@ exports.InlineQueryActionProcessor = void 0;
4
4
  const incomingQuery_1 = require("../../dtos/incomingQuery");
5
5
  const inlineQueryContext_1 = require("../../entities/context/inlineQueryContext");
6
6
  const traceFactory_1 = require("../../helpers/traceFactory");
7
- class InlineQueryActionProcessor {
7
+ const baseProcessor_1 = require("./baseProcessor");
8
+ class InlineQueryActionProcessor extends baseProcessor_1.BaseActionProcessor {
8
9
  constructor(botName, storage, scheduler, logger) {
9
- this.storage = storage;
10
- this.scheduler = scheduler;
11
- this.logger = logger;
12
- this.botName = botName;
10
+ super(botName, storage, scheduler, logger);
13
11
  }
14
12
  initialize(api, telegraf, inlineQueries, period) {
15
- this.api = api;
16
- this.telegraf = telegraf;
13
+ this.initializeDependencies(api, telegraf);
17
14
  this.inlineQueries = inlineQueries;
18
15
  let pendingInlineQueries = [];
19
16
  const queriesInProcessing = new Map();
@@ -39,20 +36,14 @@ class InlineQueryActionProcessor {
39
36
  queriesInProcessing.set(inlineQuery.userId, inlineQuery);
40
37
  for (const inlineQueryAction of this.inlineQueries) {
41
38
  this.initializeInlineQueryContext(ctx, inlineQuery.query, inlineQuery.queryId, inlineQueryAction, inlineQuery.abortController.signal, inlineQuery.traceId);
42
- try {
43
- const responses = await inlineQueryAction.exec(ctx);
44
- this.api.enqueueBatchedResponses(responses);
45
- ctx.isInitialized = false;
46
- }
47
- catch (err) {
48
- const error = err;
39
+ this.executeAction(inlineQueryAction, ctx, (error, ctx) => {
49
40
  if (error.name == 'AbortError') {
50
41
  ctx.logger.logWithTraceId(`Aborting query ${inlineQuery.queryId} (${inlineQuery.query}) successful.`);
51
42
  }
52
43
  else {
53
44
  ctx.logger.errorWithTraceId(error, ctx);
54
45
  }
55
- }
46
+ });
56
47
  }
57
48
  queriesInProcessing.delete(inlineQuery.userId);
58
49
  }