chz-telegram-bot 0.7.31 → 0.7.32
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/commandAction.js +1 -1
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +12 -7
- package/dist/helpers/mapUtils.d.ts +1 -1
- package/dist/helpers/mapUtils.d.ts.map +1 -1
- package/dist/helpers/mapUtils.js +3 -3
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +2 -1
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +21 -21
- package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -1
- package/dist/services/nodeTimeoutScheduler.js +6 -1
- package/dist/types/events.d.ts +4 -4
- package/dist/types/events.js +4 -4
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ export class CommandAction {
|
|
|
41
41
|
this.maxAllowedSimultaniousExecutions =
|
|
42
42
|
maxAllowedSimultaniousExecutions;
|
|
43
43
|
this.semaphoreFactory = () => new Semaphore(this.maxAllowedSimultaniousExecutions);
|
|
44
|
-
this.key = `command:${this.name.
|
|
44
|
+
this.key = `command:${this.name.replaceAll('.', '-')}`;
|
|
45
45
|
}
|
|
46
46
|
async exec(ctx) {
|
|
47
47
|
let lock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../src/entities/actions/scheduledAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAA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BlC"}
|
|
@@ -17,7 +17,7 @@ export class ScheduledAction {
|
|
|
17
17
|
handler;
|
|
18
18
|
constructor(name, handler, providers, cachedStateFactories, stateConstructor) {
|
|
19
19
|
this.name = name;
|
|
20
|
-
this.key = `scheduled:${this.name.
|
|
20
|
+
this.key = `scheduled:${this.name.replaceAll('.', '-')}`;
|
|
21
21
|
this.timeinHoursProvider = providers.timeinHoursProvider;
|
|
22
22
|
this.activeProvider = providers.isActiveProvider;
|
|
23
23
|
this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
|
|
@@ -67,7 +67,10 @@ export class ScheduledAction {
|
|
|
67
67
|
});
|
|
68
68
|
const value = await cachedItemFactory.getValue();
|
|
69
69
|
this.cachedState.set(key, value);
|
|
70
|
-
ctx.scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () =>
|
|
70
|
+
ctx.scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => {
|
|
71
|
+
this.cachedState.delete(key);
|
|
72
|
+
ScheduledAction.locks.delete(semaphoreKey);
|
|
73
|
+
}, hoursToMilliseconds(cachedItemFactory.invalidationTimeoutInHours), ctx.botName);
|
|
71
74
|
return value;
|
|
72
75
|
}
|
|
73
76
|
finally {
|
|
@@ -82,12 +85,14 @@ export class ScheduledAction {
|
|
|
82
85
|
}
|
|
83
86
|
checkIfShouldBeExecuted(state, ctx) {
|
|
84
87
|
const now = new Date();
|
|
85
|
-
const startOfToday =
|
|
88
|
+
const startOfToday = now.getTime() -
|
|
89
|
+
(now.getHours() * 3600000 +
|
|
90
|
+
now.getMinutes() * 60000 +
|
|
91
|
+
now.getSeconds() * 1000 +
|
|
92
|
+
now.getMilliseconds());
|
|
86
93
|
const lastExecutedDate = new Date(state.lastExecutedDate);
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
scheduledTime.setTime(scheduledTime.getTime() + this.timeinHoursProvider(ctx) * 3600000);
|
|
90
|
-
const isAllowedToTrigger = currentTime >= scheduledTime;
|
|
94
|
+
const scheduledTime = new Date(startOfToday + this.timeinHoursProvider(ctx) * 3600000);
|
|
95
|
+
const isAllowedToTrigger = now >= scheduledTime;
|
|
91
96
|
const hasTriggeredToday = lastExecutedDate.getTime() > startOfToday;
|
|
92
97
|
return isAllowedToTrigger && !hasTriggeredToday;
|
|
93
98
|
}
|
|
@@ -6,6 +6,6 @@ type KeyedWriteableCollection<K, V> = KeyedReadonlyCollection<K, V> & {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function getOrCreateIfNotExists<K, V>(map: KeyedWriteableCollection<K, V>, key: K, fallbackFactory: () => V): V;
|
|
8
8
|
export declare function getOrSetIfNotExists<K, V>(map: KeyedWriteableCollection<K, V>, key: K, fallback: V): V;
|
|
9
|
-
export declare function getOrThrow<K, V>(map: KeyedReadonlyCollection<K, V>, key: K, error?: string):
|
|
9
|
+
export declare function getOrThrow<K, V>(map: KeyedReadonlyCollection<K, V>, key: K, error?: string): V & ({} | null);
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=mapUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapUtils.d.ts","sourceRoot":"","sources":["../../src/helpers/mapUtils.ts"],"names":[],"mappings":"AAAA,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;CAAE,CAAC;AACxE,KAAK,wBAAwB,CAAC,CAAC,EAAE,CAAC,IAAI,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAClE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC7D,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,CAAC,EACvC,GAAG,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,GA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,GAAG,EAAE,CAAC,EACN,KAAK,GAAE,MAAsC,mBAMhD"}
|
package/dist/helpers/mapUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function getOrCreateIfNotExists(map, key, fallbackFactory) {
|
|
2
2
|
const existingValue = map.get(key);
|
|
3
|
-
if (existingValue)
|
|
3
|
+
if (existingValue !== undefined)
|
|
4
4
|
return existingValue;
|
|
5
5
|
const fallback = fallbackFactory();
|
|
6
6
|
map.set(key, fallback);
|
|
@@ -8,14 +8,14 @@ export function getOrCreateIfNotExists(map, key, fallbackFactory) {
|
|
|
8
8
|
}
|
|
9
9
|
export function getOrSetIfNotExists(map, key, fallback) {
|
|
10
10
|
const existingValue = map.get(key);
|
|
11
|
-
if (existingValue)
|
|
11
|
+
if (existingValue !== undefined)
|
|
12
12
|
return existingValue;
|
|
13
13
|
map.set(key, fallback);
|
|
14
14
|
return fallback;
|
|
15
15
|
}
|
|
16
16
|
export function getOrThrow(map, key, error = 'Key not found in collection') {
|
|
17
17
|
const existingValue = map.get(key);
|
|
18
|
-
if (existingValue)
|
|
18
|
+
if (existingValue !== undefined)
|
|
19
19
|
return existingValue;
|
|
20
20
|
throw new Error(error);
|
|
21
21
|
}
|
|
@@ -7,7 +7,8 @@ import { BotInfo, TelegramBot } from '../../types/externalAliases';
|
|
|
7
7
|
import { TraceId } from '../../types/trace';
|
|
8
8
|
import { ReplyCapture } from '../../types/postSendOperations';
|
|
9
9
|
export declare class CommandActionProcessor extends BaseActionProcessor {
|
|
10
|
-
private static readonly
|
|
10
|
+
private static readonly fallbackFactoryForChatHistory;
|
|
11
|
+
private static readonly fallbackFactoryForCaptures;
|
|
11
12
|
private readonly replyCaptures;
|
|
12
13
|
private readonly chatHistory;
|
|
13
14
|
private botInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../src/services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AACA,OA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,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,OAAO,EAAE,OAAO;IAoDpB,2BAA2B,CACvB,OAAO,EAAE,YAAY,EACrB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;IAmDpB,OAAO,CAAC,iBAAiB;YA0BX,cAAc;YAwBd,YAAY;YAwBZ,sBAAsB;CAuCvC"}
|
|
@@ -10,8 +10,9 @@ import { ChatHistoryMessage } from '../../dtos/chatHistoryMessage';
|
|
|
10
10
|
import { BotEventType } from '../../types/events';
|
|
11
11
|
import { MESSAGE_HISTORY_LENGTH_LIMIT } from '../../helpers/constants';
|
|
12
12
|
export class CommandActionProcessor extends BaseActionProcessor {
|
|
13
|
-
static
|
|
14
|
-
|
|
13
|
+
static fallbackFactoryForChatHistory = () => [];
|
|
14
|
+
static fallbackFactoryForCaptures = () => [];
|
|
15
|
+
replyCaptures = new Map();
|
|
15
16
|
chatHistory = new Map();
|
|
16
17
|
botInfo;
|
|
17
18
|
commands = typeSafeObjectFromEntries(Object.values(MessageType).map((x) => [
|
|
@@ -35,7 +36,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
35
36
|
}
|
|
36
37
|
if (commands.length > 0) {
|
|
37
38
|
telegram.on('message', ({ message }) => {
|
|
38
|
-
const internalMessage = new IncomingMessage(message, this.botName, getOrCreateIfNotExists(this.chatHistory, message.chat.id, CommandActionProcessor.
|
|
39
|
+
const internalMessage = new IncomingMessage(message, this.botName, getOrCreateIfNotExists(this.chatHistory, message.chat.id, CommandActionProcessor.fallbackFactoryForChatHistory));
|
|
39
40
|
this.eventEmitter.emit(BotEventType.messageRecieved, {
|
|
40
41
|
botInfo: this.botInfo,
|
|
41
42
|
message: internalMessage,
|
|
@@ -52,12 +53,16 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
52
53
|
chatInfo,
|
|
53
54
|
traceId
|
|
54
55
|
});
|
|
55
|
-
this.replyCaptures.
|
|
56
|
+
const chatCaptures = getOrCreateIfNotExists(this.replyCaptures, chatInfo.id, CommandActionProcessor.fallbackFactoryForCaptures);
|
|
57
|
+
chatCaptures.push(replyAction);
|
|
56
58
|
capture.abortController.signal.addEventListener('abort', () => {
|
|
57
|
-
const
|
|
59
|
+
const chatCaptures = this.replyCaptures.get(chatInfo.id);
|
|
60
|
+
if (!chatCaptures)
|
|
61
|
+
return;
|
|
62
|
+
const capturesWithController = chatCaptures.filter((x) => x.abortController == capture.abortController);
|
|
58
63
|
for (const captureToCancel of capturesWithController) {
|
|
59
|
-
const index =
|
|
60
|
-
|
|
64
|
+
const index = chatCaptures.indexOf(captureToCancel);
|
|
65
|
+
chatCaptures.splice(index, 1);
|
|
61
66
|
this.eventEmitter.emit(BotEventType.commandActionCaptureAborted, {
|
|
62
67
|
parentMessageId,
|
|
63
68
|
chatInfo,
|
|
@@ -67,36 +72,30 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
67
72
|
}, { once: true });
|
|
68
73
|
}
|
|
69
74
|
updateChatHistory(msg) {
|
|
70
|
-
const chatHistoryArray = getOrCreateIfNotExists(this.chatHistory, msg.chatInfo.id, CommandActionProcessor.
|
|
71
|
-
|
|
72
|
-
chatHistoryArray.
|
|
75
|
+
const chatHistoryArray = getOrCreateIfNotExists(this.chatHistory, msg.chatInfo.id, CommandActionProcessor.fallbackFactoryForChatHistory);
|
|
76
|
+
if (chatHistoryArray.length >= MESSAGE_HISTORY_LENGTH_LIMIT)
|
|
77
|
+
chatHistoryArray.splice(0, chatHistoryArray.length - MESSAGE_HISTORY_LENGTH_LIMIT + 1);
|
|
73
78
|
chatHistoryArray.push(new ChatHistoryMessage(msg.messageId, msg.from, msg.text, msg.type, msg.traceId, msg.replyToMessageId, msg.updateObject.date));
|
|
74
79
|
}
|
|
75
80
|
async processCommand(command, msg) {
|
|
76
81
|
const ctx = new MessageContextInternal(this.storage, this.scheduler, this.eventEmitter, command, msg, this.botName, this.botInfo);
|
|
77
82
|
const { proxy, revoke } = Proxy.revocable(ctx, {});
|
|
78
|
-
let responses = undefined;
|
|
79
83
|
try {
|
|
80
|
-
|
|
84
|
+
await this.executeAction(command, proxy);
|
|
81
85
|
}
|
|
82
86
|
finally {
|
|
83
|
-
|
|
84
|
-
this.api.flushResponses();
|
|
85
|
-
}
|
|
87
|
+
this.api.flushResponses();
|
|
86
88
|
revoke();
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
async processReply(capture, msg) {
|
|
90
92
|
const ctx = new ReplyContextInternal(this.storage, this.scheduler, this.eventEmitter, capture, msg, this.botName, this.botInfo);
|
|
91
93
|
const { proxy, revoke } = Proxy.revocable(ctx, {});
|
|
92
|
-
let responses = undefined;
|
|
93
94
|
try {
|
|
94
|
-
|
|
95
|
+
await this.executeAction(capture, proxy);
|
|
95
96
|
}
|
|
96
97
|
finally {
|
|
97
|
-
|
|
98
|
-
this.api.flushResponses();
|
|
99
|
-
}
|
|
98
|
+
this.api.flushResponses();
|
|
100
99
|
revoke();
|
|
101
100
|
}
|
|
102
101
|
}
|
|
@@ -115,7 +114,8 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
115
114
|
for (const command of commandsToCheck) {
|
|
116
115
|
actionPromises.push(this.processCommand(command, msg));
|
|
117
116
|
}
|
|
118
|
-
|
|
117
|
+
const chatCaptures = getOrCreateIfNotExists(this.replyCaptures, msg.chatInfo.id, CommandActionProcessor.fallbackFactoryForCaptures);
|
|
118
|
+
for (const capture of chatCaptures) {
|
|
119
119
|
actionPromises.push(this.processReply(capture, msg));
|
|
120
120
|
}
|
|
121
121
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeTimeoutScheduler.d.ts","sourceRoot":"","sources":["../../src/services/nodeTimeoutScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAg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AAO,EACrB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IA4BrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,OAAO,EACrB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CA2BxB"}
|
|
@@ -49,7 +49,12 @@ export class NodeTimeoutScheduler {
|
|
|
49
49
|
});
|
|
50
50
|
action();
|
|
51
51
|
};
|
|
52
|
-
setTimeout(
|
|
52
|
+
const handle = setTimeout(() => {
|
|
53
|
+
this.activeTasks.splice(this.activeTasks.indexOf(task), 1);
|
|
54
|
+
actionWrapper();
|
|
55
|
+
}, delay);
|
|
56
|
+
const task = new TaskRecord(name, handle, delay, traceId);
|
|
57
|
+
this.activeTasks.push(task);
|
|
53
58
|
this.eventEmitter.emit(BotEventType.taskCreated, {
|
|
54
59
|
name,
|
|
55
60
|
ownerName,
|
package/dist/types/events.d.ts
CHANGED
|
@@ -13,18 +13,18 @@ import { Milliseconds } from './timeValues';
|
|
|
13
13
|
import { TraceId } from './trace';
|
|
14
14
|
export declare const BotEventType: {
|
|
15
15
|
readonly error: "error.generic";
|
|
16
|
-
readonly messageRecieved: "message.
|
|
16
|
+
readonly messageRecieved: "message.received";
|
|
17
17
|
readonly messageProcessingStarted: "message.processingStarted";
|
|
18
18
|
readonly messageProcessingFinished: "message.processingFinished";
|
|
19
19
|
readonly commandActionExecuting: "command.actionExecuting";
|
|
20
20
|
readonly commandActionExecuted: "command.actionExecuted";
|
|
21
|
-
readonly commandActionCaptureStarted: "command.
|
|
22
|
-
readonly commandActionCaptureAborted: "command.
|
|
21
|
+
readonly commandActionCaptureStarted: "command.captureStarted";
|
|
22
|
+
readonly commandActionCaptureAborted: "command.captureAborted";
|
|
23
23
|
readonly replyActionExecuting: "reply.actionExecuting";
|
|
24
24
|
readonly replyActionExecuted: "reply.actionExecuted";
|
|
25
25
|
readonly inlineProcessingStarted: "inline.processingStarted";
|
|
26
26
|
readonly inlineProcessingFinished: "inline.processingFinished";
|
|
27
|
-
readonly inlineQueryRecieved: "inline.
|
|
27
|
+
readonly inlineQueryRecieved: "inline.queryReceived";
|
|
28
28
|
readonly inlineActionExecuting: "inline.actionExecuting";
|
|
29
29
|
readonly inlineActionExecuted: "inline.actionExecuted";
|
|
30
30
|
readonly inlineProcessingAborting: "inline.processingAborting";
|
package/dist/types/events.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export const BotEventType = {
|
|
2
2
|
error: 'error.generic',
|
|
3
|
-
messageRecieved: 'message.
|
|
3
|
+
messageRecieved: 'message.received',
|
|
4
4
|
messageProcessingStarted: 'message.processingStarted',
|
|
5
5
|
messageProcessingFinished: 'message.processingFinished',
|
|
6
6
|
commandActionExecuting: 'command.actionExecuting',
|
|
7
7
|
commandActionExecuted: 'command.actionExecuted',
|
|
8
|
-
commandActionCaptureStarted: 'command.
|
|
9
|
-
commandActionCaptureAborted: 'command.
|
|
8
|
+
commandActionCaptureStarted: 'command.captureStarted',
|
|
9
|
+
commandActionCaptureAborted: 'command.captureAborted',
|
|
10
10
|
replyActionExecuting: 'reply.actionExecuting',
|
|
11
11
|
replyActionExecuted: 'reply.actionExecuted',
|
|
12
12
|
inlineProcessingStarted: 'inline.processingStarted',
|
|
13
13
|
inlineProcessingFinished: 'inline.processingFinished',
|
|
14
|
-
inlineQueryRecieved: 'inline.
|
|
14
|
+
inlineQueryRecieved: 'inline.queryReceived',
|
|
15
15
|
inlineActionExecuting: 'inline.actionExecuting',
|
|
16
16
|
inlineActionExecuted: 'inline.actionExecuted',
|
|
17
17
|
inlineProcessingAborting: 'inline.processingAborting',
|