chz-telegram-bot 0.7.3 → 0.7.5

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 (54) hide show
  1. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  2. package/dist/entities/actions/commandAction.js +0 -2
  3. package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
  4. package/dist/entities/actions/inlineQueryAction.js +4 -3
  5. package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
  6. package/dist/entities/actions/replyCaptureAction.js +0 -2
  7. package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
  8. package/dist/entities/actions/scheduledAction.js +0 -2
  9. package/dist/entities/context/baseContext.d.ts +6 -10
  10. package/dist/entities/context/baseContext.d.ts.map +1 -1
  11. package/dist/entities/context/baseContext.js +7 -11
  12. package/dist/entities/context/inlineQueryContext.d.ts +10 -7
  13. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
  14. package/dist/entities/context/inlineQueryContext.js +6 -7
  15. package/dist/entities/context/messageContext.d.ts +12 -6
  16. package/dist/entities/context/messageContext.d.ts.map +1 -1
  17. package/dist/entities/context/messageContext.js +14 -4
  18. package/dist/entities/context/replyContext.d.ts +10 -6
  19. package/dist/entities/context/replyContext.d.ts.map +1 -1
  20. package/dist/entities/context/replyContext.js +11 -2
  21. package/dist/services/actionProcessors/baseProcessor.js +0 -1
  22. package/dist/services/actionProcessors/commandActionProcessor.d.ts +1 -3
  23. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  24. package/dist/services/actionProcessors/commandActionProcessor.js +26 -50
  25. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +2 -1
  26. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
  27. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +23 -20
  28. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +0 -1
  29. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -1
  30. package/dist/services/actionProcessors/scheduledActionProcessor.js +21 -22
  31. package/dist/types/events.d.ts +12 -4
  32. package/dist/types/events.d.ts.map +1 -1
  33. package/dist/types/events.js +5 -1
  34. package/package.json +1 -1
  35. package/src/entities/actions/commandAction.ts +0 -5
  36. package/src/entities/actions/inlineQueryAction.ts +9 -6
  37. package/src/entities/actions/replyCaptureAction.ts +3 -8
  38. package/src/entities/actions/scheduledAction.ts +0 -5
  39. package/src/entities/context/baseContext.ts +16 -18
  40. package/src/entities/context/inlineQueryContext.ts +33 -18
  41. package/src/entities/context/messageContext.ts +45 -6
  42. package/src/entities/context/replyContext.ts +47 -7
  43. package/src/services/actionProcessors/baseProcessor.ts +1 -1
  44. package/src/services/actionProcessors/commandActionProcessor.ts +44 -87
  45. package/src/services/actionProcessors/inlineQueryActionProcessor.ts +71 -61
  46. package/src/services/actionProcessors/scheduledActionProcessor.ts +45 -41
  47. package/src/types/events.ts +12 -20
  48. package/tests/entities/actions/inlineQueryAction.test.ts +26 -16
  49. package/tests/entities/actions/replyCaptureAction.test.ts +67 -24
  50. package/tests/entities/context/chatContext.test.ts +83 -38
  51. package/tests/entities/context/messageContext.test.ts +24 -23
  52. package/tests/services/actionProcessors/baseActionProcessor.test.ts +30 -16
  53. package/tests/services/actionProcessors/inlineQueryActionProcessor.test.ts +199 -2
  54. package/tests/services/actionProcessors/scheduledActionProcessor.test.ts +39 -0
@@ -1 +1 @@
1
- {"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,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AAE,MAAM,CAAC;IACtB,QAAQ,CAAC,mBAAmB,yBAAgC;IAC5D,QAAQ,CAAC,gCAAgC,EAAE,MAAM,CAAC;IAElD,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAEpC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAEpD,OAAO,CAAC,kBAAkB,CAAsB;gBAG5C,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,sBAAsB,EACjC,gCAAgC,EAAE,MAAM,EACxC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY,EACpC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM;IAsBxC,IAAI,CACN,GAAG,EAAE,sBAAsB,CAAC,YAAY,CAAC,GAC1C,OAAO,CAAC,WAAW,EAAE,CAAC;IAmFzB,OAAO,CAAC,uBAAuB;IA6D/B,OAAO,CAAC,YAAY;CAuCvB"}
@@ -42,8 +42,6 @@ export class CommandAction {
42
42
  this.key = `command:${this.name.replace('.', '-')}`;
43
43
  }
