chz-telegram-bot 0.7.18 → 0.7.20
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.
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +2 -1
- package/dist/entities/context/messageContext.d.ts +0 -1
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +4 -10
- package/dist/entities/context/replyContext.d.ts +0 -1
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +5 -11
- package/dist/helpers/getQuotedText.d.ts +8 -0
- package/dist/helpers/getQuotedText.d.ts.map +1 -0
- package/dist/helpers/getQuotedText.js +8 -0
- package/dist/services/actionProcessingService.d.ts.map +1 -1
- package/dist/services/actionProcessingService.js +1 -1
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +1 -2
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +42 -61
- package/dist/services/actionProcessors/scheduledActionProcessor.js +1 -1
- package/dist/services/responseProcessingQueue.d.ts +3 -3
- package/dist/services/responseProcessingQueue.d.ts.map +1 -1
- package/dist/services/responseProcessingQueue.js +12 -10
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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,2BAA2B,CAAC;AACnE,OAAO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Q,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;IA2FzB,OAAO,CAAC,uBAAuB;IA6D/B,OAAO,CAAC,YAAY;CAwCvB"}
|
|
@@ -9,6 +9,7 @@ import { getOrSetIfNotExists } from '../../helpers/mapUtils';
|
|
|
9
9
|
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
10
10
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
11
11
|
import { BotEventType } from '../../types/events';
|
|
12
|
+
const REGEX_MATCH_LIMIT = 100;
|
|
12
13
|
export class CommandAction {
|
|
13
14
|
cooldownInfoProvider;
|
|
14
15
|
isActiveProvider;
|
|
@@ -132,9 +133,9 @@ export class CommandAction {
|
|
|
132
133
|
trigger.lastIndex = 0;
|
|
133
134
|
const execResult = trigger.exec(ctx.messageInfo.text);
|
|
134
135
|
if (execResult != null) {
|
|
135
|
-
let regexMatchLimit = 100;
|
|
136
136
|
matchResults.push(execResult);
|
|
137
137
|
if (trigger.global) {
|
|
138
|
+
let regexMatchLimit = REGEX_MATCH_LIMIT;
|
|
138
139
|
while (regexMatchLimit > 0) {
|
|
139
140
|
const nextResult = trigger.exec(ctx.messageInfo.text);
|
|
140
141
|
if (nextResult == null)
|
|
@@ -29,7 +29,6 @@ export declare class MessageContextInternal<TActionState extends IActionState> e
|
|
|
29
29
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
30
30
|
matchResults: RegExpMatchArray[];
|
|
31
31
|
constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: CommandAction<TActionState>, message: IncomingMessage, botName: string, botInfo: BotInfo);
|
|
32
|
-
private getQuotePart;
|
|
33
32
|
private replyWithText;
|
|
34
33
|
private replyWithImage;
|
|
35
34
|
private replyWithVideo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../src/entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAA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4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,yDAAyD;IACzD,cAAc,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;gBAGlC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,iBAAiB,EAC/B,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,EACnC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO;IA2BpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB,YAAY;IAIZ,mBAAmB,CAAC,cAAc,EAAE,OAAO;IAK3C;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAEvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAGnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
|
|
@@ -7,6 +7,7 @@ import { ChatContextInternal } from './chatContext';
|
|
|
7
7
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
8
8
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
9
9
|
import { UserInfo } from '../../dtos/userInfo';
|
|
10
|
+
import { getQuotedText } from '../../helpers/getQuotedText';
|
|
10
11
|
/**
|
|
11
12
|
* Context of action executed in chat, in response to a message
|
|
12
13
|
*/
|
|
@@ -30,27 +31,20 @@ export class MessageContextInternal extends ChatContextInternal {
|
|
|
30
31
|
(message.from?.last_name ? ` ${message.from.last_name}` : ''));
|
|
31
32
|
this.botInfo = botInfo;
|
|
32
33
|
}
|
|
33
|
-
getQuotePart(quote) {
|
|
34
|
-
if (typeof quote != 'boolean')
|
|
35
|
-
return quote;
|
|
36
|
-
return this.matchResults.length == 0
|
|
37
|
-
? this.messageInfo.text
|
|
38
|
-
: this.matchResults[0][1];
|
|
39
|
-
}
|
|
40
34
|
replyWithText(text, quote, options) {
|
|
41
|
-
const quotedPart = this
|
|
35
|
+
const quotedPart = getQuotedText(this, quote);
|
|
42
36
|
const response = new TextMessage(text, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
43
37
|
this.responses.push(response);
|
|
44
38
|
return this.createCaptureController(response);
|
|
45
39
|
}
|
|
46
40
|
replyWithImage(name, quote, options) {
|
|
47
|
-
const quotedPart = this
|
|
41
|
+
const quotedPart = getQuotedText(this, quote);
|
|
48
42
|
const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
49
43
|
this.responses.push(response);
|
|
50
44
|
return this.createCaptureController(response);
|
|
51
45
|
}
|
|
52
46
|
replyWithVideo(name, quote, options) {
|
|
53
|
-
const quotedPart = this
|
|
47
|
+
const quotedPart = getQuotedText(this, quote);
|
|
54
48
|
const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
55
49
|
this.responses.push(response);
|
|
56
50
|
return this.createCaptureController(response);
|
|
@@ -22,7 +22,6 @@ export declare class ReplyContextInternal<TParentActionState extends IActionStat
|
|
|
22
22
|
/** Bot info from Telegram */
|
|
23
23
|
readonly botInfo: TelegramUser;
|
|
24
24
|
constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter, action: ReplyCaptureAction<TParentActionState>, message: IncomingMessage, botName: string, botInfo: BotInfo);
|
|
25
|
-
private getQuotePart;
|
|
26
25
|
private replyWithText;
|
|
27
26
|
private replyWithImage;
|
|
28
27
|
private replyWithVideo;
|
|
@@ -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,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACH,YAAY,EACZ,aAAa,EACb,OAAO,EACV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
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,O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,MAAM,EACf,OAAO,EAAE,OAAO;IA2BpB,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"}
|
|
@@ -7,6 +7,7 @@ import { resolve } from 'path';
|
|
|
7
7
|
import { BaseContextInternal } from './baseContext';
|
|
8
8
|
import { UserInfo } from '../../dtos/userInfo';
|
|
9
9
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
10
|
+
import { getQuotedText } from '../../helpers/getQuotedText';
|
|
10
11
|
export class ReplyContextInternal extends BaseContextInternal {
|
|
11
12
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
12
13
|
matchResults = [];
|
|
@@ -22,31 +23,24 @@ export class ReplyContextInternal extends BaseContextInternal {
|
|
|
22
23
|
super(storage, scheduler, eventEmitter, action, message.chatInfo, message.traceId, botName);
|
|
23
24
|
this.replyMessageId = message.replyToMessageId;
|
|
24
25
|
this.messageInfo = new MessageInfo(message.messageId, message.text, message.type, message.updateObject);
|
|
25
|
-
this.userInfo = new UserInfo(message.from?.id ??
|
|
26
|
+
this.userInfo = new UserInfo(message.from?.id ?? null, (message.from?.first_name ?? 'Unknown user') +
|
|
26
27
|
(message.from?.last_name ? ` ${message.from.last_name}` : ''));
|
|
27
28
|
this.botInfo = botInfo;
|
|
28
29
|
}
|
|
29
|
-
getQuotePart(quote) {
|
|
30
|
-
if (typeof quote != 'boolean')
|
|
31
|
-
return quote;
|
|
32
|
-
return this.matchResults.length == 0
|
|
33
|
-
? this.messageInfo.text
|
|
34
|
-
: this.matchResults[0][1];
|
|
35
|
-
}
|
|
36
30
|
replyWithText(text, quote, options) {
|
|
37
|
-
const quotedPart = this
|
|
31
|
+
const quotedPart = getQuotedText(this, quote);
|
|
38
32
|
const response = new TextMessage(text, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
39
33
|
this.responses.push(response);
|
|
40
34
|
return this.createCaptureController(response);
|
|
41
35
|
}
|
|
42
36
|
replyWithImage(name, quote, options) {
|
|
43
|
-
const quotedPart = this
|
|
37
|
+
const quotedPart = getQuotedText(this, quote);
|
|
44
38
|
const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
45
39
|
this.responses.push(response);
|
|
46
40
|
return this.createCaptureController(response);
|
|
47
41
|
}
|
|
48
42
|
replyWithVideo(name, quote, options) {
|
|
49
|
-
const quotedPart = this
|
|
43
|
+
const quotedPart = getQuotedText(this, quote);
|
|
50
44
|
const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.observability.traceId, this.action, new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
51
45
|
this.responses.push(response);
|
|
52
46
|
return this.createCaptureController(response);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MessageInfo } from '../dtos/messageInfo';
|
|
2
|
+
type ContextWithMessageInfo = {
|
|
3
|
+
readonly messageInfo: MessageInfo;
|
|
4
|
+
readonly matchResults: RegExpMatchArray[];
|
|
5
|
+
};
|
|
6
|
+
export declare function getQuotedText(context: ContextWithMessageInfo, quote: boolean | string): string;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=getQuotedText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getQuotedText.d.ts","sourceRoot":"","sources":["../../src/helpers/getQuotedText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,KAAK,sBAAsB,GAAG;IAC1B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,aAAa,CACzB,OAAO,EAAE,sBAAsB,EAC/B,KAAK,EAAE,OAAO,GAAG,MAAM,UAQ1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../src/services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../src/services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAS,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAOtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,WAAW,CAAe;gBAG9B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,iBAAiB;IA4B7B,UAAU,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO;IAoD7B,IAAI;CAGP"}
|
|
@@ -36,7 +36,7 @@ export class ActionProcessingService {
|
|
|
36
36
|
]
|
|
37
37
|
: [];
|
|
38
38
|
this.commandProcessor.initialize(api, this.telegramBot, commandActions, botInfo);
|
|
39
|
-
this.inlineQueryProcessor.initialize(api, this.telegramBot, actions.inlineQueries
|
|
39
|
+
this.inlineQueryProcessor.initialize(api, this.telegramBot, actions.inlineQueries);
|
|
40
40
|
this.scheduledProcessor.initialize(api, actions.scheduled, scheduledPeriod ?? hoursToSeconds(1));
|
|
41
41
|
void this.telegramBot.launch();
|
|
42
42
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
2
2
|
import { TelegramBot } from '../../types/externalAliases';
|
|
3
|
-
import { Milliseconds } from '../../types/timeValues';
|
|
4
3
|
import { TelegramApiService } from '../telegramApi';
|
|
5
4
|
import { BaseActionProcessor } from './baseProcessor';
|
|
6
5
|
export declare class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
7
6
|
private inlineQueries;
|
|
8
7
|
/** Fake chat info, since inline queries are chat-less */
|
|
9
8
|
private readonly fakeChatInfo;
|
|
10
|
-
initialize(api: TelegramApiService, telegram: TelegramBot, inlineQueries: InlineQueryAction[]
|
|
9
|
+
initialize(api: TelegramApiService, telegram: TelegramBot, inlineQueries: InlineQueryAction[]): void;
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=inlineQueryActionProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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;CA4GzC"}
|
|
@@ -8,13 +8,12 @@ export class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
|
8
8
|
inlineQueries;
|
|
9
9
|
/** Fake chat info, since inline queries are chat-less */
|
|
10
10
|
fakeChatInfo = new ChatInfo(Math.random(), 'Inline Query', []);
|
|
11
|
-
initialize(api, telegram, inlineQueries
|
|
11
|
+
initialize(api, telegram, inlineQueries) {
|
|
12
12
|
this.initializeDependencies(api);
|
|
13
13
|
this.inlineQueries = inlineQueries;
|
|
14
|
-
let pendingInlineQueries = [];
|
|
15
14
|
const queriesInProcessing = new Map();
|
|
16
15
|
if (this.inlineQueries.length > 0) {
|
|
17
|
-
telegram.on('inline_query', ({ inlineQuery }) => {
|
|
16
|
+
telegram.on('inline_query', async ({ inlineQuery }) => {
|
|
18
17
|
const query = new IncomingInlineQuery(inlineQuery.id, inlineQuery.query, inlineQuery.from.id, createTrace('InlineQuery', this.botName, inlineQuery.id));
|
|
19
18
|
this.eventEmitter.emit(BotEventType.inlineQueryRecieved, {
|
|
20
19
|
query,
|
|
@@ -30,69 +29,51 @@ export class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
|
30
29
|
queryBeingProcessed.abortController.abort();
|
|
31
30
|
queriesInProcessing.delete(query.userId);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.eventEmitter.emit(BotEventType.error, {
|
|
58
|
-
error,
|
|
59
|
-
traceId: inlineQuery.traceId
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return executePromise.finally(() => {
|
|
64
|
-
revoke();
|
|
65
|
-
this.api.flushResponses();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
const queryPromise = Promise.allSettled(actionPromises)
|
|
69
|
-
.then(() => {
|
|
70
|
-
queriesInProcessing.delete(inlineQuery.userId);
|
|
71
|
-
this.eventEmitter.emit(BotEventType.inlineProcessingFinished, {
|
|
72
|
-
botName: this.botName,
|
|
73
|
-
traceId: inlineQuery.traceId
|
|
74
|
-
});
|
|
75
|
-
})
|
|
76
|
-
.catch((reason) => {
|
|
77
|
-
queriesInProcessing.delete(inlineQuery.userId);
|
|
78
|
-
this.eventEmitter.emit(BotEventType.error, {
|
|
79
|
-
error: reason instanceof Error
|
|
80
|
-
? reason
|
|
81
|
-
: new Error('Unknown error'),
|
|
82
|
-
traceId: inlineQuery.traceId
|
|
83
|
-
});
|
|
32
|
+
this.eventEmitter.emit(BotEventType.inlineProcessingStarted, {
|
|
33
|
+
botName: this.botName,
|
|
34
|
+
traceId: query.traceId
|
|
35
|
+
});
|
|
36
|
+
queriesInProcessing.set(query.userId, query);
|
|
37
|
+
const actionPromises = this.inlineQueries.map((inlineQueryAction) => {
|
|
38
|
+
const ctx = new InlineQueryContextInternal(this.storage, this.scheduler, this.eventEmitter, inlineQueryAction, query, this.fakeChatInfo, this.botName);
|
|
39
|
+
const { proxy, revoke } = Proxy.revocable(ctx, {});
|
|
40
|
+
return this.executeAction(inlineQueryAction, proxy, (error, _) => {
|
|
41
|
+
if (error.name == 'AbortError') {
|
|
42
|
+
this.eventEmitter.emit(BotEventType.inlineProcessingAborted, {
|
|
43
|
+
abortedQuery: query,
|
|
44
|
+
traceId: query.traceId
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.eventEmitter.emit(BotEventType.error, {
|
|
49
|
+
error,
|
|
50
|
+
traceId: query.traceId
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}).finally(() => {
|
|
54
|
+
revoke();
|
|
55
|
+
this.api.flushResponses();
|
|
84
56
|
});
|
|
85
|
-
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
await Promise.allSettled(actionPromises);
|
|
86
60
|
}
|
|
87
|
-
|
|
61
|
+
catch (error) {
|
|
88
62
|
this.eventEmitter.emit(BotEventType.error, {
|
|
89
|
-
error:
|
|
90
|
-
?
|
|
63
|
+
error: error instanceof Error
|
|
64
|
+
? error
|
|
91
65
|
: new Error('Unknown error'),
|
|
92
|
-
traceId:
|
|
66
|
+
traceId: query.traceId
|
|
93
67
|
});
|
|
94
|
-
}
|
|
95
|
-
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
queriesInProcessing.delete(query.userId);
|
|
71
|
+
this.eventEmitter.emit(BotEventType.inlineProcessingFinished, {
|
|
72
|
+
botName: this.botName,
|
|
73
|
+
traceId: query.traceId
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
96
77
|
}
|
|
97
78
|
}
|
|
98
79
|
}
|
|
@@ -56,7 +56,7 @@ export class ScheduledActionProcessor extends BaseActionProcessor {
|
|
|
56
56
|
});
|
|
57
57
|
void Promise.allSettled(promises)
|
|
58
58
|
.then(() => {
|
|
59
|
-
this.eventEmitter.emit(BotEventType.
|
|
59
|
+
this.eventEmitter.emit(BotEventType.scheduledProcessingFinished, {
|
|
60
60
|
botName: this.botName,
|
|
61
61
|
traceId: this.taskTrace
|
|
62
62
|
});
|
|
@@ -3,9 +3,9 @@ export type QueueItem = {
|
|
|
3
3
|
callback: () => Promise<void>;
|
|
4
4
|
};
|
|
5
5
|
export declare class ResponseProcessingQueue {
|
|
6
|
-
|
|
7
|
-
items
|
|
8
|
-
isFlushing
|
|
6
|
+
private readonly rateLimiter;
|
|
7
|
+
private readonly items;
|
|
8
|
+
private isFlushing;
|
|
9
9
|
enqueue(item: QueueItem): void;
|
|
10
10
|
flushReadyItems(): Promise<void>;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseProcessingQueue.d.ts","sourceRoot":"","sources":["../../src/services/responseProcessingQueue.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAAC;
|
|
1
|
+
{"version":3,"file":"responseProcessingQueue.d.ts","sourceRoot":"","sources":["../../src/services/responseProcessingQueue.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAAC;AAIF,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAEzB;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,IAAI,EAAE,SAAS;IAmBjB,eAAe;CAkBxB"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RateLimit } from 'async-sema';
|
|
2
|
-
function notEmpty(arr) {
|
|
3
|
-
return arr.length > 0;
|
|
4
|
-
}
|
|
5
2
|
const TELEGRAM_RATELIMIT_DELAY = 35;
|
|
6
3
|
export class ResponseProcessingQueue {
|
|
7
|
-
rateLimiter = RateLimit(1, {
|
|
4
|
+
rateLimiter = RateLimit(1, {
|
|
5
|
+
timeUnit: TELEGRAM_RATELIMIT_DELAY
|
|
6
|
+
});
|
|
8
7
|
items = [];
|
|
9
8
|
isFlushing = false;
|
|
10
9
|
enqueue(item) {
|
|
@@ -24,14 +23,17 @@ export class ResponseProcessingQueue {
|
|
|
24
23
|
if (this.isFlushing)
|
|
25
24
|
return;
|
|
26
25
|
this.isFlushing = true;
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
try {
|
|
27
|
+
while (this.items.length > 0) {
|
|
29
28
|
await this.rateLimiter();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (Date.now() >= this.items[0].priority) {
|
|
30
|
+
const item = this.items.shift();
|
|
31
|
+
await item?.callback();
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
finally {
|
|
36
|
+
this.isFlushing = false;
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../src/services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACH,WAAW,EAGd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAmB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGlE,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoB;IACjD,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAKlC;IAEV,OAAO,CAAC,QAAQ,CAAC,kCAAkC,
|
|
1
|
+
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../src/services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACH,WAAW,EAGd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CA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