chz-telegram-bot 0.3.15 → 0.3.17

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 (33) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/builtin/helpAction.d.ts +1 -1
  3. package/dist/builtin/helpAction.d.ts.map +1 -1
  4. package/dist/dtos/incomingMessage.d.ts +1 -0
  5. package/dist/dtos/incomingMessage.d.ts.map +1 -1
  6. package/dist/dtos/incomingMessage.js +6 -6
  7. package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
  8. package/dist/entities/actions/replyCaptureAction.js +3 -4
  9. package/dist/entities/context/messageContext.d.ts +6 -6
  10. package/dist/entities/context/messageContext.js +5 -5
  11. package/dist/entities/context/replyContext.js +5 -5
  12. package/dist/helpers/builders/commandActionBuilder.js +1 -1
  13. package/dist/helpers/noop.d.ts +2 -1
  14. package/dist/helpers/noop.d.ts.map +1 -1
  15. package/dist/helpers/noop.js +6 -1
  16. package/dist/index.d.ts +14 -9
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +14 -11
  19. package/dist/services/actionProcessors/commandActionProcessor.d.ts +1 -1
  20. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  21. package/dist/services/actionProcessors/commandActionProcessor.js +7 -7
  22. package/dist/services/jsonLogger.d.ts.map +1 -1
  23. package/dist/services/jsonLogger.js +4 -1
  24. package/dtos/incomingMessage.ts +7 -6
  25. package/entities/actions/replyCaptureAction.ts +3 -6
  26. package/entities/context/messageContext.ts +5 -5
  27. package/entities/context/replyContext.ts +5 -5
  28. package/helpers/builders/commandActionBuilder.ts +1 -1
  29. package/helpers/noop.ts +7 -3
  30. package/index.ts +14 -9
  31. package/package.json +15 -1
  32. package/services/actionProcessors/commandActionProcessor.ts +10 -8
  33. package/services/jsonLogger.ts +5 -1
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alex Halanin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,2 +1,2 @@
1
- export declare function buildHelpCommand(readmes: string[], botUsername: string): import("../entities/actions/commandAction").CommandAction<import("..").ActionStateBase>;
1
+ export declare function buildHelpCommand(readmes: string[], botUsername: string): import("..").CommandAction<import("..").ActionStateBase>;
2
2
  //# sourceMappingURL=helpAction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpAction.d.ts","sourceRoot":"","sources":["../../builtin/helpAction.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,2FAUtE"}
