chz-telegram-bot 0.3.5 → 0.3.7

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.
@@ -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;gBAoBb,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAsBlE"}
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;gBAoBb,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CA2BlE"}
@@ -43,7 +43,12 @@ class IncomingMessage {
43
43
  ? ctxMessage.reply_to_message?.message_id
44
44
  : undefined;
45
45
  this.from = ctxMessage.from;
46
- this.text = 'text' in ctxMessage ? ctxMessage.text : '';
46
+ this.text =
47
+ 'text' in ctxMessage
48
+ ? ctxMessage.text
49
+ : 'caption' in ctxMessage
50
+ ? ctxMessage.caption ?? ''
51
+ : '';
47
52
  this.chatInfo = new chatInfo_1.ChatInfo(ctxMessage.chat.id, 'title' in ctxMessage.chat
48
53
  ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
49
54
  : 'DM');
@@ -26,6 +26,7 @@ export declare class MessageContext<TActionState extends IActionState> extends C
26
26
  /** Message object recieved from Telegram */
27
27
  messageUpdateObject: TelegrafContextMessage;
28
28
  constructor(storage: IStorageClient, scheduler: IScheduler);
29
+ private getQuotePart;
29
30
  private replyWithText;
30
31
  private replyWithImage;
31
32
  private replyWithVideo;
@@ -44,21 +45,21 @@ export declare class MessageContext<TActionState extends IActionState> extends C
44
45
  * @param text Message contents.
45
46
  * @param options Message sending option.
46
47
  */
47
- withText: (text: string, options?: TextMessageSendingOptions) => import("../../types/capture").ICaptureController;
48
+ withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => import("../../types/capture").ICaptureController;
48
49
  /**
49
50
  * Reply with image message to message that triggered this action after action execution is finished.
50
51
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
51
52
  * @param text Message contents.
52
53
  * @param options Message sending option.
53
54
  */
54
- withImage: (name: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
55
+ withImage: (name: string, quote?: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
55
56
  /**
56
57
  * Reply with video/gif message to message that triggered this action after action execution is finished.
57
58
  * 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
59
  * @param text Message contents.
59
60
  * @param options Message sending option.
60
61
  */
61
- withVideo: (name: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
62
+ withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => import("../../types/capture").ICaptureController;
62
63
  };
63
64
  /**
64
65
  * Reply with text message to message that triggered this action after action execution is finished.
@@ -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,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,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B,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;gBAEjC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAEvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAGnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
@@ -33,21 +33,21 @@ class MessageContext extends chatContext_1.ChatContext {
33
33
  * @param text Message contents.
34
34
  * @param options Message sending option.
35
35
  */
36
- withText: (text, options) => this.replyWithText(text, true, options),
36
+ withText: (text, quote, options) => this.replyWithText(text, quote ?? true, options),
37
37
  /**
38
38
  * Reply with image message to message that triggered this action after action execution is finished.
39
39
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
40
40
  * @param text Message contents.
41
41
  * @param options Message sending option.
42
42
  */
43
- withImage: (name, options) => this.replyWithImage(name, true, options),
43
+ withImage: (name, quote, options) => this.replyWithImage(name, quote ?? true, options),
44
44
  /**
45
45
  * Reply with video/gif message to message that triggered this action after action execution is finished.
46
46
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
47
47
  * @param text Message contents.
48
48
  * @param options Message sending option.
49
49
  */
50
- withVideo: (name, options) => this.replyWithVideo(name, true, options)
50
+ withVideo: (name, quote, options) => this.replyWithVideo(name, quote ?? true, options)
51
51
  },
52
52
  /**
53
53
  * Reply with text message to message that triggered this action after action execution is finished.
@@ -80,26 +80,27 @@ class MessageContext extends chatContext_1.ChatContext {
80
80
  }
81
81
  };
82
82
  }
83
+ getQuotePart(quote) {
84
+ return typeof quote == 'boolean'
85
+ ? this.matchResults.length != 0
86
+ ? this.matchResults[0][1]
87
+ : this.messageText
88
+ : quote;
89
+ }
83
90
  replyWithText(text, quote, options) {
84
- const quotedPart = this.matchResults.length != 0
85
- ? this.matchResults[0][1]
86
- : this.messageText;
91
+ const quotedPart = this.getQuotePart(quote);
87
92
  const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
88
93
  this.responses.push(response);
89
94
  return this.createCaptureController(response);
90
95
  }
91
96
  replyWithImage(name, quote, options) {
92
- const quotedPart = this.matchResults.length != 0
93
- ? this.matchResults[0][1]
94
- : this.messageText;
97
+ const quotedPart = this.getQuotePart(quote);
95
98
  const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
96
99
  this.responses.push(response);
97
100
  return this.createCaptureController(response);
98
101
  }
99
102
  replyWithVideo(name, quote, options) {
100
- const quotedPart = this.matchResults.length != 0
101
- ? this.matchResults[0][1]
102
- : this.messageText;
103
+ const quotedPart = this.getQuotePart(quote);
103
104
  const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
104
105
  this.responses.push(response);
105
106
  return this.createCaptureController(response);
@@ -43,6 +43,7 @@ export declare class ReplyContext<TParentActionState extends IActionState> {
43
43
  messageUpdateObject: TelegrafContextMessage;
44
44
  isInitialized: boolean;
45
45
  constructor(storage: IStorageClient, scheduler: IScheduler);
46
+ private getQuotePart;
46
47
  private replyWithText;
47
48
  private replyWithImage;
48
49
  private replyWithVideo;
@@ -65,21 +66,21 @@ export declare class ReplyContext<TParentActionState extends IActionState> {
65
66
  * @param text Message contents.
66
67
  * @param options Message sending option.
67
68
  */
68
- withText: (text: string, options?: TextMessageSendingOptions) => void;
69
+ withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => void;
69
70
  /**
70
71
  * Reply with image message to message that triggered this action after action execution is finished.
71
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.
72
73
  * @param text Message contents.
73
74
  * @param options Message sending option.
74
75
  */
75
- withImage: (name: string, options?: MessageSendingOptions) => void;
76
+ withImage: (name: string, quote?: string, options?: MessageSendingOptions) => void;
76
77
  /**
77
78
  * Reply with video/gif message to message that triggered this action after action execution is finished.
78
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.
79
80
  * @param text Message contents.
80
81
  * @param options Message sending option.
81
82
  */
82
- withVideo: (name: string, options?: MessageSendingOptions) => void;
83
+ withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => void;
83
84
  };
84
85
  /**
85
86
  * Reply with text message to message that triggered this action after action execution is finished.
@@ -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,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAClC,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,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,qBAAa,YAAY,CAAC,kBAAkB,SAAS,YAAY;IAC7D,MAAM,EAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IAEhD,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAE/B,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wDAAwD;IACxD,MAAM,EAAG,aAAa,CAAC;IAEvB,uDAAuD;IACvD,SAAS,EAAE,WAAW,EAAE,CAAM;IAC9B,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC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U;IAK1D,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"}
@@ -27,21 +27,21 @@ class ReplyContext {
27
27
  * @param text Message contents.
28
28
  * @param options Message sending option.
29
29
  */
30
- withText: (text, options) => this.replyWithText(text, true, options),
30
+ withText: (text, quote, options) => this.replyWithText(text, quote ?? true, options),
31
31
  /**
32
32
  * Reply with image message to message that triggered this action after action execution is finished.
33
33
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
34
34
  * @param text Message contents.
35
35
  * @param options Message sending option.
36
36
  */
37
- withImage: (name, options) => this.replyWithImage(name, true, options),
37
+ withImage: (name, quote, options) => this.replyWithImage(name, quote ?? true, options),
38
38
  /**
39
39
  * Reply with video/gif message to message that triggered this action after action execution is finished.
40
40
  * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
41
41
  * @param text Message contents.
42
42
  * @param options Message sending option.
43
43
  */
44
- withVideo: (name, options) => this.replyWithVideo(name, true, options)
44
+ withVideo: (name, quote, options) => this.replyWithVideo(name, quote ?? true, options)
45
45
  },
