chz-telegram-bot 0.5.3 → 0.5.5
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/builtin/helpAction.d.ts +2 -0
- package/dist/builtin/helpAction.d.ts.map +1 -0
- package/dist/builtin/helpAction.js +14 -0
- package/dist/dtos/chatHistoryMessage.d.ts +35 -0
- package/dist/dtos/chatHistoryMessage.d.ts.map +1 -0
- package/dist/dtos/chatHistoryMessage.js +32 -0
- package/dist/dtos/chatInfo.d.ts +17 -0
- package/dist/dtos/chatInfo.d.ts.map +1 -0
- package/dist/dtos/chatInfo.js +16 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts +24 -0
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -0
- package/dist/dtos/commandTriggerCheckResult.js +34 -0
- package/dist/dtos/cooldownInfo.d.ts +13 -0
- package/dist/dtos/cooldownInfo.d.ts.map +1 -0
- package/dist/dtos/cooldownInfo.js +12 -0
- package/dist/dtos/incomingMessage.d.ts +19 -0
- package/dist/dtos/incomingMessage.d.ts.map +1 -0
- package/dist/dtos/incomingMessage.js +63 -0
- package/dist/dtos/incomingQuery.d.ts +10 -0
- package/dist/dtos/incomingQuery.d.ts.map +1 -0
- package/dist/dtos/incomingQuery.js +14 -0
- package/dist/dtos/messageInfo.d.ts +22 -0
- package/dist/dtos/messageInfo.d.ts.map +1 -0
- package/dist/dtos/messageInfo.js +20 -0
- package/dist/dtos/propertyProviderSets.d.ts +16 -0
- package/dist/dtos/propertyProviderSets.d.ts.map +1 -0
- package/dist/dtos/propertyProviderSets.js +1 -0
- package/dist/dtos/replyInfo.d.ts +6 -0
- package/dist/dtos/replyInfo.d.ts.map +1 -0
- package/dist/dtos/replyInfo.js +8 -0
- package/dist/dtos/responses/delay.d.ts +16 -0
- package/dist/dtos/responses/delay.d.ts.map +1 -0
- package/dist/dtos/responses/delay.js +15 -0
- package/dist/dtos/responses/imageMessage.d.ts +22 -0
- package/dist/dtos/responses/imageMessage.d.ts.map +1 -0
- package/dist/dtos/responses/imageMessage.js +21 -0
- package/dist/dtos/responses/inlineQueryResponse.d.ts +13 -0
- package/dist/dtos/responses/inlineQueryResponse.d.ts.map +1 -0
- package/dist/dtos/responses/inlineQueryResponse.js +15 -0
- package/dist/dtos/responses/reaction.d.ts +16 -0
- package/dist/dtos/responses/reaction.d.ts.map +1 -0
- package/dist/dtos/responses/reaction.js +17 -0
- package/dist/dtos/responses/textMessage.d.ts +23 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -0
- package/dist/dtos/responses/textMessage.js +24 -0
- package/dist/dtos/responses/unpin.d.ts +15 -0
- package/dist/dtos/responses/unpin.d.ts.map +1 -0
- package/dist/dtos/responses/unpin.js +15 -0
- package/dist/dtos/responses/videoMessage.d.ts +22 -0
- package/dist/dtos/responses/videoMessage.d.ts.map +1 -0
- package/dist/dtos/responses/videoMessage.js +21 -0
- package/dist/dtos/userInfo.d.ts +12 -0
- package/dist/dtos/userInfo.d.ts.map +1 -0
- package/dist/dtos/userInfo.js +12 -0
- package/dist/entities/actions/commandAction.d.ts +31 -0
- package/dist/entities/actions/commandAction.d.ts.map +1 -0
- package/dist/entities/actions/commandAction.js +139 -0
- package/dist/entities/actions/inlineQueryAction.d.ts +14 -0
- package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -0
- package/dist/entities/actions/inlineQueryAction.js +43 -0
- package/dist/entities/actions/replyCaptureAction.d.ts +15 -0
- package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -0
- package/dist/entities/actions/replyCaptureAction.js +58 -0
- package/dist/entities/actions/scheduledAction.d.ts +24 -0
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -0
- package/dist/entities/actions/scheduledAction.js +72 -0
- package/dist/entities/botInstance.d.ts +37 -0
- package/dist/entities/botInstance.d.ts.map +1 -0
- package/dist/entities/botInstance.js +37 -0
- package/dist/entities/cachedStateFactory.d.ts +7 -0
- package/dist/entities/cachedStateFactory.d.ts.map +1 -0
- package/dist/entities/cachedStateFactory.js +8 -0
- package/dist/entities/context/baseContext.d.ts +39 -0
- package/dist/entities/context/baseContext.d.ts.map +1 -0
- package/dist/entities/context/baseContext.js +55 -0
- package/dist/entities/context/chatContext.d.ts +50 -0
- package/dist/entities/context/chatContext.d.ts.map +1 -0
- package/dist/entities/context/chatContext.js +65 -0
- package/dist/entities/context/inlineQueryContext.d.ts +27 -0
- package/dist/entities/context/inlineQueryContext.d.ts.map +1 -0
- package/dist/entities/context/inlineQueryContext.js +29 -0
- package/dist/entities/context/messageContext.d.ts +92 -0
- package/dist/entities/context/messageContext.d.ts.map +1 -0
- package/dist/entities/context/messageContext.js +116 -0
- package/dist/entities/context/replyContext.d.ts +89 -0
- package/dist/entities/context/replyContext.d.ts.map +1 -0
- package/dist/entities/context/replyContext.js +124 -0
- package/dist/entities/states/actionStateBase.d.ts +6 -0
- package/dist/entities/states/actionStateBase.d.ts.map +1 -0
- package/dist/entities/states/actionStateBase.js +4 -0
- package/dist/entities/taskRecord.d.ts +8 -0
- package/dist/entities/taskRecord.d.ts.map +1 -0
- package/dist/entities/taskRecord.js +10 -0
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/eslint.config.js +51 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts +100 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/commandActionBuilder.js +146 -0
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +37 -0
- package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/inlineQueryActionBuilder.js +50 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +68 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/scheduledActionBuilder.js +95 -0
- package/dist/helpers/mapUtils.d.ts +10 -0
- package/dist/helpers/mapUtils.d.ts.map +1 -0
- package/dist/helpers/mapUtils.js +13 -0
- package/dist/helpers/noop.d.ts +9 -0
- package/dist/helpers/noop.d.ts.map +1 -0
- package/dist/helpers/noop.js +17 -0
- package/dist/helpers/objectFromEntries.d.ts +2 -0
- package/dist/helpers/objectFromEntries.d.ts.map +1 -0
- package/dist/helpers/objectFromEntries.js +3 -0
- package/dist/helpers/timeConvertions.d.ts +5 -0
- package/dist/helpers/timeConvertions.d.ts.map +1 -0
- package/dist/helpers/timeConvertions.js +9 -0
- package/dist/helpers/toArray.d.ts +2 -0
- package/dist/helpers/toArray.d.ts.map +1 -0
- package/dist/helpers/toArray.js +3 -0
- package/dist/helpers/traceFactory.d.ts +3 -0
- package/dist/helpers/traceFactory.d.ts.map +1 -0
- package/dist/helpers/traceFactory.js +3 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/main.d.ts +52 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +34 -0
- package/dist/services/actionProcessingService.d.ts +25 -0
- package/dist/services/actionProcessingService.d.ts.map +1 -0
- package/dist/services/actionProcessingService.js +50 -0
- package/dist/services/actionProcessors/baseProcessor.d.ts +18 -0
- package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -0
- package/dist/services/actionProcessors/baseProcessor.js +29 -0
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +20 -0
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -0
- package/dist/services/actionProcessors/commandActionProcessor.js +116 -0
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +11 -0
- package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -0
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +61 -0
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +17 -0
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -0
- package/dist/services/actionProcessors/scheduledActionProcessor.js +56 -0
- package/dist/services/jsonFileStorage.d.ts +23 -0
- package/dist/services/jsonFileStorage.d.ts.map +1 -0
- package/dist/services/jsonFileStorage.js +109 -0
- package/dist/services/jsonLogger.d.ts +11 -0
- package/dist/services/jsonLogger.d.ts.map +1 -0
- package/dist/services/jsonLogger.js +66 -0
- package/dist/services/nodeTimeoutScheduler.d.ts +13 -0
- package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -0
- package/dist/services/nodeTimeoutScheduler.js +31 -0
- package/dist/services/responseProcessingQueue.d.ts +12 -0
- package/dist/services/responseProcessingQueue.d.ts.map +1 -0
- package/dist/services/responseProcessingQueue.js +37 -0
- package/dist/services/telegramApi.d.ts +23 -0
- package/dist/services/telegramApi.d.ts.map +1 -0
- package/dist/services/telegramApi.js +133 -0
- package/dist/types/action.d.ts +14 -0
- package/dist/types/action.d.ts.map +1 -0
- package/dist/types/action.js +1 -0
- package/dist/types/actionState.d.ts +5 -0
- package/dist/types/actionState.d.ts.map +1 -0
- package/dist/types/actionState.js +1 -0
- package/dist/types/cachedValueAccessor.d.ts +2 -0
- package/dist/types/cachedValueAccessor.d.ts.map +1 -0
- package/dist/types/cachedValueAccessor.js +1 -0
- package/dist/types/capture.d.ts +24 -0
- package/dist/types/capture.d.ts.map +1 -0
- package/dist/types/capture.js +1 -0
- package/dist/types/commandCondition.d.ts +8 -0
- package/dist/types/commandCondition.d.ts.map +1 -0
- package/dist/types/commandCondition.js +1 -0
- package/dist/types/commandTrigger.d.ts +2 -0
- package/dist/types/commandTrigger.d.ts.map +1 -0
- package/dist/types/commandTrigger.js +1 -0
- package/dist/types/externalAliases.d.ts +11 -0
- package/dist/types/externalAliases.d.ts.map +1 -0
- package/dist/types/externalAliases.js +1 -0
- package/dist/types/handlers.d.ts +21 -0
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/handlers.js +1 -0
- package/dist/types/inputFile.d.ts +5 -0
- package/dist/types/inputFile.d.ts.map +1 -0
- package/dist/types/inputFile.js +1 -0
- package/dist/types/logger.d.ts +13 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +1 -0
- package/dist/types/messageSendingOptions.d.ts +9 -0
- package/dist/types/messageSendingOptions.d.ts.map +1 -0
- package/dist/types/messageSendingOptions.js +1 -0
- package/dist/types/messageTypes.d.ts +20 -0
- package/dist/types/messageTypes.d.ts.map +1 -0
- package/dist/types/messageTypes.js +18 -0
- package/dist/types/propertyProvider.d.ts +8 -0
- package/dist/types/propertyProvider.d.ts.map +1 -0
- package/dist/types/propertyProvider.js +1 -0
- package/dist/types/response.d.ts +39 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +9 -0
- package/dist/types/scheduler.d.ts +7 -0
- package/dist/types/scheduler.d.ts.map +1 -0
- package/dist/types/scheduler.js +1 -0
- package/dist/types/storage.d.ts +11 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +1 -0
- package/dist/types/timeValues.d.ts +15 -0
- package/dist/types/timeValues.d.ts.map +1 -0
- package/dist/types/timeValues.js +1 -0
- package/dist/types/trace.d.ts +6 -0
- package/dist/types/trace.d.ts.map +1 -0
- package/dist/types/trace.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ScheduledAction } from '../../entities/actions/scheduledAction';
|
|
2
|
+
import { CachedStateFactory } from '../../entities/cachedStateFactory';
|
|
3
|
+
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
4
|
+
import { Noop } from '../noop';
|
|
5
|
+
/**
|
|
6
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
7
|
+
*/
|
|
8
|
+
export class ScheduledActionBuilderWithState {
|
|
9
|
+
name;
|
|
10
|
+
cachedStateFactories = new Map();
|
|
11
|
+
stateConstructor;
|
|
12
|
+
handler = Noop.call;
|
|
13
|
+
whitelistProvider = () => [];
|
|
14
|
+
activeProvider = () => true;
|
|
15
|
+
timeinHoursProvider = () => 0;
|
|
16
|
+
/**
|
|
17
|
+
* Builder for `ScheduledAction` with state represented by `TActionState`
|
|
18
|
+
* @param name Action name, will be used for logging and storage
|
|
19
|
+
* @param stateConstructor Function that creates default state object
|
|
20
|
+
*/
|
|
21
|
+
constructor(name, stateConstructor) {
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.stateConstructor = stateConstructor;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sets whitelist for this action.
|
|
27
|
+
* @param chatIds Chat ids to execute in.
|
|
28
|
+
*/
|
|
29
|
+
in(chatIds) {
|
|
30
|
+
this.whitelistProvider = () => chatIds;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Defines time for scheduled item execution.
|
|
35
|
+
* @param time Time of day (0 - 23) to execute action.
|
|
36
|
+
*/
|
|
37
|
+
runAt(time) {
|
|
38
|
+
this.timeinHoursProvider = () => time;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/** Defines action logic itself, will be executed on timer.
|
|
42
|
+
* @param handler Callback that will be called on timer.
|
|
43
|
+
*/
|
|
44
|
+
do(handler) {
|
|
45
|
+
this.handler = handler;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Defines process-wide cache, that is shared by all actions of this type (even in different bot instances).
|
|
50
|
+
* Can be used for fetch request de-duping, etc.
|
|
51
|
+
* @param key Key that will be used to retrieve value from cache.
|
|
52
|
+
* @param itemFactory Callback that will be executed once to create cached value.
|
|
53
|
+
* @param invalidationTimeoutInHours Timeout for cache invalidation.
|
|
54
|
+
*/
|
|
55
|
+
withSharedCache(key, itemFactory, invalidationTimeoutInHours = 20) {
|
|
56
|
+
this.cachedStateFactories.set(key, new CachedStateFactory(itemFactory, invalidationTimeoutInHours));
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/** If called during building, action is marked as disabled and never checked. */
|
|
60
|
+
disabled() {
|
|
61
|
+
this.activeProvider = () => false;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configures action to use property value providers instead of static value to allow changes in runtime
|
|
66
|
+
*/
|
|
67
|
+
withConfiguration(configuration) {
|
|
68
|
+
if (configuration.chatsWhitelistProvider)
|
|
69
|
+
this.whitelistProvider = configuration.chatsWhitelistProvider;
|
|
70
|
+
if (configuration.timeinHoursProvider)
|
|
71
|
+
this.timeinHoursProvider = configuration.timeinHoursProvider;
|
|
72
|
+
if (configuration.isActiveProvider)
|
|
73
|
+
this.activeProvider = configuration.isActiveProvider;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/** Builds action */
|
|
77
|
+
build() {
|
|
78
|
+
return new ScheduledAction(this.name, this.handler, {
|
|
79
|
+
chatsWhitelistProvider: this.whitelistProvider,
|
|
80
|
+
isActiveProvider: this.activeProvider,
|
|
81
|
+
timeinHoursProvider: this.timeinHoursProvider
|
|
82
|
+
}, this.cachedStateFactories, this.stateConstructor);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
87
|
+
*/
|
|
88
|
+
export class ScheduledActionBuilder extends ScheduledActionBuilderWithState {
|
|
89
|
+
/**
|
|
90
|
+
* Builder for `ScheduledAction` with state represented by default state (containing only last execution date).
|
|
91
|
+
*/
|
|
92
|
+
constructor(name) {
|
|
93
|
+
super(name, () => new ActionStateBase());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type KeyedReadonlyCollection<K, V> = {
|
|
2
|
+
get: (key: K) => V | undefined;
|
|
3
|
+
};
|
|
4
|
+
type KeyedWriteableCollection<K, V> = KeyedReadonlyCollection<K, V> & {
|
|
5
|
+
set: (key: K, value: V) => KeyedWriteableCollection<K, V>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getOrSetIfNotExists<K, V>(map: KeyedWriteableCollection<K, V>, key: K, fallback: V): V;
|
|
8
|
+
export declare function getOrThrow<K, V>(map: KeyedReadonlyCollection<K, V>, key: K, error?: string): NonNullable<V>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=mapUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapUtils.d.ts","sourceRoot":"","sources":["../../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,mBAAmB,CAAC,CAAC,EAAE,CAAC,EACpC,GAAG,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,GAAG,EAAE,CAAC,EACN,QAAQ,EAAE,CAAC,KAQd;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC3B,GAAG,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,CAAC,EACN,KAAK,GAAE,MAAsC,kBAMhD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getOrSetIfNotExists(map, key, fallback) {
|
|
2
|
+
const existingValue = map.get(key);
|
|
3
|
+
if (existingValue)
|
|
4
|
+
return existingValue;
|
|
5
|
+
map.set(key, fallback);
|
|
6
|
+
return fallback;
|
|
7
|
+
}
|
|
8
|
+
export function getOrThrow(map, key, error = 'Key not found in collection') {
|
|
9
|
+
const existingValue = map.get(key);
|
|
10
|
+
if (existingValue)
|
|
11
|
+
return existingValue;
|
|
12
|
+
throw new Error(error);
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BotResponse } from '../types/response';
|
|
2
|
+
export declare class Noop {
|
|
3
|
+
static readonly NoResponse: BotResponse[];
|
|
4
|
+
static true(arg1: unknown): boolean;
|
|
5
|
+
static false(arg1: unknown): boolean;
|
|
6
|
+
static emptyString(): string;
|
|
7
|
+
static call(arg1: unknown): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,qBAAa,IAAI;IACb,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAAM;IAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;IAGzB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO;IAG1B,MAAM,CAAC,WAAW;WAGL,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
3
|
+
export class Noop {
|
|
4
|
+
static NoResponse = [];
|
|
5
|
+
static true(arg1) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
static false(arg1) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
static emptyString() {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
static async call(arg1, arg2) {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectFromEntries.d.ts","sourceRoot":"","sources":["../../helpers/objectFromEntries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,GAClC,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,EAE9D,SAAS,CAAC,KACX,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAElC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Hours, Milliseconds, Seconds } from '../types/timeValues';
|
|
2
|
+
export declare function secondsToMilliseconds(value: Seconds): Milliseconds;
|
|
3
|
+
export declare function hoursToMilliseconds(value: Hours): Milliseconds;
|
|
4
|
+
export declare function hoursToSeconds(value: Hours): Seconds;
|
|
5
|
+
//# sourceMappingURL=timeConvertions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeConvertions.d.ts","sourceRoot":"","sources":["../../helpers/timeConvertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAElE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,CAE9D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toArray.d.ts","sourceRoot":"","sources":["../../helpers/toArray.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,WAEpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceFactory.d.ts","sourceRoot":"","sources":["../../helpers/traceFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,wBAAgB,WAAW,CACvB,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAIa,OAAO,CACxC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './main';
|
|
2
|
+
export * from './helpers/builders/inlineQueryActionBuilder';
|
|
3
|
+
export * from './helpers/builders/commandActionBuilder';
|
|
4
|
+
export * from './helpers/builders/scheduledActionBuilder';
|
|
5
|
+
export * from './types/actionState';
|
|
6
|
+
export * from './entities/states/actionStateBase';
|
|
7
|
+
export * from './types/messageTypes';
|
|
8
|
+
export * from './helpers/timeConvertions';
|
|
9
|
+
export * from './types/action';
|
|
10
|
+
export * from './types/externalAliases';
|
|
11
|
+
export * from './types/storage';
|
|
12
|
+
export * from './types/logger';
|
|
13
|
+
export * from './types/scheduler';
|
|
14
|
+
export { CommandAction } from './entities/actions/commandAction';
|
|
15
|
+
export { InlineQueryAction } from './entities/actions/inlineQueryAction';
|
|
16
|
+
export { ReplyCaptureAction } from './entities/actions/replyCaptureAction';
|
|
17
|
+
export { ScheduledAction } from './entities/actions/scheduledAction';
|
|
18
|
+
export { Hours, Milliseconds, Seconds } from './types/timeValues';
|
|
19
|
+
export { ChatContext } from './entities/context/chatContext';
|
|
20
|
+
export { InlineQueryContext } from './entities/context/inlineQueryContext';
|
|
21
|
+
export { MessageContext } from './entities/context/messageContext';
|
|
22
|
+
export { ReplyContext } from './entities/context/replyContext';
|
|
23
|
+
export { ICaptureController } from './types/capture';
|
|
24
|
+
export { ChatInfo } from './dtos/chatInfo';
|
|
25
|
+
export { MessageInfo } from './dtos/messageInfo';
|
|
26
|
+
export { UserInfo } from './dtos/userInfo';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './main';
|
|
2
|
+
export * from './helpers/builders/inlineQueryActionBuilder';
|
|
3
|
+
export * from './helpers/builders/commandActionBuilder';
|
|
4
|
+
export * from './helpers/builders/scheduledActionBuilder';
|
|
5
|
+
export * from './types/actionState';
|
|
6
|
+
export * from './entities/states/actionStateBase';
|
|
7
|
+
export * from './types/messageTypes';
|
|
8
|
+
export * from './helpers/timeConvertions';
|
|
9
|
+
export * from './types/action';
|
|
10
|
+
export * from './types/externalAliases';
|
|
11
|
+
export * from './types/storage';
|
|
12
|
+
export * from './types/logger';
|
|
13
|
+
export * from './types/scheduler';
|
|
14
|
+
export { CommandAction } from './entities/actions/commandAction';
|
|
15
|
+
export { InlineQueryAction } from './entities/actions/inlineQueryAction';
|
|
16
|
+
export { ReplyCaptureAction } from './entities/actions/replyCaptureAction';
|
|
17
|
+
export { ScheduledAction } from './entities/actions/scheduledAction';
|
|
18
|
+
export { ChatInfo } from './dtos/chatInfo';
|
|
19
|
+
export { MessageInfo } from './dtos/messageInfo';
|
|
20
|
+
export { UserInfo } from './dtos/userInfo';
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IStorageClient } from './types/storage';
|
|
2
|
+
import { CommandAction } from './entities/actions/commandAction';
|
|
3
|
+
import { ScheduledAction } from './entities/actions/scheduledAction';
|
|
4
|
+
import { BotInstance } from './entities/botInstance';
|
|
5
|
+
import { Seconds } from './types/timeValues';
|
|
6
|
+
import { IScheduler } from './types/scheduler';
|
|
7
|
+
import { ILogger } from './types/logger';
|
|
8
|
+
import { InlineQueryAction } from './entities/actions/inlineQueryAction';
|
|
9
|
+
import { IActionState } from './types/actionState';
|
|
10
|
+
declare class BotOrchestrator {
|
|
11
|
+
bots: BotInstance[];
|
|
12
|
+
/**
|
|
13
|
+
* Starts bot
|
|
14
|
+
*/
|
|
15
|
+
startBot(options: {
|
|
16
|
+
/** Bot name, used in logging */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Path to file containing Telegram Bot token. */
|
|
19
|
+
tokenFilePath: string;
|
|
20
|
+
actions: {
|
|
21
|
+
/** Collection of actions that will be executed as a response to message from used. Created using `CommandActionBuilder`.*/
|
|
22
|
+
commands: CommandAction<IActionState>[];
|
|
23
|
+
/** Collection of actions that will be executed on timer. Created using `ScheduledActionBuilder`.*/
|
|
24
|
+
scheduled: ScheduledAction<IActionState>[];
|
|
25
|
+
/** Collection of actions that will handle inline queries */
|
|
26
|
+
inlineQueries: InlineQueryAction[];
|
|
27
|
+
};
|
|
28
|
+
/** Object containing chat name and chat id pairs. Used for logging and execution of scheduled action. */
|
|
29
|
+
chats: Record<string, number>;
|
|
30
|
+
/** 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.*/
|
|
31
|
+
storagePath?: string;
|
|
32
|
+
/** Period of time between execution of scheduled actions. */
|
|
33
|
+
scheduledPeriod?: Seconds;
|
|
34
|
+
/** If true, telegram API objects will be logged instead of message content. */
|
|
35
|
+
verboseLoggingForIncomingMessage?: boolean;
|
|
36
|
+
services?: {
|
|
37
|
+
/** Storage client for bot state storage. If not provided, default `JsonFileStorage` will be used. */
|
|
38
|
+
storageClient?: IStorageClient;
|
|
39
|
+
/** Logger client for bot logging. If not provided, default `JsonFileStorage` will be used. */
|
|
40
|
+
logger?: ILogger;
|
|
41
|
+
/** Scheduler client for bot scheduling. If not provided, default `NodeTimeoutScheduler` will be used. */
|
|
42
|
+
scheduler?: IScheduler;
|
|
43
|
+
};
|
|
44
|
+
}): Promise<BotInstance>;
|
|
45
|
+
/**
|
|
46
|
+
* Terminates all scheduled tasks, closes storage connections and stops all bots.
|
|
47
|
+
*/
|
|
48
|
+
stopBots(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare const botOrchestrator: BotOrchestrator;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,cAAM,eAAe;IACjB,IAAI,EAAE,WAAW,EAAE,CAAM;IAEzB;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE;QACpB,gCAAgC;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,kDAAkD;QAClD,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE;YACL,2HAA2H;YAC3H,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,mGAAmG;YACnG,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,4DAA4D;YAC5D,aAAa,EAAE,iBAAiB,EAAE,CAAC;SACtC,CAAC;QACF,yGAAyG;QACzG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,2KAA2K;QAC3K,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,6DAA6D;QAC7D,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,+EAA+E;QAC/E,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,QAAQ,CAAC,EAAE;YACP,qGAAqG;YACrG,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,8FAA8F;YAC9F,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,yGAAyG;YACzG,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IA0BD;;OAEG;IACG,QAAQ;CAKjB;AAED,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { BotInstance } from './entities/botInstance';
|
|
3
|
+
class BotOrchestrator {
|
|
4
|
+
bots = [];
|
|
5
|
+
/**
|
|
6
|
+
* Starts bot
|
|
7
|
+
*/
|
|
8
|
+
async startBot(options) {
|
|
9
|
+
const token = await readFile(options.tokenFilePath, 'utf8');
|
|
10
|
+
const bot = new BotInstance({
|
|
11
|
+
name: options.name,
|
|
12
|
+
actions: options.actions,
|
|
13
|
+
chats: options.chats,
|
|
14
|
+
services: {
|
|
15
|
+
storageClient: options.services?.storageClient,
|
|
16
|
+
logger: options.services?.logger,
|
|
17
|
+
scheduler: options.services?.scheduler
|
|
18
|
+
},
|
|
19
|
+
storagePath: options.storagePath
|
|
20
|
+
});
|
|
21
|
+
await bot.start(token, options.actions, options.scheduledPeriod, options.verboseLoggingForIncomingMessage);
|
|
22
|
+
this.bots.push(bot);
|
|
23
|
+
return bot;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Terminates all scheduled tasks, closes storage connections and stops all bots.
|
|
27
|
+
*/
|
|
28
|
+
async stopBots() {
|
|
29
|
+
for (const bot of this.bots) {
|
|
30
|
+
await bot.stop();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const botOrchestrator = new BotOrchestrator();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Seconds } from '../types/timeValues';
|
|
2
|
+
import { ILogger } from '../types/logger';
|
|
3
|
+
import { IScheduler } from '../types/scheduler';
|
|
4
|
+
import { IStorageClient } from '../types/storage';
|
|
5
|
+
import { InlineQueryAction } from '../entities/actions/inlineQueryAction';
|
|
6
|
+
import { IActionState } from '../types/actionState';
|
|
7
|
+
import { CommandAction } from '../entities/actions/commandAction';
|
|
8
|
+
import { ScheduledAction } from '../entities/actions/scheduledAction';
|
|
9
|
+
export declare class ActionProcessingService {
|
|
10
|
+
private readonly storage;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private readonly commandProcessor;
|
|
13
|
+
private readonly scheduledProcessor;
|
|
14
|
+
private readonly inlineQueryProcessor;
|
|
15
|
+
private readonly botName;
|
|
16
|
+
private telegramBot;
|
|
17
|
+
constructor(botName: string, chats: Record<string, number>, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
18
|
+
initialize(token: string, actions: {
|
|
19
|
+
commands: CommandAction<IActionState>[];
|
|
20
|
+
scheduled: ScheduledAction<IActionState>[];
|
|
21
|
+
inlineQueries: InlineQueryAction[];
|
|
22
|
+
}, scheduledPeriod?: Seconds, verboseLoggingForIncomingMessage?: boolean): Promise<void>;
|
|
23
|
+
stop(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=actionProcessingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionProcessingService.d.ts","sourceRoot":"","sources":["../../services/actionProcessingService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAQtE,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA6B;IAElE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,WAAW,CAAe;gBAG9B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IA4Bb,UAAU,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO,EACzB,gCAAgC,CAAC,EAAE,OAAO;IA2D9C,IAAI;CAGP"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { hoursToSeconds } from '../helpers/timeConvertions';
|
|
2
|
+
import { TelegramApiService } from './telegramApi';
|
|
3
|
+
import { buildHelpCommand } from '../builtin/helpAction';
|
|
4
|
+
import { CommandActionProcessor } from './actionProcessors/commandActionProcessor';
|
|
5
|
+
import { InlineQueryActionProcessor } from './actionProcessors/inlineQueryActionProcessor';
|
|
6
|
+
import { ScheduledActionProcessor } from './actionProcessors/scheduledActionProcessor';
|
|
7
|
+
import { Telegraf } from 'telegraf';
|
|
8
|
+
export class ActionProcessingService {
|
|
9
|
+
storage;
|
|
10
|
+
logger;
|
|
11
|
+
commandProcessor;
|
|
12
|
+
scheduledProcessor;
|
|
13
|
+
inlineQueryProcessor;
|
|
14
|
+
botName;
|
|
15
|
+
telegramBot;
|
|
16
|
+
constructor(botName, chats, storage, scheduler, logger) {
|
|
17
|
+
this.storage = storage;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this.commandProcessor = new CommandActionProcessor(botName, storage, scheduler, logger);
|
|
20
|
+
this.scheduledProcessor = new ScheduledActionProcessor(botName, chats, storage, scheduler, logger);
|
|
21
|
+
this.inlineQueryProcessor = new InlineQueryActionProcessor(botName, storage, scheduler, logger);
|
|
22
|
+
this.botName = botName;
|
|
23
|
+
}
|
|
24
|
+
async initialize(token, actions, scheduledPeriod, verboseLoggingForIncomingMessage) {
|
|
25
|
+
this.telegramBot = new Telegraf(token);
|
|
26
|
+
const api = new TelegramApiService(this.botName, this.telegramBot.telegram, this.storage, this.logger, (capture, id, chatInfo, traceId) => {
|
|
27
|
+
this.commandProcessor.captureRegistrationCallback(capture, id, chatInfo, traceId);
|
|
28
|
+
});
|
|
29
|
+
const botInfo = await this.telegramBot.telegram.getMe();
|
|
30
|
+
const commandActions = actions.commands.length > 0 && botInfo.username
|
|
31
|
+
? [
|
|
32
|
+
buildHelpCommand(actions.commands
|
|
33
|
+
.map((x) => x.readmeFactory(botInfo.username))
|
|
34
|
+
.filter((x) => !!x), botInfo.username),
|
|
35
|
+
...actions.commands
|
|
36
|
+
]
|
|
37
|
+
: [];
|
|
38
|
+
this.commandProcessor.initialize(api, this.telegramBot, commandActions, verboseLoggingForIncomingMessage ?? false, botInfo);
|
|
39
|
+
this.inlineQueryProcessor.initialize(api, this.telegramBot, actions.inlineQueries, 300);
|
|
40
|
+
this.scheduledProcessor.initialize(api, actions.scheduled, scheduledPeriod ?? hoursToSeconds(1));
|
|
41
|
+
void this.telegramBot.launch();
|
|
42
|
+
void this.storage.saveMetadata([
|
|
43
|
+
...actions.scheduled,
|
|
44
|
+
...commandActions
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
stop() {
|
|
48
|
+
this.telegramBot.stop();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ILogger } from '../../types/logger';
|
|
2
|
+
import { IScheduler } from '../../types/scheduler';
|
|
3
|
+
import { IStorageClient } from '../../types/storage';
|
|
4
|
+
import { TelegramApiService } from '../telegramApi';
|
|
5
|
+
import { IAction } from '../../types/action';
|
|
6
|
+
import { BaseContextInternal } from '../../entities/context/baseContext';
|
|
7
|
+
export declare abstract class BaseActionProcessor {
|
|
8
|
+
protected readonly storage: IStorageClient;
|
|
9
|
+
protected readonly scheduler: IScheduler;
|
|
10
|
+
protected readonly logger: ILogger;
|
|
11
|
+
protected readonly botName: string;
|
|
12
|
+
protected api: TelegramApiService;
|
|
13
|
+
constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
14
|
+
private defaultErrorHandler;
|
|
15
|
+
initializeDependencies(api: TelegramApiService): void;
|
|
16
|
+
executeAction<TAction extends IAction, TActionContext extends BaseContextInternal<TAction>>(action: TAction, ctx: TActionContext, errorHandler?: (error: Error, ctx: TActionContext) => void): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=baseProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/baseProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,8BAAsB,mBAAmB;IACrC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEnC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAG,kBAAkB,CAAC;gBAG/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IASnB,OAAO,CAAC,mBAAmB;IAO3B,sBAAsB,CAAC,GAAG,EAAE,kBAAkB;IAIxC,aAAa,CACf,OAAO,SAAS,OAAO,EACvB,cAAc,SAAS,mBAAmB,CAAC,OAAO,CAAC,EAEnD,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,cAAc,EACnB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;CAUjE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class BaseActionProcessor {
|
|
2
|
+
storage;
|
|
3
|
+
scheduler;
|
|
4
|
+
logger;
|
|
5
|
+
botName;
|
|
6
|
+
api;
|
|
7
|
+
constructor(botName, storage, scheduler, logger) {
|
|
8
|
+
this.storage = storage;
|
|
9
|
+
this.scheduler = scheduler;
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.botName = botName;
|
|
12
|
+
}
|
|
13
|
+
defaultErrorHandler(error, ctx) {
|
|
14
|
+
ctx.logger.errorWithTraceId(error, ctx);
|
|
15
|
+
}
|
|
16
|
+
initializeDependencies(api) {
|
|
17
|
+
this.api = api;
|
|
18
|
+
}
|
|
19
|
+
async executeAction(action, ctx, errorHandler) {
|
|
20
|
+
try {
|
|
21
|
+
const responses = await action.exec(ctx);
|
|
22
|
+
this.api.enqueueBatchedResponses(responses);
|
|
23
|
+
ctx.isInitialized = false;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
(errorHandler ?? this.defaultErrorHandler)(error, ctx);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommandAction } from '../../entities/actions/commandAction';
|
|
2
|
+
import { IActionState } from '../../types/actionState';
|
|
3
|
+
import { TelegramApiService } from '../telegramApi';
|
|
4
|
+
import { IReplyCapture } from '../../types/capture';
|
|
5
|
+
import { TraceId } from '../../types/trace';
|
|
6
|
+
import { ChatInfo } from '../../dtos/chatInfo';
|
|
7
|
+
import { BaseActionProcessor } from './baseProcessor';
|
|
8
|
+
import { BotInfo, TelegramBot } from '../../types/externalAliases';
|
|
9
|
+
export declare class CommandActionProcessor extends BaseActionProcessor {
|
|
10
|
+
private readonly replyCaptures;
|
|
11
|
+
private readonly chatHistory;
|
|
12
|
+
private botInfo;
|
|
13
|
+
private commands;
|
|
14
|
+
initialize(api: TelegramApiService, telegram: TelegramBot, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean, botInfo: BotInfo): void;
|
|
15
|
+
captureRegistrationCallback(capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId): void;
|
|
16
|
+
private processMessage;
|
|
17
|
+
private initializeReplyCaptureContext;
|
|
18
|
+
private initializeMessageContext;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=commandActionProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAKtD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAInE,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,OAAO,CAAW;IAE1B,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO,EACzC,OAAO,EAAE,OAAO;IA0DpB,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YAgCN,cAAc;IAqD5B,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,wBAAwB;CAmCnC"}
|