chz-telegram-bot 0.0.50 → 0.0.52
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/dtos/actionExecutionResult.d.ts +7 -0
- package/dist/dtos/actionExecutionResult.d.ts.map +1 -0
- package/dist/dtos/actionExecutionResult.js +10 -0
- package/dist/dtos/chatInfo.d.ts +8 -0
- package/dist/dtos/chatInfo.d.ts.map +1 -0
- package/dist/dtos/chatInfo.js +10 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts +10 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -0
- package/dist/dtos/commandTriggerCheckResult.js +20 -0
- package/dist/dtos/incomingMessage.d.ts +14 -0
- package/dist/dtos/incomingMessage.d.ts.map +1 -0
- package/dist/dtos/incomingMessage.js +44 -0
- package/dist/dtos/responses/delay.d.ts +14 -0
- package/dist/dtos/responses/delay.d.ts.map +1 -0
- package/dist/dtos/responses/delay.js +14 -0
- package/dist/dtos/responses/imageMessage.d.ts +18 -0
- package/dist/dtos/responses/imageMessage.d.ts.map +1 -0
- package/dist/dtos/responses/imageMessage.js +17 -0
- package/dist/dtos/responses/reaction.d.ts +15 -0
- package/dist/dtos/responses/reaction.d.ts.map +1 -0
- package/dist/dtos/responses/reaction.js +15 -0
- package/dist/dtos/responses/textMessage.d.ts +17 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -0
- package/dist/dtos/responses/textMessage.js +17 -0
- package/dist/dtos/responses/unpin.d.ts +13 -0
- package/dist/dtos/responses/unpin.d.ts.map +1 -0
- package/dist/dtos/responses/unpin.js +14 -0
- package/dist/dtos/responses/videoMessage.d.ts +18 -0
- package/dist/dtos/responses/videoMessage.d.ts.map +1 -0
- package/dist/dtos/responses/videoMessage.js +17 -0
- package/dist/entities/actions/commandAction.d.ts +11 -10
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +41 -40
- package/dist/entities/actions/scheduledAction.d.ts +11 -11
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +14 -18
- package/dist/entities/botInstance.d.ts +16 -8
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +26 -18
- package/dist/entities/cachedStateFactory.d.ts +2 -2
- package/dist/entities/cachedStateFactory.d.ts.map +1 -1
- package/dist/entities/context/chatContext.d.ts +13 -14
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +16 -24
- package/dist/entities/context/messageContext.d.ts +5 -3
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +13 -13
- package/dist/entities/taskRecord.d.ts +3 -3
- package/dist/entities/taskRecord.d.ts.map +1 -1
- package/dist/helpers/noop.d.ts +4 -2
- package/dist/helpers/noop.d.ts.map +1 -1
- package/dist/helpers/noop.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/main.d.ts +10 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -11
- package/dist/services/jsonFileStorage.d.ts +5 -6
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +3 -5
- package/dist/services/jsonLogger.d.ts +8 -0
- package/dist/services/jsonLogger.d.ts.map +1 -0
- package/dist/services/jsonLogger.js +28 -0
- package/dist/services/nodeTimeoutScheduler.d.ts +13 -0
- package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -0
- package/dist/services/nodeTimeoutScheduler.js +33 -0
- package/dist/services/taskScheduler.d.ts +1 -1
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/telegramApi.d.ts +7 -14
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +12 -20
- package/dist/types/actionWithState.d.ts +2 -2
- package/dist/types/actionWithState.d.ts.map +1 -1
- package/dist/types/commandCondition.d.ts +1 -1
- package/dist/types/commandCondition.d.ts.map +1 -1
- package/dist/types/logger.d.ts +6 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +2 -0
- package/dist/types/response.d.ts +15 -14
- package/dist/types/response.d.ts.map +1 -1
- package/dist/types/scheduler.d.ts +7 -0
- package/dist/types/scheduler.d.ts.map +1 -0
- package/dist/types/scheduler.js +2 -0
- package/dist/types/storage.d.ts +1 -2
- package/dist/types/storage.d.ts.map +1 -1
- package/dtos/chatInfo.ts +11 -0
- package/{entities → dtos}/commandTriggerCheckResult.ts +10 -10
- package/{entities → dtos}/incomingMessage.ts +13 -12
- package/{entities → dtos}/responses/delay.ts +8 -7
- package/{entities → dtos}/responses/imageMessage.ts +11 -10
- package/{entities → dtos}/responses/reaction.ts +9 -8
- package/{entities → dtos}/responses/textMessage.ts +11 -10
- package/{entities → dtos}/responses/unpin.ts +8 -7
- package/{entities → dtos}/responses/videoMessage.ts +11 -10
- package/entities/actions/commandAction.ts +64 -56
- package/entities/actions/scheduledAction.ts +40 -43
- package/entities/botInstance.ts +64 -35
- package/entities/cachedStateFactory.ts +2 -2
- package/entities/context/chatContext.ts +40 -34
- package/entities/context/messageContext.ts +21 -18
- package/entities/taskRecord.ts +3 -3
- package/helpers/noop.ts +5 -2
- package/index.ts +3 -1
- package/main.ts +16 -15
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +8 -10
- package/services/{logger.ts → jsonLogger.ts} +3 -3
- package/services/{taskScheduler.ts → nodeTimeoutScheduler.ts} +12 -8
- package/services/telegramApi.ts +19 -54
- package/types/actionWithState.ts +2 -2
- package/types/commandCondition.ts +1 -1
- package/types/logger.ts +24 -0
- package/types/response.ts +15 -14
- package/types/scheduler.ts +20 -0
- package/types/storage.ts +1 -2
- package/entities/actionExecutionResult.ts +0 -11
- package/helpers/inverseRecord.ts +0 -7
|
@@ -7,9 +7,7 @@ exports.ScheduledAction = void 0;
|
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
const async_sema_1 = require("async-sema");
|
|
9
9
|
const timeConvertions_1 = require("../../helpers/timeConvertions");
|
|
10
|
-
const
|
|
11
|
-
const logger_1 = require("../../services/logger");
|
|
12
|
-
const taskScheduler_1 = require("../../services/taskScheduler");
|
|
10
|
+
const noop_1 = require("../../helpers/noop");
|
|
13
11
|
class ScheduledAction {
|
|
14
12
|
constructor(name, handler, timeinHours, active, whitelist, cachedStateFactories, stateConstructor) {
|
|
15
13
|
this.cachedState = new Map();
|
|
@@ -25,21 +23,19 @@ class ScheduledAction {
|
|
|
25
23
|
async exec(ctx) {
|
|
26
24
|
if (!ctx.isInitialized)
|
|
27
25
|
throw new Error(`Context for ${this.key} is not initialized or already consumed`);
|
|
28
|
-
if (!this.active || !this.chatsWhitelist.includes(ctx.
|
|
29
|
-
return
|
|
30
|
-
const state = await ctx.storage.getActionState(this, ctx.
|
|
31
|
-
const isAllowedToTrigger = this.
|
|
32
|
-
if (isAllowedToTrigger)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
ctx.isInitialized = false;
|
|
26
|
+
if (!this.active || !this.chatsWhitelist.includes(ctx.chatInfo.id))
|
|
27
|
+
return noop_1.Noop.NoResponse;
|
|
28
|
+
const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
|
|
29
|
+
const isAllowedToTrigger = this.checkIfShouldBeExecuted(state);
|
|
30
|
+
if (!isAllowedToTrigger)
|
|
31
|
+
return noop_1.Noop.NoResponse;
|
|
32
|
+
ctx.logger.logWithTraceId(ctx.botName, ctx.traceId, ctx.chatInfo.name, ` - Executing [${this.name}] in ${ctx.chatInfo.id}`);
|
|
33
|
+
await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName, ctx.scheduler), state);
|
|
34
|
+
state.lastExecutedDate = (0, moment_1.default)().valueOf();
|
|
35
|
+
await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
|
|
40
36
|
return ctx.responses;
|
|
41
37
|
}
|
|
42
|
-
async getCachedValue(key, botName) {
|
|
38
|
+
async getCachedValue(key, botName, scheduler) {
|
|
43
39
|
if (!this.cachedStateFactories.has(key)) {
|
|
44
40
|
throw new Error(`No shared cache was set up for the key [${key}] in action '${this.name}'`);
|
|
45
41
|
}
|
|
@@ -60,14 +56,14 @@ class ScheduledAction {
|
|
|
60
56
|
const cachedItemFactory = this.cachedStateFactories.get(key);
|
|
61
57
|
const value = await cachedItemFactory.getValue();
|
|
62
58
|
this.cachedState.set(key, value);
|
|
63
|
-
|
|
59
|
+
scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), (0, timeConvertions_1.hoursToMilliseconds)(cachedItemFactory.invalidationTimeoutInHours), botName);
|
|
64
60
|
return value;
|
|
65
61
|
}
|
|
66
62
|
finally {
|
|
67
63
|
semaphore.release();
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
|
-
|
|
66
|
+
checkIfShouldBeExecuted(state) {
|
|
71
67
|
const startOfToday = (0, moment_1.default)().startOf('day').valueOf();
|
|
72
68
|
const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
|
|
73
69
|
const currentTime = (0, moment_1.default)();
|
|
@@ -3,24 +3,32 @@ import { IStorageClient } from '../types/storage';
|
|
|
3
3
|
import { IActionState } from '../types/actionState';
|
|
4
4
|
import { CommandAction } from './actions/commandAction';
|
|
5
5
|
import { ScheduledAction } from './actions/scheduledAction';
|
|
6
|
+
import { ILogger } from '../types/logger';
|
|
7
|
+
import { IScheduler } from '../types/scheduler';
|
|
6
8
|
export declare class BotInstance {
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
9
|
+
private readonly api;
|
|
10
|
+
private readonly storage;
|
|
11
|
+
private readonly scheduler;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
private readonly telegraf;
|
|
15
|
+
private readonly commands;
|
|
16
|
+
private readonly scheduled;
|
|
17
|
+
private readonly chats;
|
|
14
18
|
constructor(options: {
|
|
15
19
|
name: string;
|
|
16
20
|
token: string;
|
|
17
21
|
commands: CommandAction<IActionState>[];
|
|
18
22
|
scheduled: ScheduledAction<IActionState>[];
|
|
19
23
|
chats: Record<string, number>;
|
|
20
|
-
storageClient?: IStorageClient;
|
|
21
24
|
storagePath?: string;
|
|
22
25
|
scheduledPeriod?: Seconds;
|
|
23
26
|
verboseLoggingForIncomingMessage?: boolean;
|
|
27
|
+
services?: {
|
|
28
|
+
storageClient?: IStorageClient;
|
|
29
|
+
logger?: ILogger;
|
|
30
|
+
scheduler?: IScheduler;
|
|
31
|
+
};
|
|
24
32
|
});
|
|
25
33
|
private initializeScheduledProcessing;
|
|
26
34
|
private initializeMessageProcessing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,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":"AAKA,OAAO,EAAuB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,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;AAO5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAC5D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;gBAEnC,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,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,QAAQ,CAAC,EAAE;YACP,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IAwCD,OAAO,CAAC,6BAA6B;IA2CrC,OAAO,CAAC,2BAA2B;IAiC7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAaT,YAAY;YAmCZ,cAAc;CA2B/B"}
|
|
@@ -8,12 +8,13 @@ const telegraf_1 = require("telegraf");
|
|
|
8
8
|
const timeConvertions_1 = require("../helpers/timeConvertions");
|
|
9
9
|
const jsonFileStorage_1 = require("../services/jsonFileStorage");
|
|
10
10
|
const telegramApi_1 = require("../services/telegramApi");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const incomingMessage_1 = require("./incomingMessage");
|
|
11
|
+
const jsonLogger_1 = require("../services/jsonLogger");
|
|
12
|
+
const incomingMessage_1 = require("../dtos/incomingMessage");
|
|
14
13
|
const moment_1 = __importDefault(require("moment"));
|
|
15
14
|
const chatContext_1 = require("./context/chatContext");
|
|
16
15
|
const messageContext_1 = require("./context/messageContext");
|
|
16
|
+
const chatInfo_1 = require("../dtos/chatInfo");
|
|
17
|
+
const nodeTimeoutScheduler_1 = require("../services/nodeTimeoutScheduler");
|
|
17
18
|
class BotInstance {
|
|
18
19
|
constructor(options) {
|
|
19
20
|
this.name = options.name;
|
|
@@ -21,22 +22,26 @@ class BotInstance {
|
|
|
21
22
|
this.scheduled = options.scheduled;
|
|
22
23
|
this.chats = options.chats;
|
|
23
24
|
const actions = [...this.commands, ...this.scheduled];
|
|
24
|
-
logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Start`, 'System', 'Starting bot...');
|
|
25
25
|
this.telegraf = new telegraf_1.Telegraf(options.token);
|
|
26
|
+
this.logger = options.services?.logger ?? new jsonLogger_1.JsonLogger();
|
|
27
|
+
this.scheduler =
|
|
28
|
+
options.services?.scheduler ??
|
|
29
|
+
new nodeTimeoutScheduler_1.NodeTimeoutScheduler(this.logger);
|
|
26
30
|
this.storage =
|
|
27
|
-
options.storageClient ??
|
|
31
|
+
options.services?.storageClient ??
|
|
28
32
|
new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
|
|
29
|
-
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.
|
|
33
|
+
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.logger);
|
|
30
34
|
this.initializeMessageProcessing(options.verboseLoggingForIncomingMessage ?? false);
|
|
31
35
|
this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
|
|
32
36
|
this.storage.saveMetadata(actions, this.name);
|
|
37
|
+
this.logger.logWithTraceId(this.name, `System:Bot-${this.name}-Start`, 'System', 'Starting bot...');
|
|
33
38
|
this.telegraf.launch();
|
|
34
39
|
}
|
|
35
40
|
initializeScheduledProcessing(period) {
|
|
36
41
|
if (this.scheduled.length > 0) {
|
|
37
42
|
const now = (0, moment_1.default)();
|
|
38
43
|
if (now.minute() == 0 && now.second() == 0) {
|
|
39
|
-
|
|
44
|
+
this.scheduler.createTask('ScheduledProcessing', async () => {
|
|
40
45
|
await this.runScheduled();
|
|
41
46
|
}, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
|
|
42
47
|
return;
|
|
@@ -46,8 +51,8 @@ class BotInstance {
|
|
|
46
51
|
nextExecutionTime = nextExecutionTime.add(1, 'hour');
|
|
47
52
|
}
|
|
48
53
|
const delay = nextExecutionTime.diff(now);
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
this.scheduler.createOnetimeTask('ScheduledProcessing_OneTime', async () => {
|
|
55
|
+
this.scheduler.createTask('ScheduledProcessing', async () => {
|
|
51
56
|
await this.runScheduled();
|
|
52
57
|
}, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
|
|
53
58
|
}, delay, this.name);
|
|
@@ -61,46 +66,49 @@ class BotInstance {
|
|
|
61
66
|
const messageFromName = msg.from?.first_name ?? 'Unknown';
|
|
62
67
|
const messageFromId = msg.from?.id ?? 'Unknown';
|
|
63
68
|
if (verboseLoggingForIncomingMessage) {
|
|
64
|
-
|
|
69
|
+
this.logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatInfo.name, ctx.update.message);
|
|
65
70
|
}
|
|
66
71
|
else {
|
|
67
|
-
|
|
72
|
+
this.logger.logWithTraceId(this.name, msg.traceId, msg.chatInfo.name, `${messageFromName} (${messageFromId}): ${messageContent}`);
|
|
68
73
|
}
|
|
69
74
|
await this.processMessage(msg);
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
async stop(code) {
|
|
74
|
-
|
|
79
|
+
this.logger.logWithTraceId(this.name, `System:Bot-${this.name}-Stop`, 'System', 'Stopping bot...');
|
|
80
|
+
this.scheduler.stopAll();
|
|
75
81
|
await this.storage.close();
|
|
76
82
|
this.telegraf.stop(code);
|
|
77
83
|
}
|
|
78
84
|
async runScheduled() {
|
|
79
|
-
const ctx = new chatContext_1.ChatContext();
|
|
85
|
+
const ctx = new chatContext_1.ChatContext(this.storage, this.logger, this.scheduler);
|
|
80
86
|
for (const [chatName, chatId] of Object.entries(this.chats)) {
|
|
81
87
|
for (const scheduledAction of this.scheduled) {
|
|
82
|
-
this.
|
|
88
|
+
ctx.initializeChatContext(this.name, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), `Scheduled:${scheduledAction.key}:${chatId}`);
|
|
83
89
|
try {
|
|
84
90
|
const responses = await scheduledAction.exec(ctx);
|
|
85
91
|
this.api.enqueueBatchedResponses(responses);
|
|
92
|
+
ctx.isInitialized = false;
|
|
86
93
|
}
|
|
87
94
|
catch (error) {
|
|
88
|
-
|
|
95
|
+
this.logger.errorWithTraceId(ctx.botName, ctx.traceId, chatName, error, ctx);
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
await this.api.flushResponses();
|
|
93
100
|
}
|
|
94
101
|
async processMessage(msg) {
|
|
95
|
-
const ctx = new messageContext_1.MessageContext();
|
|
102
|
+
const ctx = new messageContext_1.MessageContext(this.storage, this.logger, this.scheduler);
|
|
96
103
|
for (const commandAction of this.commands) {
|
|
97
|
-
this.
|
|
104
|
+
ctx.initializeMessageContext(this.name, commandAction, msg);
|
|
98
105
|
try {
|
|
99
106
|
const responses = await commandAction.exec(ctx);
|
|
100
107
|
this.api.enqueueBatchedResponses(responses);
|
|
108
|
+
ctx.isInitialized = false;
|
|
101
109
|
}
|
|
102
110
|
catch (error) {
|
|
103
|
-
|
|
111
|
+
this.logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatInfo.name, error, ctx);
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
await this.api.flushResponses();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hours } from '../types/timeValues';
|
|
2
2
|
export declare class CachedStateFactory {
|
|
3
|
-
getValue: () => Promise<unknown>;
|
|
4
|
-
invalidationTimeoutInHours: Hours;
|
|
3
|
+
readonly getValue: () => Promise<unknown>;
|
|
4
|
+
readonly invalidationTimeoutInHours: Hours;
|
|
5
5
|
constructor(itemFactory: () => Promise<unknown>, invalidationTimeout: Hours);
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=cachedStateFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cachedStateFactory.d.ts","sourceRoot":"","sources":["../../entities/cachedStateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,kBAAkB;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cachedStateFactory.d.ts","sourceRoot":"","sources":["../../entities/cachedStateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,kBAAkB;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,0BAA0B,EAAE,KAAK,CAAC;gBAGvC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,mBAAmB,EAAE,KAAK;CAKjC"}
|
|
@@ -4,32 +4,31 @@ import { IActionWithState } from '../../types/actionWithState';
|
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { BotResponse } from '../../types/response';
|
|
6
6
|
import { Milliseconds } from '../../types/timeValues';
|
|
7
|
+
import { ChatInfo } from '../../dtos/chatInfo';
|
|
8
|
+
import { ILogger } from '../../types/logger';
|
|
9
|
+
import { IScheduler } from '../../types/scheduler';
|
|
7
10
|
/**
|
|
8
11
|
* Context of action executed in chat.
|
|
9
12
|
*/
|
|
10
13
|
export declare class ChatContext<TActionState extends IActionState> {
|
|
11
14
|
protected action: IActionWithState<TActionState>;
|
|
12
|
-
|
|
15
|
+
/** Storage client instance for the bot executing this action. */
|
|
16
|
+
readonly storage: IStorageClient;
|
|
17
|
+
/** Logger instance for the bot executing this action */
|
|
18
|
+
readonly logger: ILogger;
|
|
19
|
+
/** Scheduler instance for the bot executing this action */
|
|
20
|
+
readonly scheduler: IScheduler;
|
|
13
21
|
/** Trace id of a action execution. */
|
|
14
22
|
traceId: number | string;
|
|
15
23
|
/** Name of a bot that executes this action. */
|
|
16
24
|
botName: string;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/** Name of a chat that action is executed in. */
|
|
20
|
-
chatName: string;
|
|
21
|
-
/** Storage client instance for this bot. */
|
|
22
|
-
storage: IStorageClient;
|
|
25
|
+
/** Chat information. */
|
|
26
|
+
chatInfo: ChatInfo;
|
|
23
27
|
/** Ordered collection of responses to be processed */
|
|
24
28
|
responses: BotResponse[];
|
|
25
29
|
isInitialized: boolean;
|
|
26
|
-
constructor();
|
|
27
|
-
initializeChatContext(botName: string, action: IActionWithState<TActionState>,
|
|
28
|
-
/**
|
|
29
|
-
* Manually update the state of an action.
|
|
30
|
-
* @param stateUpdateAction Function that will modify state.
|
|
31
|
-
*/
|
|
32
|
-
updateState(stateUpdateAction: (state: TActionState) => void): void;
|
|
30
|
+
constructor(storage: IStorageClient, logger: ILogger, scheduler: IScheduler);
|
|
31
|
+
initializeChatContext(botName: string, action: IActionWithState<TActionState>, chatInfo: ChatInfo, traceId: number | string): this;
|
|
33
32
|
/**
|
|
34
33
|
* Sends text message to chat after action execution is finished.
|
|
35
34
|
* 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":"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,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
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,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY,SAAS,YAAY;IACtD,SAAS,CAAC,MAAM,EAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAElD,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAG,cAAc,CAAC;IAClC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAG,OAAO,CAAC;IAC1B,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAG,UAAU,CAAC;IAEhC,sCAAsC;IACtC,OAAO,EAAG,MAAM,GAAG,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,uDAAuD;IACvD,SAAS,EAAE,WAAW,EAAE,CAAM;IAE9B,aAAa,UAAS;gBAGlB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,UAAU;IAOzB,qBAAqB,CACjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM;IAa5B;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAahE;;;;;OAKG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;;;OAKG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;IAW9B;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,YAAY;CAKxC"}
|
|
@@ -2,40 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatContext = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const imageMessage_1 = require("
|
|
6
|
-
const textMessage_1 = require("
|
|
7
|
-
const videoMessage_1 = require("
|
|
8
|
-
const unpin_1 = require("
|
|
9
|
-
const delay_1 = require("
|
|
5
|
+
const imageMessage_1 = require("../../dtos/responses/imageMessage");
|
|
6
|
+
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
7
|
+
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
8
|
+
const unpin_1 = require("../../dtos/responses/unpin");
|
|
9
|
+
const delay_1 = require("../../dtos/responses/delay");
|
|
10
10
|
/**
|
|
11
11
|
* Context of action executed in chat.
|
|
12
12
|
*/
|
|
13
13
|
class ChatContext {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.updateActions = [];
|
|
14
|
+
constructor(storage, logger, scheduler) {
|
|
16
15
|
/** Ordered collection of responses to be processed */
|
|
17
16
|
this.responses = [];
|
|
18
17
|
this.isInitialized = false;
|
|
18
|
+
this.storage = storage;
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
this.scheduler = scheduler;
|
|
19
21
|
}
|
|
20
|
-
initializeChatContext(botName, action,
|
|
22
|
+
initializeChatContext(botName, action, chatInfo, traceId) {
|
|
21
23
|
this.botName = botName;
|
|
22
24
|
this.action = action;
|
|
23
|
-
this.
|
|
24
|
-
this.chatName = chatName;
|
|
25
|
+
this.chatInfo = chatInfo;
|
|
25
26
|
this.traceId = traceId;
|
|
26
|
-
this.storage = storage;
|
|
27
|
-
this.updateActions = [];
|
|
28
27
|
this.isInitialized = true;
|
|
29
28
|
this.responses = [];
|
|
30
29
|
return this;
|
|
31
30
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Manually update the state of an action.
|
|
34
|
-
* @param stateUpdateAction Function that will modify state.
|
|
35
|
-
*/
|
|
36
|
-
updateState(stateUpdateAction) {
|
|
37
|
-
this.updateActions.push(stateUpdateAction);
|
|
38
|
-
}
|
|
39
31
|
/**
|
|
40
32
|
* Sends text message to chat after action execution is finished.
|
|
41
33
|
* 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.
|
|
@@ -43,7 +35,7 @@ class ChatContext {
|
|
|
43
35
|
* @param options Message sending option.
|
|
44
36
|
*/
|
|
45
37
|
sendTextToChat(text, options) {
|
|
46
|
-
this.responses.push(new textMessage_1.TextMessage(text, this.
|
|
38
|
+
this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, undefined, this.traceId, this.action, options));
|
|
47
39
|
}
|
|
48
40
|
/**
|
|
49
41
|
* Sends image message to chat after action execution is finished.
|
|
@@ -53,7 +45,7 @@ class ChatContext {
|
|
|
53
45
|
*/
|
|
54
46
|
sendImageToChat(name, options) {
|
|
55
47
|
const filePath = `./content/${name}.png`;
|
|
56
|
-
this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.
|
|
48
|
+
this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
|
|
57
49
|
}
|
|
58
50
|
/**
|
|
59
51
|
* Sends video/gif message to chat after action execution is finished.
|
|
@@ -63,7 +55,7 @@ class ChatContext {
|
|
|
63
55
|
*/
|
|
64
56
|
sendVideoToChat(name, options) {
|
|
65
57
|
const filePath = `./content/${name}.mp4`;
|
|
66
|
-
this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.
|
|
58
|
+
this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, undefined, this.traceId, this.action, options));
|
|
67
59
|
}
|
|
68
60
|
/**
|
|
69
61
|
* Unpins message after action execution is finished.
|
|
@@ -71,14 +63,14 @@ class ChatContext {
|
|
|
71
63
|
* @param messageId Message id.
|
|
72
64
|
*/
|
|
73
65
|
unpinMessage(messageId) {
|
|
74
|
-
this.responses.push(new unpin_1.UnpinResponse(messageId, this.
|
|
66
|
+
this.responses.push(new unpin_1.UnpinResponse(messageId, this.chatInfo, this.traceId, this.action));
|
|
75
67
|
}
|
|
76
68
|
/**
|
|
77
69
|
* Delays next response by specified amount of time.
|
|
78
70
|
* @param delay Delay in milliseconds.
|
|
79
71
|
*/
|
|
80
72
|
delayNextResponse(delay) {
|
|
81
|
-
this.responses.push(new delay_1.DelayResponse(delay, this.
|
|
73
|
+
this.responses.push(new delay_1.DelayResponse(delay, this.chatInfo, this.traceId, this.action));
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
76
|
exports.ChatContext = ChatContext;
|
|
@@ -2,10 +2,12 @@ import { TelegramEmoji } from 'telegraf/types';
|
|
|
2
2
|
import { IStorageClient } from '../../types/storage';
|
|
3
3
|
import { IActionState } from '../../types/actionState';
|
|
4
4
|
import { ChatContext } from './chatContext';
|
|
5
|
-
import { IncomingMessage } from '
|
|
5
|
+
import { IncomingMessage } from '../../dtos/incomingMessage';
|
|
6
6
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
7
7
|
import { IActionWithState } from '../../types/actionWithState';
|
|
8
8
|
import { MessageTypeValue } from '../../types/messageTypes';
|
|
9
|
+
import { ILogger } from '../../types/logger';
|
|
10
|
+
import { IScheduler } from '../../types/scheduler';
|
|
9
11
|
/**
|
|
10
12
|
* Context of action executed in chat, in response to a message
|
|
11
13
|
*/
|
|
@@ -24,8 +26,8 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
24
26
|
fromUserName: string;
|
|
25
27
|
/** Type of message being received */
|
|
26
28
|
messageType: MessageTypeValue;
|
|
27
|
-
constructor();
|
|
28
|
-
initializeMessageContext(botName: string, action: IActionWithState<TActionState>, message: IncomingMessage
|
|
29
|
+
constructor(storage: IStorageClient, logger: ILogger, scheduler: IScheduler);
|
|
30
|
+
initializeMessageContext(botName: string, action: IActionWithState<TActionState>, message: IncomingMessage): this;
|
|
29
31
|
/**
|
|
30
32
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
31
33
|
* @param commandName Name of an action to load state of.
|
|
@@ -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;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
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;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,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;gBAG3B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,UAAU;IAKzB,wBAAwB,CACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,EAAE,eAAe;IAqB5B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageContext = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const imageMessage_1 = require("
|
|
6
|
-
const reaction_1 = require("
|
|
7
|
-
const textMessage_1 = require("
|
|
8
|
-
const videoMessage_1 = require("
|
|
5
|
+
const imageMessage_1 = require("../../dtos/responses/imageMessage");
|
|
6
|
+
const reaction_1 = require("../../dtos/responses/reaction");
|
|
7
|
+
const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
8
|
+
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
9
9
|
const actionStateBase_1 = require("../states/actionStateBase");
|
|
10
10
|
const chatContext_1 = require("./chatContext");
|
|
11
11
|
/**
|
|
12
12
|
* Context of action executed in chat, in response to a message
|
|
13
13
|
*/
|
|
14
14
|
class MessageContext extends chatContext_1.ChatContext {
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
15
|
+
constructor(storage, logger, scheduler) {
|
|
16
|
+
super(storage, logger, scheduler);
|
|
17
17
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
18
18
|
this.matchResults = [];
|
|
19
19
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
20
20
|
this.startCooldown = true;
|
|
21
21
|
}
|
|
22
|
-
initializeMessageContext(botName, action, message
|
|
22
|
+
initializeMessageContext(botName, action, message) {
|
|
23
23
|
this.messageId = message.message_id;
|
|
24
24
|
this.messageText = message.text ?? '';
|
|
25
25
|
this.messageType = message.type;
|
|
@@ -29,7 +29,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
29
29
|
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
30
30
|
this.matchResults = [];
|
|
31
31
|
this.startCooldown = true;
|
|
32
|
-
return this.initializeChatContext(botName, action, message.
|
|
32
|
+
return this.initializeChatContext(botName, action, message.chatInfo, message.traceId);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
@@ -39,7 +39,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
39
39
|
async loadStateOf(commandName) {
|
|
40
40
|
const storageKey = `command:${commandName.replace('.', '-')}`;
|
|
41
41
|
const allStates = await this.storage.load(storageKey);
|
|
42
|
-
const stateForChat = allStates[this.
|
|
42
|
+
const stateForChat = allStates[this.chatInfo.id];
|
|
43
43
|
if (!stateForChat) {
|
|
44
44
|
return new actionStateBase_1.ActionStateBase();
|
|
45
45
|
}
|
|
@@ -52,7 +52,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
52
52
|
* @param options Message sending option.
|
|
53
53
|
*/
|
|
54
54
|
replyWithText(text, options) {
|
|
55
|
-
this.responses.push(new textMessage_1.TextMessage(text, this.
|
|
55
|
+
this.responses.push(new textMessage_1.TextMessage(text, this.chatInfo, this.messageId, this.traceId, this.action, options));
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Reply with image message to message that triggered this action after action execution is finished.
|
|
@@ -62,7 +62,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
62
62
|
*/
|
|
63
63
|
replyWithImage(name, options) {
|
|
64
64
|
const filePath = `./content/${name}.png`;
|
|
65
|
-
this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.
|
|
65
|
+
this.responses.push(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
@@ -72,7 +72,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
72
72
|
*/
|
|
73
73
|
replyWithVideo(name, options) {
|
|
74
74
|
const filePath = `./content/${name}.mp4`;
|
|
75
|
-
this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.
|
|
75
|
+
this.responses.push(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatInfo, this.messageId, this.traceId, this.action, options));
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* React to the message that triggered this action after action execution is finished.
|
|
@@ -80,7 +80,7 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
80
80
|
* @param emoji Telegram emoji to react with.
|
|
81
81
|
*/
|
|
82
82
|
react(emoji) {
|
|
83
|
-
this.responses.push(new reaction_1.Reaction(this.traceId, this.
|
|
83
|
+
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageId, emoji, this.action));
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
exports.MessageContext = MessageContext;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Milliseconds } from '../types/timeValues';
|
|
2
2
|
export declare class TaskRecord {
|
|
3
|
-
name: string;
|
|
4
|
-
taskId: NodeJS.Timeout;
|
|
5
|
-
interval: Milliseconds;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly taskId: NodeJS.Timeout;
|
|
5
|
+
readonly interval: Milliseconds;
|
|
6
6
|
constructor(name: string, taskId: NodeJS.Timeout, interval: Milliseconds);
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=taskRecord.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;gBAEpB,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;CAK3E"}
|
package/dist/helpers/noop.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { BotResponse } from '../types/response';
|
|
1
2
|
export declare class Noop {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
3
|
+
static NoResponse: BotResponse[];
|
|
4
|
+
static true<T1>(arg1: T1): boolean;
|
|
5
|
+
static false<T1>(arg1: T1): boolean;
|
|
4
6
|
static call<T1, T2>(arg1: T1, arg2: T2): Promise<void>;
|
|
5
7
|
}
|
|
6
8
|
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,qBAAa,IAAI;IACb,MAAM,CAAC,UAAU,EAAE,WAAW,EAAE,CAAM;IACtC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;IAGxB,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;WAGZ,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAE/D"}
|
package/dist/helpers/noop.js
CHANGED
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Noop = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
5
|
class Noop {
|
|
6
|
-
static
|
|
6
|
+
static true(arg1) {
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
|
-
static
|
|
9
|
+
static false(arg1) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
static async call(arg1) { }
|
|
13
13
|
}
|
|
14
14
|
exports.Noop = Noop;
|
|
15
|
+
Noop.NoResponse = [];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { startBot, stopBots } from './main';
|
|
2
2
|
export { CommandActionBuilder } from './helpers/builders/commandActionBuilder';
|
|
3
3
|
export { CommandActionBuilderWithState } from './helpers/builders/commandActionBuilder';
|
|
4
|
-
export * from './helpers/builders/scheduledActionBuilder';
|
|
5
4
|
export { IStorageClient } from './types/storage';
|
|
5
|
+
export { ILogger } from './types/logger';
|
|
6
|
+
export { IScheduler } from './types/scheduler';
|
|
7
|
+
export * from './helpers/builders/scheduledActionBuilder';
|
|
6
8
|
export * from './types/actionState';
|
|
7
9
|
export * from './entities/states/actionStateBase';
|
|
8
10
|
export { Hours, Milliseconds, Seconds } from './types/timeValues';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/main.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { ScheduledAction } from './entities/actions/scheduledAction';
|
|
|
4
4
|
import { IActionState } from './types/actionState';
|
|
5
5
|
import { BotInstance } from './entities/botInstance';
|
|
6
6
|
import { Seconds } from './types/timeValues';
|
|
7
|
+
import { IScheduler } from './types/scheduler';
|
|
8
|
+
import { ILogger } from './types/logger';
|
|
7
9
|
/**
|
|
8
10
|
* Starts bot
|
|
9
11
|
*/
|
|
@@ -18,14 +20,20 @@ declare function startBot(options: {
|
|
|
18
20
|
scheduled: ScheduledAction<IActionState>[];
|
|
19
21
|
/** Object containing chat name and chat id pairs. Used for logging and execution of scheduled action. */
|
|
20
22
|
chats: Record<string, number>;
|
|
21
|
-
/** Storage client for bot state storage. If not provided, default `JsonFileStorage` will be used. */
|
|
22
|
-
storageClient?: IStorageClient;
|
|
23
23
|
/** Storage path for default `JsonFileStorage` client. Will be used only if `storageClient` is not provided. If not provided, default value of `./storage/` will be used.*/
|
|
24
24
|
storagePath?: string;
|
|
25
25
|
/** Period of time between execution of scheduled actions. */
|
|
26
26
|
scheduledPeriod?: Seconds;
|
|
27
27
|
/** If true, telegram API objects will be logged instead of message content. */
|
|
28
28
|
verboseLoggingForIncomingMessage?: boolean;
|
|
29
|
+
services?: {
|
|
30
|
+
/** Storage client for bot state storage. If not provided, default `JsonFileStorage` will be used. */
|
|
31
|
+
storageClient?: IStorageClient;
|
|
32
|
+
/** Logger client for bot logging. If not provided, default `JsonFileStorage` will be used. */
|
|
33
|
+
logger?: ILogger;
|
|
34
|
+
/** Scheduler client for bot scheduling. If not provided, default `NodeTimeoutScheduler` will be used. */
|
|
35
|
+
scheduler?: IScheduler;
|
|
36
|
+
};
|
|
29
37
|
}): Promise<BotInstance>;
|
|
30
38
|
/**
|
|
31
39
|
* Terminates all scheduled tasks, closes storage connections and stops all bots.
|