chz-telegram-bot 0.3.23 → 0.3.25
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 +4 -1
- package/dist/entities/context/baseContext.d.ts.map +1 -1
- package/dist/entities/context/baseContext.js +15 -0
- package/dist/entities/context/chatContext.d.ts +3 -6
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +0 -12
- package/dist/entities/context/replyContext.d.ts +6 -9
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +0 -12
- package/dist/services/jsonLogger.d.ts +1 -0
- package/dist/services/jsonLogger.d.ts.map +1 -1
- package/dist/services/jsonLogger.js +19 -1
- package/dist/types/capture.d.ts +1 -1
- package/dist/types/capture.d.ts.map +1 -1
- package/entities/context/baseContext.ts +28 -1
- package/entities/context/chatContext.ts +0 -25
- package/entities/context/replyContext.ts +0 -24
- package/package.json +1 -1
- package/services/jsonLogger.ts +23 -1
- package/types/capture.ts +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ChatInfo } from '../../dtos/chatInfo';
|
|
2
2
|
import { IAction, IActionWithState } from '../../types/action';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
|
+
import { ICaptureController } from '../../types/capture';
|
|
4
5
|
import { IScopedLogger } from '../../types/logger';
|
|
5
|
-
import { BotResponse } from '../../types/response';
|
|
6
|
+
import { BotResponse, IReplyResponse } from '../../types/response';
|
|
6
7
|
import { IScheduler } from '../../types/scheduler';
|
|
7
8
|
import { IStorageClient } from '../../types/storage';
|
|
8
9
|
import { TraceId } from '../../types/trace';
|
|
@@ -22,10 +23,12 @@ export declare abstract class BaseContextInternal<TAction extends IAction> {
|
|
|
22
23
|
botName: string;
|
|
23
24
|
/** Chat information. */
|
|
24
25
|
chatInfo: ChatInfo;
|
|
26
|
+
get actionKey(): import("../../types/action").ActionKey;
|
|
25
27
|
/** Ordered collection of responses to be processed */
|
|
26
28
|
get responses(): BotResponse[];
|
|
27
29
|
set responses(value: BotResponse[]);
|
|
28
30
|
constructor(storage: IStorageClient, scheduler: IScheduler);
|
|
31
|
+
protected createCaptureController(response: IReplyResponse): ICaptureController;
|
|
29
32
|
/**
|
|
30
33
|
* Loads state of another action for current chat.
|
|
31
34
|
* @param action Action to load state of.
|
|
@@ -1 +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;
|
|
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,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,MAAM,MAAM,2BAA2B,GACjC,QAAQ,GACR,eAAe,GACf,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,GACX,SAAS,GACT,SAAS,CAAC;AAEhB,8BAAsB,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC7D,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;IACpB,IAAI,SAAS,2CAEZ;IAED,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,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;CAWpD"}
|
|
@@ -16,6 +16,9 @@ class BaseContextInternal {
|
|
|
16
16
|
botName;
|
|
17
17
|
/** Chat information. */
|
|
18
18
|
chatInfo;
|
|
19
|
+
get actionKey() {
|
|
20
|
+
return this.action.key;
|
|
21
|
+
}
|
|
19
22
|
/** Ordered collection of responses to be processed */
|
|
20
23
|
get responses() {
|
|
21
24
|
return this._responses;
|
|
@@ -27,6 +30,18 @@ class BaseContextInternal {
|
|
|
27
30
|
this.storage = storage;
|
|
28
31
|
this.scheduler = scheduler;
|
|
29
32
|
}
|
|
33
|
+
createCaptureController(response) {
|
|
34
|
+
return {
|
|
35
|
+
captureReplies: (trigger, handler, abortController) => {
|
|
36
|
+
response.captures.push({
|
|
37
|
+
trigger,
|
|
38
|
+
handler,
|
|
39
|
+
abortController: abortController ?? new AbortController(),
|
|
40
|
+
action: this.action
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
30
45
|
/**
|
|
31
46
|
* Loads state of another action for current chat.
|
|
32
47
|
* @param action Action to load state of.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
2
|
import { IActionWithState } from '../../types/action';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
|
-
import { IReplyResponse } from '../../types/response';
|
|
5
4
|
import { Milliseconds } from '../../types/timeValues';
|
|
6
|
-
import { ICaptureController } from '../../types/capture';
|
|
7
5
|
import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
|
|
8
6
|
import { ScheduledAction } from '../actions/scheduledAction';
|
|
9
7
|
export type ChatContext<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> = Omit<ChatContextInternal<TActionState, TAction>, BaseContextPropertiesToOmit>;
|
|
@@ -11,7 +9,6 @@ export type ChatContext<TActionState extends IActionState, TAction extends IActi
|
|
|
11
9
|
* Context of action executed in chat.
|
|
12
10
|
*/
|
|
13
11
|
export declare class ChatContextInternal<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> extends BaseContextInternal<TAction> {
|
|
14
|
-
protected createCaptureController(response: IReplyResponse): ICaptureController;
|
|
15
12
|
/**
|
|
16
13
|
* Collection of actions that send something to chat as a standalone message.
|
|
17
14
|
*/
|
|
@@ -22,21 +19,21 @@ export declare class ChatContextInternal<TActionState extends IActionState, TAct
|
|
|
22
19
|
* @param text Message contents.
|
|
23
20
|
* @param options Message sending option.
|
|
24
21
|
*/
|
|
25
|
-
text: (text: string, options?: TextMessageSendingOptions) => ICaptureController;
|
|
22
|
+
text: (text: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
|
|
26
23
|
/**
|
|
27
24
|
* Sends image message to chat after action execution is finished.
|
|
28
25
|
* 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.
|
|
29
26
|
* @param name Message contents.
|
|
30
27
|
* @param options Message sending option.
|
|
31
28
|
*/
|
|
32
|
-
image: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
29
|
+
image: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
33
30
|
/**
|
|
34
31
|
* Sends video/gif message to chat after action execution is finished.
|
|
35
32
|
* 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.
|
|
36
33
|
* @param name Message contents.
|
|
37
34
|
* @param options Message sending option.
|
|
38
35
|
*/
|
|
39
|
-
video: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
36
|
+
video: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
40
37
|
};
|
|
41
38
|
/**
|
|
42
39
|
* Unpins message after action execution is finished.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AAKA,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":"AAKA,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,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,WAAW,CACnB,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,IAC9E,IAAI,CACJ,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC,EAC1C,2BAA2B,CAC9B,CAAC;AAEF;;GAEG;AACH,qBAAa,mBAAmB,CAC5B,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAChF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IAClC;;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"}
|
|
@@ -12,18 +12,6 @@ const baseContext_1 = require("./baseContext");
|
|
|
12
12
|
* Context of action executed in chat.
|
|
13
13
|
*/
|
|
14
14
|
class ChatContextInternal extends baseContext_1.BaseContextInternal {
|
|
15
|
-
createCaptureController(response) {
|
|
16
|
-
return {
|
|
17
|
-
captureReplies: (trigger, handler, abortController) => {
|
|
18
|
-
response.captures.push({
|
|
19
|
-
trigger,
|
|
20
|
-
handler,
|
|
21
|
-
abortController,
|
|
22
|
-
action: this.action
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
15
|
/**
|
|
28
16
|
* Collection of actions that send something to chat as a standalone message.
|
|
29
17
|
*/
|
|
@@ -5,11 +5,8 @@ import { ReplyCaptureAction } from '../actions/replyCaptureAction';
|
|
|
5
5
|
import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
|
|
6
6
|
import { UserInfo } from '../../dtos/userInfo';
|
|
7
7
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
8
|
-
import { ICaptureController } from '../../types/capture';
|
|
9
|
-
import { IReplyResponse } from '../../types/response';
|
|
10
8
|
export type ReplyContext<TActionState extends IActionState> = Omit<ReplyContextInternal<TActionState>, BaseContextPropertiesToOmit | 'messageId' | 'startCooldown' | 'customCooldown'>;
|
|
11
9
|
export declare class ReplyContextInternal<TParentActionState extends IActionState> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
12
|
-
protected createCaptureController(response: IReplyResponse): ICaptureController;
|
|
13
10
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
14
11
|
matchResults: RegExpExecArray[];
|
|
15
12
|
/** Id of a message that triggered this action. */
|
|
@@ -44,21 +41,21 @@ export declare class ReplyContextInternal<TParentActionState extends IActionStat
|
|
|
44
41
|
* @param text Message contents.
|
|
45
42
|
* @param options Message sending option.
|
|
46
43
|
*/
|
|
47
|
-
withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => ICaptureController;
|
|
44
|
+
withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
|
|
48
45
|
/**
|
|
49
46
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
50
47
|
* 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
48
|
* @param text Message contents.
|
|
52
49
|
* @param options Message sending option.
|
|
53
50
|
*/
|
|
54
|
-
withImage: (name: string, quote?: string, options?: MessageSendingOptions) => ICaptureController;
|
|
51
|
+
withImage: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
55
52
|
/**
|
|
56
53
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
57
54
|
* 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
55
|
* @param text Message contents.
|
|
59
56
|
* @param options Message sending option.
|
|
60
57
|
*/
|
|
61
|
-
withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => ICaptureController;
|
|
58
|
+
withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
62
59
|
};
|
|
63
60
|
/**
|
|
64
61
|
* Reply with text message to message that triggered this action after action execution is finished.
|
|
@@ -66,21 +63,21 @@ export declare class ReplyContextInternal<TParentActionState extends IActionStat
|
|
|
66
63
|
* @param text Message contents.
|
|
67
64
|
* @param options Message sending option.
|
|
68
65
|
*/
|
|
69
|
-
withText: (text: string, options?: TextMessageSendingOptions) => ICaptureController;
|
|
66
|
+
withText: (text: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
|
|
70
67
|
/**
|
|
71
68
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
72
69
|
* 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.
|
|
73
70
|
* @param text Message contents.
|
|
74
71
|
* @param options Message sending option.
|
|
75
72
|
*/
|
|
76
|
-
withImage: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
73
|
+
withImage: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
77
74
|
/**
|
|
78
75
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
79
76
|
* 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.
|
|
80
77
|
* @param text Message contents.
|
|
81
78
|
* @param options Message sending option.
|
|
82
79
|
*/
|
|
83
|
-
withVideo: (name: string, options?: MessageSendingOptions) => ICaptureController;
|
|
80
|
+
withVideo: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
|
|
84
81
|
/**
|
|
85
82
|
* React to the message that triggered this action after action execution is finished.
|
|
86
83
|
* 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,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;
|
|
1
|
+
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,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;AAErD,MAAM,MAAM,YAAY,CAAC,YAAY,SAAS,YAAY,IAAI,IAAI,CAC9D,oBAAoB,CAAC,YAAY,CAAC,EAChC,2BAA2B,GAC3B,WAAW,GACX,eAAe,GACf,gBAAgB,CACrB,CAAC;AAEF,qBAAa,oBAAoB,CAC7B,kBAAkB,SAAS,YAAY,CACzC,SAAQ,mBAAmB,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IACjE,4HAA4H;IAC5H,YAAY,EAAG,eAAe,EAAE,CAAC;IACjC,kDAAkD;IAClD,cAAc,EAAG,MAAM,GAAG,SAAS,CAAC;IACpC,4DAA4D;IAC5D,QAAQ,EAAG,QAAQ,CAAC;IACpB,+DAA+D;IAC/D,WAAW,EAAG,WAAW,CAAC;IAC1B,6BAA6B;IAC7B,OAAO,EAAG,aAAa,CAAC;IAExB,aAAa,UAAS;IAEtB,OAAO,CAAC,YAAY;IAQpB,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"}
|
|
@@ -9,18 +9,6 @@ const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const baseContext_1 = require("./baseContext");
|
|
11
11
|
class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
12
|
-
createCaptureController(response) {
|
|
13
|
-
return {
|
|
14
|
-
captureReplies: (trigger, handler, abortController) => {
|
|
15
|
-
response.captures.push({
|
|
16
|
-
trigger,
|
|
17
|
-
handler,
|
|
18
|
-
abortController,
|
|
19
|
-
action: this.action
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
12
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
25
13
|
matchResults;
|
|
26
14
|
/** Id of a message that triggered this action. */
|
|
@@ -2,6 +2,7 @@ import { ILogger, IScopedLogger } from '../types/logger';
|
|
|
2
2
|
import { TraceId } from '../types/trace';
|
|
3
3
|
export declare class JsonLogger implements ILogger {
|
|
4
4
|
private serializeError;
|
|
5
|
+
private getCircularReplacer;
|
|
5
6
|
createScope(botName: string, traceId: TraceId, chatName: string): IScopedLogger;
|
|
6
7
|
logObjectWithTraceId(botName: string, traceId: TraceId, chatName: string, data: any): void;
|
|
7
8
|
logWithTraceId(botName: string, traceId: TraceId, chatName: string, text: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAQtB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,mBAAmB;IAmB3B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;CAe1B"}
|
|
@@ -9,6 +9,24 @@ class JsonLogger {
|
|
|
9
9
|
});
|
|
10
10
|
return JSON.stringify(plainObject);
|
|
11
11
|
}
|
|
12
|
+
getCircularReplacer() {
|
|
13
|
+
const ancestors = [];
|
|
14
|
+
return function (_, value) {
|
|
15
|
+
if (typeof value !== 'object' || value === null) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
// `this` is the object that value is contained in,
|
|
19
|
+
// i.e., its direct parent.
|
|
20
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
21
|
+
ancestors.pop();
|
|
22
|
+
}
|
|
23
|
+
if (ancestors.includes(value)) {
|
|
24
|
+
return '[Circular]';
|
|
25
|
+
}
|
|
26
|
+
ancestors.push(value);
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
12
30
|
createScope(botName, traceId, chatName) {
|
|
13
31
|
return {
|
|
14
32
|
logObjectWithTraceId: (data) => {
|
|
@@ -33,7 +51,7 @@ class JsonLogger {
|
|
|
33
51
|
}
|
|
34
52
|
errorWithTraceId(botName, traceId, chatName, errorObj, extraData) {
|
|
35
53
|
const dataString = extraData
|
|
36
|
-
? `,"extraData":${JSON.stringify(extraData)}`
|
|
54
|
+
? `,"extraData":${JSON.stringify(extraData, this.getCircularReplacer())}`
|
|
37
55
|
: '';
|
|
38
56
|
console.error(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(errorObj)}${dataString}}`);
|
|
39
57
|
}
|
package/dist/types/capture.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface ICaptureController {
|
|
|
13
13
|
/** Callback that will be called on trigger */
|
|
14
14
|
handler: (replyContext: ReplyContext<TParentActionState>) => Promise<void>,
|
|
15
15
|
/** Abort controller to abort capturing manually */
|
|
16
|
-
abortController
|
|
16
|
+
abortController?: AbortController) => void;
|
|
17
17
|
}
|
|
18
18
|
export interface IReplyCapture {
|
|
19
19
|
trigger: CommandTrigger[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,oBAAoB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,CAAC,kBAAkB,SAAS,YAAY;IACpD;;;;OAIG;IACH,OAAO,EAAE,cAAc,EAAE;IACzB,8CAA8C;IAC9C,OAAO,EAAE,CACL,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC;IAClB,mDAAmD;IACnD,eAAe,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,oBAAoB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,CAAC,kBAAkB,SAAS,YAAY;IACpD;;;;OAIG;IACH,OAAO,EAAE,cAAc,EAAE;IACzB,8CAA8C;IAC9C,OAAO,EAAE,CACL,YAAY,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAC7C,OAAO,CAAC,IAAI,CAAC;IAClB,mDAAmD;IACnD,eAAe,CAAC,EAAE,eAAe,KAChC,IAAI,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,YAAY,CAAC,KAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,MAAM,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ChatInfo } from '../../dtos/chatInfo';
|
|
2
2
|
import { IAction, IActionWithState } from '../../types/action';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
|
+
import { ICaptureController } from '../../types/capture';
|
|
5
|
+
import { CommandTrigger } from '../../types/commandTrigger';
|
|
4
6
|
import { IScopedLogger } from '../../types/logger';
|
|
5
|
-
import { BotResponse } from '../../types/response';
|
|
7
|
+
import { BotResponse, IReplyResponse } from '../../types/response';
|
|
6
8
|
import { IScheduler } from '../../types/scheduler';
|
|
7
9
|
import { IStorageClient } from '../../types/storage';
|
|
8
10
|
import { TraceId } from '../../types/trace';
|
|
11
|
+
import { ReplyContext } from './replyContext';
|
|
9
12
|
|
|
10
13
|
export type BaseContextPropertiesToOmit =
|
|
11
14
|
| 'action'
|
|
@@ -34,6 +37,9 @@ export abstract class BaseContextInternal<TAction extends IAction> {
|
|
|
34
37
|
botName!: string;
|
|
35
38
|
/** Chat information. */
|
|
36
39
|
chatInfo!: ChatInfo;
|
|
40
|
+
get actionKey() {
|
|
41
|
+
return this.action.key;
|
|
42
|
+
}
|
|
37
43
|
|
|
38
44
|
/** Ordered collection of responses to be processed */
|
|
39
45
|
public get responses(): BotResponse[] {
|
|
@@ -48,6 +54,27 @@ export abstract class BaseContextInternal<TAction extends IAction> {
|
|
|
48
54
|
this.scheduler = scheduler;
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
protected createCaptureController(
|
|
58
|
+
response: IReplyResponse
|
|
59
|
+
): ICaptureController {
|
|
60
|
+
return {
|
|
61
|
+
captureReplies: (
|
|
62
|
+
trigger: CommandTrigger[],
|
|
63
|
+
handler: (
|
|
64
|
+
replyContext: ReplyContext<IActionState>
|
|
65
|
+
) => Promise<void>,
|
|
66
|
+
abortController?: AbortController
|
|
67
|
+
) => {
|
|
68
|
+
response.captures.push({
|
|
69
|
+
trigger,
|
|
70
|
+
handler,
|
|
71
|
+
abortController: abortController ?? new AbortController(),
|
|
72
|
+
action: this.action
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
/**
|
|
52
79
|
* Loads state of another action for current chat.
|
|
53
80
|
* @param action Action to load state of.
|
|
@@ -9,12 +9,8 @@ import {
|
|
|
9
9
|
} from '../../types/messageSendingOptions';
|
|
10
10
|
import { IActionWithState } from '../../types/action';
|
|
11
11
|
import { IActionState } from '../../types/actionState';
|
|
12
|
-
import { IReplyResponse } from '../../types/response';
|
|
13
12
|
import { Milliseconds } from '../../types/timeValues';
|
|
14
13
|
import { DelayResponse } from '../../dtos/responses/delay';
|
|
15
|
-
import { ICaptureController } from '../../types/capture';
|
|
16
|
-
import { CommandTrigger } from '../../types/commandTrigger';
|
|
17
|
-
import { ReplyContext } from './replyContext';
|
|
18
14
|
import {
|
|
19
15
|
BaseContextInternal,
|
|
20
16
|
BaseContextPropertiesToOmit
|
|
@@ -36,27 +32,6 @@ export class ChatContextInternal<
|
|
|
36
32
|
TActionState extends IActionState,
|
|
37
33
|
TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>
|
|
38
34
|
> extends BaseContextInternal<TAction> {
|
|
39
|
-
protected createCaptureController(
|
|
40
|
-
response: IReplyResponse
|
|
41
|
-
): ICaptureController {
|
|
42
|
-
return {
|
|
43
|
-
captureReplies: (
|
|
44
|
-
trigger: CommandTrigger[],
|
|
45
|
-
handler: (
|
|
46
|
-
replyContext: ReplyContext<TActionState>
|
|
47
|
-
) => Promise<void>,
|
|
48
|
-
abortController: AbortController
|
|
49
|
-
) => {
|
|
50
|
-
response.captures.push({
|
|
51
|
-
trigger,
|
|
52
|
-
handler,
|
|
53
|
-
abortController,
|
|
54
|
-
action: this.action
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
35
|
/**
|
|
61
36
|
* Collection of actions that send something to chat as a standalone message.
|
|
62
37
|
*/
|
|
@@ -17,9 +17,6 @@ import {
|
|
|
17
17
|
} from './baseContext';
|
|
18
18
|
import { UserInfo } from '../../dtos/userInfo';
|
|
19
19
|
import { MessageInfo } from '../../dtos/messageInfo';
|
|
20
|
-
import { ICaptureController } from '../../types/capture';
|
|
21
|
-
import { CommandTrigger } from '../../types/commandTrigger';
|
|
22
|
-
import { IReplyResponse } from '../../types/response';
|
|
23
20
|
|
|
24
21
|
export type ReplyContext<TActionState extends IActionState> = Omit<
|
|
25
22
|
ReplyContextInternal<TActionState>,
|
|
@@ -32,27 +29,6 @@ export type ReplyContext<TActionState extends IActionState> = Omit<
|
|
|
32
29
|
export class ReplyContextInternal<
|
|
33
30
|
TParentActionState extends IActionState
|
|
34
31
|
> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
35
|
-
protected createCaptureController(
|
|
36
|
-
response: IReplyResponse
|
|
37
|
-
): ICaptureController {
|
|
38
|
-
return {
|
|
39
|
-
captureReplies: (
|
|
40
|
-
trigger: CommandTrigger[],
|
|
41
|
-
handler: (
|
|
42
|
-
replyContext: ReplyContext<TParentActionState>
|
|
43
|
-
) => Promise<void>,
|
|
44
|
-
abortController: AbortController
|
|
45
|
-
) => {
|
|
46
|
-
response.captures.push({
|
|
47
|
-
trigger,
|
|
48
|
-
handler,
|
|
49
|
-
abortController,
|
|
50
|
-
action: this.action
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
32
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
57
33
|
matchResults!: RegExpExecArray[];
|
|
58
34
|
/** Id of a message that triggered this action. */
|
package/package.json
CHANGED
package/services/jsonLogger.ts
CHANGED
|
@@ -12,6 +12,25 @@ export class JsonLogger implements ILogger {
|
|
|
12
12
|
return JSON.stringify(plainObject);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
private getCircularReplacer() {
|
|
16
|
+
const ancestors: unknown[] = [];
|
|
17
|
+
return function <V>(this: V, _: unknown, value: V) {
|
|
18
|
+
if (typeof value !== 'object' || value === null) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
// `this` is the object that value is contained in,
|
|
22
|
+
// i.e., its direct parent.
|
|
23
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
24
|
+
ancestors.pop();
|
|
25
|
+
}
|
|
26
|
+
if (ancestors.includes(value)) {
|
|
27
|
+
return '[Circular]';
|
|
28
|
+
}
|
|
29
|
+
ancestors.push(value);
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
15
34
|
createScope(botName: string, traceId: TraceId, chatName: string) {
|
|
16
35
|
return {
|
|
17
36
|
logObjectWithTraceId: (data: any) => {
|
|
@@ -63,7 +82,10 @@ export class JsonLogger implements ILogger {
|
|
|
63
82
|
extraData?: unknown
|
|
64
83
|
) {
|
|
65
84
|
const dataString = extraData
|
|
66
|
-
? `,"extraData":${JSON.stringify(
|
|
85
|
+
? `,"extraData":${JSON.stringify(
|
|
86
|
+
extraData,
|
|
87
|
+
this.getCircularReplacer()
|
|
88
|
+
)}`
|
|
67
89
|
: '';
|
|
68
90
|
|
|
69
91
|
console.error(
|
package/types/capture.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface ICaptureController {
|
|
|
19
19
|
replyContext: ReplyContext<TParentActionState>
|
|
20
20
|
) => Promise<void>,
|
|
21
21
|
/** Abort controller to abort capturing manually */
|
|
22
|
-
abortController
|
|
22
|
+
abortController?: AbortController
|
|
23
23
|
) => void;
|
|
24
24
|
}
|
|
25
25
|
|