chz-telegram-bot 0.0.25 → 0.0.26
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.d.ts +1 -1
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +12 -7
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.d.ts +2 -1
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +15 -7
- package/dist/helpers/builders/commandActionBuilder.d.ts +3 -3
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/services/logger.d.ts.map +1 -1
- package/dist/services/logger.js +2 -8
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/taskScheduler.js +0 -1
- package/dist/services/telegramApi.d.ts +1 -1
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +3 -6
- package/entities/actions/commandAction.ts +17 -9
- package/entities/context/chatContext.ts +1 -3
- package/entities/context/messageContext.ts +20 -21
- package/helpers/builders/commandActionBuilder.ts +3 -3
- package/package.json +1 -1
- package/services/logger.ts +6 -8
- package/services/taskScheduler.ts +0 -1
- package/services/telegramApi.ts +5 -14
|
@@ -15,7 +15,7 @@ export declare class CommandAction<TActionState extends IActionState> implements
|
|
|
15
15
|
condition: CommandCondition<TActionState>;
|
|
16
16
|
stateConstructor: () => TActionState;
|
|
17
17
|
key: string;
|
|
18
|
-
constructor(trigger: string | RegExp |
|
|
18
|
+
constructor(trigger: string | RegExp | string[] | RegExp[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
|
|
19
19
|
exec(ctx: MessageContext<TActionState>): Promise<void>;
|
|
20
20
|
private checkTrigger;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI3D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;gBAGR,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI3D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;gBAGR,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,EAC9C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY;IAelC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAgD5C,OAAO,CAAC,YAAY;CAkDvB"}
|
|
@@ -62,15 +62,20 @@ class CommandAction {
|
|
|
62
62
|
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
trigger.lastIndex = 0;
|
|
66
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
67
|
+
if (execResult != null) {
|
|
68
|
+
matchResults.push(execResult);
|
|
69
|
+
if (trigger.global) {
|
|
70
|
+
while (true) {
|
|
71
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
72
|
+
if (nextResult == null)
|
|
73
|
+
break;
|
|
74
|
+
matchResults.push(nextResult);
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
|
-
shouldTrigger = true;
|
|
73
77
|
}
|
|
78
|
+
shouldTrigger = matchResults.length > 0;
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, !isUserAllowed);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY;IACjC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC5C,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,sCAAsC;IACtC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,G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,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;CAUjC"}
|
|
@@ -3,6 +3,7 @@ import { TelegramEmoji } from 'telegraf/types';
|
|
|
3
3
|
import { IStorageClient } from '../../types/storage';
|
|
4
4
|
import { IActionState } from '../../types/actionState';
|
|
5
5
|
import { ChatContext } from './chatContext';
|
|
6
|
+
import { IncomingMessage } from '../incomingMessage';
|
|
6
7
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
7
8
|
/**
|
|
8
9
|
* Context of action executed in chat, in response to a message
|
|
@@ -20,7 +21,7 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
20
21
|
startCooldown: boolean;
|
|
21
22
|
/** Name of a user that sent a message that triggered this action. */
|
|
22
23
|
fromUserName: string;
|
|
23
|
-
constructor(botName: string, scheduledKey: string, interactions: IBotApiInteractions,
|
|
24
|
+
constructor(botName: string, scheduledKey: string, interactions: IBotApiInteractions, message: IncomingMessage, storage: IStorageClient);
|
|
24
25
|
/**
|
|
25
26
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
26
27
|
* @param commandName Name of an action to load state of.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB,EACjC,
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,cAAc;IAoB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAY/B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
|
|
@@ -12,16 +12,18 @@ const chatContext_1 = require("./chatContext");
|
|
|
12
12
|
* Context of action executed in chat, in response to a message
|
|
13
13
|
*/
|
|
14
14
|
class MessageContext extends chatContext_1.ChatContext {
|
|
15
|
-
constructor(botName, scheduledKey, interactions,
|
|
16
|
-
super(botName, scheduledKey, interactions,
|
|
15
|
+
constructor(botName, scheduledKey, interactions, message, storage) {
|
|
16
|
+
super(botName, scheduledKey, interactions, message.chat.id, message.chatName, message.traceId, storage);
|
|
17
17
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
18
18
|
this.matchResults = [];
|
|
19
19
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
20
20
|
this.startCooldown = true;
|
|
21
|
-
this.messageId =
|
|
22
|
-
this.messageText =
|
|
23
|
-
this.fromUserId =
|
|
24
|
-
this.fromUserName =
|
|
21
|
+
this.messageId = message.message_id;
|
|
22
|
+
this.messageText = message.text ?? '';
|
|
23
|
+
this.fromUserId = message.from?.id;
|
|
24
|
+
this.fromUserName =
|
|
25
|
+
(message.from?.first_name ?? 'Unknown user') +
|
|
26
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
@@ -29,7 +31,13 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
29
31
|
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
30
32
|
*/
|
|
31
33
|
async loadStateOf(commandName) {
|
|
32
|
-
|
|
34
|
+
const storageKey = `command:${commandName.replace('.', '-')}`;
|
|
35
|
+
const allStates = await this.storage.load(storageKey);
|
|
36
|
+
const stateForChat = allStates[this.chatId];
|
|
37
|
+
if (!stateForChat) {
|
|
38
|
+
return new actionStateBase_1.ActionStateBase();
|
|
39
|
+
}
|
|
40
|
+
return stateForChat;
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* Reply with text message to message that triggered this action.
|
|
@@ -9,7 +9,7 @@ import { IActionState } from '../../types/actionState';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
11
11
|
name: string;
|
|
12
|
-
trigger: string | RegExp |
|
|
12
|
+
trigger: string | RegExp | string[] | RegExp[];
|
|
13
13
|
active: boolean;
|
|
14
14
|
cooldownSeconds: Seconds;
|
|
15
15
|
blacklist: number[];
|
|
@@ -29,11 +29,11 @@ export declare class CommandActionBuilderWithState<TActionState extends IActionS
|
|
|
29
29
|
*
|
|
30
30
|
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
31
31
|
*/
|
|
32
|
-
on(trigger: string | RegExp |
|
|
32
|
+
on(trigger: string | RegExp | string[] | RegExp[]): this;
|
|
33
33
|
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
34
34
|
* @param id User id or ids
|
|
35
35
|
*/
|
|
36
|
-
from(id: number |
|
|
36
|
+
from(id: number | number[]): this;
|
|
37
37
|
/** Defines action logic itself, will be executed on trigger.
|
|
38
38
|
* @param handler Callback that will be called on trigger
|
|
39
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD;;GAEG;AACH,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,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{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../services/logger.ts"],"names":[],"mappings":"AAAA,cAAM,UAAU;IAEZ,OAAO,CAAC,cAAc;IAQtB,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;AAED,eAAO,MAAM,MAAM,YAAmB,CAAC"}
|
package/dist/services/logger.js
CHANGED
|
@@ -11,16 +11,10 @@ class JsonLogger {
|
|
|
11
11
|
return JSON.stringify(plainObject);
|
|
12
12
|
}
|
|
13
13
|
logWithTraceId(botName, traceId, chatName, text) {
|
|
14
|
-
console.log(
|
|
14
|
+
console.log(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","text":"${text}"}`);
|
|
15
15
|
}
|
|
16
16
|
errorWithTraceId(botName, traceId, chatName, errorObj, extraData) {
|
|
17
|
-
console.error(JSON.stringify(
|
|
18
|
-
botName,
|
|
19
|
-
traceId,
|
|
20
|
-
chatName,
|
|
21
|
-
error: this.serializeError(errorObj),
|
|
22
|
-
extraData
|
|
23
|
-
}));
|
|
17
|
+
console.error(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(errorObj)}${extraData ? `,"extraData":${JSON.stringify(extraData)}` : ''}}`);
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
exports.Logger = new JsonLogger();
|
|
@@ -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;IAE/B,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;
|
|
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;IAE/B,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"}
|
|
@@ -13,7 +13,6 @@ class TaskScheduler {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
createTask(name, action, interval, executeRightAway, ownerName) {
|
|
16
|
-
executeRightAway = executeRightAway ?? false;
|
|
17
16
|
const taskId = setInterval(action, interval);
|
|
18
17
|
const task = new taskRecord_1.TaskRecord(name, taskId, interval);
|
|
19
18
|
if (executeRightAway) {
|
|
@@ -14,7 +14,7 @@ import { IActionState } from '../types/actionState';
|
|
|
14
14
|
import { CommandAction } from '../entities/actions/commandAction';
|
|
15
15
|
export declare class TelegramApiService {
|
|
16
16
|
isFlushing: boolean;
|
|
17
|
-
messageQueue:
|
|
17
|
+
messageQueue: BotResponse[];
|
|
18
18
|
botName: string;
|
|
19
19
|
telegram: Telegram;
|
|
20
20
|
chats: Record<number, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAA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YAAY,GAAG,YAAY,KAAK,IAAI,CAAC;IACvE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD"}
|
|
@@ -6,6 +6,7 @@ const messageContext_1 = require("../entities/context/messageContext");
|
|
|
6
6
|
const reverseRecord_1 = require("../helpers/reverseRecord");
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
8
|
const promises_1 = require("timers/promises");
|
|
9
|
+
const TELEGRAM_RATELIMIT_DELAY = 35;
|
|
9
10
|
class TelegramApiService {
|
|
10
11
|
constructor(botName, telegram, storage, chats) {
|
|
11
12
|
this.isFlushing = false;
|
|
@@ -25,7 +26,7 @@ class TelegramApiService {
|
|
|
25
26
|
break;
|
|
26
27
|
try {
|
|
27
28
|
await this.processResponse(message);
|
|
28
|
-
await (0, promises_1.setTimeout)(
|
|
29
|
+
await (0, promises_1.setTimeout)(TELEGRAM_RATELIMIT_DELAY);
|
|
29
30
|
}
|
|
30
31
|
catch (error) {
|
|
31
32
|
logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats[message.chatId], error, message);
|
|
@@ -94,11 +95,7 @@ class TelegramApiService {
|
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
97
|
createContextForMessage(incomingMessage, command) {
|
|
97
|
-
|
|
98
|
-
const lastName = incomingMessage.from?.last_name
|
|
99
|
-
? ` ${incomingMessage.from?.last_name}`
|
|
100
|
-
: '';
|
|
101
|
-
return new messageContext_1.MessageContext(this.botName, command.key, this.getInteractions(), incomingMessage.chat.id, incomingMessage.chatName, incomingMessage.message_id, incomingMessage.text, incomingMessage.from?.id, incomingMessage.traceId, firstName + lastName, this.storage);
|
|
98
|
+
return new messageContext_1.MessageContext(this.botName, command.key, this.getInteractions(), incomingMessage, this.storage);
|
|
102
99
|
}
|
|
103
100
|
createContextForChat(chatId, scheduledAction) {
|
|
104
101
|
return new chatContext_1.ChatContext(this.botName, scheduledAction.key, this.getInteractions(), chatId, this.chats[chatId], `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
|
|
@@ -26,13 +26,13 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
26
26
|
key: string;
|
|
27
27
|
|
|
28
28
|
constructor(
|
|
29
|
-
trigger: string | RegExp |
|
|
29
|
+
trigger: string | RegExp | string[] | RegExp[],
|
|
30
30
|
handler: CommandHandler<TActionState>,
|
|
31
31
|
name: string,
|
|
32
32
|
active: boolean,
|
|
33
33
|
cooldown: Seconds,
|
|
34
|
-
chatsBlacklist:
|
|
35
|
-
allowedUsers:
|
|
34
|
+
chatsBlacklist: number[],
|
|
35
|
+
allowedUsers: number[],
|
|
36
36
|
condition: CommandCondition<TActionState>,
|
|
37
37
|
stateConstructor: () => TActionState
|
|
38
38
|
) {
|
|
@@ -122,14 +122,22 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
122
122
|
if (typeof trigger == 'string') {
|
|
123
123
|
shouldTrigger = ctx.messageText.toLowerCase() == trigger;
|
|
124
124
|
} else {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
trigger.lastIndex = 0;
|
|
126
|
+
|
|
127
|
+
const execResult = trigger.exec(ctx.messageText);
|
|
128
|
+
if (execResult != null) {
|
|
129
|
+
matchResults.push(execResult);
|
|
130
|
+
|
|
131
|
+
if (trigger.global) {
|
|
132
|
+
while (true) {
|
|
133
|
+
const nextResult = trigger.exec(ctx.messageText);
|
|
134
|
+
if (nextResult == null) break;
|
|
135
|
+
matchResults.push(nextResult);
|
|
136
|
+
}
|
|
130
137
|
}
|
|
131
|
-
shouldTrigger = true;
|
|
132
138
|
}
|
|
139
|
+
|
|
140
|
+
shouldTrigger = matchResults.length > 0;
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
|
|
@@ -51,9 +51,7 @@ export class ChatContext<TActionState> {
|
|
|
51
51
|
* @param stateUpdateAction Function that will modify state.
|
|
52
52
|
*/
|
|
53
53
|
updateState(stateUpdateAction: (state: TActionState) => void) {
|
|
54
|
-
this.updateActions.push(
|
|
55
|
-
stateUpdateAction as (state: TActionState) => void
|
|
56
|
-
);
|
|
54
|
+
this.updateActions.push(stateUpdateAction);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
/**
|
|
@@ -9,6 +9,7 @@ import { TextMessage } from '../responses/textMessage';
|
|
|
9
9
|
import { VideoMessage } from '../responses/videoMessage';
|
|
10
10
|
import { ActionStateBase } from '../states/actionStateBase';
|
|
11
11
|
import { ChatContext } from './chatContext';
|
|
12
|
+
import { IncomingMessage } from '../incomingMessage';
|
|
12
13
|
import {
|
|
13
14
|
MessageSendingOptions,
|
|
14
15
|
TextMessageSendingOptions
|
|
@@ -37,29 +38,25 @@ export class MessageContext<
|
|
|
37
38
|
botName: string,
|
|
38
39
|
scheduledKey: string,
|
|
39
40
|
interactions: IBotApiInteractions,
|
|
40
|
-
|
|
41
|
-
chatName: string,
|
|
42
|
-
messageId: number,
|
|
43
|
-
messageText: string,
|
|
44
|
-
fromUserId: number | undefined,
|
|
45
|
-
traceId: number | string,
|
|
46
|
-
fromUserName: string,
|
|
41
|
+
message: IncomingMessage,
|
|
47
42
|
storage: IStorageClient
|
|
48
43
|
) {
|
|
49
44
|
super(
|
|
50
45
|
botName,
|
|
51
46
|
scheduledKey,
|
|
52
47
|
interactions,
|
|
53
|
-
|
|
54
|
-
chatName,
|
|
55
|
-
traceId,
|
|
48
|
+
message.chat.id,
|
|
49
|
+
message.chatName,
|
|
50
|
+
message.traceId,
|
|
56
51
|
storage
|
|
57
52
|
);
|
|
58
53
|
|
|
59
|
-
this.messageId =
|
|
60
|
-
this.messageText =
|
|
61
|
-
this.fromUserId =
|
|
62
|
-
this.fromUserName =
|
|
54
|
+
this.messageId = message.message_id;
|
|
55
|
+
this.messageText = message.text ?? '';
|
|
56
|
+
this.fromUserId = message.from?.id;
|
|
57
|
+
this.fromUserName =
|
|
58
|
+
(message.from?.first_name ?? 'Unknown user') +
|
|
59
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
/**
|
|
@@ -70,13 +67,15 @@ export class MessageContext<
|
|
|
70
67
|
async loadStateOf<TAnotherActionState extends IActionState>(
|
|
71
68
|
commandName: string
|
|
72
69
|
): Promise<TAnotherActionState> {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const storageKey = `command:${commandName.replace('.', '-')}`;
|
|
71
|
+
const allStates = await this.storage.load(storageKey);
|
|
72
|
+
const stateForChat = allStates[this.chatId];
|
|
73
|
+
|
|
74
|
+
if (!stateForChat) {
|
|
75
|
+
return new ActionStateBase() as TAnotherActionState;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return stateForChat as TAnotherActionState;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -12,7 +12,7 @@ import { Noop } from '../noop';
|
|
|
12
12
|
*/
|
|
13
13
|
export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
14
14
|
name: string;
|
|
15
|
-
trigger: string | RegExp |
|
|
15
|
+
trigger: string | RegExp | string[] | RegExp[] = [];
|
|
16
16
|
|
|
17
17
|
active = true;
|
|
18
18
|
cooldownSeconds: Seconds = 0 as Seconds;
|
|
@@ -38,7 +38,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
38
38
|
*
|
|
39
39
|
* If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
|
|
40
40
|
*/
|
|
41
|
-
on(trigger: string | RegExp |
|
|
41
|
+
on(trigger: string | RegExp | string[] | RegExp[]) {
|
|
42
42
|
this.trigger = trigger;
|
|
43
43
|
|
|
44
44
|
return this;
|
|
@@ -47,7 +47,7 @@ export class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
|
47
47
|
/** Defines id (or ids) of users that are allowed to trigger this action.
|
|
48
48
|
* @param id User id or ids
|
|
49
49
|
*/
|
|
50
|
-
from(id: number |
|
|
50
|
+
from(id: number | number[]) {
|
|
51
51
|
this.allowedUsers = toArray(id);
|
|
52
52
|
|
|
53
53
|
return this;
|
package/package.json
CHANGED
package/services/logger.ts
CHANGED
|
@@ -14,7 +14,9 @@ class JsonLogger {
|
|
|
14
14
|
chatName: string,
|
|
15
15
|
text: string
|
|
16
16
|
) {
|
|
17
|
-
console.log(
|
|
17
|
+
console.log(
|
|
18
|
+
`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","text":"${text}"}`
|
|
19
|
+
);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
errorWithTraceId<TData>(
|
|
@@ -25,13 +27,9 @@ class JsonLogger {
|
|
|
25
27
|
extraData?: TData | undefined
|
|
26
28
|
) {
|
|
27
29
|
console.error(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
chatName,
|
|
32
|
-
error: this.serializeError(errorObj),
|
|
33
|
-
extraData
|
|
34
|
-
})
|
|
30
|
+
`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","error":${this.serializeError(
|
|
31
|
+
errorObj
|
|
32
|
+
)}${extraData ? `,"extraData":${JSON.stringify(extraData)}` : ''}}`
|
|
35
33
|
);
|
|
36
34
|
}
|
|
37
35
|
}
|
package/services/telegramApi.ts
CHANGED
|
@@ -18,9 +18,11 @@ import { ScheduledAction } from '../entities/actions/scheduledAction';
|
|
|
18
18
|
import { IActionState } from '../types/actionState';
|
|
19
19
|
import { CommandAction } from '../entities/actions/commandAction';
|
|
20
20
|
|
|
21
|
+
const TELEGRAM_RATELIMIT_DELAY = 35 as Milliseconds;
|
|
22
|
+
|
|
21
23
|
export class TelegramApiService {
|
|
22
24
|
isFlushing = false;
|
|
23
|
-
messageQueue:
|
|
25
|
+
messageQueue: BotResponse[] = [];
|
|
24
26
|
|
|
25
27
|
botName: string;
|
|
26
28
|
telegram: Telegram;
|
|
@@ -51,7 +53,7 @@ export class TelegramApiService {
|
|
|
51
53
|
|
|
52
54
|
try {
|
|
53
55
|
await this.processResponse(message);
|
|
54
|
-
await setTimeout(
|
|
56
|
+
await setTimeout(TELEGRAM_RATELIMIT_DELAY);
|
|
55
57
|
} catch (error) {
|
|
56
58
|
Logger.errorWithTraceId(
|
|
57
59
|
this.botName,
|
|
@@ -178,22 +180,11 @@ export class TelegramApiService {
|
|
|
178
180
|
incomingMessage: IncomingMessage,
|
|
179
181
|
command: CommandAction<TActionState>
|
|
180
182
|
) {
|
|
181
|
-
const firstName = incomingMessage.from?.first_name ?? 'Unknown user';
|
|
182
|
-
const lastName = incomingMessage.from?.last_name
|
|
183
|
-
? ` ${incomingMessage.from?.last_name}`
|
|
184
|
-
: '';
|
|
185
|
-
|
|
186
183
|
return new MessageContext<TActionState>(
|
|
187
184
|
this.botName,
|
|
188
185
|
command.key,
|
|
189
186
|
this.getInteractions(),
|
|
190
|
-
incomingMessage
|
|
191
|
-
incomingMessage.chatName,
|
|
192
|
-
incomingMessage.message_id,
|
|
193
|
-
incomingMessage.text,
|
|
194
|
-
incomingMessage.from?.id,
|
|
195
|
-
incomingMessage.traceId,
|
|
196
|
-
firstName + lastName,
|
|
187
|
+
incomingMessage,
|
|
197
188
|
this.storage
|
|
198
189
|
);
|
|
199
190
|
}
|