chz-telegram-bot 0.3.7 → 0.3.8
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/context/baseContext.d.ts +35 -0
- package/dist/entities/context/baseContext.d.ts.map +1 -0
- package/dist/entities/context/baseContext.js +32 -0
- package/dist/entities/context/chatContext.d.ts +4 -27
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +3 -19
- package/dist/entities/context/inlineQueryContext.d.ts +2 -15
- package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
- package/dist/entities/context/inlineQueryContext.js +3 -4
- package/dist/entities/context/messageContext.d.ts +2 -1
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.d.ts +2 -20
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +3 -5
- package/dist/services/actionProcessors/baseProcessor.d.ts +20 -0
- package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -0
- package/dist/services/actionProcessors/baseProcessor.js +29 -0
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +2 -7
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +12 -27
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +2 -7
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +6 -15
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +2 -6
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/scheduledActionProcessor.js +5 -14
- package/dist/types/action.d.ts +3 -0
- package/dist/types/action.d.ts.map +1 -1
- package/entities/context/baseContext.ts +58 -0
- package/entities/context/chatContext.ts +8 -45
- package/entities/context/inlineQueryContext.ts +3 -20
- package/entities/context/messageContext.ts +2 -1
- package/entities/context/replyContext.ts +5 -25
- package/package.json +1 -1
- package/services/actionProcessors/baseProcessor.ts +60 -0
- package/services/actionProcessors/commandActionProcessor.ts +19 -42
- package/services/actionProcessors/inlineQueryActionProcessor.ts +16 -32
- package/services/actionProcessors/scheduledActionProcessor.ts +7 -23
- package/types/action.ts +3 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ChatInfo } from '../../dtos/chatInfo';
|
|
2
|
+
import { IAction, IActionWithState } from '../../types/action';
|
|
3
|
+
import { IActionState } from '../../types/actionState';
|
|
4
|
+
import { IScopedLogger } from '../../types/logger';
|
|
5
|
+
import { BotResponse } from '../../types/response';
|
|
6
|
+
import { IScheduler } from '../../types/scheduler';
|
|
7
|
+
import { IStorageClient } from '../../types/storage';
|
|
8
|
+
import { TraceId } from '../../types/trace';
|
|
9
|
+
export declare abstract class BaseContext<TAction extends IAction> {
|
|
10
|
+
isInitialized: boolean;
|
|
11
|
+
private _responses;
|
|
12
|
+
action: TAction;
|
|
13
|
+
/** Storage client instance for the bot executing this action. */
|
|
14
|
+
readonly storage: IStorageClient;
|
|
15
|
+
/** Scheduler instance for the bot executing this action */
|
|
16
|
+
readonly scheduler: IScheduler;
|
|
17
|
+
logger: IScopedLogger;
|
|
18
|
+
/** Trace id of a action execution. */
|
|
19
|
+
traceId: TraceId;
|
|
20
|
+
/** Name of a bot that executes this action. */
|
|
21
|
+
botName: string;
|
|
22
|
+
/** Chat information. */
|
|
23
|
+
chatInfo: ChatInfo;
|
|
24
|
+
/** Ordered collection of responses to be processed */
|
|
25
|
+
get responses(): BotResponse[];
|
|
26
|
+
set responses(value: BotResponse[]);
|
|
27
|
+
constructor(storage: IStorageClient, scheduler: IScheduler);
|
|
28
|
+
/**
|
|
29
|
+
* Loads state of another action for current chat.
|
|
30
|
+
* @param action Action to load state of.
|
|
31
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
32
|
+
*/
|
|
33
|
+
loadStateOf<TAnotherActionState extends IActionState>(action: IActionWithState<TAnotherActionState>): Promise<Readonly<TAnotherActionState>>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=baseContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,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;AAE5C,8BAAsB,WAAW,CAAC,OAAO,SAAS,OAAO;IACrD,aAAa,UAAS;IACtB,OAAO,CAAC,UAAU,CAAqB;IAEvC,MAAM,EAAG,OAAO,CAAC;IAEjB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,MAAM,EAAG,aAAa,CAAC;IACvB,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IAEpB,uDAAuD;IACvD,IAAW,SAAS,IAAI,WAAW,EAAE,CAEpC;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAExC;gBAEW,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAK1D;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;CAWpD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseContext = void 0;
|
|
4
|
+
class BaseContext {
|
|
5
|
+
/** Ordered collection of responses to be processed */
|
|
6
|
+
get responses() {
|
|
7
|
+
return this._responses;
|
|
8
|
+
}
|
|
9
|
+
set responses(value) {
|
|
10
|
+
this._responses = value;
|
|
11
|
+
}
|
|
12
|
+
constructor(storage, scheduler) {
|
|
13
|
+
this.isInitialized = false;
|
|
14
|
+
this._responses = [];
|
|
15
|
+
this.storage = storage;
|
|
16
|
+
this.scheduler = scheduler;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads state of another action for current chat.
|
|
20
|
+
* @param action Action to load state of.
|
|
21
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
22
|
+
*/
|
|
23
|
+
async loadStateOf(action) {
|
|
24
|
+
const allStates = await this.storage.load(action.key);
|
|
25
|
+
const stateForChat = allStates[this.chatInfo.id];
|
|
26
|
+
if (!stateForChat) {
|
|
27
|
+
return Object.freeze(action.stateConstructor());
|
|
28
|
+
}
|
|
29
|
+
return Object.freeze(stateForChat);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.BaseContext = BaseContext;
|
|
@@ -2,41 +2,18 @@ import { IStorageClient } from '../../types/storage';
|
|
|
2
2
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
3
3
|
import { IActionWithState } from '../../types/action';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
|
-
import {
|
|
5
|
+
import { IReplyResponse } from '../../types/response';
|
|
6
6
|
import { Milliseconds } from '../../types/timeValues';
|
|
7
|
-
import { ChatInfo } from '../../dtos/chatInfo';
|
|
8
|
-
import { IScopedLogger } from '../../types/logger';
|
|
9
7
|
import { IScheduler } from '../../types/scheduler';
|
|
10
|
-
import { TraceId } from '../../types/trace';
|
|
11
8
|
import { ICaptureController } from '../../types/capture';
|
|
9
|
+
import { BaseContext } from './baseContext';
|
|
10
|
+
import { ScheduledAction } from '../actions/scheduledAction';
|
|
12
11
|
/**
|
|
13
12
|
* Context of action executed in chat.
|
|
14
13
|
*/
|
|
15
|
-
export declare class ChatContext<TActionState extends IActionState> {
|
|
16
|
-
action: IActionWithState<TActionState>;
|
|
17
|
-
/** Storage client instance for the bot executing this action. */
|
|
18
|
-
readonly storage: IStorageClient;
|
|
19
|
-
/** Logger instance for the bot executing this action */
|
|
20
|
-
/** Scheduler instance for the bot executing this action */
|
|
21
|
-
readonly scheduler: IScheduler;
|
|
22
|
-
logger: IScopedLogger;
|
|
23
|
-
/** Trace id of a action execution. */
|
|
24
|
-
traceId: TraceId;
|
|
25
|
-
/** Name of a bot that executes this action. */
|
|
26
|
-
botName: string;
|
|
27
|
-
/** Chat information. */
|
|
28
|
-
chatInfo: ChatInfo;
|
|
29
|
-
/** Ordered collection of responses to be processed */
|
|
30
|
-
responses: BotResponse[];
|
|
31
|
-
isInitialized: boolean;
|
|
14
|
+
export declare class ChatContext<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> extends BaseContext<TAction> {
|
|
32
15
|
constructor(storage: IStorageClient, scheduler: IScheduler);
|
|
33
16
|
protected createCaptureController(response: IReplyResponse): ICaptureController;
|
|
34
|
-
/**
|
|
35
|
-
* Loads state of another action for current chat.
|
|
36
|
-
* @param action Action to load state of.
|
|
37
|
-
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
38
|
-
*/
|
|
39
|
-
loadStateOf<TAnotherActionState extends IActionState>(action: IActionWithState<TAnotherActionState>): Promise<Readonly<TAnotherActionState>>;
|
|
40
17
|
/**
|
|
41
18
|
* Collection of actions that send something to chat as a standalone message.
|
|
42
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;GAEG;AACH,qBAAa,WAAW,CACpB,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAChF,SAAQ,WAAW,CAAC,OAAO,CAAC;gBACd,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;OAEG;IACH,IAAI;QACA;;;;;WAKG;qBACU,MAAM,YAAY,yBAAyB;QAexD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;QAerD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;MAcvD;IAEF;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;IAW9B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,YAAY;CAK3B"}
|
|
@@ -7,14 +7,13 @@ const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
|
7
7
|
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
8
8
|
const unpin_1 = require("../../dtos/responses/unpin");
|
|
9
9
|
const delay_1 = require("../../dtos/responses/delay");
|
|
10
|
+
const baseContext_1 = require("./baseContext");
|
|
10
11
|
/**
|
|
11
12
|
* Context of action executed in chat.
|
|
12
13
|
*/
|
|
13
|
-
class ChatContext {
|
|
14
|
+
class ChatContext extends baseContext_1.BaseContext {
|
|
14
15
|
constructor(storage, scheduler) {
|
|
15
|
-
|
|
16
|
-
this.responses = [];
|
|
17
|
-
this.isInitialized = false;
|
|
16
|
+
super(storage, scheduler);
|
|
18
17
|
/**
|
|
19
18
|
* Collection of actions that send something to chat as a standalone message.
|
|
20
19
|
*/
|
|
@@ -53,8 +52,6 @@ class ChatContext {
|
|
|
53
52
|
return this.createCaptureController(response);
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
|
-
this.storage = storage;
|
|
57
|
-
this.scheduler = scheduler;
|
|
58
55
|
}
|
|
59
56
|
createCaptureController(response) {
|
|
60
57
|
return {
|
|
@@ -68,19 +65,6 @@ class ChatContext {
|
|
|
68
65
|
}
|
|
69
66
|
};
|
|
70
67
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Loads state of another action for current chat.
|
|
73
|
-
* @param action Action to load state of.
|
|
74
|
-
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
75
|
-
*/
|
|
76
|
-
async loadStateOf(action) {
|
|
77
|
-
const allStates = await this.storage.load(action.key);
|
|
78
|
-
const stateForChat = allStates[this.chatInfo.id];
|
|
79
|
-
if (!stateForChat) {
|
|
80
|
-
return Object.freeze(action.stateConstructor());
|
|
81
|
-
}
|
|
82
|
-
return Object.freeze(stateForChat);
|
|
83
|
-
}
|
|
84
68
|
/**
|
|
85
69
|
* Unpins message after action execution is finished.
|
|
86
70
|
* 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.
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import { InlineQueryResult } from 'telegraf/types';
|
|
2
|
-
import { IScopedLogger } from '../../types/logger';
|
|
3
2
|
import { BotResponse } from '../../types/response';
|
|
4
3
|
import { IScheduler } from '../../types/scheduler';
|
|
5
4
|
import { IStorageClient } from '../../types/storage';
|
|
6
|
-
import { TraceId } from '../../types/trace';
|
|
7
5
|
import { InlineQueryAction } from '../actions/inlineQueryAction';
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { BaseContext } from './baseContext';
|
|
7
|
+
export declare class InlineQueryContext extends BaseContext<InlineQueryAction> {
|
|
10
8
|
queryResults: InlineQueryResult[];
|
|
11
|
-
/** Storage client instance for the bot executing this action. */
|
|
12
|
-
readonly storage: IStorageClient;
|
|
13
|
-
/** Scheduler instance for the bot executing this action */
|
|
14
|
-
readonly scheduler: IScheduler;
|
|
15
|
-
/** Logger instance for the bot executing this action */
|
|
16
|
-
logger: IScopedLogger;
|
|
17
|
-
/** Trace id of a action execution. */
|
|
18
|
-
traceId: TraceId;
|
|
19
|
-
/** Name of a bot that executes this action. */
|
|
20
|
-
botName: string;
|
|
21
9
|
/**
|
|
22
10
|
* Abort signal to be utilized in query handler.
|
|
23
11
|
* Signal will be aborted if new query comes from the same user.
|
|
@@ -31,7 +19,6 @@ export declare class InlineQueryContext {
|
|
|
31
19
|
queryId: string;
|
|
32
20
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
33
21
|
matchResults: RegExpMatchArray[];
|
|
34
|
-
isInitialized: boolean;
|
|
35
22
|
constructor(storage: IStorageClient, scheduler: IScheduler);
|
|
36
23
|
/**
|
|
37
24
|
* This result will be shown to user as a response to inline query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,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,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,kBAAmB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;IAClE,YAAY,EAAE,iBAAiB,EAAE,CAAM;IACvC;;;OAGG;IACH,WAAW,EAAG,WAAW,CAAC;IAE1B,uDAAuD;IACvD,IAAI,SAAS,IAAI,WAAW,EAAE,CAS7B;IACD,wBAAwB;IACxB,SAAS,EAAG,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,EAAG,MAAM,CAAC;IACjB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;gBAE1B,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,iBAAiB;CAGvD"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InlineQueryContext = void 0;
|
|
4
4
|
const inlineQueryResponse_1 = require("../../dtos/responses/inlineQueryResponse");
|
|
5
|
-
|
|
5
|
+
const baseContext_1 = require("./baseContext");
|
|
6
|
+
class InlineQueryContext extends baseContext_1.BaseContext {
|
|
6
7
|
/** Ordered collection of responses to be processed */
|
|
7
8
|
get responses() {
|
|
8
9
|
return [
|
|
@@ -10,12 +11,10 @@ class InlineQueryContext {
|
|
|
10
11
|
];
|
|
11
12
|
}
|
|
12
13
|
constructor(storage, scheduler) {
|
|
14
|
+
super(storage, scheduler);
|
|
13
15
|
this.queryResults = [];
|
|
14
16
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
15
17
|
this.matchResults = [];
|
|
16
|
-
this.isInitialized = false;
|
|
17
|
-
this.storage = storage;
|
|
18
|
-
this.scheduler = scheduler;
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* This result will be shown to user as a response to inline query.
|
|
@@ -5,10 +5,11 @@ import { ChatContext } from './chatContext';
|
|
|
5
5
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
6
6
|
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
7
7
|
import { IScheduler } from '../../types/scheduler';
|
|
8
|
+
import { CommandAction } from '../actions/commandAction';
|
|
8
9
|
/**
|
|
9
10
|
* Context of action executed in chat, in response to a message
|
|
10
11
|
*/
|
|
11
|
-
export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState
|
|
12
|
+
export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState, CommandAction<TActionState>> {
|
|
12
13
|
/** Id of a message that triggered this action. */
|
|
13
14
|
messageId: number;
|
|
14
15
|
/** Text of a message that triggered this action. */
|
|
@@ -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;
|
|
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;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC5D,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"}
|
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
-
import { ChatInfo } from '../../dtos/chatInfo';
|
|
3
2
|
import { IActionState } from '../../types/actionState';
|
|
4
|
-
import { IScopedLogger } from '../../types/logger';
|
|
5
3
|
import { TextMessageSendingOptions, MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
6
4
|
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
7
|
-
import { BotResponse } from '../../types/response';
|
|
8
5
|
import { IScheduler } from '../../types/scheduler';
|
|
9
6
|
import { IStorageClient } from '../../types/storage';
|
|
10
|
-
import { TraceId } from '../../types/trace';
|
|
11
7
|
import { ReplyCaptureAction } from '../actions/replyCaptureAction';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/** Storage client instance for the bot executing this action. */
|
|
15
|
-
readonly storage: IStorageClient;
|
|
16
|
-
/** Scheduler instance for the bot executing this action */
|
|
17
|
-
readonly scheduler: IScheduler;
|
|
18
|
-
/** Trace id of a action execution. */
|
|
19
|
-
traceId: TraceId;
|
|
20
|
-
/** Name of a bot that executes this action. */
|
|
21
|
-
botName: string;
|
|
22
|
-
/** Logger instance for the bot executing this action */
|
|
23
|
-
logger: IScopedLogger;
|
|
24
|
-
/** Ordered collection of responses to be processed */
|
|
25
|
-
responses: BotResponse[];
|
|
26
|
-
/** Chat information. */
|
|
27
|
-
chatInfo: ChatInfo;
|
|
8
|
+
import { BaseContext } from './baseContext';
|
|
9
|
+
export declare class ReplyContext<TParentActionState extends IActionState> extends BaseContext<ReplyCaptureAction<TParentActionState>> {
|
|
28
10
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
29
11
|
matchResults: RegExpExecArray[];
|
|
30
12
|
/** Id of a message that triggered this action. */
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,YAAY,CACrB,kBAAkB,SAAS,YAAY,CACzC,SAAQ,WAAW,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACzD,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC;IACjC,kDAAkD;IAClD,cAAc,EAAG,MAAM,GAAG,SAAS,CAAC;IACpC,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;IAC/B,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,qEAAqE;IACrE,YAAY,EAAG,MAAM,CAAC;IACtB,4CAA4C;IAC5C,mBAAmB,EAAG,sBAAsB,CAAC;IAE7C,aAAa,UAAS;gBAEV,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU;IAI1D,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"}
|
|
@@ -7,10 +7,10 @@ const reaction_1 = require("../../dtos/responses/reaction");
|
|
|
7
7
|
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
8
8
|
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
-
|
|
10
|
+
const baseContext_1 = require("./baseContext");
|
|
11
|
+
class ReplyContext extends baseContext_1.BaseContext {
|
|
11
12
|
constructor(storage, scheduler) {
|
|
12
|
-
|
|
13
|
-
this.responses = [];
|
|
13
|
+
super(storage, scheduler);
|
|
14
14
|
this.isInitialized = false;
|
|
15
15
|
/**
|
|
16
16
|
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
@@ -73,8 +73,6 @@ class ReplyContext {
|
|
|
73
73
|
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
this.storage = storage;
|
|
77
|
-
this.scheduler = scheduler;
|
|
78
76
|
}
|
|
79
77
|
getQuotePart(quote) {
|
|
80
78
|
return typeof quote == 'boolean'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Telegraf } from 'telegraf';
|
|
2
|
+
import { ILogger } from '../../types/logger';
|
|
3
|
+
import { IScheduler } from '../../types/scheduler';
|
|
4
|
+
import { IStorageClient } from '../../types/storage';
|
|
5
|
+
import { TelegramApiService } from '../telegramApi';
|
|
6
|
+
import { IAction } from '../../types/action';
|
|
7
|
+
import { BaseContext } from '../../entities/context/baseContext';
|
|
8
|
+
export declare abstract class BaseActionProcessor {
|
|
9
|
+
protected readonly storage: IStorageClient;
|
|
10
|
+
protected readonly scheduler: IScheduler;
|
|
11
|
+
protected readonly logger: ILogger;
|
|
12
|
+
protected readonly botName: string;
|
|
13
|
+
protected api: TelegramApiService;
|
|
14
|
+
protected telegraf: Telegraf;
|
|
15
|
+
constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
16
|
+
private defaultErrorHandler;
|
|
17
|
+
initializeDependencies(api: TelegramApiService, telegraf: Telegraf): void;
|
|
18
|
+
executeAction<TAction extends IAction, TActionContext extends BaseContext<TAction>>(action: TAction, ctx: TActionContext, errorHandler?: (error: Error, ctx: TActionContext) => void): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=baseProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/baseProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,8BAAsB,mBAAmB;IACrC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEnC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAG,kBAAkB,CAAC;IACnC,SAAS,CAAC,QAAQ,EAAG,QAAQ,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IASnB,OAAO,CAAC,mBAAmB;IAO3B,sBAAsB,CAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ;IAK5D,aAAa,CACf,OAAO,SAAS,OAAO,EACvB,cAAc,SAAS,WAAW,CAAC,OAAO,CAAC,EAE3C,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,cAAc,EACnB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;CAUjE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseActionProcessor = void 0;
|
|
4
|
+
class BaseActionProcessor {
|
|
5
|
+
constructor(botName, storage, scheduler, logger) {
|
|
6
|
+
this.storage = storage;
|
|
7
|
+
this.scheduler = scheduler;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.botName = botName;
|
|
10
|
+
}
|
|
11
|
+
defaultErrorHandler(error, ctx) {
|
|
12
|
+
ctx.logger.errorWithTraceId(error, ctx);
|
|
13
|
+
}
|
|
14
|
+
initializeDependencies(api, telegraf) {
|
|
15
|
+
this.api = api;
|
|
16
|
+
this.telegraf = telegraf;
|
|
17
|
+
}
|
|
18
|
+
async executeAction(action, ctx, errorHandler) {
|
|
19
|
+
try {
|
|
20
|
+
const responses = await action.exec(ctx);
|
|
21
|
+
this.api.enqueueBatchedResponses(responses);
|
|
22
|
+
ctx.isInitialized = false;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
(errorHandler ?? this.defaultErrorHandler)(error, ctx);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BaseActionProcessor = BaseActionProcessor;
|
|
@@ -8,14 +8,9 @@ import { TelegramApiService } from '../telegramApi';
|
|
|
8
8
|
import { IReplyCapture } from '../../types/capture';
|
|
9
9
|
import { TraceId } from '../../types/trace';
|
|
10
10
|
import { ChatInfo } from '../../dtos/chatInfo';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private readonly scheduler;
|
|
14
|
-
private readonly logger;
|
|
15
|
-
private readonly botName;
|
|
11
|
+
import { BaseActionProcessor } from './baseProcessor';
|
|
12
|
+
export declare class CommandActionProcessor extends BaseActionProcessor {
|
|
16
13
|
private readonly replyCaptures;
|
|
17
|
-
private api;
|
|
18
|
-
private telegraf;
|
|
19
14
|
private commands;
|
|
20
15
|
constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
21
16
|
initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean): 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;
|
|
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,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,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;AAEtD,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IAExE,OAAO,CAAC,QAAQ,CAKd;gBAGE,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAKnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO;IAyD7C,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YA+BN,cAAc;IAiC5B,OAAO,CAAC,6BAA6B;IA6BrC,OAAO,CAAC,wBAAwB;CA8BnC"}
|
|
@@ -7,21 +7,18 @@ const messageContext_1 = require("../../entities/context/messageContext");
|
|
|
7
7
|
const replyContext_1 = require("../../entities/context/replyContext");
|
|
8
8
|
const messageTypes_1 = require("../../types/messageTypes");
|
|
9
9
|
const objectFromEntries_1 = require("../../helpers/objectFromEntries");
|
|
10
|
-
|
|
10
|
+
const baseProcessor_1 = require("./baseProcessor");
|
|
11
|
+
class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
11
12
|
constructor(botName, storage, scheduler, logger) {
|
|
13
|
+
super(botName, storage, scheduler, logger);
|
|
14
|
+
this.replyCaptures = [];
|
|
12
15
|
this.commands = (0, objectFromEntries_1.typeSafeObjectFromEntries)(Object.values(messageTypes_1.MessageType).map((x) => [
|
|
13
16
|
x,
|
|
14
17
|
[]
|
|
15
18
|
]));
|
|
16
|
-
this.storage = storage;
|
|
17
|
-
this.scheduler = scheduler;
|
|
18
|
-
this.logger = logger;
|
|
19
|
-
this.botName = botName;
|
|
20
|
-
this.replyCaptures = [];
|
|
21
19
|
}
|
|
22
20
|
initialize(api, telegraf, commands, verboseLoggingForIncomingMessage) {
|
|
23
|
-
this.api
|
|
24
|
-
this.telegraf = telegraf;
|
|
21
|
+
this.initializeDependencies(api, telegraf);
|
|
25
22
|
for (const msgType of Object.values(messageTypes_1.MessageType)) {
|
|
26
23
|
if (msgType == messageTypes_1.MessageType.Text) {
|
|
27
24
|
this.commands[msgType] = commands.filter((cmd) => cmd.triggers.find((x) => typeof x != 'string') !=
|
|
@@ -64,29 +61,17 @@ class CommandActionProcessor {
|
|
|
64
61
|
const ctx = new messageContext_1.MessageContext(this.storage, this.scheduler);
|
|
65
62
|
const commandsToCheck = new Set(this.commands[msg.type]);
|
|
66
63
|
if (msg.type != messageTypes_1.MessageType.Text && msg.text != '') {
|
|
67
|
-
this.commands[messageTypes_1.MessageType.Text].
|
|
64
|
+
this.commands[messageTypes_1.MessageType.Text].forEach((x) => commandsToCheck.add(x));
|
|
68
65
|
}
|
|
69
66
|
for (const commandAction of commandsToCheck) {
|
|
70
67
|
this.initializeMessageContext(ctx, commandAction, msg);
|
|
71
|
-
|
|
72
|
-
const responses = await commandAction.exec(ctx);
|
|
73
|
-
this.api.enqueueBatchedResponses(responses);
|
|
74
|
-
ctx.isInitialized = false;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
ctx.logger.errorWithTraceId(error, ctx);
|
|
78
|
-
}
|
|
68
|
+
this.executeAction(commandAction, ctx);
|
|
79
69
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.api.enqueueBatchedResponses(responses);
|
|
86
|
-
replyCtx.isInitialized = false;
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
replyCtx.logger.errorWithTraceId(error, replyCtx);
|
|
70
|
+
if (this.replyCaptures.length != 0) {
|
|
71
|
+
const replyCtx = new replyContext_1.ReplyContext(this.storage, this.scheduler);
|
|
72
|
+
for (const replyAction of this.replyCaptures) {
|
|
73
|
+
this.initializeReplyCaptureContext(replyCtx, replyAction, msg);
|
|
74
|
+
this.executeAction(replyAction, replyCtx);
|
|
90
75
|
}
|
|
91
76
|
}
|
|
92
77
|
this.api.flushResponses();
|
|
@@ -5,13 +5,8 @@ import { IScheduler } from '../../types/scheduler';
|
|
|
5
5
|
import { IStorageClient } from '../../types/storage';
|
|
6
6
|
import { Milliseconds } from '../../types/timeValues';
|
|
7
7
|
import { TelegramApiService } from '../telegramApi';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private readonly scheduler;
|
|
11
|
-
private readonly logger;
|
|
12
|
-
private readonly botName;
|
|
13
|
-
private api;
|
|
14
|
-
private telegraf;
|
|
8
|
+
import { BaseActionProcessor } from './baseProcessor';
|
|
9
|
+
export declare class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
15
10
|
private inlineQueries;
|
|
16
11
|
constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
17
12
|
initialize(api: TelegramApiService, telegraf: Telegraf, inlineQueries: InlineQueryAction[], period: Milliseconds): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,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;gBAGxC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAKnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IAqGxB,OAAO,CAAC,4BAA4B;CAqBvC"}
|
|
@@ -4,16 +4,13 @@ exports.InlineQueryActionProcessor = void 0;
|
|
|
4
4
|
const incomingQuery_1 = require("../../dtos/incomingQuery");
|
|
5
5
|
const inlineQueryContext_1 = require("../../entities/context/inlineQueryContext");
|
|
6
6
|
const traceFactory_1 = require("../../helpers/traceFactory");
|
|
7
|
-
|
|
7
|
+
const baseProcessor_1 = require("./baseProcessor");
|
|
8
|
+
class InlineQueryActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
8
9
|
constructor(botName, storage, scheduler, logger) {
|
|
9
|
-
|
|
10
|
-
this.scheduler = scheduler;
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
this.botName = botName;
|
|
10
|
+
super(botName, storage, scheduler, logger);
|
|
13
11
|
}
|
|
14
12
|
initialize(api, telegraf, inlineQueries, period) {
|
|
15
|
-
this.api
|
|
16
|
-
this.telegraf = telegraf;
|
|
13
|
+
this.initializeDependencies(api, telegraf);
|
|
17
14
|
this.inlineQueries = inlineQueries;
|
|
18
15
|
let pendingInlineQueries = [];
|
|
19
16
|
const queriesInProcessing = new Map();
|
|
@@ -39,20 +36,14 @@ class InlineQueryActionProcessor {
|
|
|
39
36
|
queriesInProcessing.set(inlineQuery.userId, inlineQuery);
|
|
40
37
|
for (const inlineQueryAction of this.inlineQueries) {
|
|
41
38
|
this.initializeInlineQueryContext(ctx, inlineQuery.query, inlineQuery.queryId, inlineQueryAction, inlineQuery.abortController.signal, inlineQuery.traceId);
|
|
42
|
-
|
|
43
|
-
const responses = await inlineQueryAction.exec(ctx);
|
|
44
|
-
this.api.enqueueBatchedResponses(responses);
|
|
45
|
-
ctx.isInitialized = false;
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
const error = err;
|
|
39
|
+
this.executeAction(inlineQueryAction, ctx, (error, ctx) => {
|
|
49
40
|
if (error.name == 'AbortError') {
|
|
50
41
|
ctx.logger.logWithTraceId(`Aborting query ${inlineQuery.queryId} (${inlineQuery.query}) successful.`);
|
|
51
42
|
}
|
|
52
43
|
else {
|
|
53
44
|
ctx.logger.errorWithTraceId(error, ctx);
|
|
54
45
|
}
|
|
55
|
-
}
|
|
46
|
+
});
|
|
56
47
|
}
|
|
57
48
|
queriesInProcessing.delete(inlineQuery.userId);
|
|
58
49
|
}
|
|
@@ -5,13 +5,9 @@ import { IScheduler } from '../../types/scheduler';
|
|
|
5
5
|
import { IStorageClient } from '../../types/storage';
|
|
6
6
|
import { Seconds } from '../../types/timeValues';
|
|
7
7
|
import { TelegramApiService } from '../telegramApi';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private readonly scheduler;
|
|
11
|
-
private readonly logger;
|
|
12
|
-
private readonly botName;
|
|
8
|
+
import { BaseActionProcessor } from './baseProcessor';
|
|
9
|
+
export declare class ScheduledActionProcessor extends BaseActionProcessor {
|
|
13
10
|
private readonly chats;
|
|
14
|
-
private api;
|
|
15
11
|
private scheduled;
|
|
16
12
|
constructor(botName: string, chats: Record<string, number>, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
17
13
|
initialize(api: TelegramApiService, scheduled: ScheduledAction<IActionState>[], period: Seconds): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/scheduledActionProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/scheduledActionProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAIzE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAgB,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,wBAAyB,SAAQ,mBAAmB;IAC7D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAE/C,OAAO,CAAC,SAAS,CAAmC;gBAGhD,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAMnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,EAC1C,MAAM,EAAE,OAAO;YAgDL,YAAY;IAuB1B,OAAO,CAAC,qBAAqB;CAmBhC"}
|
|
@@ -9,16 +9,14 @@ const chatInfo_1 = require("../../dtos/chatInfo");
|
|
|
9
9
|
const chatContext_1 = require("../../entities/context/chatContext");
|
|
10
10
|
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
11
11
|
const traceFactory_1 = require("../../helpers/traceFactory");
|
|
12
|
-
|
|
12
|
+
const baseProcessor_1 = require("./baseProcessor");
|
|
13
|
+
class ScheduledActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
13
14
|
constructor(botName, chats, storage, scheduler, logger) {
|
|
14
|
-
|
|
15
|
-
this.scheduler = scheduler;
|
|
16
|
-
this.logger = logger;
|
|
17
|
-
this.botName = botName;
|
|
15
|
+
super(botName, storage, scheduler, logger);
|
|
18
16
|
this.chats = chats;
|
|
19
17
|
}
|
|
20
18
|
initialize(api, scheduled, period) {
|
|
21
|
-
this.api
|
|
19
|
+
this.initializeDependencies(api, null);
|
|
22
20
|
this.scheduled = scheduled;
|
|
23
21
|
if (this.scheduled.length > 0) {
|
|
24
22
|
const now = (0, moment_1.default)();
|
|
@@ -45,14 +43,7 @@ class ScheduledActionProcessor {
|
|
|
45
43
|
for (const [chatName, chatId] of Object.entries(this.chats)) {
|
|
46
44
|
for (const scheduledAction of this.scheduled) {
|
|
47
45
|
this.initializeChatContext(ctx, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), (0, traceFactory_1.createTrace)(scheduledAction, this.botName, `${scheduledAction.key}-${chatId}`));
|
|
48
|
-
|
|
49
|
-
const responses = await scheduledAction.exec(ctx);
|
|
50
|
-
this.api.enqueueBatchedResponses(responses);
|
|
51
|
-
ctx.isInitialized = false;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
ctx.logger.errorWithTraceId(error, ctx);
|
|
55
|
-
}
|
|
46
|
+
this.executeAction(scheduledAction, ctx);
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
this.api.flushResponses();
|