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
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAIzC;;GAEG;AACH,iBAAe,QAAQ,CAAC,OAAO,EAAE;IAC7B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,2HAA2H;IAC3H,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;IACxC,mGAAmG;IACnG,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;IAC3C,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,2KAA2K;IAC3K,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,+EAA+E;IAC/E,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAC3C,QAAQ,CAAC,EAAE;QACP,qGAAqG;QACrG,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,8FAA8F;QAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,yGAAyG;QACzG,SAAS,CAAC,EAAE,UAAU,CAAC;KAC1B,CAAC;CACL,wBAqBA;AAED;;GAEG;AACH,iBAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,iBAIrC;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -3,13 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.startBot = startBot;
|
|
4
4
|
exports.stopBots = stopBots;
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
|
-
const logger_1 = require("./services/logger");
|
|
7
|
-
const taskScheduler_1 = require("./services/taskScheduler");
|
|
8
6
|
const botInstance_1 = require("./entities/botInstance");
|
|
9
7
|
const bots = [];
|
|
10
|
-
function log(text) {
|
|
11
|
-
logger_1.Logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
|
|
12
|
-
}
|
|
13
8
|
/**
|
|
14
9
|
* Starts bot
|
|
15
10
|
*/
|
|
@@ -21,10 +16,14 @@ async function startBot(options) {
|
|
|
21
16
|
commands: options.commands,
|
|
22
17
|
scheduled: options.scheduled,
|
|
23
18
|
chats: options.chats,
|
|
24
|
-
storageClient: options.storageClient,
|
|
25
19
|
storagePath: options.storagePath,
|
|
26
20
|
scheduledPeriod: options.scheduledPeriod,
|
|
27
|
-
verboseLoggingForIncomingMessage: options.verboseLoggingForIncomingMessage
|
|
21
|
+
verboseLoggingForIncomingMessage: options.verboseLoggingForIncomingMessage,
|
|
22
|
+
services: {
|
|
23
|
+
storageClient: options.services?.storageClient,
|
|
24
|
+
logger: options.services?.logger,
|
|
25
|
+
scheduler: options.services?.scheduler
|
|
26
|
+
}
|
|
28
27
|
});
|
|
29
28
|
bots.push(bot);
|
|
30
29
|
return bot;
|
|
@@ -33,10 +32,6 @@ async function startBot(options) {
|
|
|
33
32
|
* Terminates all scheduled tasks, closes storage connections and stops all bots.
|
|
34
33
|
*/
|
|
35
34
|
async function stopBots(reason) {
|
|
36
|
-
log(`Recieved termination code: ${reason}`);
|
|
37
|
-
taskScheduler_1.Scheduler.stopAll();
|
|
38
|
-
log('Acquiring storage semaphore...');
|
|
39
|
-
log('Stopping bots...');
|
|
40
35
|
for (const bot of bots) {
|
|
41
36
|
await bot.stop(reason);
|
|
42
37
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { IStorageClient } from '../types/storage';
|
|
2
|
-
import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
3
2
|
import { IActionState } from '../types/actionState';
|
|
4
3
|
import { IActionWithState, ActionKey } from '../types/actionWithState';
|
|
5
4
|
export declare class JsonFileStorage implements IStorageClient {
|
|
6
|
-
private locks;
|
|
7
|
-
private cache;
|
|
8
|
-
private storagePath;
|
|
9
|
-
private botName;
|
|
5
|
+
private readonly locks;
|
|
6
|
+
private readonly cache;
|
|
7
|
+
private readonly storagePath;
|
|
8
|
+
private readonly botName;
|
|
10
9
|
constructor(botName: string, actions: IActionWithState<IActionState>[], path?: string);
|
|
11
10
|
private lock;
|
|
12
11
|
private loadInternal;
|
|
@@ -15,7 +14,7 @@ export declare class JsonFileStorage implements IStorageClient {
|
|
|
15
14
|
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
16
15
|
saveMetadata(actions: IActionWithState<IActionState>[], botName: string): Promise<void>;
|
|
17
16
|
getActionState<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number): Promise<TActionState>;
|
|
18
|
-
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number,
|
|
17
|
+
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, state: TActionState): Promise<void>;
|
|
19
18
|
close(): Promise<void>;
|
|
20
19
|
updateStateFor<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
21
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEvE,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;IAClE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,MAAM;YAiBH,IAAI;YAgBJ,YAAY;YAqBZ,IAAI;IAgBlB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,SAAS;IAMtD,YAAY,CACd,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,OAAO,EAAE,MAAM;IAWb,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM;IAYZ,yBAAyB,CAAC,YAAY,SAAS,YAAY,EAC7D,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY;IAWjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAcrD"}
|
|
@@ -76,13 +76,11 @@ class JsonFileStorage {
|
|
|
76
76
|
return Object.assign(action.stateConstructor(), data[chatId]);
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
async saveActionExecutionResult(action, chatId,
|
|
79
|
+
async saveActionExecutionResult(action, chatId, state) {
|
|
80
80
|
await this.lock(action.key, async () => {
|
|
81
81
|
const data = await this.loadInternal(action.key);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await this.save(data, action.key);
|
|
85
|
-
}
|
|
82
|
+
data[chatId] = state;
|
|
83
|
+
await this.save(data, action.key);
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
async close() {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ILogger } from '../types/logger';
|
|
2
|
+
export declare class JsonLogger implements ILogger {
|
|
3
|
+
private serializeError;
|
|
4
|
+
logObjectWithTraceId(botName: string, traceId: string | number, chatName: string, data: any): void;
|
|
5
|
+
logWithTraceId(botName: string, traceId: string | number, chatName: string, text: string): void;
|
|
6
|
+
errorWithTraceId<TData>(botName: string, traceId: string | number, chatName: string, errorObj: unknown, extraData?: TData | undefined): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=jsonLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,qBAAa,UAAW,YAAW,OAAO;IAEtC,OAAO,CAAC,cAAc;IAQtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAEhB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CAAC,KAAK,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS;CAQpC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonLogger = void 0;
|
|
4
|
+
class JsonLogger {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
serializeError(error) {
|
|
7
|
+
const plainObject = {};
|
|
8
|
+
Object.getOwnPropertyNames(error).forEach(function (key) {
|
|
9
|
+
plainObject[key] = error[key];
|
|
10
|
+
});
|
|
11
|
+
return JSON.stringify(plainObject);
|
|
12
|
+
}
|
|
13
|
+
logObjectWithTraceId(botName, traceId, chatName,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
data) {
|
|
16
|
+
data.botName = botName;
|
|
17
|
+
data.traceId = traceId;
|
|
18
|
+
data.chatName = chatName;
|
|
19
|
+
console.log(data);
|
|
20
|
+
}
|
|
21
|
+
logWithTraceId(botName, traceId, chatName, text) {
|
|
22
|
+
console.log(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","text":"${text}"}`);
|
|
23
|
+
}
|
|
24
|
+
errorWithTraceId(botName, traceId, chatName, errorObj, extraData) {
|
|
25
|
+
console.error(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(errorObj)}${extraData ? `,"extraData":${JSON.stringify(extraData)}` : ''}}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.JsonLogger = JsonLogger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TaskRecord } from '../entities/taskRecord';
|
|
2
|
+
import { ILogger } from '../types/logger';
|
|
3
|
+
import { IScheduler } from '../types/scheduler';
|
|
4
|
+
import { Milliseconds } from '../types/timeValues';
|
|
5
|
+
export declare class NodeTimeoutScheduler implements IScheduler {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
readonly activeTasks: TaskRecord[];
|
|
8
|
+
constructor(logger: ILogger);
|
|
9
|
+
stopAll(): void;
|
|
10
|
+
createTask(name: string, action: () => void, interval: Milliseconds, executeRightAway: boolean, ownerName: string): void;
|
|
11
|
+
createOnetimeTask(name: string, action: () => void, delay: Milliseconds, ownerName: string): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=nodeTimeoutScheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeTimeoutScheduler.d.ts","sourceRoot":"","sources":["../../services/nodeTimeoutScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,oBAAqB,YAAW,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAClC,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAM;gBAE5B,MAAM,EAAE,OAAO;IAI3B,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IAmBrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CAoBxB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeTimeoutScheduler = void 0;
|
|
4
|
+
const taskRecord_1 = require("../entities/taskRecord");
|
|
5
|
+
class NodeTimeoutScheduler {
|
|
6
|
+
constructor(logger) {
|
|
7
|
+
this.activeTasks = [];
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
stopAll() {
|
|
11
|
+
this.activeTasks.forEach((task) => {
|
|
12
|
+
clearInterval(task.taskId);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
createTask(name, action, interval, executeRightAway, ownerName) {
|
|
16
|
+
const taskId = setInterval(action, interval);
|
|
17
|
+
const task = new taskRecord_1.TaskRecord(name, taskId, interval);
|
|
18
|
+
if (executeRightAway) {
|
|
19
|
+
setImmediate(action);
|
|
20
|
+
}
|
|
21
|
+
this.logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created task [${taskId}]${name}, that will run every ${interval}ms.`);
|
|
22
|
+
this.activeTasks.push(task);
|
|
23
|
+
}
|
|
24
|
+
createOnetimeTask(name, action, delay, ownerName) {
|
|
25
|
+
const actionWrapper = () => {
|
|
26
|
+
this.logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Executing delayed oneshot [${taskId}]${name}`);
|
|
27
|
+
action();
|
|
28
|
+
};
|
|
29
|
+
const taskId = setTimeout(actionWrapper, delay);
|
|
30
|
+
this.logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created oneshot task [${taskId}]${name}, that will run in ${delay}ms.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.NodeTimeoutScheduler = NodeTimeoutScheduler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TaskRecord } from '../entities/taskRecord';
|
|
2
2
|
import { Milliseconds } from '../types/timeValues';
|
|
3
3
|
declare class TaskScheduler {
|
|
4
|
-
activeTasks: TaskRecord[];
|
|
4
|
+
readonly activeTasks: TaskRecord[];
|
|
5
5
|
stopAll(): void;
|
|
6
6
|
createTask(name: string, action: () => void, interval: Milliseconds, executeRightAway: boolean, ownerName: string): void;
|
|
7
7
|
createOnetimeTask(name: string, action: () => void, delay: Milliseconds, ownerName: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,cAAM,aAAa;IACf,WAAW,EAAE,UAAU,EAAE,CAAM;
|
|
1
|
+
{"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,cAAM,aAAa;IACf,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAM;IAExC,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IAmBrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CAoBxB;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC"}
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { ChatContext } from '../entities/context/chatContext';
|
|
2
|
-
import { MessageContext } from '../entities/context/messageContext';
|
|
3
1
|
import { IStorageClient } from '../types/storage';
|
|
4
|
-
import { IncomingMessage } from '../entities/incomingMessage';
|
|
5
2
|
import { BotResponse } from '../types/response';
|
|
6
3
|
import { Telegram } from 'telegraf/typings/telegram';
|
|
7
|
-
import {
|
|
8
|
-
import { IActionState } from '../types/actionState';
|
|
9
|
-
import { CommandAction } from '../entities/actions/commandAction';
|
|
4
|
+
import { ILogger } from '../types/logger';
|
|
10
5
|
export declare class TelegramApiService {
|
|
6
|
+
private readonly telegram;
|
|
7
|
+
private readonly storage;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly botName;
|
|
10
|
+
private readonly messageQueue;
|
|
11
11
|
isFlushing: boolean;
|
|
12
|
-
|
|
13
|
-
botName: string;
|
|
14
|
-
telegram: Telegram;
|
|
15
|
-
chats: Record<number, string>;
|
|
16
|
-
storage: IStorageClient;
|
|
17
|
-
constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Record<string, number>);
|
|
12
|
+
constructor(botName: string, telegram: Telegram, storage: IStorageClient, logger: ILogger);
|
|
18
13
|
enqueueBatchedResponses(responses: BotResponse[]): void;
|
|
19
14
|
flushResponses(): Promise<void>;
|
|
20
15
|
private pinIfShould;
|
|
21
16
|
private processResponse;
|
|
22
|
-
initializeContextForMessage<TActionState extends IActionState>(ctx: MessageContext<TActionState>, incomingMessage: IncomingMessage, command: CommandAction<TActionState>): MessageContext<TActionState>;
|
|
23
|
-
initializeContextForChat<TActionState extends IActionState>(ctx: ChatContext<TActionState>, chatId: number, scheduledAction: ScheduledAction<TActionState>): ChatContext<TActionState>;
|
|
24
17
|
}
|
|
25
18
|
//# sourceMappingURL=telegramApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAI1C,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,UAAU,UAAS;gBAGf,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO;IAQnB,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAM1C,cAAc;YA2BN,WAAW;YAqBX,eAAe;CA8EhC"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TelegramApiService = void 0;
|
|
4
|
-
const inverseRecord_1 = require("../helpers/inverseRecord");
|
|
5
|
-
const logger_1 = require("./logger");
|
|
6
4
|
const promises_1 = require("timers/promises");
|
|
7
5
|
const TELEGRAM_RATELIMIT_DELAY = 35;
|
|
8
6
|
class TelegramApiService {
|
|
9
|
-
constructor(botName, telegram, storage,
|
|
10
|
-
this.isFlushing = false;
|
|
7
|
+
constructor(botName, telegram, storage, logger) {
|
|
11
8
|
this.messageQueue = [];
|
|
9
|
+
this.isFlushing = false;
|
|
12
10
|
this.telegram = telegram;
|
|
13
11
|
this.botName = botName;
|
|
14
|
-
this.chats = (0, inverseRecord_1.inverseRecord)(chats);
|
|
15
12
|
this.storage = storage;
|
|
13
|
+
this.logger = logger;
|
|
16
14
|
}
|
|
17
15
|
enqueueBatchedResponses(responses) {
|
|
18
16
|
for (const response of responses) {
|
|
@@ -32,15 +30,15 @@ class TelegramApiService {
|
|
|
32
30
|
await (0, promises_1.setTimeout)(TELEGRAM_RATELIMIT_DELAY);
|
|
33
31
|
}
|
|
34
32
|
catch (error) {
|
|
35
|
-
|
|
33
|
+
this.logger.errorWithTraceId(this.botName, message.traceId, message.chatInfo.name, error, message);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
this.isFlushing = false;
|
|
39
37
|
}
|
|
40
38
|
async pinIfShould(response, sentMessage) {
|
|
41
39
|
if (response.shouldPin) {
|
|
42
|
-
await this.telegram.pinChatMessage(response.
|
|
43
|
-
await this.storage.updateStateFor(response.action, response.
|
|
40
|
+
await this.telegram.pinChatMessage(response.chatInfo.id, sentMessage.message_id, { disable_notification: true });
|
|
41
|
+
await this.storage.updateStateFor(response.action, response.chatInfo.id, async (state) => {
|
|
44
42
|
state.pinnedMessages.push(sentMessage.message_id);
|
|
45
43
|
});
|
|
46
44
|
}
|
|
@@ -49,7 +47,7 @@ class TelegramApiService {
|
|
|
49
47
|
let sentMessage;
|
|
50
48
|
switch (response.kind) {
|
|
51
49
|
case 'text':
|
|
52
|
-
sentMessage = await this.telegram.sendMessage(response.
|
|
50
|
+
sentMessage = await this.telegram.sendMessage(response.chatInfo.id, response.content, {
|
|
53
51
|
reply_to_message_id: response.replyId,
|
|
54
52
|
parse_mode: 'MarkdownV2',
|
|
55
53
|
disable_web_page_preview: response.disableWebPreview
|
|
@@ -58,21 +56,21 @@ class TelegramApiService {
|
|
|
58
56
|
await this.pinIfShould(response, sentMessage);
|
|
59
57
|
break;
|
|
60
58
|
case 'image':
|
|
61
|
-
sentMessage = await this.telegram.sendPhoto(response.
|
|
59
|
+
sentMessage = await this.telegram.sendPhoto(response.chatInfo.id, response.content, response.replyId
|
|
62
60
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
61
|
{ reply_to_message_id: response.replyId }
|
|
64
62
|
: undefined);
|
|
65
63
|
await this.pinIfShould(response, sentMessage);
|
|
66
64
|
break;
|
|
67
65
|
case 'video':
|
|
68
|
-
sentMessage = await this.telegram.sendVideo(response.
|
|
66
|
+
sentMessage = await this.telegram.sendVideo(response.chatInfo.id, response.content, response.replyId
|
|
69
67
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
68
|
{ reply_to_message_id: response.replyId }
|
|
71
69
|
: undefined);
|
|
72
70
|
await this.pinIfShould(response, sentMessage);
|
|
73
71
|
break;
|
|
74
72
|
case 'react':
|
|
75
|
-
await this.telegram.setMessageReaction(response.
|
|
73
|
+
await this.telegram.setMessageReaction(response.chatInfo.id, response.messageId, [
|
|
76
74
|
{
|
|
77
75
|
type: 'emoji',
|
|
78
76
|
emoji: response.emoji
|
|
@@ -80,8 +78,8 @@ class TelegramApiService {
|
|
|
80
78
|
], true);
|
|
81
79
|
return;
|
|
82
80
|
case 'unpin':
|
|
83
|
-
await this.telegram.unpinChatMessage(response.
|
|
84
|
-
await this.storage.updateStateFor(response.action, response.
|
|
81
|
+
await this.telegram.unpinChatMessage(response.chatInfo.id, response.messageId);
|
|
82
|
+
await this.storage.updateStateFor(response.action, response.chatInfo.id, async (state) => {
|
|
85
83
|
state.pinnedMessages = state.pinnedMessages.filter((x) => x != response.messageId);
|
|
86
84
|
});
|
|
87
85
|
break;
|
|
@@ -91,11 +89,5 @@ class TelegramApiService {
|
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
|
-
initializeContextForMessage(ctx, incomingMessage, command) {
|
|
95
|
-
return ctx.initializeMessageContext(this.botName, command, incomingMessage, this.storage);
|
|
96
|
-
}
|
|
97
|
-
initializeContextForChat(ctx, chatId, scheduledAction) {
|
|
98
|
-
return ctx.initializeChatContext(this.botName, scheduledAction, chatId, this.chats[chatId], `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
|
|
99
|
-
}
|
|
100
92
|
}
|
|
101
93
|
exports.TelegramApiService = TelegramApiService;
|
|
@@ -3,7 +3,7 @@ export type ActionKey = string & {
|
|
|
3
3
|
__brand: 'actionKey';
|
|
4
4
|
};
|
|
5
5
|
export interface IActionWithState<TActionState extends IActionState> {
|
|
6
|
-
key: ActionKey;
|
|
7
|
-
stateConstructor: () => TActionState;
|
|
6
|
+
readonly key: ActionKey;
|
|
7
|
+
readonly stateConstructor: () => TActionState;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=actionWithState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY;IAC/D,GAAG,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY;IAC/D,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACjD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MessageContext } from '../entities/context/messageContext';
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
|
-
export type CommandCondition<TActionState extends IActionState> = (ctx: MessageContext<TActionState>) =>
|
|
3
|
+
export type CommandCondition<TActionState extends IActionState> = (ctx: MessageContext<TActionState>) => boolean;
|
|
4
4
|
//# sourceMappingURL=commandCondition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandCondition.d.ts","sourceRoot":"","sources":["../../types/commandCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI,CAC9D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,KAChC,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"commandCondition.d.ts","sourceRoot":"","sources":["../../types/commandCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI,CAC9D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,KAChC,OAAO,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface ILogger {
|
|
2
|
+
logObjectWithTraceId(botName: string, traceId: string | number, chatName: string, data: any): void;
|
|
3
|
+
logWithTraceId(botName: string, traceId: string | number, chatName: string, text: string): void;
|
|
4
|
+
errorWithTraceId<TData>(botName: string, traceId: string | number, chatName: string, errorObj: unknown, extraData?: TData | undefined): void;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../types/logger.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAEhB,IAAI,EAAE,GAAG,GACV,IAAI,CAAC;IAER,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACb,IAAI,CAAC;IAER,gBAAgB,CAAC,KAAK,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,GAC9B,IAAI,CAAC;CACX"}
|
package/dist/types/response.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { ChatInfo } from '../dtos/chatInfo';
|
|
2
|
+
import { DelayResponse } from '../dtos/responses/delay';
|
|
3
|
+
import { ImageMessage } from '../dtos/responses/imageMessage';
|
|
4
|
+
import { Reaction } from '../dtos/responses/reaction';
|
|
5
|
+
import { TextMessage } from '../dtos/responses/textMessage';
|
|
6
|
+
import { UnpinResponse } from '../dtos/responses/unpin';
|
|
7
|
+
import { VideoMessage } from '../dtos/responses/videoMessage';
|
|
7
8
|
import { IActionState } from './actionState';
|
|
8
9
|
import { IActionWithState } from './actionWithState';
|
|
9
10
|
export declare const BotResponseTypes: {
|
|
@@ -16,15 +17,15 @@ export declare const BotResponseTypes: {
|
|
|
16
17
|
};
|
|
17
18
|
export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | DelayResponse | ImageMessage;
|
|
18
19
|
export interface IChatResponse {
|
|
19
|
-
kind: keyof typeof BotResponseTypes;
|
|
20
|
-
|
|
21
|
-
traceId: number | string;
|
|
22
|
-
action: IActionWithState<IActionState>;
|
|
20
|
+
readonly kind: keyof typeof BotResponseTypes;
|
|
21
|
+
readonly chatInfo: ChatInfo;
|
|
22
|
+
readonly traceId: number | string;
|
|
23
|
+
readonly action: IActionWithState<IActionState>;
|
|
23
24
|
}
|
|
24
25
|
export interface IReplyMessage<TType> extends IChatResponse {
|
|
25
|
-
content: TType;
|
|
26
|
-
replyId: number | undefined;
|
|
27
|
-
disableWebPreview: boolean;
|
|
28
|
-
shouldPin: boolean;
|
|
26
|
+
readonly content: TType;
|
|
27
|
+
readonly replyId: number | undefined;
|
|
28
|
+
readonly disableWebPreview: boolean;
|
|
29
|
+
readonly shouldPin: boolean;
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=response.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAEX,MAAM,MAAM,WAAW,GACjB,aAAa,GACb,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,aAAa,GACb,YAAY,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,aAAa;IACvD,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Milliseconds } from './timeValues';
|
|
2
|
+
export interface IScheduler {
|
|
3
|
+
stopAll(): void;
|
|
4
|
+
createTask(name: string, action: () => void, interval: Milliseconds, executeRightAway: boolean, ownerName: string): void;
|
|
5
|
+
createOnetimeTask(name: string, action: () => void, delay: Milliseconds, ownerName: string): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../types/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,UAAU;IACvB,OAAO,IAAI,IAAI,CAAC;IAEhB,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM,GAClB,IAAI,CAAC;IAER,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,GAClB,IAAI,CAAC;CACX"}
|
package/dist/types/storage.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
2
1
|
import { IActionState } from './actionState';
|
|
3
2
|
import { ActionKey, IActionWithState } from './actionWithState';
|
|
4
3
|
export interface IStorageClient {
|
|
@@ -7,6 +6,6 @@ export interface IStorageClient {
|
|
|
7
6
|
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
8
7
|
saveMetadata<TActionState extends IActionState>(actions: IActionWithState<TActionState>[], botName: string): Promise<void>;
|
|
9
8
|
getActionState<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number): Promise<TActionState>;
|
|
10
|
-
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number,
|
|
9
|
+
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, state: TActionState): Promise<void>;
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,YAAY,SAAS,YAAY,EAClC,GAAG,EAAE,SAAS,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,YAAY,CAAC,YAAY,SAAS,YAAY,EAC1C,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,yBAAyB,CAAC,YAAY,SAAS,YAAY,EACvD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
|
package/dtos/chatInfo.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class ChatInfo {
|
|
2
|
+
/** Id of a chat that action is executed in. */
|
|
3
|
+
readonly id: number;
|
|
4
|
+
/** Name of a chat that action is executed in. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
|
|
7
|
+
constructor(chatId: number, chatName: string) {
|
|
8
|
+
this.id = chatId;
|
|
9
|
+
this.name = chatName;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -6,25 +6,25 @@ export class CommandTriggerCheckResult {
|
|
|
6
6
|
return new CommandTriggerCheckResult(false, [], false);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
matchResults: RegExpExecArray[];
|
|
11
|
-
skipCooldown: boolean;
|
|
9
|
+
readonly shouldExecute: boolean;
|
|
10
|
+
readonly matchResults: RegExpExecArray[];
|
|
11
|
+
readonly skipCooldown: boolean;
|
|
12
12
|
|
|
13
13
|
constructor(
|
|
14
|
-
|
|
14
|
+
shouldExecute: boolean,
|
|
15
15
|
matchResults: RegExpExecArray[],
|
|
16
16
|
skipCooldown: boolean
|
|
17
17
|
) {
|
|
18
|
-
this.
|
|
18
|
+
this.shouldExecute = shouldExecute;
|
|
19
19
|
this.matchResults = matchResults;
|
|
20
20
|
this.skipCooldown = skipCooldown;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
mergeWith(other: CommandTriggerCheckResult) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
return new CommandTriggerCheckResult(
|
|
25
|
+
this.shouldExecute || other.shouldExecute,
|
|
26
|
+
this.matchResults.concat(other.matchResults),
|
|
27
|
+
this.skipCooldown || other.skipCooldown
|
|
28
|
+
);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Message, Update, User } from 'telegraf/types';
|
|
2
2
|
import { randomInt } from 'crypto';
|
|
3
3
|
import { MessageType, MessageTypeValue } from '../types/messageTypes';
|
|
4
|
+
import { ChatInfo } from './chatInfo';
|
|
4
5
|
|
|
5
6
|
export class IncomingMessage {
|
|
6
|
-
message_id: number;
|
|
7
|
-
|
|
8
|
-
from: User | undefined;
|
|
9
|
-
text: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
traceId = randomInt(10000, 99999);
|
|
7
|
+
readonly message_id: number;
|
|
8
|
+
readonly chatInfo: ChatInfo;
|
|
9
|
+
readonly from: User | undefined;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly type: MessageTypeValue;
|
|
12
|
+
readonly traceId = randomInt(10000, 99999);
|
|
13
13
|
|
|
14
14
|
private detectMessageType(
|
|
15
15
|
message: Update.New & (Update.NonChannel & Message)
|
|
@@ -31,13 +31,14 @@ export class IncomingMessage {
|
|
|
31
31
|
|
|
32
32
|
constructor(ctxMessage: Update.New & (Update.NonChannel & Message)) {
|
|
33
33
|
this.message_id = ctxMessage.message_id;
|
|
34
|
-
this.chat = ctxMessage.chat;
|
|
35
34
|
this.from = ctxMessage.from;
|
|
36
35
|
this.text = 'text' in ctxMessage ? ctxMessage.text : '';
|
|
37
|
-
this.
|
|
38
|
-
|
|
36
|
+
this.chatInfo = new ChatInfo(
|
|
37
|
+
ctxMessage.chat.id,
|
|
39
38
|
'title' in ctxMessage.chat
|
|
40
39
|
? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
|
|
41
|
-
: 'DM'
|
|
40
|
+
: 'DM'
|
|
41
|
+
);
|
|
42
|
+
this.type = this.detectMessageType(ctxMessage);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -2,22 +2,23 @@ import { IActionState } from '../../types/actionState';
|
|
|
2
2
|
import { IActionWithState } from '../../types/actionWithState';
|
|
3
3
|
import { BotResponseTypes, IChatResponse } from '../../types/response';
|
|
4
4
|
import { Milliseconds } from '../../types/timeValues';
|
|
5
|
+
import { ChatInfo } from '../chatInfo';
|
|
5
6
|
|
|
6
7
|
export class DelayResponse implements IChatResponse {
|
|
7
|
-
kind = BotResponseTypes.delay;
|
|
8
|
+
readonly kind = BotResponseTypes.delay;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
traceId: number | string;
|
|
11
|
-
delay: Milliseconds;
|
|
12
|
-
action: IActionWithState<IActionState>;
|
|
10
|
+
readonly chatInfo: ChatInfo;
|
|
11
|
+
readonly traceId: number | string;
|
|
12
|
+
readonly delay: Milliseconds;
|
|
13
|
+
readonly action: IActionWithState<IActionState>;
|
|
13
14
|
|
|
14
15
|
constructor(
|
|
15
16
|
delay: Milliseconds,
|
|
16
|
-
|
|
17
|
+
chatInfo: ChatInfo,
|
|
17
18
|
traceId: number | string,
|
|
18
19
|
action: IActionWithState<IActionState>
|
|
19
20
|
) {
|
|
20
|
-
this.
|
|
21
|
+
this.chatInfo = chatInfo;
|
|
21
22
|
this.delay = delay;
|
|
22
23
|
this.traceId = traceId;
|
|
23
24
|
this.action = action;
|