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.
@@ -1 +1 @@
1
- {"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../src/services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AACnE,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,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,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, 300);
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[], period: Milliseconds): void;
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,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,0BAA2B,SAAQ,mBAAmB;IAC/D,OAAO,CAAC,aAAa,CAAuB;IAC5C,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAI3B;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;CAmK3B"}
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, period) {
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
- pendingInlineQueries = pendingInlineQueries.filter((q) => q.userId != query.userId);
34
- pendingInlineQueries.push(query);
35
- });
36
- this.scheduler.createTask('InlineQueryProcessing', () => {
37
- const queriesToProcess = [...pendingInlineQueries];
38
- pendingInlineQueries = [];
39
- const promises = [];
40
- for (const inlineQuery of queriesToProcess) {
41
- this.eventEmitter.emit(BotEventType.inlineProcessingStarted, {
42
- botName: this.botName,
43
- traceId: inlineQuery.traceId
44
- });
45
- queriesInProcessing.set(inlineQuery.userId, inlineQuery);
46
- const actionPromises = this.inlineQueries.map((inlineQueryAction) => {
47
- const ctx = new InlineQueryContextInternal(this.storage, this.scheduler, this.eventEmitter, inlineQueryAction, inlineQuery, this.fakeChatInfo, this.botName);
48
- const { proxy, revoke } = Proxy.revocable(ctx, {});
49
- const executePromise = this.executeAction(inlineQueryAction, proxy, (error, _) => {
50
- if (error.name == 'AbortError') {
51
- this.eventEmitter.emit(BotEventType.inlineProcessingAborted, {
52
- abortedQuery: inlineQuery,
53
- traceId: inlineQuery.traceId
54
- });
55
- }
56
- else {
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
- promises.push(queryPromise);
57
+ });
58
+ try {
59
+ await Promise.allSettled(actionPromises);
86
60
  }
87
- void Promise.allSettled(promises).catch((reason) => {
61
+ catch (error) {
88
62
  this.eventEmitter.emit(BotEventType.error, {
89
- error: reason instanceof Error
90
- ? reason
63
+ error: error instanceof Error
64
+ ? error
91
65
  : new Error('Unknown error'),
92
- traceId: createTrace(this, this.botName, 'Error')
66
+ traceId: query.traceId
93
67
  });
94
- });
95
- }, period, false, this.botName);
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;AAQF,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
+ {"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
- while (notEmpty(this.items)) {
30
- await this.rateLimiter();
31
- if (Date.now() >= this.items[0].priority) {
32
- const [item] = this.items;
33
- this.items.shift();
34
- await item.callback();
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
- this.isFlushing = false;
35
+ finally {
36
+ this.isFlushing = false;
37
+ }
38
38
  }
39
39
  }
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "type": "git",
15
15
  "url": "https://github.com/AlexSolari/botFramework.git"
16
16
  },
17
- "version": "0.7.19",
17
+ "version": "0.7.20",
18
18
  "type": "module",
19
19
  "dependencies": {
20
20
  "async-sema": "^3.1.1",