46
46
  /**
47
47
  * Reply with text message to message that triggered this action after action execution is finished.
@@ -76,24 +76,25 @@ class ReplyContext {
76
76
  this.storage = storage;
77
77
  this.scheduler = scheduler;
78
78
  }
79
+ getQuotePart(quote) {
80
+ return typeof quote == 'boolean'
81
+ ? this.matchResults.length != 0
82
+ ? this.matchResults[0][1]
83
+ : this.messageText
84
+ : quote;
85
+ }
79
86
  replyWithText(text, quote, options) {
80
- const quotedPart = this.matchResults.length != 0
81
- ? this.matchResults[0][1]
82
- : this.messageText;
87
+ const quotedPart = this.getQuotePart(quote);
83
88
  const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
84
89
  this.responses.push(response);
85
90
  }
86
91
  replyWithImage(name, quote, options) {
87
- const quotedPart = this.matchResults.length != 0
88
- ? this.matchResults[0][1]
89
- : this.messageText;
92
+ const quotedPart = this.getQuotePart(quote);
90
93
  const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
91
94
  this.responses.push(response);
92
95
  }
93
96
  replyWithVideo(name, quote, options) {
94
- const quotedPart = this.matchResults.length != 0
95
- ? this.matchResults[0][1]
96
- : this.messageText;
97
+ const quotedPart = this.getQuotePart(quote);
97
98
  const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageId, quote ? quotedPart : undefined), options);
98
99
  this.responses.push(response);
99
100
  }
@@ -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,E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CAAC,wBAAwB;CA8BnC"}
@@ -62,7 +62,11 @@ class CommandActionProcessor {
62
62
  }
63
63
  async processMessage(msg) {
64
64
  const ctx = new messageContext_1.MessageContext(this.storage, this.scheduler);
65
- for (const commandAction of this.commands[msg.type]) {
65
+ const commandsToCheck = new Set(this.commands[msg.type]);
66
+ if (msg.type != messageTypes_1.MessageType.Text && msg.text != '') {
67
+ this.commands[messageTypes_1.MessageType.Text].map((x) => commandsToCheck.add(x));
68
+ }
69
+ for (const commandAction of commandsToCheck) {
66
70
  this.initializeMessageContext(ctx, commandAction, msg);
67
71
  try {
68
72
  const responses = await commandAction.exec(ctx);
@@ -52,7 +52,12 @@ export class IncomingMessage {
52
52
  ? ctxMessage.reply_to_message?.message_id
53
53
  : undefined;
54
54
  this.from = ctxMessage.from;
55
- this.text = 'text' in ctxMessage ? ctxMessage.text : '';
55
+ this.text =
56
+ 'text' in ctxMessage
57
+ ? ctxMessage.text
58
+ : 'caption' in ctxMessage
59
+ ? ctxMessage.caption ?? ''
60
+ : '';
56
61
  this.chatInfo = new ChatInfo(
57
62
  ctxMessage.chat.id,
58
63
  'title' in ctxMessage.chat
@@ -45,15 +45,20 @@ export class MessageContext<
45
45
  super(storage, scheduler);
46
46
  }
47
47
 
48
+ private getQuotePart(quote: boolean | string) {
49
+ return typeof quote == 'boolean'
50
+ ? this.matchResults.length != 0
51
+ ? this.matchResults[0][1]
52
+ : this.messageText
53
+ : quote;
54
+ }
55
+
48
56
  private replyWithText(
49
57
  text: string,
50
- quote: boolean,
58
+ quote: boolean | string,
51
59
  options?: TextMessageSendingOptions
52
60
  ) {
53
- const quotedPart =
54
- this.matchResults.length != 0
55
- ? this.matchResults[0][1]
56
- : this.messageText;
61
+ const quotedPart = this.getQuotePart(quote);
57
62
 
58
63
  const response = new TextMessage(
59
64
  text,
@@ -71,13 +76,10 @@ export class MessageContext<
71
76
 
72
77
  private replyWithImage(
73
78
  name: string,
74
- quote: boolean,
79
+ quote: boolean | string,
75
80
  options?: MessageSendingOptions
76
81
  ) {
77
- const quotedPart =
78
- this.matchResults.length != 0
79
- ? this.matchResults[0][1]
80
- : this.messageText;
82
+ const quotedPart = this.getQuotePart(quote);
81
83
 
82
84
  const response = new ImageMessage(
83
85
  { source: resolve(`./content/${name}.png`) },
@@ -95,13 +97,10 @@ export class MessageContext<
95
97
 
96
98
  private replyWithVideo(
97
99
  name: string,
98
- quote: boolean,
100
+ quote: boolean | string,
99
101
  options?: MessageSendingOptions
100
102
  ) {
101
- const quotedPart =
102
- this.matchResults.length != 0
103
- ? this.matchResults[0][1]
104
- : this.messageText;
103
+ const quotedPart = this.getQuotePart(quote);
105
104
 
106
105
  const response = new VideoMessage(
107
106
  { source: resolve(`./content/${name}.mp4`) },
@@ -132,16 +131,22 @@ export class MessageContext<
132
131
  * @param text Message contents.
133
132
  * @param options Message sending option.
134
133
  */
