chz-telegram-bot 0.7.19 → 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/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/responseProcessingQueue.d.ts.map +1 -1
- package/dist/services/responseProcessingQueue.js +10 -10
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -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,7 +1,4 @@
|
|
|
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
4
|
rateLimiter = RateLimit(1, {
|
|
@@ -26,14 +23,17 @@ export class ResponseProcessingQueue {
|
|
|
26
23
|
if (this.isFlushing)
|
|
27
24
|
return;
|
|
28
25
|
this.isFlushing = true;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
try {
|
|
27
|
+
while (this.items.length > 0) {
|
|
28
|
+
await this.rateLimiter();
|
|
29
|
+
if (Date.now() >= this.items[0].priority) {
|
|
30
|
+
const item = this.items.shift();
|
|
31
|
+
await item?.callback();
|
|
32
|
+
}
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
|
|
35
|
+
finally {
|
|
36
|
+
this.isFlushing = false;
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
}
|