chz-telegram-bot 0.3.14 → 0.3.15
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/chatInfo.d.ts +10 -1
- package/dist/dtos/chatInfo.d.ts.map +1 -1
- package/dist/dtos/chatInfo.js +11 -5
- package/dist/dtos/commandTriggerCheckResult.d.ts +5 -5
- package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -1
- package/dist/dtos/commandTriggerCheckResult.js +4 -4
- package/dist/dtos/cooldownInfo.d.ts +9 -3
- package/dist/dtos/cooldownInfo.d.ts.map +1 -1
- package/dist/dtos/cooldownInfo.js +5 -1
- package/dist/dtos/incomingMessage.d.ts +1 -1
- package/dist/dtos/incomingMessage.d.ts.map +1 -1
- package/dist/dtos/incomingMessage.js +2 -2
- package/dist/dtos/incomingQuery.d.ts.map +1 -1
- package/dist/dtos/messageInfo.d.ts +21 -0
- package/dist/dtos/messageInfo.d.ts.map +1 -0
- package/dist/dtos/messageInfo.js +24 -0
- package/dist/dtos/userInfo.d.ts +12 -0
- package/dist/dtos/userInfo.d.ts.map +1 -0
- package/dist/dtos/userInfo.js +16 -0
- package/dist/entities/actions/commandAction.d.ts +2 -2
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +7 -7
- package/dist/entities/actions/inlineQueryAction.d.ts +2 -2
- package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -1
- package/dist/entities/actions/replyCaptureAction.d.ts +4 -4
- package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -1
- package/dist/entities/actions/replyCaptureAction.js +4 -4
- package/dist/entities/actions/scheduledAction.d.ts +2 -2
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/context/baseContext.d.ts +2 -1
- package/dist/entities/context/baseContext.d.ts.map +1 -1
- package/dist/entities/context/baseContext.js +3 -3
- package/dist/entities/context/chatContext.d.ts +3 -2
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +3 -3
- package/dist/entities/context/inlineQueryContext.d.ts +3 -2
- package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
- package/dist/entities/context/inlineQueryContext.js +3 -3
- package/dist/entities/context/messageContext.d.ts +11 -15
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +15 -20
- package/dist/entities/context/replyContext.d.ts +9 -15
- package/dist/entities/context/replyContext.d.ts.map +1 -1
- package/dist/entities/context/replyContext.js +12 -20
- package/dist/helpers/mapUtils.d.ts +9 -2
- package/dist/helpers/mapUtils.d.ts.map +1 -1
- package/dist/helpers/mapUtils.js +1 -1
- package/dist/services/actionProcessors/baseProcessor.d.ts +2 -2
- package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.d.ts +1 -0
- package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/commandActionProcessor.js +18 -19
- package/dist/services/actionProcessors/inlineQueryActionProcessor.js +1 -1
- package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -1
- package/dist/services/actionProcessors/scheduledActionProcessor.js +2 -2
- package/dist/types/action.d.ts +2 -2
- package/dist/types/action.d.ts.map +1 -1
- package/dist/types/capture.d.ts +3 -3
- package/dist/types/capture.d.ts.map +1 -1
- package/dtos/chatInfo.ts +10 -9
- package/dtos/commandTriggerCheckResult.ts +5 -15
- package/dtos/cooldownInfo.ts +6 -1
- package/dtos/incomingMessage.ts +7 -2
- package/dtos/incomingQuery.ts +4 -12
- package/dtos/messageInfo.ts +17 -0
- package/dtos/userInfo.ts +8 -0
- package/entities/actions/commandAction.ts +11 -11
- package/entities/actions/inlineQueryAction.ts +2 -2
- package/entities/actions/replyCaptureAction.ts +9 -9
- package/entities/actions/scheduledAction.ts +2 -2
- package/entities/context/baseContext.ts +11 -1
- package/entities/context/chatContext.ts +16 -5
- package/entities/context/inlineQueryContext.ts +10 -2
- package/entities/context/messageContext.ts +24 -25
- package/entities/context/replyContext.ts +26 -25
- package/helpers/mapUtils.ts +15 -2
- package/package.json +1 -1
- package/services/actionProcessors/baseProcessor.ts +3 -3
- package/services/actionProcessors/commandActionProcessor.ts +43 -21
- package/services/actionProcessors/inlineQueryActionProcessor.ts +3 -3
- package/services/actionProcessors/scheduledActionProcessor.ts +7 -4
- package/types/action.ts +2 -2
- package/types/capture.ts +5 -3
- package/chz-telegram-bot-0.3.14.tgz +0 -0
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
2
2
|
import { IActionState } from '../../types/actionState';
|
|
3
|
-
import {
|
|
3
|
+
import { ChatContextInternal } from './chatContext';
|
|
4
4
|
import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
5
|
-
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
6
5
|
import { CommandAction } from '../actions/commandAction';
|
|
7
6
|
import { Seconds } from '../../types/timeValues';
|
|
7
|
+
import { BaseContextPropertiesToOmit } from './baseContext';
|
|
8
|
+
import { MessageInfo } from '../../dtos/messageInfo';
|
|
9
|
+
import { UserInfo } from '../../dtos/userInfo';
|
|
10
|
+
export type MessageContext<TActionState extends IActionState> = Omit<MessageContextInternal<TActionState>, BaseContextPropertiesToOmit | 'startCooldown' | 'customCooldown'>;
|
|
8
11
|
/**
|
|
9
12
|
* Context of action executed in chat, in response to a message
|
|
10
13
|
*/
|
|
11
|
-
export declare class
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
export declare class MessageContextInternal<TActionState extends IActionState> extends ChatContextInternal<TActionState, CommandAction<TActionState>> {
|
|
15
|
+
/** Information about the user that triggered this action */
|
|
16
|
+
userInfo: UserInfo;
|
|
17
|
+
/** Information about the message that triggered this action */
|
|
18
|
+
messageInfo: MessageInfo;
|
|
16
19
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
17
20
|
matchResults: RegExpMatchArray[];
|
|
18
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
19
|
-
fromUserId: number | undefined;
|
|
20
21
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
21
22
|
startCooldown: boolean;
|
|
22
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
23
|
-
fromUserName: string;
|
|
24
|
-
/** Type of message being received */
|
|
25
|
-
messageType: MessageTypeValue;
|
|
26
|
-
/** Message object recieved from Telegram */
|
|
27
|
-
messageUpdateObject: TelegrafContextMessage;
|
|
28
23
|
/** Bot info from Telegram */
|
|
29
24
|
botInfo: UserFromGetMe;
|
|
30
25
|
customCooldown: Seconds | undefined;
|
|
@@ -32,6 +27,7 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
32
27
|
private replyWithText;
|
|
33
28
|
private replyWithImage;
|
|
34
29
|
private replyWithVideo;
|
|
30
|
+
skipCooldown(): void;
|
|
35
31
|
startCustomCooldown(customCooldown: Seconds): void;
|
|
36
32
|
/**
|
|
37
33
|
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAA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,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MessageContextInternal = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const imageMessage_1 = require("../../dtos/responses/imageMessage");
|
|
6
6
|
const reaction_1 = require("../../dtos/responses/reaction");
|
|
@@ -11,23 +11,15 @@ const replyInfo_1 = require("../../dtos/replyInfo");
|
|
|
11
11
|
/**
|
|
12
12
|
* Context of action executed in chat, in response to a message
|
|
13
13
|
*/
|
|
14
|
-
class
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
14
|
+
class MessageContextInternal extends chatContext_1.ChatContextInternal {
|
|
15
|
+
/** Information about the user that triggered this action */
|
|
16
|
+
userInfo;
|
|
17
|
+
/** Information about the message that triggered this action */
|
|
18
|
+
messageInfo;
|
|
19
19
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
20
20
|
matchResults = [];
|
|
21
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
22
|
-
fromUserId;
|
|
23
21
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
24
22
|
startCooldown = true;
|
|
25
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
26
|
-
fromUserName;
|
|
27
|
-
/** Type of message being received */
|
|
28
|
-
messageType;
|
|
29
|
-
/** Message object recieved from Telegram */
|
|
30
|
-
messageUpdateObject;
|
|
31
23
|
/** Bot info from Telegram */
|
|
32
24
|
botInfo;
|
|
33
25
|
customCooldown;
|
|
@@ -35,27 +27,30 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
35
27
|
return typeof quote == 'boolean'
|
|
36
28
|
? this.matchResults.length != 0
|
|
37
29
|
? this.matchResults[0][1]
|
|
38
|
-
: this.
|
|
30
|
+
: this.messageInfo.text
|
|
39
31
|
: quote;
|
|
40
32
|
}
|
|
41
33
|
replyWithText(text, quote, options) {
|
|
42
34
|
const quotedPart = this.getQuotePart(quote);
|
|
43
|
-
const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
35
|
+
const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
44
36
|
this.responses.push(response);
|
|
45
37
|
return this.createCaptureController(response);
|
|
46
38
|
}
|
|
47
39
|
replyWithImage(name, quote, options) {
|
|
48
40
|
const quotedPart = this.getQuotePart(quote);
|
|
49
|
-
const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
41
|
+
const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
50
42
|
this.responses.push(response);
|
|
51
43
|
return this.createCaptureController(response);
|
|
52
44
|
}
|
|
53
45
|
replyWithVideo(name, quote, options) {
|
|
54
46
|
const quotedPart = this.getQuotePart(quote);
|
|
55
|
-
const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
47
|
+
const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
56
48
|
this.responses.push(response);
|
|
57
49
|
return this.createCaptureController(response);
|
|
58
50
|
}
|
|
51
|
+
skipCooldown() {
|
|
52
|
+
this.startCooldown = false;
|
|
53
|
+
}
|
|
59
54
|
startCustomCooldown(customCooldown) {
|
|
60
55
|
this.startCooldown = true;
|
|
61
56
|
this.customCooldown = customCooldown;
|
|
@@ -118,8 +113,8 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
118
113
|
* @param emoji Telegram emoji to react with.
|
|
119
114
|
*/
|
|
120
115
|
withReaction: (emoji) => {
|
|
121
|
-
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.
|
|
116
|
+
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageInfo.id, emoji, this.action));
|
|
122
117
|
}
|
|
123
118
|
};
|
|
124
119
|
}
|
|
125
|
-
exports.
|
|
120
|
+
exports.MessageContextInternal = MessageContextInternal;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
|
|
2
2
|
import { IActionState } from '../../types/actionState';
|
|
3
3
|
import { TextMessageSendingOptions, MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
-
import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
|
|
5
4
|
import { ReplyCaptureAction } from '../actions/replyCaptureAction';
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
|
|
6
|
+
import { UserInfo } from '../../dtos/userInfo';
|
|
7
|
+
import { MessageInfo } from '../../dtos/messageInfo';
|
|
8
|
+
export type ReplyContext<TActionState extends IActionState> = Omit<ReplyContextInternal<TActionState>, BaseContextPropertiesToOmit | 'messageId' | 'startCooldown' | 'customCooldown'>;
|
|
9
|
+
export declare class ReplyContextInternal<TParentActionState extends IActionState> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
8
10
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
9
11
|
matchResults: RegExpExecArray[];
|
|
10
12
|
/** Id of a message that triggered this action. */
|
|
11
13
|
replyMessageId: number | undefined;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
/** Text of a message that triggered this action. */
|
|
17
|
-
messageText: string;
|
|
18
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
19
|
-
fromUserId: number | undefined;
|
|
20
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
21
|
-
fromUserName: string;
|
|
22
|
-
/** Message object recieved from Telegram */
|
|
23
|
-
messageUpdateObject: TelegrafContextMessage;
|
|
14
|
+
/** Information about the user that triggered this action */
|
|
15
|
+
userInfo: UserInfo;
|
|
16
|
+
/** Information about the message that triggered this action */
|
|
17
|
+
messageInfo: MessageInfo;
|
|
24
18
|
/** Bot info from Telegram */
|
|
25
19
|
botInfo: UserFromGetMe;
|
|
26
20
|
isInitialized: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"replyContext.d.ts","sourceRoot":"","sources":["../../../entities/context/replyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,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;CACL"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ReplyContextInternal = void 0;
|
|
4
4
|
const replyInfo_1 = require("../../dtos/replyInfo");
|
|
5
5
|
const imageMessage_1 = require("../../dtos/responses/imageMessage");
|
|
6
6
|
const reaction_1 = require("../../dtos/responses/reaction");
|
|
@@ -8,23 +8,15 @@ const textMessage_1 = require("../../dtos/responses/textMessage");
|
|
|
8
8
|
const videoMessage_1 = require("../../dtos/responses/videoMessage");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const baseContext_1 = require("./baseContext");
|
|
11
|
-
class
|
|
11
|
+
class ReplyContextInternal extends baseContext_1.BaseContextInternal {
|
|
12
12
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
13
13
|
matchResults;
|
|
14
14
|
/** Id of a message that triggered this action. */
|
|
15
15
|
replyMessageId;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/** Text of a message that triggered this action. */
|
|
21
|
-
messageText;
|
|
22
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
23
|
-
fromUserId;
|
|
24
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
25
|
-
fromUserName;
|
|
26
|
-
/** Message object recieved from Telegram */
|
|
27
|
-
messageUpdateObject;
|
|
16
|
+
/** Information about the user that triggered this action */
|
|
17
|
+
userInfo;
|
|
18
|
+
/** Information about the message that triggered this action */
|
|
19
|
+
messageInfo;
|
|
28
20
|
/** Bot info from Telegram */
|
|
29
21
|
botInfo;
|
|
30
22
|
isInitialized = false;
|
|
@@ -32,22 +24,22 @@ class ReplyContext extends baseContext_1.BaseContext {
|
|
|
32
24
|
return typeof quote == 'boolean'
|
|
33
25
|
? this.matchResults.length != 0
|
|
34
26
|
? this.matchResults[0][1]
|
|
35
|
-
: this.
|
|
27
|
+
: this.messageInfo.text
|
|
36
28
|
: quote;
|
|
37
29
|
}
|
|
38
30
|
replyWithText(text, quote, options) {
|
|
39
31
|
const quotedPart = this.getQuotePart(quote);
|
|
40
|
-
const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
32
|
+
const response = new textMessage_1.TextMessage(text, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
41
33
|
this.responses.push(response);
|
|
42
34
|
}
|
|
43
35
|
replyWithImage(name, quote, options) {
|
|
44
36
|
const quotedPart = this.getQuotePart(quote);
|
|
45
|
-
const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
37
|
+
const response = new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
46
38
|
this.responses.push(response);
|
|
47
39
|
}
|
|
48
40
|
replyWithVideo(name, quote, options) {
|
|
49
41
|
const quotedPart = this.getQuotePart(quote);
|
|
50
|
-
const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.
|
|
42
|
+
const response = new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, new replyInfo_1.ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined), options);
|
|
51
43
|
this.responses.push(response);
|
|
52
44
|
}
|
|
53
45
|
/**
|
|
@@ -126,8 +118,8 @@ class ReplyContext extends baseContext_1.BaseContext {
|
|
|
126
118
|
* @param emoji Telegram emoji to react with.
|
|
127
119
|
*/
|
|
128
120
|
withReaction: (emoji) => {
|
|
129
|
-
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.
|
|
121
|
+
this.responses.push(new reaction_1.Reaction(this.traceId, this.chatInfo, this.messageInfo.id, emoji, this.action));
|
|
130
122
|
}
|
|
131
123
|
};
|
|
132
124
|
}
|
|
133
|
-
exports.
|
|
125
|
+
exports.ReplyContextInternal = ReplyContextInternal;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 {};
|
|
3
10
|
//# sourceMappingURL=mapUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapUtils.d.ts","sourceRoot":"","sources":["../../helpers/mapUtils.ts"],"names":[],"mappings":"AAAA,
|
|
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"}
|
package/dist/helpers/mapUtils.js
CHANGED
|
@@ -9,7 +9,7 @@ function getOrSetIfNotExists(map, key, fallback) {
|
|
|
9
9
|
map.set(key, fallback);
|
|
10
10
|
return fallback;
|
|
11
11
|
}
|
|
12
|
-
function getOrThrow(map, key, error) {
|
|
12
|
+
function getOrThrow(map, key, error = 'Key not found in collection') {
|
|
13
13
|
const existingValue = map.get(key);
|
|
14
14
|
if (existingValue)
|
|
15
15
|
return existingValue;
|
|
@@ -3,7 +3,7 @@ import { IScheduler } from '../../types/scheduler';
|
|
|
3
3
|
import { IStorageClient } from '../../types/storage';
|
|
4
4
|
import { TelegramApiService } from '../telegramApi';
|
|
5
5
|
import { IAction } from '../../types/action';
|
|
6
|
-
import {
|
|
6
|
+
import { BaseContextInternal } from '../../entities/context/baseContext';
|
|
7
7
|
export declare abstract class BaseActionProcessor {
|
|
8
8
|
protected readonly storage: IStorageClient;
|
|
9
9
|
protected readonly scheduler: IScheduler;
|
|
@@ -13,6 +13,6 @@ export declare abstract class BaseActionProcessor {
|
|
|
13
13
|
constructor(botName: string, storage: IStorageClient, scheduler: IScheduler, logger: ILogger);
|
|
14
14
|
private defaultErrorHandler;
|
|
15
15
|
initializeDependencies(api: TelegramApiService): void;
|
|
16
|
-
executeAction<TAction extends IAction, TActionContext extends
|
|
16
|
+
executeAction<TAction extends IAction, TActionContext extends BaseContextInternal<TAction>>(action: TAction, ctx: TActionContext, errorHandler?: (error: Error, ctx: TActionContext) => void): Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=baseProcessor.d.ts.map
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -10,6 +10,7 @@ import { UserFromGetMe } from 'telegraf/types';
|
|
|
10
10
|
export declare class CommandActionProcessor extends BaseActionProcessor {
|
|
11
11
|
private readonly replyCaptures;
|
|
12
12
|
private botInfo;
|
|
13
|
+
private lastMessages;
|
|
13
14
|
private commands;
|
|
14
15
|
initialize(api: TelegramApiService, telegraf: Telegraf, commands: CommandAction<IActionState>[], verboseLoggingForIncomingMessage: boolean, botInfo: UserFromGetMe): void;
|
|
15
16
|
captureRegistrationCallback(capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,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;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"commandActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/commandActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,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;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO/C,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,YAAY,CAAwC;IAE5D,OAAO,CAAC,QAAQ,CAKd;IAEF,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,EACvC,gCAAgC,EAAE,OAAO,EACzC,OAAO,EAAE,aAAa;IA2D1B,2BAA2B,CACvB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO;YA+BN,cAAc;IA0C5B,OAAO,CAAC,6BAA6B;IAiCrC,OAAO,CAAC,wBAAwB;CAmCnC"}
|
|
@@ -8,9 +8,14 @@ const replyContext_1 = require("../../entities/context/replyContext");
|
|
|
8
8
|
const messageTypes_1 = require("../../types/messageTypes");
|
|
9
9
|
const objectFromEntries_1 = require("../../helpers/objectFromEntries");
|
|
10
10
|
const baseProcessor_1 = require("./baseProcessor");
|
|
11
|
+
const mapUtils_1 = require("../../helpers/mapUtils");
|
|
12
|
+
const messageInfo_1 = require("../../dtos/messageInfo");
|
|
13
|
+
const userInfo_1 = require("../../dtos/userInfo");
|
|
14
|
+
const MESSAGE_HISTORY_LENGTH_LIMIT = 100;
|
|
11
15
|
class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
12
16
|
replyCaptures = [];
|
|
13
17
|
botInfo;
|
|
18
|
+
lastMessages = new Map();
|
|
14
19
|
commands = (0, objectFromEntries_1.typeSafeObjectFromEntries)(Object.values(messageTypes_1.MessageType).map((x) => [
|
|
15
20
|
x,
|
|
16
21
|
[]
|
|
@@ -33,7 +38,7 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
33
38
|
}
|
|
34
39
|
if (commands.length > 0) {
|
|
35
40
|
telegraf.on('message', (ctx) => {
|
|
36
|
-
const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.botName);
|
|
41
|
+
const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.botName, (0, mapUtils_1.getOrSetIfNotExists)(this.lastMessages, ctx.chat.id, []));
|
|
37
42
|
const logger = this.logger.createScope(this.botName, msg.traceId, msg.chatInfo.name);
|
|
38
43
|
if (verboseLoggingForIncomingMessage) {
|
|
39
44
|
logger.logObjectWithTraceId(ctx.update.message);
|
|
@@ -57,7 +62,11 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
async processMessage(msg) {
|
|
60
|
-
const
|
|
65
|
+
const messageHistoryArray = (0, mapUtils_1.getOrSetIfNotExists)(this.lastMessages, msg.chatInfo.id, []);
|
|
66
|
+
if (messageHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
|
|
67
|
+
messageHistoryArray.shift();
|
|
68
|
+
messageHistoryArray.push(msg);
|
|
69
|
+
const ctx = new messageContext_1.MessageContextInternal(this.storage, this.scheduler);
|
|
61
70
|
const commandsToCheck = new Set(this.commands[msg.type]);
|
|
62
71
|
if (msg.type != messageTypes_1.MessageType.Text && msg.text != '') {
|
|
63
72
|
this.commands[messageTypes_1.MessageType.Text].forEach((x) => commandsToCheck.add(x));
|
|
@@ -67,7 +76,7 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
67
76
|
await this.executeAction(commandAction, ctx);
|
|
68
77
|
}
|
|
69
78
|
if (this.replyCaptures.length != 0) {
|
|
70
|
-
const replyCtx = new replyContext_1.
|
|
79
|
+
const replyCtx = new replyContext_1.ReplyContextInternal(this.storage, this.scheduler);
|
|
71
80
|
for (const replyAction of this.replyCaptures) {
|
|
72
81
|
this.initializeReplyCaptureContext(replyCtx, replyAction, msg);
|
|
73
82
|
await this.executeAction(replyAction, replyCtx);
|
|
@@ -77,14 +86,9 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
77
86
|
}
|
|
78
87
|
initializeReplyCaptureContext(ctx, action, message) {
|
|
79
88
|
ctx.replyMessageId = message.replyToMessageId;
|
|
80
|
-
ctx.
|
|
81
|
-
ctx.
|
|
82
|
-
|
|
83
|
-
ctx.fromUserId = message.from?.id;
|
|
84
|
-
ctx.fromUserName =
|
|
85
|
-
(message.from?.first_name ?? 'Unknown user') +
|
|
86
|
-
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
87
|
-
ctx.messageUpdateObject = message.updateObject;
|
|
89
|
+
ctx.messageInfo = new messageInfo_1.MessageInfo(message.messageId, message.text, message.type, message.updateObject);
|
|
90
|
+
ctx.userInfo = new userInfo_1.UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
|
|
91
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : ''));
|
|
88
92
|
ctx.botName = this.botName;
|
|
89
93
|
ctx.action = action;
|
|
90
94
|
ctx.chatInfo = message.chatInfo;
|
|
@@ -95,14 +99,9 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
95
99
|
ctx.logger = this.logger.createScope(this.botName, message.traceId, message.chatInfo.name);
|
|
96
100
|
}
|
|
97
101
|
initializeMessageContext(ctx, action, message) {
|
|
98
|
-
ctx.
|
|
99
|
-
ctx.
|
|
100
|
-
|
|
101
|
-
ctx.fromUserId = message.from?.id;
|
|
102
|
-
ctx.fromUserName =
|
|
103
|
-
(message.from?.first_name ?? 'Unknown user') +
|
|
104
|
-
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
105
|
-
ctx.messageUpdateObject = message.updateObject;
|
|
102
|
+
ctx.messageInfo = new messageInfo_1.MessageInfo(message.messageId, message.text, message.type, message.updateObject);
|
|
103
|
+
ctx.userInfo = new userInfo_1.UserInfo(message.from?.id ?? -1, (message.from?.first_name ?? 'Unknown user') +
|
|
104
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : ''));
|
|
106
105
|
ctx.matchResults = [];
|
|
107
106
|
ctx.startCooldown = true;
|
|
108
107
|
ctx.responses = [];
|
|
@@ -27,7 +27,7 @@ class InlineQueryActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
27
27
|
pendingInlineQueries.push(query);
|
|
28
28
|
});
|
|
29
29
|
this.scheduler.createTask('InlineQueryProcessing', async () => {
|
|
30
|
-
const ctx = new inlineQueryContext_1.
|
|
30
|
+
const ctx = new inlineQueryContext_1.InlineQueryContextInternal(this.storage, this.scheduler);
|
|
31
31
|
const queriesToProcess = [...pendingInlineQueries];
|
|
32
32
|
pendingInlineQueries = [];
|
|
33
33
|
for (const inlineQuery of queriesToProcess) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/scheduledActionProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAA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gB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,wBAAyB,SAAQ,mBAAmB;IAC7D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAE/C,OAAO,CAAC,SAAS,CAAmC;gBAGhD,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO;IAMnB,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,EAC1C,MAAM,EAAE,OAAO;YAgDL,YAAY;IA0B1B,OAAO,CAAC,qBAAqB;CAmBhC"}
|
|
@@ -41,10 +41,10 @@ class ScheduledActionProcessor extends baseProcessor_1.BaseActionProcessor {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
async runScheduled() {
|
|
44
|
-
const ctx = new chatContext_1.
|
|
44
|
+
const ctx = new chatContext_1.ChatContextInternal(this.storage, this.scheduler);
|
|
45
45
|
for (const [chatName, chatId] of Object.entries(this.chats)) {
|
|
46
46
|
for (const scheduledAction of this.scheduled) {
|
|
47
|
-
this.initializeChatContext(ctx, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName), (0, traceFactory_1.createTrace)(scheduledAction, this.botName, `${scheduledAction.key}-${chatId}`));
|
|
47
|
+
this.initializeChatContext(ctx, scheduledAction, new chatInfo_1.ChatInfo(chatId, chatName, []), (0, traceFactory_1.createTrace)(scheduledAction, this.botName, `${scheduledAction.key}-${chatId}`));
|
|
48
48
|
await this.executeAction(scheduledAction, ctx);
|
|
49
49
|
}
|
|
50
50
|
}
|
package/dist/types/action.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseContextInternal } from '../entities/context/baseContext';
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
3
|
import { BotResponse } from './response';
|
|
4
4
|
export type ActionKey = string & {
|
|
@@ -9,6 +9,6 @@ export interface IActionWithState<TActionState extends IActionState> extends IAc
|
|
|
9
9
|
}
|
|
10
10
|
export interface IAction {
|
|
11
11
|
readonly key: ActionKey;
|
|
12
|
-
exec(ctx:
|
|
12
|
+
exec(ctx: BaseContextInternal<IAction>): Promise<BotResponse[]>;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=action.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../types/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../types/action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY,CAC/D,SAAQ,OAAO;IACf,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACjD;AAED,MAAM,WAAW,OAAO;IACpB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CACnE"}
|
package/dist/types/capture.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReplyContextInternal } from '../entities/context/replyContext';
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
3
|
import { CommandTrigger } from './commandTrigger';
|
|
4
4
|
import { IActionWithState } from './action';
|
|
@@ -11,13 +11,13 @@ export interface ICaptureController {
|
|
|
11
11
|
*/
|
|
12
12
|
trigger: CommandTrigger[],
|
|
13
13
|
/** Callback that will be called on trigger */
|
|
14
|
-
handler: (replyContext:
|
|
14
|
+
handler: (replyContext: ReplyContextInternal<TParentActionState>) => Promise<void>,
|
|
15
15
|
/** Abort controller to abort capturing manually */
|
|
16
16
|
abortController: AbortController) => void;
|
|
17
17
|
}
|
|
18
18
|
export interface IReplyCapture {
|
|
19
19
|
trigger: CommandTrigger[];
|
|
20
|
-
handler: (replyContext:
|
|
20
|
+
handler: (replyContext: ReplyContextInternal<IActionState>) => Promise<void>;
|
|
21
21
|
abortController: AbortController;
|
|
22
22
|
action: IActionWithState<IActionState>;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../types/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,CAAC,kBAAkB,SAAS,YAAY;IACpD;;;;OAIG;IACH,OAAO,EAAE,cAAc,EAAE;IACzB,8CAA8C;IAC9C,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,KACrD,OAAO,CAAC,IAAI,CAAC;IAClB,mDAAmD;IACnD,eAAe,EAAE,eAAe,KAC/B,IAAI,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,CACL,YAAY,EAAE,oBAAoB,CAAC,YAAY,CAAC,KAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;CAC1C"}
|
package/dtos/chatInfo.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
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;
|
|
1
|
+
import { IncomingMessage } from './incomingMessage';
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export class ChatInfo {
|
|
4
|
+
constructor(
|
|
5
|
+
/** Id of a chat that action is executed in. */
|
|
6
|
+
readonly id: number,
|
|
7
|
+
/** Name of a chat that action is executed in. */
|
|
8
|
+
readonly name: string,
|
|
9
|
+
/** Last 100 messages in chat where action is executed */
|
|
10
|
+
readonly messageHistory: IncomingMessage[]
|
|
11
|
+
) {}
|
|
11
12
|
}
|
|
@@ -20,22 +20,12 @@ export class CommandTriggerCheckResult {
|
|
|
20
20
|
return new CommandTriggerCheckResult(true, [], false);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
readonly shouldExecute: boolean;
|
|
24
|
-
readonly matchResults: RegExpExecArray[];
|
|
25
|
-
readonly skipCooldown: boolean;
|
|
26
|
-
readonly reason: SkipTriggerReasons | undefined;
|
|
27
|
-
|
|
28
23
|
constructor(
|
|
29
|
-
shouldExecute: boolean,
|
|
30
|
-
matchResults: RegExpExecArray[],
|
|
31
|
-
skipCooldown: boolean,
|
|
32
|
-
reason?: SkipTriggerReasons
|
|
33
|
-
) {
|
|
34
|
-
this.shouldExecute = shouldExecute;
|
|
35
|
-
this.matchResults = matchResults;
|
|
36
|
-
this.skipCooldown = skipCooldown;
|
|
37
|
-
this.reason = reason;
|
|
38
|
-
}
|
|
24
|
+
readonly shouldExecute: boolean,
|
|
25
|
+
readonly matchResults: RegExpExecArray[],
|
|
26
|
+
readonly skipCooldown: boolean,
|
|
27
|
+
readonly reason?: SkipTriggerReasons
|
|
28
|
+
) {}
|
|
39
29
|
|
|
40
30
|
mergeWith(other: CommandTriggerCheckResult) {
|
|
41
31
|
return new CommandTriggerCheckResult(
|
package/dtos/cooldownInfo.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Seconds } from '../types/timeValues';
|
|
2
2
|
|
|
3
3
|
export class CooldownInfo {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(
|
|
5
|
+
/** New one-time cooldown in seconds */
|
|
6
|
+
readonly seconds: Seconds,
|
|
7
|
+
/** Cooldown message to be shown */
|
|
8
|
+
readonly message: string | undefined
|
|
9
|
+
) {}
|
|
5
10
|
}
|
package/dtos/incomingMessage.ts
CHANGED
|
@@ -40,7 +40,11 @@ export class IncomingMessage {
|
|
|
40
40
|
return MessageType.Unknown;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(
|
|
44
|
+
ctxMessage: TelegrafContextMessage,
|
|
45
|
+
botName: string,
|
|
46
|
+
history: IncomingMessage[]
|
|
47
|
+
) {
|
|
44
48
|
this.traceId = createTrace(
|
|
45
49
|
this,
|
|
46
50
|
botName,
|
|
@@ -62,7 +66,8 @@ export class IncomingMessage {
|
|
|
62
66
|
ctxMessage.chat.id,
|
|
63
67
|
'title' in ctxMessage.chat
|
|
64
68
|
? `${ctxMessage.chat.title} ${ctxMessage.chat.id}`
|
|
65
|
-
: 'DM'
|
|
69
|
+
: 'DM',
|
|
70
|
+
history
|
|
66
71
|
);
|
|
67
72
|
this.type = this.detectMessageType(ctxMessage);
|
|
68
73
|
this.updateObject = ctxMessage;
|