chz-telegram-bot 0.0.23 → 0.0.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/actions/scheduledAction.d.ts +1 -1
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +1 -0
- package/dist/entities/botInstance.d.ts +1 -1
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +30 -12
- package/dist/entities/context/chatContext.d.ts +37 -4
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +30 -0
- package/dist/entities/context/messageContext.d.ts +34 -3
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +29 -4
- package/dist/helpers/builders/commandActionBuilder.d.ts +38 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +38 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +34 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/scheduledActionBuilder.js +34 -0
- package/dist/helpers/reverseRecord.d.ts +2 -0
- package/dist/helpers/reverseRecord.d.ts.map +1 -0
- package/dist/helpers/reverseRecord.js +6 -0
- package/dist/main.d.ts +14 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +7 -1
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/taskScheduler.js +1 -2
- package/dist/services/telegramApi.d.ts +7 -4
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +8 -7
- package/dist/types/handlers.d.ts +12 -2
- package/dist/types/handlers.d.ts.map +1 -1
- package/entities/actions/scheduledAction.ts +2 -1
- package/entities/botInstance.ts +52 -17
- package/entities/context/chatContext.ts +42 -4
- package/entities/context/messageContext.ts +34 -8
- package/helpers/builders/commandActionBuilder.ts +38 -0
- package/helpers/builders/scheduledActionBuilder.ts +34 -0
- package/helpers/reverseRecord.ts +7 -0
- package/main.ts +15 -2
- package/package.json +1 -1
- package/services/taskScheduler.ts +2 -3
- package/services/telegramApi.ts +22 -14
- package/types/handlers.ts +6 -1
- package/helpers/reverseMap.ts +0 -3
|
@@ -17,7 +17,7 @@ export declare class ScheduledAction<TActionState extends IActionState> implemen
|
|
|
17
17
|
cachedStateFactories: Map<string, CachedStateFactory>;
|
|
18
18
|
handler: ScheduledHandler<TActionState>;
|
|
19
19
|
constructor(name: string, handler: ScheduledHandler<TActionState>, timeinHours: HoursOfDay, active: boolean, whitelist: number[], cachedStateFactories: Map<string, CachedStateFactory>, stateConstructor: () => TActionState);
|
|
20
|
-
exec(ctx: ChatContext): Promise<void>;
|
|
20
|
+
exec(ctx: ChatContext<TActionState>): Promise<void>;
|
|
21
21
|
private getCachedValue;
|
|
22
22
|
private shouldTrigger;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB;IAE3B,MAAM,CAAC,SAAS,YAAoB;IAEpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,CAAC;IACxB,MAAM,EAAE,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,EAAE,MAAM,CAAC;IAEZ,WAAW,uBAA8B;IACzC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACtD,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,WAAW,EAAE,UAAU,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAYlC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC;YAmC3B,cAAc;IAqC5B,OAAO,CAAC,aAAa;CASxB"}
|
|
@@ -31,6 +31,7 @@ class ScheduledAction {
|
|
|
31
31
|
logger_1.Logger.logWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, ` - Executing [${this.name}] in ${ctx.chatId}`);
|
|
32
32
|
await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName), state);
|
|
33
33
|
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
34
|
+
ctx.updateActions.forEach((action) => action(state));
|
|
34
35
|
await ctx.storage.saveActionExecutionResult(this, ctx.chatId, new actionExecutionResult_1.ActionExecutionResult(state, isAllowedToTrigger));
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -15,7 +15,7 @@ export declare class BotInstance {
|
|
|
15
15
|
token: string;
|
|
16
16
|
commands: CommandAction<IActionState>[];
|
|
17
17
|
scheduled: ScheduledAction<IActionState>[];
|
|
18
|
-
chats:
|
|
18
|
+
chats: Record<string, number>;
|
|
19
19
|
storageClient?: IStorageClient;
|
|
20
20
|
storagePath?: string;
|
|
21
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB;IAkCD,OAAO,CAAC,6BAA6B;IA6CrC,OAAO,CAAC,2BAA2B;IAsB7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAyBZ,cAAc;CAmB/B"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.BotInstance = void 0;
|
|
4
7
|
const telegraf_1 = require("telegraf");
|
|
@@ -8,6 +11,7 @@ const telegramApi_1 = require("../services/telegramApi");
|
|
|
8
11
|
const logger_1 = require("../services/logger");
|
|
9
12
|
const taskScheduler_1 = require("../services/taskScheduler");
|
|
10
13
|
const incomingMessage_1 = require("./incomingMessage");
|
|
14
|
+
const moment_1 = __importDefault(require("moment"));
|
|
11
15
|
class BotInstance {
|
|
12
16
|
constructor(options) {
|
|
13
17
|
this.name = options.name;
|
|
@@ -27,9 +31,23 @@ class BotInstance {
|
|
|
27
31
|
}
|
|
28
32
|
initializeScheduledProcessing() {
|
|
29
33
|
if (this.scheduled.length > 0) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const now = (0, moment_1.default)();
|
|
35
|
+
let nextExecutionTime = now.clone().startOf('hour');
|
|
36
|
+
if (now.minute() == 0 && now.second() == 0) {
|
|
37
|
+
taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
|
|
38
|
+
await this.runScheduled();
|
|
39
|
+
}, (0, timeConvertions_1.hoursToMilliseconds)(1), true, this.name);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (now.minute() > 0 || now.second() > 0) {
|
|
43
|
+
nextExecutionTime = nextExecutionTime.add(1, 'hour');
|
|
44
|
+
}
|
|
45
|
+
const delay = nextExecutionTime.diff(now);
|
|
46
|
+
taskScheduler_1.Scheduler.createOnetimeTask('ScheduledProcessing_OneTime', async () => {
|
|
47
|
+
taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
|
|
48
|
+
await this.runScheduled();
|
|
49
|
+
}, (0, timeConvertions_1.hoursToMilliseconds)(1), true, this.name);
|
|
50
|
+
}, delay, this.name);
|
|
33
51
|
}
|
|
34
52
|
}
|
|
35
53
|
initializeMessageProcessing() {
|
|
@@ -52,30 +70,30 @@ class BotInstance {
|
|
|
52
70
|
this.telegraf.stop(code);
|
|
53
71
|
}
|
|
54
72
|
async runScheduled() {
|
|
55
|
-
for (const [chatName, chatId] of this.chats
|
|
56
|
-
for (const
|
|
57
|
-
const ctx = this.api.createContextForChat(chatId,
|
|
73
|
+
for (const [chatName, chatId] of Object.entries(this.chats)) {
|
|
74
|
+
for (const scheduledAction of this.scheduled) {
|
|
75
|
+
const ctx = this.api.createContextForChat(chatId, scheduledAction);
|
|
58
76
|
try {
|
|
59
|
-
await
|
|
77
|
+
await scheduledAction.exec(ctx);
|
|
60
78
|
}
|
|
61
79
|
catch (error) {
|
|
62
80
|
logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, chatName, error, ctx);
|
|
63
81
|
}
|
|
64
82
|
}
|
|
65
83
|
}
|
|
66
|
-
this.api.flushResponses();
|
|
84
|
+
await this.api.flushResponses();
|
|
67
85
|
}
|
|
68
86
|
async processMessage(msg) {
|
|
69
|
-
for (const
|
|
70
|
-
const ctx = this.api.createContextForMessage(msg,
|
|
87
|
+
for (const commandAction of this.commands) {
|
|
88
|
+
const ctx = this.api.createContextForMessage(msg, commandAction);
|
|
71
89
|
try {
|
|
72
|
-
await
|
|
90
|
+
await commandAction.exec(ctx);
|
|
73
91
|
}
|
|
74
92
|
catch (error) {
|
|
75
93
|
logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, error, ctx);
|
|
76
94
|
}
|
|
77
95
|
}
|
|
78
|
-
this.api.flushResponses();
|
|
96
|
+
await this.api.flushResponses();
|
|
79
97
|
}
|
|
80
98
|
}
|
|
81
99
|
exports.BotInstance = BotInstance;
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
import { IBotApiInteractions } from '../../services/telegramApi';
|
|
2
2
|
import { IStorageClient } from '../../types/storage';
|
|
3
3
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Context of action executed in chat.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ChatContext<TActionState> {
|
|
8
|
+
protected actionKey: string;
|
|
9
|
+
protected interactions: IBotApiInteractions;
|
|
10
|
+
updateActions: Array<(state: TActionState) => void>;
|
|
11
|
+
/** Trace id of a action execution. */
|
|
12
|
+
traceId: number | string;
|
|
13
|
+
/** Name of a bot that executes this action. */
|
|
5
14
|
botName: string;
|
|
6
|
-
|
|
7
|
-
interactions: IBotApiInteractions;
|
|
15
|
+
/** Id of a chat that action is executed in. */
|
|
8
16
|
chatId: number;
|
|
17
|
+
/** Name of a chat that action is executed in. */
|
|
9
18
|
chatName: string;
|
|
10
|
-
|
|
19
|
+
/** Storage client instance for this bot. */
|
|
11
20
|
storage: IStorageClient;
|
|
12
21
|
constructor(botName: string, actionKey: string, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient);
|
|
22
|
+
/**
|
|
23
|
+
* Manually update the state of an action.
|
|
24
|
+
* @param stateUpdateAction Function that will modify state.
|
|
25
|
+
*/
|
|
26
|
+
updateState(stateUpdateAction: (state: TActionState) => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Sends text message to chat.
|
|
29
|
+
* @param text Message contents.
|
|
30
|
+
* @param options Message sending option.
|
|
31
|
+
*/
|
|
13
32
|
sendTextToChat(text: string, options?: TextMessageSendingOptions): void;
|
|
33
|
+
/**
|
|
34
|
+
* Sends image message to chat.
|
|
35
|
+
* @param name Message contents.
|
|
36
|
+
* @param options Message sending option.
|
|
37
|
+
*/
|
|
14
38
|
sendImageToChat(name: string, options?: MessageSendingOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Sends video/gif message to chat.
|
|
41
|
+
* @param name Message contents.
|
|
42
|
+
* @param options Message sending option.
|
|
43
|
+
*/
|
|
15
44
|
sendVideoToChat(name: string, options?: MessageSendingOptions): void;
|
|
45
|
+
/**
|
|
46
|
+
* Unpins message.
|
|
47
|
+
* @param messageId Message id.
|
|
48
|
+
*/
|
|
16
49
|
unpinMessage(messageId: number): void;
|
|
17
50
|
}
|
|
18
51
|
//# sourceMappingURL=chatContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C,qBAAa,WAAW;
|
|
1
|
+
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY;IACjC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC5C,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,sCAAsC;IACtC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,EAAE,cAAc;IAW3B;;;OAGG;IACH,WAAW,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;IAM5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAahE;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;CAUjC"}
|
|
@@ -6,8 +6,12 @@ const imageMessage_1 = require("../responses/imageMessage");
|
|
|
6
6
|
const textMessage_1 = require("../responses/textMessage");
|
|
7
7
|
const videoMessage_1 = require("../responses/videoMessage");
|
|
8
8
|
const unpin_1 = require("../responses/unpin");
|
|
9
|
+
/**
|
|
10
|
+
* Context of action executed in chat.
|
|
11
|
+
*/
|
|
9
12
|
class ChatContext {
|
|
10
13
|
constructor(botName, actionKey, interactions, chatId, chatName, traceId, storage) {
|
|
14
|
+
this.updateActions = [];
|
|
11
15
|
this.botName = botName;
|
|
12
16
|
this.actionKey = actionKey;
|
|
13
17
|
this.interactions = interactions;
|
|
@@ -16,17 +20,43 @@ class ChatContext {
|
|
|
16
20
|
this.traceId = traceId;
|
|
17
21
|
this.storage = storage;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Manually update the state of an action.
|
|
25
|
+
* @param stateUpdateAction Function that will modify state.
|
|
26
|
+
*/
|
|
27
|
+
updateState(stateUpdateAction) {
|
|
28
|
+
this.updateActions.push(stateUpdateAction);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sends text message to chat.
|
|
32
|
+
* @param text Message contents.
|
|
33
|
+
* @param options Message sending option.
|
|
34
|
+
*/
|
|
19
35
|
sendTextToChat(text, options) {
|
|
20
36
|
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.actionKey, options));
|
|
21
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Sends image message to chat.
|
|
40
|
+
* @param name Message contents.
|
|
41
|
+
* @param options Message sending option.
|
|
42
|
+
*/
|
|
22
43
|
sendImageToChat(name, options) {
|
|
23
44
|
const filePath = `./content/${name}.png`;
|
|
24
45
|
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.actionKey, options));
|
|
25
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Sends video/gif message to chat.
|
|
49
|
+
* @param name Message contents.
|
|
50
|
+
* @param options Message sending option.
|
|
51
|
+
*/
|
|
26
52
|
sendVideoToChat(name, options) {
|
|
27
53
|
const filePath = `./content/${name}.mp4`;
|
|
28
54
|
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.actionKey, options));
|
|
29
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Unpins message.
|
|
58
|
+
* @param messageId Message id.
|
|
59
|
+
*/
|
|
30
60
|
unpinMessage(messageId) {
|
|
31
61
|
this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.actionKey));
|
|
32
62
|
}
|
|
@@ -4,20 +4,51 @@ import { IStorageClient } from '../../types/storage';
|
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { ChatContext } from './chatContext';
|
|
6
6
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Context of action executed in chat, in response to a message
|
|
9
|
+
*/
|
|
10
|
+
export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState> {
|
|
11
|
+
/** Id of a message that triggered this action. */
|
|
8
12
|
messageId: number;
|
|
13
|
+
/** Text of a message that triggered this action. */
|
|
9
14
|
messageText: string;
|
|
15
|
+
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
10
16
|
matchResults: RegExpMatchArray[];
|
|
17
|
+
/** Id of a user that sent a message that triggered this action. */
|
|
11
18
|
fromUserId: number | undefined;
|
|
19
|
+
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
12
20
|
startCooldown: boolean;
|
|
13
|
-
|
|
21
|
+
/** Name of a user that sent a message that triggered this action. */
|
|
14
22
|
fromUserName: string;
|
|
15
23
|
constructor(botName: string, scheduledKey: string, interactions: IBotApiInteractions, chatId: number, chatName: string, messageId: number, messageText: string, fromUserId: number | undefined, traceId: number | string, fromUserName: string, storage: IStorageClient);
|
|
24
|
+
/**
|
|
25
|
+
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
26
|
+
* @param commandName Name of an action to load state of.
|
|
27
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
28
|
+
*/
|
|
16
29
|
loadStateOf<TAnotherActionState extends IActionState>(commandName: string): Promise<TAnotherActionState>;
|
|
17
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Reply with text message to message that triggered this action.
|
|
32
|
+
* @param text Message contents.
|
|
33
|
+
* @param options Message sending option.
|
|
34
|
+
*/
|
|
18
35
|
replyWithText(text: string, options?: TextMessageSendingOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Reply with image message to message that triggered this action.
|
|
38
|
+
* @param text Message contents.
|
|
39
|
+
* @param options Message sending option.
|
|
40
|
+
*/
|
|
19
41
|
replyWithImage(name: string, options?: MessageSendingOptions): void;
|
|
42
|
+
/**
|
|
43
|
+
* Reply with video/gif message to message that triggered this action.
|
|
44
|
+
* @param text Message contents.
|
|
45
|
+
* @param options Message sending option.
|
|
46
|
+
*/
|
|
20
47
|
replyWithVideo(name: string, options?: MessageSendingOptions): void;
|
|
48
|
+
/**
|
|
49
|
+
* React to the message that triggered this action.
|
|
50
|
+
* @param emoji Telegram emoji to react with.
|
|
51
|
+
*/
|
|
21
52
|
react(emoji: TelegramEmoji): void;
|
|
22
53
|
}
|
|
23
54
|
//# sourceMappingURL=messageContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,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,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,cAAc;IAkB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAU/B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
|
|
@@ -8,34 +8,59 @@ const textMessage_1 = require("../responses/textMessage");
|
|
|
8
8
|
const videoMessage_1 = require("../responses/videoMessage");
|
|
9
9
|
const actionStateBase_1 = require("../states/actionStateBase");
|
|
10
10
|
const chatContext_1 = require("./chatContext");
|
|
11
|
+
/**
|
|
12
|
+
* Context of action executed in chat, in response to a message
|
|
13
|
+
*/
|
|
11
14
|
class MessageContext extends chatContext_1.ChatContext {
|
|
12
15
|
constructor(botName, scheduledKey, interactions, chatId, chatName, messageId, messageText, fromUserId, traceId, fromUserName, storage) {
|
|
13
16
|
super(botName, scheduledKey, interactions, chatId, chatName, traceId, storage);
|
|
17
|
+
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
14
18
|
this.matchResults = [];
|
|
19
|
+
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
15
20
|
this.startCooldown = true;
|
|
16
|
-
this.updateActions = [];
|
|
17
21
|
this.messageId = messageId;
|
|
18
22
|
this.messageText = messageText;
|
|
19
23
|
this.fromUserId = fromUserId;
|
|
20
24
|
this.fromUserName = fromUserName;
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
28
|
+
* @param commandName Name of an action to load state of.
|
|
29
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
30
|
+
*/
|
|
22
31
|
async loadStateOf(commandName) {
|
|
23
32
|
return ((await this.storage.load(`command:${commandName.replace('.', '-')}`))[this.chatId] ?? new actionStateBase_1.ActionStateBase());
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Reply with text message to message that triggered this action.
|
|
36
|
+
* @param text Message contents.
|
|
37
|
+
* @param options Message sending option.
|
|
38
|
+
*/
|
|
28
39
|
replyWithText(text, options) {
|
|
29
40
|
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.actionKey, options));
|
|
30
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Reply with image message to message that triggered this action.
|
|
44
|
+
* @param text Message contents.
|
|
45
|
+
* @param options Message sending option.
|
|
46
|
+
*/
|
|
31
47
|
replyWithImage(name, options) {
|
|
32
48
|
const filePath = `./content/${name}.png`;
|
|
33
49
|
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.actionKey, options));
|
|
34
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Reply with video/gif message to message that triggered this action.
|
|
53
|
+
* @param text Message contents.
|
|
54
|
+
* @param options Message sending option.
|
|
55
|
+
*/
|
|
35
56
|
replyWithVideo(name, options) {
|
|
36
57
|
const filePath = `./content/${name}.mp4`;
|
|
37
58
|
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.actionKey, options));
|
|
38
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* React to the message that triggered this action.
|
|
62
|
+
* @param emoji Telegram emoji to react with.
|
|
63
|
+
*/
|
|
39
64
|
react(emoji) {
|
|
40
65
|
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.actionKey));
|
|
41
66
|
}
|
|
@@ -4,6 +4,9 @@ import { Seconds } from '../../types/timeValues';
|
|
|
4
4
|
import { CommandAction } from '../../entities/actions/commandAction';
|
|
5
5
|
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
6
6
|
import { IActionState } from '../../types/actionState';
|
|
7
|
+
/**
|
|
8
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
9
|
+
*/
|
|
7
10
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
8
11
|
name: string;
|
|
9
12
|
trigger: string | RegExp | Array<string> | Array<RegExp>;
|
|
@@ -14,17 +17,52 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
14
17
|
stateConstructor: () => TActionState;
|
|
15
18
|
handler: CommandHandler<TActionState>;
|
|
16
19
|
condition: CommandCondition<TActionState>;
|
|
20
|
+
/**
|
|
21
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
22
|
+
* @param name Action name, will be used for logging and storage
|
|
23
|
+
* @param stateConstructor Function that creates default state object
|
|
24
|
+
*/
|
|
17
25
|
constructor(name: string, stateConstructor: () => TActionState);
|
|
26
|
+
/**
|
|
27
|
+
* Defines action trigger
|
|
28
|
+
* @param trigger If `string` or `string[]` is provided, will be triggered only on exact message match.
|
|
29
|
+
*
|
|
30
|
+
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
31
|
+
*/
|
|
18
32
|
on(trigger: string | RegExp | Array<string> | Array<RegExp>): this;
|
|
33
|
+
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
34
|
+
* @param id User id or ids
|
|
35
|
+
*/
|
|
19
36
|
from(id: number | Array<number>): this;
|
|
37
|
+
/** Defines action logic itself, will be executed on trigger.
|
|
38
|
+
* @param handler Callback that will be called on trigger
|
|
39
|
+
*/
|
|
20
40
|
do(handler: CommandHandler<TActionState>): this;
|
|
41
|
+
/** Defines condition that will be checked before trigger match check is executed.
|
|
42
|
+
* @param condition Condition check predicate
|
|
43
|
+
*/
|
|
21
44
|
when(condition: CommandCondition<TActionState>): this;
|
|
45
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
22
46
|
disabled(): this;
|
|
47
|
+
/** Sets action cooldown.
|
|
48
|
+
* @param seconds Cooldown in seconds.
|
|
49
|
+
*/
|
|
23
50
|
cooldown(seconds: Seconds): this;
|
|
51
|
+
/**
|
|
52
|
+
* Adds a chat to ignore list for this action.
|
|
53
|
+
* @param chatId Chat id to ignore.
|
|
54
|
+
*/
|
|
24
55
|
ignoreChat(chatId: number): this;
|
|
56
|
+
/** Builds action */
|
|
25
57
|
build(): CommandAction<TActionState>;
|
|
26
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
61
|
+
*/
|
|
27
62
|
export declare class CommandActionBuilder extends CommandActionBuilderWithState<ActionStateBase> {
|
|
63
|
+
/**
|
|
64
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
65
|
+
*/
|
|
28
66
|
constructor(name: string);
|
|
29
67
|
}
|
|
30
68
|
//# sourceMappingURL=commandActionBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAM;IAE9D,MAAM,UAAQ;IACd,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;
|
|
1
|
+
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EA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
@@ -5,7 +5,15 @@ const commandAction_1 = require("../../entities/actions/commandAction");
|
|
|
5
5
|
const actionStateBase_1 = require("../../entities/states/actionStateBase");
|
|
6
6
|
const toArray_1 = require("../toArray");
|
|
7
7
|
const noop_1 = require("../noop");
|
|
8
|
+
/**
|
|
9
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
10
|
+
*/
|
|
8
11
|
class CommandActionBuilderWithState {
|
|
12
|
+
/**
|
|
13
|
+
* Builder for `CommandAction` with state represented by `TActionState`
|
|
14
|
+
* @param name Action name, will be used for logging and storage
|
|
15
|
+
* @param stateConstructor Function that creates default state object
|
|
16
|
+
*/
|
|
9
17
|
constructor(name, stateConstructor) {
|
|
10
18
|
this.trigger = [];
|
|
11
19
|
this.active = true;
|
|
@@ -17,40 +25,70 @@ class CommandActionBuilderWithState {
|
|
|
17
25
|
this.name = name;
|
|
18
26
|
this.stateConstructor = stateConstructor;
|
|
19
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Defines action trigger
|
|
30
|
+
* @param trigger If `string` or `string[]` is provided, will be triggered only on exact message match.
|
|
31
|
+
*
|
|
32
|
+
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
33
|
+
*/
|
|
20
34
|
on(trigger) {
|
|
21
35
|
this.trigger = trigger;
|
|
22
36
|
return this;
|
|
23
37
|
}
|
|
38
|
+
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
39
|
+
* @param id User id or ids
|
|
40
|
+
*/
|
|
24
41
|
from(id) {
|
|
25
42
|
this.allowedUsers = (0, toArray_1.toArray)(id);
|
|
26
43
|
return this;
|
|
27
44
|
}
|
|
45
|
+
/** Defines action logic itself, will be executed on trigger.
|
|
46
|
+
* @param handler Callback that will be called on trigger
|
|
47
|
+
*/
|
|
28
48
|
do(handler) {
|
|
29
49
|
this.handler = handler;
|
|
30
50
|
return this;
|
|
31
51
|
}
|
|
52
|
+
/** Defines condition that will be checked before trigger match check is executed.
|
|
53
|
+
* @param condition Condition check predicate
|
|
54
|
+
*/
|
|
32
55
|
when(condition) {
|
|
33
56
|
this.condition = condition;
|
|
34
57
|
return this;
|
|
35
58
|
}
|
|
59
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
36
60
|
disabled() {
|
|
37
61
|
this.active = false;
|
|
38
62
|
return this;
|
|
39
63
|
}
|
|
64
|
+
/** Sets action cooldown.
|
|
65
|
+
* @param seconds Cooldown in seconds.
|
|
66
|
+
*/
|
|
40
67
|
cooldown(seconds) {
|
|
41
68
|
this.cooldownSeconds = seconds;
|
|
42
69
|
return this;
|
|
43
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Adds a chat to ignore list for this action.
|
|
73
|
+
* @param chatId Chat id to ignore.
|
|
74
|
+
*/
|
|
44
75
|
ignoreChat(chatId) {
|
|
45
76
|
this.blacklist.push(chatId);
|
|
46
77
|
return this;
|
|
47
78
|
}
|
|
79
|
+
/** Builds action */
|
|
48
80
|
build() {
|
|
49
81
|
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor);
|
|
50
82
|
}
|
|
51
83
|
}
|
|
52
84
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
85
|
+
/**
|
|
86
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
87
|
+
*/
|
|
53
88
|
class CommandActionBuilder extends CommandActionBuilderWithState {
|
|
89
|
+
/**
|
|
90
|
+
* Builder for `CommandAction` with state represented by default state (containing only last execution date).
|
|
91
|
+
*/
|
|
54
92
|
constructor(name) {
|
|
55
93
|
super(name, () => new actionStateBase_1.ActionStateBase());
|
|
56
94
|
}
|
|
@@ -4,6 +4,9 @@ import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { ScheduledHandler } from '../../types/handlers';
|
|
6
6
|
import { Hours, HoursOfDay } from '../../types/timeValues';
|
|
7
|
+
/**
|
|
8
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
9
|
+
*/
|
|
7
10
|
export declare class ScheduledActionBuilderWithState<TActionState extends IActionState> {
|
|
8
11
|
active: boolean;
|
|
9
12
|
time: HoursOfDay;
|
|
@@ -12,15 +15,46 @@ export declare class ScheduledActionBuilderWithState<TActionState extends IActio
|
|
|
12
15
|
stateConstructor: () => TActionState;
|
|
13
16
|
handler: ScheduledHandler<TActionState>;
|
|
14
17
|
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
20
|
+
* @param name Action name, will be used for logging and storage
|
|
21
|
+
* @param stateConstructor Function that creates default state object
|
|
22
|
+
*/
|
|
15
23
|
constructor(name: string, stateConstructor: () => TActionState);
|
|
24
|
+
/**
|
|
25
|
+
* Adds a chat to whitelist for this action.
|
|
26
|
+
* @param chatId Chat id to execute in.
|
|
27
|
+
*/
|
|
16
28
|
allowIn(chatId: number): this;
|
|
29
|
+
/**
|
|
30
|
+
* Defines time for scheduled item execution.
|
|
31
|
+
* @param time Time of day (0 - 23) to execute action.
|
|
32
|
+
*/
|
|
17
33
|
runAt(time: HoursOfDay): this;
|
|
34
|
+
/** Defines action logic itself, will be executed on timer.
|
|
35
|
+
* @param handler Callback that will be called on timer.
|
|
36
|
+
*/
|
|
18
37
|
do(handler: ScheduledHandler<TActionState>): this;
|
|
38
|
+
/**
|
|
39
|
+
* Defines process-wide cache, that is shared by all actions of this type (even in different bot instances).
|
|
40
|
+
* Can be used for fetch request de-duping, etc.
|
|
41
|
+
* @param key Key that will be used to retrieve value from cache.
|
|
42
|
+
* @param itemFactory Callback that will be executed once to create cached value.
|
|
43
|
+
* @param invalidationTimeoutInHours Timeout for cache invalidation.
|
|
44
|
+
*/
|
|
19
45
|
withSharedCache(key: string, itemFactory: () => Promise<unknown>, invalidationTimeoutInHours?: Hours): this;
|
|
46
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
20
47
|
disabled(): this;
|
|
48
|
+
/** Builds action */
|
|
21
49
|
build(): ScheduledAction<TActionState>;
|
|
22
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
53
|
+
*/
|
|
23
54
|
export declare class ScheduledActionBuilder extends ScheduledActionBuilderWithState<ActionStateBase> {
|
|
55
|
+
/**
|
|
56
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
57
|
+
*/
|
|
24
58
|
constructor(name: string);
|
|
25
59
|
}
|
|
26
60
|
//# sourceMappingURL=scheduledActionBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG3D,qBAAa,+BAA+B,CACxC,YAAY,SAAS,YAAY;IAEjC,MAAM,UAAQ;IACd,IAAI,EAAE,UAAU,CAAK;IACrB,oBAAoB,kCAAyC;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;IAEpD,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe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