135
- withText: (text: string, options?: TextMessageSendingOptions) =>
136
- this.replyWithText(text, true, options),
134
+ withText: (
135
+ text: string,
136
+ quote?: string,
137
+ options?: TextMessageSendingOptions
138
+ ) => this.replyWithText(text, quote ?? true, options),
137
139
  /**
138
140
  * Reply with image message to message that triggered this action after action execution is finished.
139
141
  * 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.
140
142
  * @param text Message contents.
141
143
  * @param options Message sending option.
142
144
  */
143
- withImage: (name: string, options?: MessageSendingOptions) =>
144
- this.replyWithImage(name, true, options),
145
+ withImage: (
146
+ name: string,
147
+ quote?: string,
148
+ options?: MessageSendingOptions
149
+ ) => this.replyWithImage(name, quote ?? true, options),
145
150
 
146
151
  /**
147
152
  * Reply with video/gif message to message that triggered this action after action execution is finished.
@@ -149,8 +154,11 @@ export class MessageContext<
149
154
  * @param text Message contents.
150
155
  * @param options Message sending option.
151
156
  */
152
- withVideo: (name: string, options?: MessageSendingOptions) =>
153
- this.replyWithVideo(name, true, options)
157
+ withVideo: (
158
+ name: string,
159
+ quote?: string,
160
+ options?: MessageSendingOptions
161
+ ) => this.replyWithVideo(name, quote ?? true, options)
154
162
  },