1
+ {"version":3,"file":"helpAction.d.ts","sourceRoot":"","sources":["../../builtin/helpAction.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,4DAUtE"}
@@ -13,5 +13,6 @@ export declare class IncomingMessage {
13
13
  readonly updateObject: TelegrafContextMessage;
14
14
  private detectMessageType;
15
15
  constructor(ctxMessage: TelegrafContextMessage, botName: string, history: IncomingMessage[]);
16
+ private getMessageText;
16
17
  }
17
18
  //# sourceMappingURL=incomingMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../dtos/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAEH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,eAAe;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;IAE9C,OAAO,CAAC,iBAAiB;gBAqBrB,UAAU,EAAE,sBAAsB,EAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EAAE;CA6BjC"}
1
+ {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../dtos/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAEH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,eAAe;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;IAE9C,OAAO,CAAC,iBAAiB;gBAqBrB,UAAU,EAAE,sBAAsB,EAClC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EAAE;IAyB9B,OAAO,CAAC,cAAc;CAKzB"}
@@ -51,17 +51,17 @@ class IncomingMessage {
51
51
  ? ctxMessage.reply_to_message?.message_id
52
52
  : undefined;
53
53
  this.from = ctxMessage.from;
54
- this.text =
55
- 'text' in ctxMessage
56
- ? ctxMessage.text
57
- : 'caption' in ctxMessage
58
- ? ctxMessage.caption ?? ''
59
- : '';
54
+ this.text = this.getMessageText(ctxMessage);
60
55
  this.chatInfo = new chatInfo_1.ChatInfo(ctxMessage.chat.id, 'title' in ctxMessage.chat
61
56
  ? `${ctxMessage.chat.title} ${ctxMessage.chat.id}`
62
57
  : 'DM', history);
63
58
  this.type = this.detectMessageType(ctxMessage);
64
59
  this.updateObject = ctxMessage;
65
60
  }
61
+ getMessageText(ctxMessage) {
62
+ if ('text' in ctxMessage)
63
+ return ctxMessage.text;
64
+ return 'caption' in ctxMessage ? ctxMessage.caption ?? '' : '';
65
+ }
66
66
  }
67
67
  exports.IncomingMessage = IncomingMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../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,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,qBAAa,kBAAkB,CAAC,kBAAkB,SAAS,YAAY,CACnE,YAAW,OAAO;IAElB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,CACd,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;gBAGtC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,EAClD,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;CA+ClC"}
1
+ {"version":3,"file":"replyCaptureAction.d.ts","sourceRoot":"","sources":["../../../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,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,qBAAa,kBAAkB,CAAC,kBAAkB,SAAS,YAAY,CACnE,YAAW,OAAO;IAElB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,CACd,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;gBAGtC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,EAClD,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"}
@@ -37,10 +37,9 @@ class ReplyCaptureAction {
37
37
  if (trigger == ctx.messageInfo.type)
38
38
  return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
39
39
  if (typeof trigger == 'string')
40
- if (ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase())
41
- return commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger();
42
- else
43
- return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
40
+ return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
41
+ ? commandTriggerCheckResult_1.CommandTriggerCheckResult.Trigger()
42
+ : commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
44
43
  const matchResults = [];
45
44
  trigger.lastIndex = 0;
46
45
  const execResult = trigger.exec(ctx.messageInfo.text);
@@ -44,21 +44,21 @@ export declare class MessageContextInternal<TActionState extends IActionState> e
44
44
  * @param text Message contents.
45
45
  * @param options Message sending option.
46
46
  */
47
- withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => import("../../types/capture").ICaptureController;
47
+ withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
48
48
  /**
49
49
  * Reply with image message to message that triggered this action after action execution is finished.
50
50
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
51
51
  * @param text Message contents.
52
52
  * @param options Message sending option.
53
53
  */
54
- withImage: (name: string, quote?: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
54
+ withImage: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
55
55
  /**
56
56
  * Reply with video/gif message to message that triggered this action after action execution is finished.
57
57
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
58
58
  * @param text Message contents.
59
59
  * @param options Message sending option.
60
60
  */
61
- withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
61
+ withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
62
62
  };
63
63
  /**
64
64
  * Reply with text message to message that triggered this action after action execution is finished.
@@ -66,21 +66,21 @@ export declare class MessageContextInternal<TActionState extends IActionState> e
66
66
  * @param text Message contents.
67
67
  * @param options Message sending option.
68
68
  */
69
- withText: (text: string, options?: TextMessageSendingOptions) => import("../../types/capture").ICaptureController;
69
+ withText: (text: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
70
70
  /**
71
71
  * Reply with image message to message that triggered this action after action execution is finished.
72
72
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
73
73
  * @param text Message contents.
74
74
  * @param options Message sending option.
75
75
  */
76
- withImage: (name: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
76
+ withImage: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
77
77
  /**
78
78
  * Reply with video/gif message to message that triggered this action after action execution is finished.
79
79
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
80
80
  * @param text Message contents.
81
81
  * @param options Message sending option.
82
82
  */
83
- withVideo: (name: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
83
+ withVideo: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
84
84
  /**
85
85
  * React to the message that triggered this action after action execution is finished.
86
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.
@@ -24,11 +24,11 @@ class MessageContextInternal extends chatContext_1.ChatContextInternal {
24
24
  botInfo;
25
25
  customCooldown;
26
26
  getQuotePart(quote) {
27
- return typeof quote == 'boolean'
28
- ? this.matchResults.length != 0
29
- ? this.matchResults[0][1]
30
- : this.messageInfo.text
31
- : quote;
27
+ if (typeof quote != 'boolean')
28
+ return quote;
29
+ return this.matchResults.length != 0
30
+ ? this.matchResults[0][1]
31
+ : this.messageInfo.text;
32
32
  }
33
33
  replyWithText(text, quote, options) {
34
34
  const quotedPart = this.getQuotePart(quote);
@@ -21,11 +21,11 @@ class ReplyContextInternal extends baseContext_1.BaseContextInternal {
21
21
  botInfo;
22
22
  isInitialized = false;
23
23
  getQuotePart(quote) {
24
- return typeof quote == 'boolean'
25
- ? this.matchResults.length != 0
26
- ? this.matchResults[0][1]
27
- : this.messageInfo.text
28
- : quote;
24
+ if (typeof quote != 'boolean')
25
+ return quote;
26
+ return this.matchResults.length != 0
27
+ ? this.matchResults[0][1]
28
+ : this.messageInfo.text;
29
29
  }
30
30
  replyWithText(text, quote, options) {
31
31
  const quotedPart = this.getQuotePart(quote);
@@ -101,7 +101,7 @@ class CommandActionBuilderWithState {
101
101
  }
102
102
  /** Builds action */
103
103
  build() {
104
- return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, new cooldownInfo_1.CooldownInfo(this.cooldownSeconds, this.cooldownMessage), this.blacklist, this.allowedUsers, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory != null ? this.readmeFactory : (_) => '');
104
+ return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, new cooldownInfo_1.CooldownInfo(this.cooldownSeconds, this.cooldownMessage), this.blacklist, this.allowedUsers, this.maxAllowedSimultaniousExecutions, this.condition, this.stateConstructor, this.readmeFactory ?? noop_1.Noop.emptyString);
105
105
  }
106
106
  }
107
107
  exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
@@ -1,8 +1,9 @@
1
1
  import { BotResponse } from '../types/response';
2
2
  export declare class Noop {
3
- static NoResponse: BotResponse[];
3
+ static readonly NoResponse: BotResponse[];
4
4
  static true(arg1: unknown): boolean;
5
5
  static false(arg1: unknown): boolean;
6
+ static emptyString(): string;
6
7
  static call(arg1: unknown): Promise<void>;
7
8
  }
8
9
  //# sourceMappingURL=noop.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,qBAAa,IAAI;IACb,MAAM,CAAC,UAAU,EAAE,WAAW,EAAE,CAAM;IACtC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;IAGzB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO;WAIb,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAElD"}
1
+ {"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,qBAAa,IAAI;IACb,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAAM;IAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;IAGzB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO;IAG1B,MAAM,CAAC,WAAW;WAGL,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}
@@ -11,6 +11,11 @@ class Noop {
11
11
  static false(arg1) {
12
12
  return false;
13
13
  }
14
- static async call(arg1, arg2) { }
14
+ static emptyString() {
15
+ return '';
16
+ }
17
+ static async call(arg1, arg2) {
18
+ return Promise.resolve();
19
+ }
15
20
  }
16
21
  exports.Noop = Noop;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,19 @@
1
- export { botOrchestrator } from './main';
2
- export { InlineQueryActionBuilder } from './helpers/builders/inlineQueryActionBuilder';
3
- export { CommandActionBuilder } from './helpers/builders/commandActionBuilder';
4
- export { CommandActionBuilderWithState } from './helpers/builders/commandActionBuilder';
5
- export { IStorageClient } from './types/storage';
6
- export { ILogger } from './types/logger';
7
- export { IScheduler } from './types/scheduler';
1
+ export * from './main';
2
+ export * from './helpers/builders/inlineQueryActionBuilder';
3
+ export * from './helpers/builders/commandActionBuilder';
8
4
  export * from './helpers/builders/scheduledActionBuilder';
9
5
  export * from './types/actionState';
10
6
  export * from './entities/states/actionStateBase';
7
+ export * from './types/messageTypes';
8
+ export * from './helpers/timeConvertions';
9
+ export { CommandAction } from './entities/actions/commandAction';
10
+ export { InlineQueryAction } from './entities/actions/inlineQueryAction';
11
+ export { ReplyCaptureAction } from './entities/actions/replyCaptureAction';
12
+ export { ScheduledAction } from './entities/actions/scheduledAction';
11
13
  export { Hours, Milliseconds, Seconds } from './types/timeValues';
12
- export { MessageType } from './types/messageTypes';
13
- export { TraceId } from './types/trace';
14
+ export { ChatContext } from './entities/context/chatContext';
15
+ export { InlineQueryContext } from './entities/context/inlineQueryContext';
16
+ export { MessageContext } from './entities/context/messageContext';
17
+ export { ReplyContext } from './entities/context/replyContext';
18
+ export { ICaptureController } from './types/capture';
14
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -14,17 +14,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MessageType = exports.CommandActionBuilderWithState = exports.CommandActionBuilder = exports.InlineQueryActionBuilder = exports.botOrchestrator = void 0;
18
- var main_1 = require("./main");
19
- Object.defineProperty(exports, "botOrchestrator", { enumerable: true, get: function () { return main_1.botOrchestrator; } });
20
- var inlineQueryActionBuilder_1 = require("./helpers/builders/inlineQueryActionBuilder");
21
- Object.defineProperty(exports, "InlineQueryActionBuilder", { enumerable: true, get: function () { return inlineQueryActionBuilder_1.InlineQueryActionBuilder; } });
22
- var commandActionBuilder_1 = require("./helpers/builders/commandActionBuilder");
23
- Object.defineProperty(exports, "CommandActionBuilder", { enumerable: true, get: function () { return commandActionBuilder_1.CommandActionBuilder; } });
24
- var commandActionBuilder_2 = require("./helpers/builders/commandActionBuilder");
25
- Object.defineProperty(exports, "CommandActionBuilderWithState", { enumerable: true, get: function () { return commandActionBuilder_2.CommandActionBuilderWithState; } });
17
+ exports.ScheduledAction = exports.ReplyCaptureAction = exports.InlineQueryAction = exports.CommandAction = void 0;
18
+ __exportStar(require("./main"), exports);
19
+ __exportStar(require("./helpers/builders/inlineQueryActionBuilder"), exports);
20
+ __exportStar(require("./helpers/builders/commandActionBuilder"), exports);
26
21
  __exportStar(require("./helpers/builders/scheduledActionBuilder"), exports);
27
22
  __exportStar(require("./types/actionState"), exports);
28
23
  __exportStar(require("./entities/states/actionStateBase"), exports);
29
- var messageTypes_1 = require("./types/messageTypes");
30
- Object.defineProperty(exports, "MessageType", { enumerable: true, get: function () { return messageTypes_1.MessageType; } });
24
+ __exportStar(require("./types/messageTypes"), exports);
25
+ __exportStar(require("./helpers/timeConvertions"), exports);
26
+ var commandAction_1 = require("./entities/actions/commandAction");
27
+ Object.defineProperty(exports, "CommandAction", { enumerable: true, get: function () { return commandAction_1.CommandAction; } });
28
+ var inlineQueryAction_1 = require("./entities/actions/inlineQueryAction");
29
+ Object.defineProperty(exports, "InlineQueryAction", { enumerable: true, get: function () { return inlineQueryAction_1.InlineQueryAction; } });
30
+ var replyCaptureAction_1 = require("./entities/actions/replyCaptureAction");
31
+ Object.defineProperty(exports, "ReplyCaptureAction", { enumerable: true, get: function () { return replyCaptureAction_1.ReplyCaptureAction; } });
32
+ var scheduledAction_1 = require("./entities/actions/scheduledAction");
33
+ Object.defineProperty(exports, "ScheduledAction", { enumerable: true, get: function () { return scheduledAction_1.ScheduledAction; } });
@@ -9,8 +9,8 @@ import { BaseActionProcessor } from './baseProcessor';
9
9
  import { UserFromGetMe } from 'telegraf/types';
10
10
  export declare class CommandActionProcessor extends BaseActionProcessor {
11
11
  private readonly replyCaptures;
12
+ private readonly chatHistory;
12
13
  private botInfo;
13
- private lastMessages;
14
14
  private commands;
15
15
  initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean, botInfo: UserFromGetMe): void;
16
16
  captureRegistrationCallback(capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId): 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;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,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;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO/C,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,YAAY,CAAwC;IAE5D,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO,EACzC,OAAO,EAAE,aAAa;IA2D1B,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YA+BN,cAAc;IA0C5B,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,wBAAwB;CAmCnC"}
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;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,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;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO/C,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IACpE,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO,EACzC,OAAO,EAAE,aAAa;IA2D1B,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YAgCN,cAAc;IA2C5B,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,wBAAwB;CAmCnC"}
@@ -14,8 +14,8 @@ const userInfo_1 = require("../../dtos/userInfo");
14
14
  const MESSAGE_HISTORY_LENGTH_LIMIT = 100;
15
15
  class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
16
16
  replyCaptures = [];
17
+ chatHistory = new Map();
17
18
  botInfo;
18
- lastMessages = new Map();
19
19
  commands = (0, objectFromEntries_1.typeSafeObjectFromEntries)(Object.values(messageTypes_1.MessageType).map((x) => [
20
20
  x,
21
21
  []
@@ -38,13 +38,13 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
38
38
  }
39
39
  if (commands.length > 0) {
40
40
  telegraf.on('message', (ctx) => {
41
- const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.botName, (0, mapUtils_1.getOrSetIfNotExists)(this.lastMessages, ctx.chat.id, []));
41
+ const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.botName, (0, mapUtils_1.getOrSetIfNotExists)(this.chatHistory, ctx.chat.id, []));
42
42
  const logger = this.logger.createScope(this.botName, msg.traceId, msg.chatInfo.name);
43
43
  if (verboseLoggingForIncomingMessage) {
44
44
  logger.logObjectWithTraceId(ctx.update.message);
45
45
  }
46
46
  else {
47
- logger.logWithTraceId(`${msg.from?.first_name ?? 'Unknown'} (${msg.from?.id ?? 'Unknown'}): ${msg.text || `<non-text message: ${msg.type}>`}`);
47
+ logger.logWithTraceId(`${msg.from?.first_name ?? 'Unknown'} (${msg.from?.id ?? 'Unknown'}): ${msg.text || msg.type}`);
48
48
  }
49
49
  void this.processMessage(msg);
50
50
  });
@@ -62,10 +62,10 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
62
62
  });
63
63
  }
64
64
  async processMessage(msg) {
65
- const messageHistoryArray = (0, mapUtils_1.getOrSetIfNotExists)(this.lastMessages, msg.chatInfo.id, []);
66
- if (messageHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
67
- messageHistoryArray.shift();
68
- messageHistoryArray.push(msg);
65
+ const chatHistoryArray = (0, mapUtils_1.getOrSetIfNotExists)(this.chatHistory, msg.chatInfo.id, []);
66
+ while (chatHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
67
+ chatHistoryArray.shift();
68
+ chatHistoryArray.push(msg);
69
69
  const ctx = new messageContext_1.MessageContextInternal(this.storage, this.scheduler);
70
70
  const commandsToCheck = new Set(this.commands[msg.type]);
71
71
  if (msg.type != messageTypes_1.MessageType.Text && msg.text != '') {
@@ -1 +1 @@
1
- {"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAQtB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;CAQ1B"}
1
+ {"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAQtB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;CAY1B"}
@@ -32,7 +32,10 @@ class JsonLogger {
32
32
  console.log(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","text":"${text}"}`);
33
33
  }
34
34
  errorWithTraceId(botName, traceId, chatName, errorObj, extraData) {
35
- console.error(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(errorObj)}${extraData ? `,"extraData":${JSON.stringify(extraData)}` : ''}}`);
35
+ const dataString = extraData
36
+ ? `,"extraData":${JSON.stringify(extraData)}`
37
+ : '';
38
+ console.error(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(errorObj)}${dataString}}`);
36
39
  }
37
40
  }
38
41
  exports.JsonLogger = JsonLogger;
@@ -56,12 +56,7 @@ export class IncomingMessage {
56
56
  ? ctxMessage.reply_to_message?.message_id
57
57
  : undefined;
58
58
  this.from = ctxMessage.from;
59
- this.text =
60
- 'text' in ctxMessage
61
- ? ctxMessage.text
62
- : 'caption' in ctxMessage
63
- ? ctxMessage.caption ?? ''
64
- : '';
59
+ this.text = this.getMessageText(ctxMessage);
65
60
  this.chatInfo = new ChatInfo(
66
61
  ctxMessage.chat.id,
67
62
  'title' in ctxMessage.chat
@@ -72,4 +67,10 @@ export class IncomingMessage {
72
67
  this.type = this.detectMessageType(ctxMessage);
73
68
  this.updateObject = ctxMessage;
74
69
  }
70
+
71
+ private getMessageText(ctxMessage: TelegrafContextMessage) {
72
+ if ('text' in ctxMessage) return ctxMessage.text;
73
+
74
+ return 'caption' in ctxMessage ? ctxMessage.caption ?? '' : '';
75
+ }
75
76
  }
@@ -73,12 +73,9 @@ export class ReplyCaptureAction<TParentActionState extends IActionState>
73
73
  return CommandTriggerCheckResult.Trigger();
74
74
 
75
75
  if (typeof trigger == 'string')
76
- if (ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase())
77
- return CommandTriggerCheckResult.Trigger();
78
- else
79
- return CommandTriggerCheckResult.DoNotTrigger(
80
- 'TriggerNotSatisfied'
81
- );
76
+ return ctx.messageInfo.text.toLowerCase() == trigger.toLowerCase()
77
+ ? CommandTriggerCheckResult.Trigger()
78
+ : CommandTriggerCheckResult.DoNotTrigger('TriggerNotSatisfied');
82
79
 
83
80
  const matchResults: RegExpExecArray[] = [];
84
81
 
@@ -41,11 +41,11 @@ export class MessageContextInternal<
41
41
  customCooldown: Seconds | undefined;
42
42
 
43
43
  private getQuotePart(quote: boolean | string) {
44
- return typeof quote == 'boolean'
45
- ? this.matchResults.length != 0
46
- ? this.matchResults[0][1]
47
- : this.messageInfo.text
48
- : quote;
44
+ if (typeof quote != 'boolean') return quote;
45
+
46
+ return this.matchResults.length != 0
47
+ ? this.matchResults[0][1]
48
+ : this.messageInfo.text;
49
49
  }
50
50
 
51
51
  private replyWithText(
@@ -43,11 +43,11 @@ export class ReplyContextInternal<
43
43
  isInitialized = false;
44
44
 
45
45
  private getQuotePart(quote: boolean | string) {
46
- return typeof quote == 'boolean'
47
- ? this.matchResults.length != 0
48
- ? this.matchResults[0][1]
49
- : this.messageInfo.text
50
- : quote;
46
+ if (typeof quote != 'boolean') return quote;
47
+
48
+ return this.matchResults.length != 0
49
+ ? this.matchResults[0][1]
50
+ : this.messageInfo.text;
51
51
  }
52
52
 
53
53
  private replyWithText(
@@ -138,7 +138,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
138
138
  this.maxAllowedSimultaniousExecutions,
139
139
  this.condition,
140
140
  this.stateConstructor,
141
- this.readmeFactory != null ? this.readmeFactory : (_) => ''
141
+ this.readmeFactory ?? Noop.emptyString
142
142
  );
143
143
  }
144
144
  }
package/helpers/noop.ts CHANGED
@@ -3,14 +3,18 @@ import { BotResponse } from '../types/response';
3
3
  /* eslint-disable @typescript-eslint/no-unused-vars */
4
4
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
5
5
  export class Noop {
6
- static NoResponse: BotResponse[] = [];
6
+ static readonly NoResponse: BotResponse[] = [];
7
7
  static true(arg1: unknown) {
8
8
  return true;
9
9
  }
10
10
  static false(arg1: unknown) {
11
11
  return false;
12
12
  }
13
-
13
+ static emptyString() {
14
+ return '';
15
+ }
14
16
  static async call(arg1: unknown): Promise<void>;
15
- static async call(arg1: unknown, arg2?: unknown) {}
17
+ static async call(arg1: unknown, arg2?: unknown) {
18
+ return Promise.resolve();
19
+ }
16
20
  }
package/index.ts CHANGED
@@ -1,13 +1,18 @@
1
- export { botOrchestrator } from './main';
2
- export { InlineQueryActionBuilder } from './helpers/builders/inlineQueryActionBuilder';
3
- export { CommandActionBuilder } from './helpers/builders/commandActionBuilder';
4
- export { CommandActionBuilderWithState } from './helpers/builders/commandActionBuilder';
5
- export { IStorageClient } from './types/storage';
6
- export { ILogger } from './types/logger';
7
- export { IScheduler } from './types/scheduler';
1
+ export * from './main';
2
+ export * from './helpers/builders/inlineQueryActionBuilder';
3
+ export * from './helpers/builders/commandActionBuilder';
8
4
  export * from './helpers/builders/scheduledActionBuilder';
9
5
  export * from './types/actionState';
10
6
  export * from './entities/states/actionStateBase';
7
+ export * from './types/messageTypes';
8
+ export * from './helpers/timeConvertions';
9
+ export { CommandAction } from './entities/actions/commandAction';
10
+ export { InlineQueryAction } from './entities/actions/inlineQueryAction';
11
+ export { ReplyCaptureAction } from './entities/actions/replyCaptureAction';
12
+ export { ScheduledAction } from './entities/actions/scheduledAction';
11
13
  export { Hours, Milliseconds, Seconds } from './types/timeValues';
12
- export { MessageType } from './types/messageTypes';
13
- export { TraceId } from './types/trace';
14
+ export { ChatContext } from './entities/context/chatContext';
15
+ export { InlineQueryContext } from './entities/context/inlineQueryContext';
16
+ export { MessageContext } from './entities/context/messageContext';
17
+ export { ReplyContext } from './entities/context/replyContext';
18
+ export { ICaptureController } from './types/capture';
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.3.15",
3
+ "description": "Opinionated TypeScript framework that provides a structured approach to building Telegram bots.",
4
+ "author": {
5
+ "name": "Alex Halanin",
6
+ "url": "https://github.com/AlexSolari"
7
+ },
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "telegram",
11
+ "telegram bot"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/AlexSolari/botFramework.git"
16
+ },
17
+ "version": "0.3.17",
4
18
  "type": "module",
5
19
  "dependencies": {
6
20
  "async-sema": "^3.1.1",
@@ -24,8 +24,8 @@ const MESSAGE_HISTORY_LENGTH_LIMIT = 100;
24
24
 
25
25
  export class CommandActionProcessor extends BaseActionProcessor {
26
26
  private readonly replyCaptures: ReplyCaptureAction<IActionState>[] = [];
27
+ private readonly chatHistory = new Map<number, IncomingMessage[]>();
27
28
  private botInfo!: UserFromGetMe;
28
- private lastMessages = new Map<number, IncomingMessage[]>();
29
29
 
30
30
  private commands = typeSafeObjectFromEntries(
31
31
  Object.values(MessageType).map((x) => [
@@ -74,7 +74,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
74
74
  const msg = new IncomingMessage(
75
75
  ctx.update.message,
76
76
  this.botName,
77
- getOrSetIfNotExists(this.lastMessages, ctx.chat.id, [])
77
+ getOrSetIfNotExists(this.chatHistory, ctx.chat.id, [])
78
78
  );
79
79
 
80
80
  const logger = this.logger.createScope(
@@ -89,7 +89,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
89
89
  logger.logWithTraceId(
90
90
  `${msg.from?.first_name ?? 'Unknown'} (${
91
91
  msg.from?.id ?? 'Unknown'
92
- }): ${msg.text || `<non-text message: ${msg.type}>`}`
92
+ }): ${msg.text || msg.type}`
93
93
  );
94
94
  }
95
95
 
@@ -133,15 +133,17 @@ export class CommandActionProcessor extends BaseActionProcessor {
133
133
  );
134
134
  });
135
135
  }
136
+
136
137
  private async processMessage(msg: IncomingMessage) {
137
- const messageHistoryArray = getOrSetIfNotExists(
138
- this.lastMessages,
138
+ const chatHistoryArray = getOrSetIfNotExists(
139
+ this.chatHistory,
139
140
  msg.chatInfo.id,
140
141
  []
141
142
  );
142
- if (messageHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
143
- messageHistoryArray.shift();
144
- messageHistoryArray.push(msg);
143
+
144
+ while (chatHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
145
+ chatHistoryArray.shift();
146
+ chatHistoryArray.push(msg);
145
147
 
146
148
  const ctx = new MessageContextInternal<IActionState>(
147
149
  this.storage,
@@ -62,10 +62,14 @@ export class JsonLogger implements ILogger {
62
62
  errorObj: unknown,
63
63
  extraData?: unknown
64
64
  ) {
65
+ const dataString = extraData
66
+ ? `,"extraData":${JSON.stringify(extraData)}`
67
+ : '';
68
+
65
69
  console.error(
66
70
  `{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(
67
71
  errorObj
68
- )}${extraData ? `,"extraData":${JSON.stringify(extraData)}` : ''}}`
72
+ )}${dataString}}`
69
73
  );
70
74
  }
71
75
  }