chz-telegram-bot 0.3.13 → 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/README.md +92 -73
- 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 +11 -8
- 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 +16 -12
- 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
|
@@ -5,51 +5,46 @@ import { ImageMessage } from '../../dtos/responses/imageMessage';
|
|
|
5
5
|
import { Reaction } from '../../dtos/responses/reaction';
|
|
6
6
|
import { TextMessage } from '../../dtos/responses/textMessage';
|
|
7
7
|
import { VideoMessage } from '../../dtos/responses/videoMessage';
|
|
8
|
-
import {
|
|
8
|
+
import { ChatContextInternal } from './chatContext';
|
|
9
9
|
import {
|
|
10
10
|
MessageSendingOptions,
|
|
11
11
|
TextMessageSendingOptions
|
|
12
12
|
} from '../../types/messageSendingOptions';
|
|
13
|
-
import {
|
|
14
|
-
MessageTypeValue,
|
|
15
|
-
TelegrafContextMessage
|
|
16
|
-
} from '../../types/messageTypes';
|
|
17
13
|
import { ReplyInfo } from '../../dtos/replyInfo';
|
|
18
14
|
import { CommandAction } from '../actions/commandAction';
|
|
19
15
|
import { Seconds } from '../../types/timeValues';
|
|
16
|
+
import { BaseContextPropertiesToOmit } from './baseContext';
|
|
17
|
+
import { MessageInfo } from '../../dtos/messageInfo';
|
|
18
|
+
import { UserInfo } from '../../dtos/userInfo';
|
|
19
|
+
|
|
20
|
+
export type MessageContext<TActionState extends IActionState> = Omit<
|
|
21
|
+
MessageContextInternal<TActionState>,
|
|
22
|
+
BaseContextPropertiesToOmit | 'startCooldown' | 'customCooldown'
|
|
23
|
+
>;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Context of action executed in chat, in response to a message
|
|
23
27
|
*/
|
|
24
|
-
export class
|
|
28
|
+
export class MessageContextInternal<
|
|
25
29
|
TActionState extends IActionState
|
|
26
|
-
> extends
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
30
|
+
> extends ChatContextInternal<TActionState, CommandAction<TActionState>> {
|
|
31
|
+
/** Information about the user that triggered this action */
|
|
32
|
+
userInfo!: UserInfo;
|
|
33
|
+
/** Information about the message that triggered this action */
|
|
34
|
+
messageInfo!: MessageInfo;
|
|
31
35
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
32
36
|
matchResults: RegExpMatchArray[] = [];
|
|
33
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
34
|
-
fromUserId: number | undefined;
|
|
35
37
|
/** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
|
|
36
38
|
startCooldown: boolean = true;
|
|
37
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
38
|
-
fromUserName!: string;
|
|
39
|
-
/** Type of message being received */
|
|
40
|
-
messageType!: MessageTypeValue;
|
|
41
|
-
/** Message object recieved from Telegram */
|
|
42
|
-
messageUpdateObject!: TelegrafContextMessage;
|
|
43
39
|
/** Bot info from Telegram */
|
|
44
40
|
botInfo!: UserFromGetMe;
|
|
45
|
-
|
|
46
41
|
customCooldown: Seconds | undefined;
|
|
47
42
|
|
|
48
43
|
private getQuotePart(quote: boolean | string) {
|
|
49
44
|
return typeof quote == 'boolean'
|
|
50
45
|
? this.matchResults.length != 0
|
|
51
46
|
? this.matchResults[0][1]
|
|
52
|
-
: this.
|
|
47
|
+
: this.messageInfo.text
|
|
53
48
|
: quote;
|
|
54
49
|
}
|
|
55
50
|
|
|
@@ -65,7 +60,7 @@ export class MessageContext<
|
|
|
65
60
|
this.chatInfo,
|
|
66
61
|
this.traceId,
|
|
67
62
|
this.action,
|
|
68
|
-
new ReplyInfo(this.
|
|
63
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
69
64
|
options
|
|
70
65
|
);
|
|
71
66
|
|
|
@@ -86,7 +81,7 @@ export class MessageContext<
|
|
|
86
81
|
this.chatInfo,
|
|
87
82
|
this.traceId,
|
|
88
83
|
this.action,
|
|
89
|
-
new ReplyInfo(this.
|
|
84
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
90
85
|
options
|
|
91
86
|
);
|
|
92
87
|
|
|
@@ -107,7 +102,7 @@ export class MessageContext<
|
|
|
107
102
|
this.chatInfo,
|
|
108
103
|
this.traceId,
|
|
109
104
|
this.action,
|
|
110
|
-
new ReplyInfo(this.
|
|
105
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
111
106
|
options
|
|
112
107
|
);
|
|
113
108
|
|
|
@@ -116,6 +111,10 @@ export class MessageContext<
|
|
|
116
111
|
return this.createCaptureController(response);
|
|
117
112
|
}
|
|
118
113
|
|
|
114
|
+
skipCooldown() {
|
|
115
|
+
this.startCooldown = false;
|
|
116
|
+
}
|
|
117
|
+
|
|
119
118
|
startCustomCooldown(customCooldown: Seconds) {
|
|
120
119
|
this.startCooldown = true;
|
|
121
120
|
this.customCooldown = customCooldown;
|
|
@@ -202,7 +201,7 @@ export class MessageContext<
|
|
|
202
201
|
new Reaction(
|
|
203
202
|
this.traceId,
|
|
204
203
|
this.chatInfo,
|
|
205
|
-
this.
|
|
204
|
+
this.messageInfo.id,
|
|
206
205
|
emoji,
|
|
207
206
|
this.action
|
|
208
207
|
)
|
|
@@ -9,33 +9,34 @@ import {
|
|
|
9
9
|
TextMessageSendingOptions,
|
|
10
10
|
MessageSendingOptions
|
|
11
11
|
} from '../../types/messageSendingOptions';
|
|
12
|
-
import {
|
|
13
|
-
MessageTypeValue,
|
|
14
|
-
TelegrafContextMessage
|
|
15
|
-
} from '../../types/messageTypes';
|
|
16
12
|
import { ReplyCaptureAction } from '../actions/replyCaptureAction';
|
|
17
13
|
import { resolve } from 'path';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
import {
|
|
15
|
+
BaseContextInternal,
|
|
16
|
+
BaseContextPropertiesToOmit
|
|
17
|
+
} from './baseContext';
|
|
18
|
+
import { UserInfo } from '../../dtos/userInfo';
|
|
19
|
+
import { MessageInfo } from '../../dtos/messageInfo';
|
|
20
|
+
|
|
21
|
+
export type ReplyContext<TActionState extends IActionState> = Omit<
|
|
22
|
+
ReplyContextInternal<TActionState>,
|
|
23
|
+
| BaseContextPropertiesToOmit
|
|
24
|
+
| 'messageId'
|
|
25
|
+
| 'startCooldown'
|
|
26
|
+
| 'customCooldown'
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export class ReplyContextInternal<
|
|
21
30
|
TParentActionState extends IActionState
|
|
22
|
-
> extends
|
|
31
|
+
> extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
|
|
23
32
|
/** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
|
|
24
33
|
matchResults!: RegExpExecArray[];
|
|
25
34
|
/** Id of a message that triggered this action. */
|
|
26
35
|
replyMessageId!: number | undefined;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
/** Text of a message that triggered this action. */
|
|
32
|
-
messageText!: string;
|
|
33
|
-
/** Id of a user that sent a message that triggered this action. */
|
|
34
|
-
fromUserId: number | undefined;
|
|
35
|
-
/** Name of a user that sent a message that triggered this action. */
|
|
36
|
-
fromUserName!: string;
|
|
37
|
-
/** Message object recieved from Telegram */
|
|
38
|
-
messageUpdateObject!: TelegrafContextMessage;
|
|
36
|
+
/** Information about the user that triggered this action */
|
|
37
|
+
userInfo!: UserInfo;
|
|
38
|
+
/** Information about the message that triggered this action */
|
|
39
|
+
messageInfo!: MessageInfo;
|
|
39
40
|
/** Bot info from Telegram */
|
|
40
41
|
botInfo!: UserFromGetMe;
|
|
41
42
|
|
|
@@ -45,7 +46,7 @@ export class ReplyContext<
|
|
|
45
46
|
return typeof quote == 'boolean'
|
|
46
47
|
? this.matchResults.length != 0
|
|
47
48
|
? this.matchResults[0][1]
|
|
48
|
-
: this.
|
|
49
|
+
: this.messageInfo.text
|
|
49
50
|
: quote;
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -61,7 +62,7 @@ export class ReplyContext<
|
|
|
61
62
|
this.chatInfo,
|
|
62
63
|
this.traceId,
|
|
63
64
|
this.action,
|
|
64
|
-
new ReplyInfo(this.
|
|
65
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
65
66
|
options
|
|
66
67
|
);
|
|
67
68
|
|
|
@@ -80,7 +81,7 @@ export class ReplyContext<
|
|
|
80
81
|
this.chatInfo,
|
|
81
82
|
this.traceId,
|
|
82
83
|
this.action,
|
|
83
|
-
new ReplyInfo(this.
|
|
84
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
84
85
|
options
|
|
85
86
|
);
|
|
86
87
|
|
|
@@ -99,7 +100,7 @@ export class ReplyContext<
|
|
|
99
100
|
this.chatInfo,
|
|
100
101
|
this.traceId,
|
|
101
102
|
this.action,
|
|
102
|
-
new ReplyInfo(this.
|
|
103
|
+
new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
|
|
103
104
|
options
|
|
104
105
|
);
|
|
105
106
|
|
|
@@ -203,7 +204,7 @@ export class ReplyContext<
|
|
|
203
204
|
new Reaction(
|
|
204
205
|
this.traceId,
|
|
205
206
|
this.chatInfo,
|
|
206
|
-
this.
|
|
207
|
+
this.messageInfo.id,
|
|
207
208
|
emoji,
|
|
208
209
|
this.action
|
|
209
210
|
)
|
package/helpers/mapUtils.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
type KeyedReadonlyCollection<K, V> = { get: (key: K) => V | undefined };
|
|
2
|
+
type KeyedWriteableCollection<K, V> = KeyedReadonlyCollection<K, V> & {
|
|
3
|
+
set: (key: K, value: V) => KeyedWriteableCollection<K, V>;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export function getOrSetIfNotExists<K, V>(
|
|
7
|
+
map: KeyedWriteableCollection<K, V>,
|
|
8
|
+
key: K,
|
|
9
|
+
fallback: V
|
|
10
|
+
) {
|
|
2
11
|
const existingValue = map.get(key);
|
|
3
12
|
if (existingValue) return existingValue;
|
|
4
13
|
|
|
@@ -7,7 +16,11 @@ export function getOrSetIfNotExists<K, V>(map: Map<K, V>, key: K, fallback: V) {
|
|
|
7
16
|
return fallback;
|
|
8
17
|
}
|
|
9
18
|
|
|
10
|
-
export function getOrThrow<K, V>(
|
|
19
|
+
export function getOrThrow<K, V>(
|
|
20
|
+
map: KeyedReadonlyCollection<K, V>,
|
|
21
|
+
key: K,
|
|
22
|
+
error: string = 'Key not found in collection'
|
|
23
|
+
) {
|
|
11
24
|
const existingValue = map.get(key);
|
|
12
25
|
if (existingValue) return existingValue;
|
|
13
26
|
|
package/package.json
CHANGED
|
@@ -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
|
|
|
8
8
|
export abstract class BaseActionProcessor {
|
|
9
9
|
protected readonly storage: IStorageClient;
|
|
@@ -29,7 +29,7 @@ export abstract class BaseActionProcessor {
|
|
|
29
29
|
|
|
30
30
|
private defaultErrorHandler<TAction extends IAction>(
|
|
31
31
|
error: Error,
|
|
32
|
-
ctx:
|
|
32
|
+
ctx: BaseContextInternal<TAction>
|
|
33
33
|
) {
|
|
34
34
|
ctx.logger.errorWithTraceId(error, ctx);
|
|
35
35
|
}
|
|
@@ -40,7 +40,7 @@ export abstract class BaseActionProcessor {
|
|
|
40
40
|
|
|
41
41
|
async executeAction<
|
|
42
42
|
TAction extends IAction,
|
|
43
|
-
TActionContext extends
|
|
43
|
+
TActionContext extends BaseContextInternal<TAction>
|
|
44
44
|
>(
|
|
45
45
|
action: TAction,
|
|
46
46
|
ctx: TActionContext,
|
|
@@ -2,8 +2,8 @@ import { Telegraf } from 'telegraf';
|
|
|
2
2
|
import { IncomingMessage } from '../../dtos/incomingMessage';
|
|
3
3
|
import { CommandAction } from '../../entities/actions/commandAction';
|
|
4
4
|
import { ReplyCaptureAction } from '../../entities/actions/replyCaptureAction';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { MessageContextInternal } from '../../entities/context/messageContext';
|
|
6
|
+
import { ReplyContextInternal } from '../../entities/context/replyContext';
|
|
7
7
|
import { IActionState } from '../../types/actionState';
|
|
8
8
|
import { TelegramApiService } from '../telegramApi';
|
|
9
9
|
import { IReplyCapture } from '../../types/capture';
|
|
@@ -16,10 +16,16 @@ import {
|
|
|
16
16
|
import { typeSafeObjectFromEntries } from '../../helpers/objectFromEntries';
|
|
17
17
|
import { BaseActionProcessor } from './baseProcessor';
|
|
18
18
|
import { UserFromGetMe } from 'telegraf/types';
|
|
19
|
+
import { getOrSetIfNotExists } from '../../helpers/mapUtils';
|
|
20
|
+
import { MessageInfo } from '../../dtos/messageInfo';
|
|
21
|
+
import { UserInfo } from '../../dtos/userInfo';
|
|
22
|
+
|
|
23
|
+
const MESSAGE_HISTORY_LENGTH_LIMIT = 100;
|
|
19
24
|
|
|
20
25
|
export class CommandActionProcessor extends BaseActionProcessor {
|
|
21
26
|
private readonly replyCaptures: ReplyCaptureAction<IActionState>[] = [];
|
|
22
27
|
private botInfo!: UserFromGetMe;
|
|
28
|
+
private lastMessages = new Map<number, IncomingMessage[]>();
|
|
23
29
|
|
|
24
30
|
private commands = typeSafeObjectFromEntries(
|
|
25
31
|
Object.values(MessageType).map((x) => [
|
|
@@ -67,7 +73,8 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
67
73
|
telegraf.on('message', (ctx) => {
|
|
68
74
|
const msg = new IncomingMessage(
|
|
69
75
|
ctx.update.message,
|
|
70
|
-
this.botName
|
|
76
|
+
this.botName,
|
|
77
|
+
getOrSetIfNotExists(this.lastMessages, ctx.chat.id, [])
|
|
71
78
|
);
|
|
72
79
|
|
|
73
80
|
const logger = this.logger.createScope(
|
|
@@ -127,7 +134,16 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
136
|
private async processMessage(msg: IncomingMessage) {
|
|
130
|
-
const
|
|
137
|
+
const messageHistoryArray = getOrSetIfNotExists(
|
|
138
|
+
this.lastMessages,
|
|
139
|
+
msg.chatInfo.id,
|
|
140
|
+
[]
|
|
141
|
+
);
|
|
142
|
+
if (messageHistoryArray.length > MESSAGE_HISTORY_LENGTH_LIMIT)
|
|
143
|
+
messageHistoryArray.shift();
|
|
144
|
+
messageHistoryArray.push(msg);
|
|
145
|
+
|
|
146
|
+
const ctx = new MessageContextInternal<IActionState>(
|
|
131
147
|
this.storage,
|
|
132
148
|
this.scheduler
|
|
133
149
|
);
|
|
@@ -145,7 +161,7 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
145
161
|
}
|
|
146
162
|
|
|
147
163
|
if (this.replyCaptures.length != 0) {
|
|
148
|
-
const replyCtx = new
|
|
164
|
+
const replyCtx = new ReplyContextInternal<IActionState>(
|
|
149
165
|
this.storage,
|
|
150
166
|
this.scheduler
|
|
151
167
|
);
|
|
@@ -160,19 +176,22 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
160
176
|
}
|
|
161
177
|
|
|
162
178
|
private initializeReplyCaptureContext(
|
|
163
|
-
ctx:
|
|
179
|
+
ctx: ReplyContextInternal<IActionState>,
|
|
164
180
|
action: ReplyCaptureAction<IActionState>,
|
|
165
181
|
message: IncomingMessage
|
|
166
182
|
) {
|
|
167
183
|
ctx.replyMessageId = message.replyToMessageId;
|
|
168
|
-
ctx.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
184
|
+
ctx.messageInfo = new MessageInfo(
|
|
185
|
+
message.messageId,
|
|
186
|
+
message.text,
|
|
187
|
+
message.type,
|
|
188
|
+
message.updateObject
|
|
189
|
+
);
|
|
190
|
+
ctx.userInfo = new UserInfo(
|
|
191
|
+
message.from?.id ?? -1,
|
|
173
192
|
(message.from?.first_name ?? 'Unknown user') +
|
|
174
|
-
|
|
175
|
-
|
|
193
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '')
|
|
194
|
+
);
|
|
176
195
|
ctx.botName = this.botName;
|
|
177
196
|
ctx.action = action;
|
|
178
197
|
ctx.chatInfo = message.chatInfo;
|
|
@@ -190,18 +209,21 @@ export class CommandActionProcessor extends BaseActionProcessor {
|
|
|
190
209
|
}
|
|
191
210
|
|
|
192
211
|
private initializeMessageContext(
|
|
193
|
-
ctx:
|
|
212
|
+
ctx: MessageContextInternal<IActionState>,
|
|
194
213
|
action: CommandAction<IActionState>,
|
|
195
214
|
message: IncomingMessage
|
|
196
215
|
) {
|
|
197
|
-
ctx.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
216
|
+
ctx.messageInfo = new MessageInfo(
|
|
217
|
+
message.messageId,
|
|
218
|
+
message.text,
|
|
219
|
+
message.type,
|
|
220
|
+
message.updateObject
|
|
221
|
+
);
|
|
222
|
+
ctx.userInfo = new UserInfo(
|
|
223
|
+
message.from?.id ?? -1,
|
|
202
224
|
(message.from?.first_name ?? 'Unknown user') +
|
|
203
|
-
|
|
204
|
-
|
|
225
|
+
(message.from?.last_name ? ` ${message.from.last_name}` : '')
|
|
226
|
+
);
|
|
205
227
|
|
|
206
228
|
ctx.matchResults = [];
|
|
207
229
|
ctx.startCooldown = true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Telegraf } from 'telegraf';
|
|
2
2
|
import { IncomingInlineQuery } from '../../dtos/incomingQuery';
|
|
3
3
|
import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
|
|
4
|
-
import {
|
|
4
|
+
import { InlineQueryContextInternal } from '../../entities/context/inlineQueryContext';
|
|
5
5
|
import { createTrace } from '../../helpers/traceFactory';
|
|
6
6
|
import { Milliseconds } from '../../types/timeValues';
|
|
7
7
|
import { TraceId } from '../../types/trace';
|
|
@@ -67,7 +67,7 @@ export class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
|
67
67
|
this.scheduler.createTask(
|
|
68
68
|
'InlineQueryProcessing',
|
|
69
69
|
async () => {
|
|
70
|
-
const ctx = new
|
|
70
|
+
const ctx = new InlineQueryContextInternal(
|
|
71
71
|
this.storage,
|
|
72
72
|
this.scheduler
|
|
73
73
|
);
|
|
@@ -119,7 +119,7 @@ export class InlineQueryActionProcessor extends BaseActionProcessor {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
private initializeInlineQueryContext(
|
|
122
|
-
ctx:
|
|
122
|
+
ctx: InlineQueryContextInternal,
|
|
123
123
|
queryText: string,
|
|
124
124
|
queryId: string,
|
|
125
125
|
action: InlineQueryAction,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import { ChatInfo } from '../../dtos/chatInfo';
|
|
3
3
|
import { ScheduledAction } from '../../entities/actions/scheduledAction';
|
|
4
|
-
import {
|
|
4
|
+
import { ChatContextInternal } from '../../entities/context/chatContext';
|
|
5
5
|
import { secondsToMilliseconds } from '../../helpers/timeConvertions';
|
|
6
6
|
import { createTrace } from '../../helpers/traceFactory';
|
|
7
7
|
import { IActionState } from '../../types/actionState';
|
|
@@ -81,14 +81,17 @@ export class ScheduledActionProcessor extends BaseActionProcessor {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private async runScheduled() {
|
|
84
|
-
const ctx = new
|
|
84
|
+
const ctx = new ChatContextInternal<IActionState>(
|
|
85
|
+
this.storage,
|
|
86
|
+
this.scheduler
|
|
87
|
+
);
|
|
85
88
|
|
|
86
89
|
for (const [chatName, chatId] of Object.entries(this.chats)) {
|
|
87
90
|
for (const scheduledAction of this.scheduled) {
|
|
88
91
|
this.initializeChatContext(
|
|
89
92
|
ctx,
|
|
90
93
|
scheduledAction,
|
|
91
|
-
new ChatInfo(chatId, chatName),
|
|
94
|
+
new ChatInfo(chatId, chatName, []),
|
|
92
95
|
createTrace(
|
|
93
96
|
scheduledAction,
|
|
94
97
|
this.botName,
|
|
@@ -104,7 +107,7 @@ export class ScheduledActionProcessor extends BaseActionProcessor {
|
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
private initializeChatContext(
|
|
107
|
-
ctx:
|
|
110
|
+
ctx: ChatContextInternal<IActionState>,
|
|
108
111
|
action: ScheduledAction<IActionState>,
|
|
109
112
|
chatInfo: ChatInfo,
|
|
110
113
|
traceId: TraceId
|
package/types/action.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
|
|
|
@@ -11,5 +11,5 @@ export interface IActionWithState<TActionState extends IActionState>
|
|
|
11
11
|
|
|
12
12
|
export interface IAction {
|
|
13
13
|
readonly key: ActionKey;
|
|
14
|
-
exec(ctx:
|
|
14
|
+
exec(ctx: BaseContextInternal<IAction>): Promise<BotResponse[]>;
|
|
15
15
|
}
|
package/types/capture.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';
|
|
@@ -13,7 +13,7 @@ export interface ICaptureController {
|
|
|
13
13
|
trigger: CommandTrigger[],
|
|
14
14
|
/** Callback that will be called on trigger */
|
|
15
15
|
handler: (
|
|
16
|
-
replyContext:
|
|
16
|
+
replyContext: ReplyContextInternal<TParentActionState>
|
|
17
17
|
) => Promise<void>,
|
|
18
18
|
/** Abort controller to abort capturing manually */
|
|
19
19
|
abortController: AbortController
|
|
@@ -22,7 +22,9 @@ export interface ICaptureController {
|
|
|
22
22
|
|
|
23
23
|
export interface IReplyCapture {
|
|
24
24
|
trigger: CommandTrigger[];
|
|
25
|
-
handler: (
|
|
25
|
+
handler: (
|
|
26
|
+
replyContext: ReplyContextInternal<IActionState>
|
|
27
|
+
) => Promise<void>;
|
|
26
28
|
abortController: AbortController;
|
|
27
29
|
action: IActionWithState<IActionState>;
|
|
28
30
|
}
|