155
163
 
156
164
  /**
@@ -65,15 +65,20 @@ export class ReplyContext<TParentActionState extends IActionState> {
65
65
  this.scheduler = scheduler;
66
66
  }
67
67
 
68
+ private getQuotePart(quote: boolean | string) {
69
+ return typeof quote == 'boolean'
70
+ ? this.matchResults.length != 0
71
+ ? this.matchResults[0][1]
72
+ : this.messageText
73
+ : quote;
74
+ }
75
+
68
76
  private replyWithText(
69
77
  text: string,
70
- quote: boolean,
78
+ quote: boolean | string,
71
79
  options?: TextMessageSendingOptions
72
80
  ) {
73
- const quotedPart =
74
- this.matchResults.length != 0
75
- ? this.matchResults[0][1]
76
- : this.messageText;
81
+ const quotedPart = this.getQuotePart(quote);
77
82
 
78
83
  const response = new TextMessage(
79
84
  text,
@@ -89,13 +94,10 @@ export class ReplyContext<TParentActionState extends IActionState> {
89
94
 
90
95
  private replyWithImage(
91
96
  name: string,
92
- quote: boolean,
97
+ quote: boolean | string,
93
98
  options?: MessageSendingOptions
94
99
  ) {
95
- const quotedPart =
96
- this.matchResults.length != 0
97
- ? this.matchResults[0][1]
98
- : this.messageText;
100
+ const quotedPart = this.getQuotePart(quote);
99
101
 
100
102
  const response = new ImageMessage(
101
103
  { source: resolve(`./content/${name}.png`) },
@@ -111,13 +113,10 @@ export class ReplyContext<TParentActionState extends IActionState> {
111
113
 
112
114
  private replyWithVideo(
113
115
  name: string,
114
- quote: boolean,
116
+ quote: boolean | string,
115
117
  options?: MessageSendingOptions
116
118
  ) {
117
- const quotedPart =
118
- this.matchResults.length != 0
119
- ? this.matchResults[0][1]
120
- : this.messageText;
119
+ const quotedPart = this.getQuotePart(quote);
121
120
 
122
121
  const response = new VideoMessage(
123
122
  { source: resolve(`./content/${name}.mp4`) },
@@ -153,16 +152,22 @@ export class ReplyContext<TParentActionState extends IActionState> {
153
152
  * @param text Message contents.
154
153
  * @param options Message sending option.
155
154
  */