44
44
  async exec(ctx) {
45
- if (!ctx.isInitialized)
46
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
47
45
  let lock;
48
46
  if (this.maxAllowedSimultaniousExecutions != 0) {
49
47
  lock = getOrSetIfNotExists(this.ratelimitSemaphores, ctx.chatInfo.id, new Semaphore(this.maxAllowedSimultaniousExecutions));
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAG5E,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,4BAA4B,CAAC,OAAO,CAAC,EACrD,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,0BAA0B;CA8C7C"}
1
+ {"version":3,"file":"inlineQueryAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/inlineQueryAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAI5E,qBAAa,iBAAkB,YAAW,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAGrB,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,4BAA4B,CAAC,OAAO,CAAC,EACrD,OAAO,EAAE,MAAM;IAUb,IAAI,CAAC,GAAG,EAAE,0BAA0B;CAgD7C"}
@@ -1,5 +1,6 @@
1
1
  import { Noop } from '../../helpers/noop';
2
2
  import { BotEventType } from '../../types/events';
3
+ import { InlineQueryResponse } from '../../dtos/responses/inlineQueryResponse';
3
4
  export class InlineQueryAction {
4
5
  key;
5
6
  isActiveProvider;
@@ -14,8 +15,6 @@ export class InlineQueryAction {
14
15
  this.key = `inline:${this.name.replace('.', '-')}`;
15
16
  }
16
17
  async exec(ctx) {
17
- if (!ctx.isInitialized)
18
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
19
18
  if (!this.isActiveProvider(ctx))
20
19
  return Noop.NoResponse;
21
20
  const matchResults = [];
@@ -46,6 +45,8 @@ export class InlineQueryAction {
46
45
  action: this,
47
46
  ctx
48
47
  });
49
- return ctx.responses;
48
+ return [
49
+ new InlineQueryResponse(ctx.queryResults, ctx.queryId, ctx.traceId, ctx.action)
50
+ ];
50
51
  }
51
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/replyCaptureAction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,qBAAa,kBAAkB,CAAC,kBAAkB,SAAS,YAAY,CACnE,YAAW,OAAO;IAElB,QAAQ,CAAC,eAAe,E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,CAAC;gBAGtC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,EAClB,QAAQ,EAAE,cAAc,EAAE,EAC1B,eAAe,EAAE,eAAe;IAY9B,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,CAAC;IAyBxD,OAAO,CAAC,uBAAuB;CA4ClC"}
@@ -17,8 +17,6 @@ export class ReplyCaptureAction {
17
17
  .replace('.', '')}`;
18
18
  }
19
19
  async exec(ctx) {
20
- if (!ctx.isInitialized)
21
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
22
20
  const { shouldExecute, matchResults } = this.triggers
23
21
  .map((x) => this.checkIfShouldBeExecuted(ctx, x))
24
22
  .reduce((acc, curr) => acc.mergeWith(curr), CommandTriggerCheckResult.DoNotTrigger('Other'));
@@ -1 +1 @@
1
- {"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,qBAAa,eAAe,CACxB,YAAY,SAAS,YAAY,CACnC,YAAW,gBAAgB,CAAC,YAAY,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAgC;IAErD,QAAQ,CAAC,IAA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xB,YAAY,SAAS,YAAY,CACnC,YAAW,gBAAgB,CAAC,YAAY,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAgC;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA8C;IAClF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2C;IAC1E,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IAEF,QAAQ,CAAC,WAAW,uBAA8B;IAClD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG7C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,SAAS,EAAE,wBAAwB,EACnC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAclC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,CAAC;YA2CnC,cAAc;IA2D5B,OAAO,CAAC,uBAAuB;CAgBlC"}
@@ -26,8 +26,6 @@ export class ScheduledAction {
26
26
  this.handler = handler;
27
27
  }
28
28
  async exec(ctx) {
29
- if (!ctx.isInitialized)
30
- throw new Error(`Context for ${this.key} is not initialized or already consumed`);
31
29
  if (!this.activeProvider(ctx) ||
32
30
  !this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
33
31
  return Noop.NoResponse;
@@ -9,25 +9,21 @@ import { IStorageClient } from '../../types/storage';
9
9
  import { TraceId } from '../../types/trace';
10
10
  export type BaseContextPropertiesToOmit = 'action' | 'isInitialized' | 'storage' | 'scheduler' | 'eventEmitter' | 'responses' | 'traceId';
11
11
  export declare abstract class BaseContextInternal<TAction extends IAction> {
12
- isInitialized: boolean;
13
- private _responses;
14
- action: TAction;
12
+ readonly responses: BotResponse[];
13
+ readonly action: TAction;
15
14
  /** Storage client instance for the bot executing this action. */
16
15
  readonly storage: IStorageClient;
17
16
  /** Scheduler instance for the bot executing this action */
18
17
  readonly scheduler: IScheduler;
19
18
  readonly eventEmitter: TypedEventEmitter;
20
19
  /** Trace id of a action execution. */
21
- traceId: TraceId;
20
+ readonly traceId: TraceId;
22
21
  /** Name of a bot that executes this action. */
23
- botName: string;
22
+ readonly botName: string;
24
23
  /** Chat information. */
25
- chatInfo: ChatInfo;
24
+ readonly chatInfo: ChatInfo;
26
25
  get actionKey(): import("../..").ActionKey;
27
- /** Ordered collection of responses to be processed */
28
- get responses(): BotResponse[];
29
- set responses(value: BotResponse[]);
30
- constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter);
26
+ constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: TAction, chatInfo: ChatInfo, traceId: TraceId, botName: string);
31
27
  protected createCaptureController(response: IReplyResponse): ICaptureController;
32
28
  /**
33
29
  * Loads state of another action for current chat.
@@ -1 +1 @@
1
- {"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../src/entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAA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AAU,EACrB,YAAY,EAAE,iBAAiB,EAC/B,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM;IAWnB,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;;;OAIG;IACH,WAAW,CAAC,mBAAmB,SAAS,YAAY,EAChD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;IASjD;;;;;OAKG;IACG,aAAa,CAAC,mBAAmB,SAAS,YAAY,EACxD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,EAC7C,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC;CAI9D"}
@@ -1,6 +1,5 @@
1
1
  export class BaseContextInternal {
2
- isInitialized = false;
3
- _responses = [];
2
+ responses = [];
4
3
  action;
5
4
  /** Storage client instance for the bot executing this action. */
6
5
  storage;
@@ -16,17 +15,14 @@ export class BaseContextInternal {
16
15
  get actionKey() {
17
16
  return this.action.key;
18
17
  }
19
- /** Ordered collection of responses to be processed */
20
- get responses() {
21
- return this._responses;
22
- }
23
- set responses(value) {
24
- this._responses = value;
25
- }
26
- constructor(storage, scheduler, eventEmitter) {
18
+ constructor(storage, scheduler, eventEmitter, action, chatInfo, traceId, botName) {
27
19
  this.storage = storage;
28
20
  this.scheduler = scheduler;
29
21
  this.eventEmitter = eventEmitter;
22
+ this.botName = botName;
23
+ this.action = action;
24
+ this.chatInfo = chatInfo;
25
+ this.traceId = traceId;
30
26
  }
31
27
  createCaptureController(response) {
32
28
  return {
@@ -48,7 +44,7 @@ export class BaseContextInternal {
48
44
  loadStateOf(action) {
49
45
  const allStates = this.storage.load(action);
50
46
  const stateForChat = allStates[this.chatInfo.id] ?? action.stateConstructor();
51
- return Object.freeze(stateForChat);
47
+ return Object.freeze(structuredClone(stateForChat));
52
48
  }
53
49
  /**
54
50
  * Mutates state of another action for current chat.
@@ -1,23 +1,26 @@
1
- import { BotResponse } from '../../types/response';
2
1
  import { InlineQueryAction } from '../actions/inlineQueryAction';
3
2
  import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
4
3
  import { TelegramInlineQueryResult } from '../../types/externalAliases';
4
+ import { TypedEventEmitter } from '../../types/events';
5
+ import { IScheduler } from '../../types/scheduler';
6
+ import { IStorageClient } from '../../types/storage';
7
+ import { ChatInfo } from '../../dtos/chatInfo';
8
+ import { IncomingInlineQuery } from '../../dtos/incomingQuery';
5
9
  export type InlineQueryContext = Omit<InlineQueryContextInternal, BaseContextPropertiesToOmit | 'queryResults' | 'queryId'>;
6
10
  export declare class InlineQueryContextInternal extends BaseContextInternal<InlineQueryAction> {
7
- queryResults: TelegramInlineQueryResult[];
11
+ readonly queryResults: TelegramInlineQueryResult[];
8
12
  /**
9
13
  * Abort signal to be utilized in query handler.
10
14
  * Signal will be aborted if new query comes from the same user.
11
15
  */
12
- abortSignal: AbortSignal;
13
- /** Ordered collection of responses to be processed */
14
- get responses(): BotResponse[];
16
+ readonly abortSignal: AbortSignal;
15
17
  /** Inline query text */
16
- queryText: string;
18
+ readonly queryText: string;
17
19
  /** Internal query id */
18
- queryId: string;
20
+ readonly queryId: string;
19
21
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
20
22
  matchResults: RegExpMatchArray[];
23
+ constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: InlineQueryAction, query: IncomingInlineQuery, chatInfo: ChatInfo, botName: string);
21
24
  /**
22
25
  * This result will be shown to user as a response to inline query.
23
26
  * @param queryResult Inline query result to be shown to user.
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../src/entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8B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B,GAAG,cAAc,GAAG,SAAS,CAC3D,CAAC;AAEF,qBAAa,0BAA2B,SAAQ,mBAAmB,CAAC,iBAAiB,CAAC;IAClF,QAAQ,CAAC,YAAY,EAAE,yBAAyB,EAAE,CAAM;IACxD;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,wBAAwB;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wBAAwB;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;gBAGlC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,iBAAiB,EAC/B,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,mBAAmB,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM;IAiBnB;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,yBAAyB;CAG/D"}
@@ -1,4 +1,3 @@
1
- import { InlineQueryResponse } from '../../dtos/responses/inlineQueryResponse';
2
1
  import { BaseContextInternal } from './baseContext';
3
2
  export class InlineQueryContextInternal extends BaseContextInternal {
4
3
  queryResults = [];
@@ -7,18 +6,18 @@ export class InlineQueryContextInternal extends BaseContextInternal {
7
6
  * Signal will be aborted if new query comes from the same user.
8
7
  */
9
8
  abortSignal;
10
- /** Ordered collection of responses to be processed */
11
- get responses() {
12
- return [
13
- new InlineQueryResponse(this.queryResults, this.queryId, this.traceId, this.action)
14
- ];
15
- }
16
9
  /** Inline query text */
17
10
  queryText;
18
11
  /** Internal query id */
19
12
  queryId;
20
13
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
21
14
  matchResults = [];
15
+ constructor(storage, scheduler, eventEmitter, action, query, chatInfo, botName) {
16
+ super(storage, scheduler, eventEmitter, action, chatInfo, query.traceId, botName);
17
+ this.queryText = query.query;
18
+ this.queryId = query.queryId;
19
+ this.abortSignal = query.abortController.signal;
20
+ }
22
21
  /**
23
22
  * This result will be shown to user as a response to inline query.
24
23
  * @param queryResult Inline query result to be shown to user.
@@ -7,22 +7,28 @@ import { BaseContextPropertiesToOmit } from './baseContext';
7
7
  import { MessageInfo } from '../../dtos/messageInfo';
8
8
  import { UserInfo } from '../../dtos/userInfo';
9
9
  import { BotInfo, TelegramEmoji } from '../../types/externalAliases';
10
+ import { TypedEventEmitter } from '../../types/events';
11
+ import { IScheduler } from '../../types/scheduler';
12
+ import { IStorageClient } from '../../types/storage';
13
+ import { IncomingMessage } from '../../dtos/incomingMessage';
10
14
  export type MessageContext<TActionState extends IActionState> = Omit<MessageContextInternal<TActionState>, BaseContextPropertiesToOmit | 'startCooldown' | 'customCooldown'>;
11
15
  /**
12
16
  * Context of action executed in chat, in response to a message
13
17
  */
14
18
  export declare class MessageContextInternal<TActionState extends IActionState> extends ChatContextInternal<TActionState, CommandAction<TActionState>> {
15
19
  /** Information about the user that triggered this action */
16
- userInfo: UserInfo;
20
+ readonly userInfo: UserInfo;
17
21
  /** Information about the message that triggered this action */
18
- messageInfo: MessageInfo;
19
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
20
- matchResults: RegExpMatchArray[];
22
+ readonly messageInfo: MessageInfo;
23
+ /** Bot info from Telegram */
24
+ readonly botInfo: BotInfo;
21
25
  /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
22
26
  startCooldown: boolean;
23
- /** Bot info from Telegram */
24
- botInfo: BotInfo;
27
+ /** Custom cooldown duration in seconds, if specified. */
25
28
  customCooldown: Seconds | undefined;
29
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
30
+ matchResults: RegExpMatchArray[];
31
+ constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: CommandAction<TActionState>, message: IncomingMessage, botName: string, botInfo: BotInfo);
26
32
  private getQuotePart;
27
33
  private replyWithText;
28
34
  private reply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5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -5,6 +5,8 @@ import { TextMessage } from '../../dtos/responses/textMessage';
5
5
  import { VideoMessage } from '../../dtos/responses/videoMessage';
6
6
  import { ChatContextInternal } from './chatContext';
7
7
  import { ReplyInfo } from '../../dtos/replyInfo';
8
+ import { MessageInfo } from '../../dtos/messageInfo';
9
+ import { UserInfo } from '../../dtos/userInfo';
8
10
  /**
9
11
  * Context of action executed in chat, in response to a message
10
12
  */
@@ -13,13 +15,21 @@ export class MessageContextInternal extends ChatContextInternal {
13
15
  userInfo;
14
16
  /** Information about the message that triggered this action */
15
17
  messageInfo;
16
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
17
- matchResults = [];
18
- /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
19
- startCooldown = true;
20
18
  /** Bot info from Telegram */
21
19
  botInfo;
20
+ /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
21
+ startCooldown = true;
22
+ /** Custom cooldown duration in seconds, if specified. */
22
23
  customCooldown;
24
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
25
+ matchResults = [];
26
+ constructor(storage, scheduler, eventEmitter, action, message, botName, botInfo) {
27
+ super(storage, scheduler, eventEmitter, action, message.chatInfo, message.traceId, botName);
28
+ this.messageInfo = new MessageInfo(message.messageId, message.text, message.type, message.updateObject);
29
+ this.userInfo = new UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
30
+ (message.from?.last_name ? ` ${message.from.last_name}` : ''));
31
+ this.botInfo = botInfo;
32
+ }
23
33
  getQuotePart(quote) {
24
34
  if (typeof quote != 'boolean')
25
35
  return quote;
@@ -4,20 +4,24 @@ import { ReplyCaptureAction } from '../actions/replyCaptureAction';
4
4
  import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
5
5
  import { UserInfo } from '../../dtos/userInfo';
6
6
  import { MessageInfo } from '../../dtos/messageInfo';
7
- import { TelegramUser, TelegramEmoji } from '../../types/externalAliases';
7
+ import { TelegramUser, TelegramEmoji, BotInfo } from '../../types/externalAliases';
8
+ import { TypedEventEmitter } from '../../types/events';
9
+ import { IScheduler } from '../../types/scheduler';
10
+ import { IStorageClient } from '../../types/storage';
11
+ import { IncomingMessage } from '../../dtos/incomingMessage';
8
12
  export type ReplyContext<TActionState extends IActionState> = Omit<ReplyContextInternal<TActionState>, BaseContextPropertiesToOmit | 'messageId' | 'startCooldown' | 'customCooldown'>;
9
13
  export declare class ReplyContextInternal<TParentActionState extends IActionState> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
10
14
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
11
15
  matchResults: RegExpExecArray[];
12
16
  /** Id of a message that triggered this action. */
13
- replyMessageId: number | undefined;
17
+ readonly replyMessageId: number | undefined;
14
18
  /** Information about the user that triggered this action */
15
- userInfo: UserInfo;
19
+ readonly userInfo: UserInfo;
16
20
  /** Information about the message that triggered this action */
17
- messageInfo: MessageInfo;
21
+ readonly messageInfo: MessageInfo;
18
22
  /** Bot info from Telegram */
19
- botInfo: TelegramUser;
20
- isInitialized: boolean;
23
+ readonly botInfo: TelegramUser;
24
+ constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: ReplyCaptureAction<TParentActionState>, message: IncomingMessage, botName: string, botInfo: BotInfo);
21
25
  private getQuotePart;
22
26
  private replyWithText;
23
27
  private replyWithImage;
@@ -1 +1 @@
1
- {"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../src/entities/context/replyContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OA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Q,EAAE,QAAQ,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;gBAG3B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,iBAAiB,EAC/B,MAAM,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,EAC9C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO;IA2BpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB;;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"}
@@ -5,9 +5,11 @@ import { TextMessage } from '../../dtos/responses/textMessage';
5
5
  import { VideoMessage } from '../../dtos/responses/videoMessage';
6
6
  import { resolve } from 'path';
7
7
  import { BaseContextInternal } from './baseContext';
8
+ import { UserInfo } from '../../dtos/userInfo';
9
+ import { MessageInfo } from '../../dtos/messageInfo';
8
10
  export class ReplyContextInternal extends BaseContextInternal {
9
11
  /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
10
- matchResults;
12
+ matchResults = [];
11
13
  /** Id of a message that triggered this action. */
12
14
  replyMessageId;
13
15
  /** Information about the user that triggered this action */
@@ -16,7 +18,14 @@ export class ReplyContextInternal extends BaseContextInternal {
16
18
  messageInfo;
17
19
  /** Bot info from Telegram */
18
20
  botInfo;
19
- isInitialized = false;
21
+ constructor(storage, scheduler, eventEmitter, action, message, botName, botInfo) {
22
+ super(storage, scheduler, eventEmitter, action, message.chatInfo, message.traceId, botName);
23
+ this.replyMessageId = message.replyToMessageId;
24
+ this.messageInfo = new MessageInfo(message.messageId, message.text, message.type, message.updateObject);
25
+ this.userInfo = new UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
26
+ (message.from?.last_name ? ` ${message.from.last_name}` : ''));
27
+ this.botInfo = botInfo;
28
+ }
20
29
  getQuotePart(quote) {
21
30
  if (typeof quote != 'boolean')
22
31
  return quote;
@@ -25,7 +25,6 @@ export class BaseActionProcessor {
25
25
  try {
26
26
  const responses = await action.exec(ctx);
27
27
  this.api.enqueueBatchedResponses(responses);
28
- ctx.isInitialized = false;
29
28
  }
30
29
  catch (e) {
31
30
  const error = e;
@@ -12,8 +12,6 @@ export declare class CommandActionProcessor extends BaseActionProcessor {
12
12
  private commands;
13
13
  initialize(api: TelegramApiService, telegram: TelegramBot, commands: CommandAction<IActionState>[], botInfo: BotInfo): void;
14
14
  captureRegistrationCallback(capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo): void;
15
- private processMessage;
16
- private initializeReplyCaptureContext;
17
- private initializeMessageContext;
15
+ private startMessageProcessing;
18
16
  }
19
17
  //# sourceMappingURL=commandActionProcessor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../src/services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa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CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,OAAO,CAAW;IAE1B,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,OAAO,EAAE,OAAO;IA+CpB,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ;IA4BtB,OAAO,CAAC,sBAAsB;CA6FjC"}
@@ -6,8 +6,6 @@ import { INTERNAL_MESSAGE_TYPE_PREFIX, MessageType } from '../../types/messageTy
6
6
  import { typeSafeObjectFromEntries } from '../../helpers/objectFromEntries';
7
7
  import { BaseActionProcessor } from './baseProcessor';
8
8
  import { getOrSetIfNotExists } from '../../helpers/mapUtils';
9
- import { MessageInfo } from '../../dtos/messageInfo';
10
- import { UserInfo } from '../../dtos/userInfo';
11
9
  import { ChatHistoryMessage } from '../../dtos/chatHistoryMessage';
12
10
  import { BotEventType } from '../../types/events';
13
11
  const MESSAGE_HISTORY_LENGTH_LIMIT = 100;
@@ -35,17 +33,13 @@ export class CommandActionProcessor extends BaseActionProcessor {
35
33
  cmd.triggers.includes(MessageType.Any));
36
34
  }
37
35
  if (commands.length > 0) {
38
- telegram.on('message', async ({ message }) => {
36
+ telegram.on('message', ({ message }) => {
39
37
  const internalMessage = new IncomingMessage(message, this.botName, getOrSetIfNotExists(this.chatHistory, message.chat.id, []));
40
38
  this.eventEmitter.emit(BotEventType.messageRecieved, {
41
39
  botInfo: this.botInfo,
42
40
  message: internalMessage
43
41
  });
44
- await this.processMessage(internalMessage);
45
- this.eventEmitter.emit(BotEventType.messageProcessingFinished, {
46
- botInfo: this.botInfo,
47
- message: internalMessage
48
- });
42
+ this.startMessageProcessing(internalMessage);
49
43
  });
50
44
  }
51
45
  }
@@ -65,7 +59,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
65
59
  });
66
60
  });
67
61
  }
68
- async processMessage(msg) {
62
+ startMessageProcessing(msg) {
69
63
  this.eventEmitter.emit(BotEventType.messageProcessingStarted, {
70
64
  botInfo: this.botInfo,
71
65
  message: msg
@@ -74,7 +68,6 @@ export class CommandActionProcessor extends BaseActionProcessor {
74
68
  while (chatHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
75
69
  chatHistoryArray.shift();
76
70
  chatHistoryArray.push(new ChatHistoryMessage(msg.messageId, msg.from, msg.text, msg.type, msg.traceId, msg.replyToMessageId, msg.updateObject.date));
77
- const ctx = new MessageContextInternal(this.storage, this.scheduler, this.eventEmitter);
78
71
  const commandsToCheck = new Set(this.commands[msg.type]);
79
72
  if (msg.type != MessageType.Text && msg.text != '') {
80
73
  for (const command of this.commands[MessageType.Text]) {
@@ -86,49 +79,32 @@ export class CommandActionProcessor extends BaseActionProcessor {
86
79
  message: msg,
87
80
  commands: commandsToCheck
88
81
  });
89
- for (const commandAction of commandsToCheck) {
90
- this.initializeMessageContext(ctx, commandAction, msg);
82
+ const promises = [...commandsToCheck].map((command) => {
83
+ const ctx = new MessageContextInternal(this.storage, this.scheduler, this.eventEmitter, command, msg, this.botName, this.botInfo);
91
84
  const { proxy, revoke } = Proxy.revocable(ctx, {});
92
- await this.executeAction(commandAction, proxy);
93
- revoke();
94
- }
85
+ const executePromise = this.executeAction(command, proxy);
86
+ return executePromise.finally(() => {
87
+ revoke();
88
+ this.api.flushResponses();
89
+ });
90
+ });
95
91
  if (this.replyCaptures.length != 0) {
96
- const replyCtx = new ReplyContextInternal(this.storage, this.scheduler, this.eventEmitter);
97
- for (const replyAction of this.replyCaptures) {
98
- this.initializeReplyCaptureContext(replyCtx, replyAction, msg);
92
+ const replyPromises = this.replyCaptures.map((capture) => {
93
+ const replyCtx = new ReplyContextInternal(this.storage, this.scheduler, this.eventEmitter, capture, msg, this.botName, this.botInfo);
99
94
  const { proxy, revoke } = Proxy.revocable(replyCtx, {});
100
- await this.executeAction(replyAction, proxy);
101
- revoke();
102
- }
95
+ const executePromise = this.executeAction(capture, proxy);
96
+ return executePromise.finally(() => {
97
+ revoke();
98
+ this.api.flushResponses();
99
+ });
100
+ });
101
+ promises.push(...replyPromises);
103
102
  }
104
- this.api.flushResponses();
105
- }
106
- initializeReplyCaptureContext(ctx, action, message) {
107
- ctx.replyMessageId = message.replyToMessageId;
108
- ctx.messageInfo = new MessageInfo(message.messageId, message.text, message.type, message.updateObject);
109
- ctx.userInfo = new UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
110
- (message.from?.last_name ? ` ${message.from.last_name}` : ''));
111
- ctx.botName = this.botName;
112
- ctx.action = action;
113
- ctx.chatInfo = message.chatInfo;
114
- ctx.traceId = message.traceId;
115
- ctx.botInfo = this.botInfo;
116
- ctx.isInitialized = true;
117
- ctx.matchResults = [];
118
- }
119
- initializeMessageContext(ctx, action, message) {
120
- ctx.messageInfo = new MessageInfo(message.messageId, message.text, message.type, message.updateObject);
121
- ctx.userInfo = new UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
122
- (message.from?.last_name ? ` ${message.from.last_name}` : ''));
123
- ctx.matchResults = [];
124
- ctx.startCooldown = true;
125
- ctx.responses = [];
126
- ctx.isInitialized = true;
127
- ctx.botName = this.botName;
128
- ctx.action = action;
129
- ctx.chatInfo = message.chatInfo;
130
- ctx.traceId = message.traceId;
131
- ctx.botInfo = this.botInfo;
132
- ctx.customCooldown = undefined;
103
+ void Promise.allSettled(promises).then(() => {
104
+ this.eventEmitter.emit(BotEventType.messageProcessingFinished, {
105
+ botInfo: this.botInfo,
106
+ message: msg
107
+ });
108
+ });
133
109
  }
134
110
  }
@@ -5,7 +5,8 @@ import { TelegramApiService } from '../telegramApi';
5
5
  import { BaseActionProcessor } from './baseProcessor';
6
6
  export declare class InlineQueryActionProcessor extends BaseActionProcessor {
7
7
  private inlineQueries;
8
+ /** Fake chat info, since inline queries are chat-less */
9
+ private readonly fakeChatInfo;
8
10
  initialize(api: TelegramApiService, telegram: TelegramBot, inlineQueries: InlineQueryAction[], period: Milliseconds): void;
9
- private initializeInlineQueryContext;
10
11
  }
11
12
  //# sourceMappingURL=inlineQueryActionProcessor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../src/services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAI7E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,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;IAE5C,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IA6GxB,OAAO,CAAC,4BAA4B;CAmBvC"}
1
+ {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../src/services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAI7E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,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;IAC5C,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAI3B;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;CAoI3B"}