156
- withText: (text: string, options?: TextMessageSendingOptions) =>
157
- this.replyWithText(text, true, options),
155
+ withText: (
156
+ text: string,
157
+ quote?: string,
158
+ options?: TextMessageSendingOptions
159
+ ) => this.replyWithText(text, quote ?? true, options),
158
160
  /**
159
161
  * Reply with image message to message that triggered this action after action execution is finished.
160
162
  * 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.
161
163
  * @param text Message contents.
162
164
  * @param options Message sending option.
163
165
  */
164
- withImage: (name: string, options?: MessageSendingOptions) =>
165
- this.replyWithImage(name, true, options),
166
+ withImage: (
167
+ name: string,
168
+ quote?: string,
169
+ options?: MessageSendingOptions
170
+ ) => this.replyWithImage(name, quote ?? true, options),
166
171
 
167
172
  /**
168
173
  * Reply with video/gif message to message that triggered this action after action execution is finished.
@@ -170,8 +175,11 @@ export class ReplyContext<TParentActionState extends IActionState> {
170
175
  * @param text Message contents.
171
176
  * @param options Message sending option.
172
177
  */
173
- withVideo: (name: string, options?: MessageSendingOptions) =>
174
- this.replyWithVideo(name, true, options)
178
+ withVideo: (
179
+ name: string,
180
+ quote?: string,
181
+ options?: MessageSendingOptions
182
+ ) => this.replyWithVideo(name, quote ?? true, options)
175
183
  },
176
184
 
177
185
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",
@@ -153,7 +153,12 @@ export class CommandActionProcessor {
153
153
  this.scheduler
154
154
  );
155
155
 
156
- for (const commandAction of this.commands[msg.type]) {
156
+ const commandsToCheck = new Set(this.commands[msg.type]);
157
+ if (msg.type != MessageType.Text && msg.text != '') {
158
+ this.commands[MessageType.Text].map((x) => commandsToCheck.add(x));
159
+ }
160
+
161
+ for (const commandAction of commandsToCheck) {
157
162
  this.initializeMessageContext(ctx, commandAction, msg);
158
163
 
159
164
  try {