chz-telegram-bot 0.7.13 → 0.7.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.
Files changed (98) hide show
  1. package/dist/dtos/propertyProviderSets.d.ts +0 -1
  2. package/dist/dtos/propertyProviderSets.d.ts.map +1 -1
  3. package/dist/entities/actions/commandAction.d.ts +1 -1
  4. package/dist/entities/actions/commandAction.d.ts.map +1 -1
  5. package/dist/entities/actions/commandAction.js +2 -2
  6. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
  7. package/dist/helpers/builders/commandActionBuilder.js +2 -3
  8. package/package.json +4 -1
  9. package/eslint.config.ts +0 -62
  10. package/src/builtin/helpAction.ts +0 -17
  11. package/src/dtos/chatHistoryMessage.ts +0 -22
  12. package/src/dtos/chatInfo.ts +0 -12
  13. package/src/dtos/commandTriggerCheckResult.ts +0 -40
  14. package/src/dtos/cooldownInfo.ts +0 -10
  15. package/src/dtos/incomingMessage.ts +0 -71
  16. package/src/dtos/incomingQuery.ts +0 -14
  17. package/src/dtos/messageInfo.ts +0 -15
  18. package/src/dtos/propertyProviderSets.ts +0 -21
  19. package/src/dtos/replyInfo.ts +0 -9
  20. package/src/dtos/responses/delay.ts +0 -28
  21. package/src/dtos/responses/imageMessage.ts +0 -41
  22. package/src/dtos/responses/inlineQueryResponse.ts +0 -26
  23. package/src/dtos/responses/reaction.ts +0 -30
  24. package/src/dtos/responses/textMessage.ts +0 -44
  25. package/src/dtos/responses/unpin.ts +0 -27
  26. package/src/dtos/responses/videoMessage.ts +0 -41
  27. package/src/dtos/userInfo.ts +0 -8
  28. package/src/entities/actions/commandAction.ts +0 -275
  29. package/src/entities/actions/inlineQueryAction.ts +0 -83
  30. package/src/entities/actions/replyCaptureAction.ts +0 -110
  31. package/src/entities/actions/scheduledAction.ts +0 -182
  32. package/src/entities/botInstance.ts +0 -92
  33. package/src/entities/cachedStateFactory.ts +0 -14
  34. package/src/entities/context/baseContext.ts +0 -111
  35. package/src/entities/context/chatContext.ts +0 -135
  36. package/src/entities/context/inlineQueryContext.ts +0 -63
  37. package/src/entities/context/messageContext.ts +0 -250
  38. package/src/entities/context/replyContext.ts +0 -260
  39. package/src/entities/states/actionStateBase.ts +0 -6
  40. package/src/entities/taskRecord.ts +0 -11
  41. package/src/helpers/builders/commandActionBuilder.ts +0 -214
  42. package/src/helpers/builders/inlineQueryActionBuilder.ts +0 -71
  43. package/src/helpers/builders/scheduledActionBuilder.ts +0 -143
  44. package/src/helpers/mapUtils.ts +0 -28
  45. package/src/helpers/noop.ts +0 -20
  46. package/src/helpers/objectFromEntries.ts +0 -7
  47. package/src/helpers/timeConvertions.ts +0 -13
  48. package/src/helpers/toArray.ts +0 -3
  49. package/src/helpers/traceFactory.ts +0 -11
  50. package/src/index.ts +0 -33
  51. package/src/main.ts +0 -76
  52. package/src/services/actionProcessingService.ts +0 -125
  53. package/src/services/actionProcessors/baseProcessor.ts +0 -67
  54. package/src/services/actionProcessors/commandActionProcessor.ts +0 -231
  55. package/src/services/actionProcessors/inlineQueryActionProcessor.ts +0 -165
  56. package/src/services/actionProcessors/scheduledActionProcessor.ts +0 -136
  57. package/src/services/jsonFileStorage.ts +0 -181
  58. package/src/services/nodeTimeoutScheduler.ts +0 -79
  59. package/src/services/responseProcessingQueue.ts +0 -57
  60. package/src/services/telegramApi.ts +0 -278
  61. package/src/types/action.ts +0 -15
  62. package/src/types/actionState.ts +0 -4
  63. package/src/types/cachedValueAccessor.ts +0 -1
  64. package/src/types/capture.ts +0 -33
  65. package/src/types/commandCondition.ts +0 -9
  66. package/src/types/commandTrigger.ts +0 -1
  67. package/src/types/events.ts +0 -286
  68. package/src/types/externalAliases.ts +0 -18
  69. package/src/types/handlers.ts +0 -26
  70. package/src/types/inputFile.ts +0 -4
  71. package/src/types/messageSendingOptions.ts +0 -10
  72. package/src/types/messageTypes.ts +0 -21
  73. package/src/types/propertyProvider.ts +0 -14
  74. package/src/types/response.ts +0 -51
  75. package/src/types/scheduler.ts +0 -20
  76. package/src/types/storage.ts +0 -23
  77. package/src/types/timeValues.ts +0 -33
  78. package/src/types/trace.ts +0 -5
  79. package/tests/dtos/commandTriggerCheckResult.test.ts +0 -301
  80. package/tests/entities/actions/inlineQueryAction.test.ts +0 -359
  81. package/tests/entities/actions/replyCaptureAction.test.ts +0 -501
  82. package/tests/entities/cachedStateFactory.test.ts +0 -98
  83. package/tests/entities/context/chatContext.test.ts +0 -606
  84. package/tests/entities/context/messageContext.test.ts +0 -370
  85. package/tests/entities/states/actionStateBase.test.ts +0 -138
  86. package/tests/entities/taskRecord.test.ts +0 -195
  87. package/tests/helpers/mapUtils.test.ts +0 -163
  88. package/tests/helpers/timeConvertions.test.ts +0 -129
  89. package/tests/services/actionProcessors/baseActionProcessor.test.ts +0 -359
  90. package/tests/services/actionProcessors/commandActionProcessor.test.ts +0 -268
  91. package/tests/services/actionProcessors/inlineQueryActionProcessor.test.ts +0 -616
  92. package/tests/services/actionProcessors/processorTestHelpers.ts +0 -147
  93. package/tests/services/actionProcessors/scheduledActionProcessor.test.ts +0 -153
  94. package/tests/services/jsonFileStorage.test.ts +0 -927
  95. package/tests/services/nodeTimeoutScheduler.test.ts +0 -421
  96. package/tests/services/responseProcessingQueue.test.ts +0 -388
  97. package/tsconfig.build.json +0 -8
  98. package/tsconfig.json +0 -118
@@ -1,260 +0,0 @@
1
- import { ReplyInfo } from '../../dtos/replyInfo';
2
- import { ImageMessage } from '../../dtos/responses/imageMessage';
3
- import { Reaction } from '../../dtos/responses/reaction';
4
- import { TextMessage } from '../../dtos/responses/textMessage';
5
- import { VideoMessage } from '../../dtos/responses/videoMessage';
6
- import { IActionState } from '../../types/actionState';
7
- import {
8
- TextMessageSendingOptions,
9
- MessageSendingOptions
10
- } from '../../types/messageSendingOptions';
11
- import { ReplyCaptureAction } from '../actions/replyCaptureAction';
12
- import { resolve } from 'path';
13
- import {
14
- BaseContextInternal,
15
- BaseContextPropertiesToOmit
16
- } from './baseContext';
17
- import { UserInfo } from '../../dtos/userInfo';
18
- import { MessageInfo } from '../../dtos/messageInfo';
19
- import {
20
- TelegramUser,
21
- TelegramEmoji,
22
- BotInfo
23
- } from '../../types/externalAliases';
24
- import { TypedEventEmitter } from '../../types/events';
25
- import { IScheduler } from '../../types/scheduler';
26
- import { IStorageClient } from '../../types/storage';
27
- import { IncomingMessage } from '../../dtos/incomingMessage';
28
-
29
- export type ReplyContext<TActionState extends IActionState> = Omit<
30
- ReplyContextInternal<TActionState>,
31
- | BaseContextPropertiesToOmit
32
- | 'messageId'
33
- | 'startCooldown'
34
- | 'customCooldown'
35
- >;
36
-
37
- export class ReplyContextInternal<
38
- TParentActionState extends IActionState
39
- > extends BaseContextInternal<ReplyCaptureAction<TParentActionState>> {
40
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
41
- matchResults: RegExpExecArray[] = [];
42
- /** Id of a message that triggered this action. */
43
- readonly replyMessageId: number | undefined;
44
- /** Information about the user that triggered this action */
45
- readonly userInfo: UserInfo;
46
- /** Information about the message that triggered this action */
47
- readonly messageInfo: MessageInfo;
48
- /** Bot info from Telegram */
49
- readonly botInfo: TelegramUser;
50
-
51
- constructor(
52
- storage: IStorageClient,
53
- scheduler: IScheduler,
54
- eventEmitter: TypedEventEmitter,
55
- action: ReplyCaptureAction<TParentActionState>,
56
- message: IncomingMessage,
57
- botName: string,
58
- botInfo: BotInfo
59
- ) {
60
- super(
61
- storage,
62
- scheduler,
63
- eventEmitter,
64
- action,
65
- message.chatInfo,
66
- message.traceId,
67
- botName
68
- );
69
-
70
- this.replyMessageId = message.replyToMessageId;
71
- this.messageInfo = new MessageInfo(
72
- message.messageId,
73
- message.text,
74
- message.type,
75
- message.updateObject
76
- );
77
- this.userInfo = new UserInfo(
78
- message.from?.id ?? -1,
79
- (message.from?.first_name ?? 'Unknown user') +
80
- (message.from?.last_name ? ` ${message.from.last_name}` : '')
81
- );
82
- this.botInfo = botInfo;
83
- }
84
-
85
- private getQuotePart(quote: boolean | string) {
86
- if (typeof quote != 'boolean') return quote;
87
-
88
- return this.matchResults.length == 0
89
- ? this.messageInfo.text
90
- : this.matchResults[0][1];
91
- }
92
-
93
- private replyWithText(
94
- text: string,
95
- quote: boolean | string,
96
- options?: TextMessageSendingOptions
97
- ) {
98
- const quotedPart = this.getQuotePart(quote);
99
-
100
- const response = new TextMessage(
101
- text,
102
- this.chatInfo,
103
- this.observability.traceId,
104
- this.action,
105
- new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
106
- options
107
- );
108
-
109
- this.responses.push(response);
110
-
111
- return this.createCaptureController(response);
112
- }
113
-
114
- private replyWithImage(
115
- name: string,
116
- quote: boolean | string,
117
- options?: MessageSendingOptions
118
- ) {
119
- const quotedPart = this.getQuotePart(quote);
120
-
121
- const response = new ImageMessage(
122
- { source: resolve(`./content/${name}.png`) },
123
- this.chatInfo,
124
- this.observability.traceId,
125
- this.action,
126
- new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
127
- options
128
- );
129
-
130
- this.responses.push(response);
131
-
132
- return this.createCaptureController(response);
133
- }
134
-
135
- private replyWithVideo(
136
- name: string,
137
- quote: boolean | string,
138
- options?: MessageSendingOptions
139
- ) {
140
- const quotedPart = this.getQuotePart(quote);
141
-
142
- const response = new VideoMessage(
143
- { source: resolve(`./content/${name}.mp4`) },
144
- this.chatInfo,
145
- this.observability.traceId,
146
- this.action,
147
- new ReplyInfo(this.messageInfo.id, quote ? quotedPart : undefined),
148
- options
149
- );
150
-
151
- this.responses.push(response);
152
-
153
- return this.createCaptureController(response);
154
- }
155
-
156
- /**
157
- * Stops capturing replies and removes this action
158
- */
159
- stopCapture() {
160
- this.action.abortController.abort();
161
- }
162
-
163
- /**
164
- * Collection of actions that can be done as a reply to a message that triggered this action
165
- */
166
- reply = {
167
- /**
168
- * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
169
- * If regex is matched, first match will be quoted
170
- */
171
- andQuote: {
172
- /**
173
- * Reply with text message to message that triggered this action after action execution is finished.
174
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
175
- * @param text Message contents.
176
- * @param options Message sending option.
177
- */
178
- withText: (
179
- text: string,
180
- quote?: string,
181
- options?: TextMessageSendingOptions
182
- ) => {
183
- return this.replyWithText(text, quote ?? true, options);
184
- },
185
- /**
186
- * Reply with image message to message that triggered this action after action execution is finished.
187
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
188
- * @param text Message contents.
189
- * @param options Message sending option.
190
- */
191
- withImage: (
192
- name: string,
193
- quote?: string,
194
- options?: MessageSendingOptions
195
- ) => {
196
- return this.replyWithImage(name, quote ?? true, options);
197
- },
198
-
199
- /**
200
- * Reply with video/gif message to message that triggered this action after action execution is finished.
201
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
202
- * @param text Message contents.
203
- * @param options Message sending option.
204
- */
205
- withVideo: (
206
- name: string,
207
- quote?: string,
208
- options?: MessageSendingOptions
209
- ) => {
210
- return this.replyWithVideo(name, quote ?? true, options);
211
- }
212
- },
213
-
214
- /**
215
- * Reply with text message to message that triggered this action after action execution is finished.
216
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
217
- * @param text Message contents.
218
- * @param options Message sending option.
219
- */
220
- withText: (text: string, options?: TextMessageSendingOptions) => {
221
- return this.replyWithText(text, false, options);
222
- },
223
- /**
224
- * Reply with image message to message that triggered this action after action execution is finished.
225
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
226
- * @param text Message contents.
227
- * @param options Message sending option.
228
- */
229
- withImage: (name: string, options?: MessageSendingOptions) => {
230
- return this.replyWithImage(name, false, options);
231
- },
232
-
233
- /**
234
- * Reply with video/gif message to message that triggered this action after action execution is finished.
235
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
236
- * @param text Message contents.
237
- * @param options Message sending option.
238
- */
239
- withVideo: (name: string, options?: MessageSendingOptions) => {
240
- return this.replyWithVideo(name, false, options);
241
- },
242
-
243
- /**
244
- * React to the message that triggered this action after action execution is finished.
245
- * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
246
- * @param emoji Telegram emoji to react with.
247
- */
248
- withReaction: (emoji: TelegramEmoji) => {
249
- this.responses.push(
250
- new Reaction(
251
- this.observability.traceId,
252
- this.chatInfo,
253
- this.messageInfo.id,
254
- emoji,
255
- this.action
256
- )
257
- );
258
- }
259
- };
260
- }
@@ -1,6 +0,0 @@
1
- import { IActionState } from '../../types/actionState';
2
-
3
- export class ActionStateBase implements IActionState {
4
- pinnedMessages: number[] = [];
5
- lastExecutedDate = 0;
6
- }
@@ -1,11 +0,0 @@
1
- import { Milliseconds } from '../types/timeValues';
2
- import { TraceId } from '../types/trace';
3
-
4
- export class TaskRecord {
5
- constructor(
6
- readonly name: string,
7
- readonly taskId: NodeJS.Timeout,
8
- readonly interval: Milliseconds,
9
- readonly traceId: TraceId
10
- ) {}
11
- }
@@ -1,214 +0,0 @@
1
- import { CommandHandler } from '../../types/handlers';
2
- import { CommandCondition } from '../../types/commandCondition';
3
- import { Seconds } from '../../types/timeValues';
4
- import { CommandAction } from '../../entities/actions/commandAction';
5
- import { ActionStateBase } from '../../entities/states/actionStateBase';
6
- import { IActionState } from '../../types/actionState';
7
- import { toArray } from '../toArray';
8
- import { Noop } from '../noop';
9
- import { CommandTrigger } from '../../types/commandTrigger';
10
- import { CooldownInfo } from '../../dtos/cooldownInfo';
11
- import { CommandActionPropertyProvider } from '../../types/propertyProvider';
12
-
13
- /**
14
- * Builder for `CommandAction` with state represented by `TActionState`
15
- */
16
- export class CommandActionBuilderWithState<TActionState extends IActionState> {
17
- private readonly name: string;
18
- private trigger: CommandTrigger | CommandTrigger[] = [];
19
-
20
- private activeProvider: CommandActionPropertyProvider<boolean> = () => true;
21
- private cooldownSettingsProvider: CommandActionPropertyProvider<CooldownInfo> =
22
- () => new CooldownInfo(0 as Seconds);
23
- private blacklistProvider: CommandActionPropertyProvider<number[]> =
24
- () => [];
25
- private whitelistProvider: CommandActionPropertyProvider<number[]> =
26
- () => [];
27
- private allowedUsersProvider: CommandActionPropertyProvider<number[]> =
28
- () => [];
29
-
30
- private readmeFactory: (botName: string) => string = Noop.emptyString;
31
- private readonly stateConstructor: () => TActionState;
32
- private handler: CommandHandler<TActionState> = Noop.call;
33
- private condition: CommandCondition<TActionState> = Noop.true;
34
- private maxAllowedSimultaniousExecutions: number = 0;
35
-
36
- /**
37
- * Builder for `CommandAction` with state represented by `TActionState`
38
- * @param name Action name, will be used for logging and storage
39
- * @param stateConstructor Function that creates default state object
40
- */
41
- constructor(name: string, stateConstructor: () => TActionState) {
42
- this.name = name;
43
- this.stateConstructor = stateConstructor;
44
- }
45
-
46
- /**
47
- * Defines action trigger
48
- * @param trigger If `string` or `string[]` is provided, will be triggered only on exact message match.
49
- *
50
- * If `RegExp` or `RegExp[]` is provided, will be triggered on successful match.
51
- */
52
- on(trigger: CommandTrigger | CommandTrigger[]) {
53
- this.trigger = trigger;
54
-
55
- return this;
56
- }
57
-
58
- /** Defines id (or ids) of users that are allowed to trigger this action.
59
- * @param id User id or ids
60
- */
61
- from(id: number | number[]) {
62
- const ids = toArray(id);
63
- this.allowedUsersProvider = () => ids;
64
-
65
- return this;
66
- }
67
-
68
- /**
69
- * Sets chats whitelist for this action.
70
- * @param chatIds Chats ids to allow.
71
- */
72
- in(chatIds: number[]) {
73
- this.whitelistProvider = () => chatIds;
74
-
75
- return this;
76
- }
77
-
78
- /**
79
- * Sets chats blacklist for this action.
80
- * @param chatIds Chats ids to ignore.
81
- */
82
- notIn(chatIds: number[]) {
83
- this.blacklistProvider = () => chatIds;
84
-
85
- return this;
86
- }
87
-
88
- /** Defines action logic itself, will be executed on trigger.
89
- * @param handler Callback that will be called on trigger
90
- */
91
- do(handler: CommandHandler<TActionState>) {
92
- this.handler = handler;
93
-
94
- return this;
95
- }
96
-
97
- /** Defines condition that will be checked before trigger match check is executed.
98
- * @param condition Condition check predicate
99
- */
100
- when(condition: CommandCondition<TActionState>) {
101
- this.condition = condition;
102
-
103
- return this;
104
- }
105
-
106
- /**
107
- * Sets factory method for readme (shown on /help) for this action.
108
- * @param readmeFactory readme factory
109
- */
110
- withHelp(readmeFactory: (botName: string) => string) {
111
- this.readmeFactory = readmeFactory;
112
-
113
- return this;
114
- }
115
-
116
- /** If called during building, action is marked as disabled and never checked. */
117
- disabled() {
118
- this.activeProvider = () => false;
119
-
120
- return this;
121
- }
122
-
123
- /** Sets maximum number of simultaniously executing handlers for this command per chat. 0 is treated as unlimited. */
124
- withRatelimit(maxAllowedSimultaniousExecutions: number) {
125
- this.maxAllowedSimultaniousExecutions =
126
- maxAllowedSimultaniousExecutions;
127
-
128
- return this;
129
- }
130
-
131
- /** Sets action cooldown settings.
132
- * @param cooldownSettings Settings.
133
- */
134
- withCooldown(cooldownSettings: { cooldown: Seconds; message?: string }) {
135
- const settings = new CooldownInfo(
136
- cooldownSettings.cooldown,
137
- cooldownSettings.message
138
- );
139
- this.cooldownSettingsProvider = () => settings;
140
-
141
- return this;
142
- }
143
-
144
- /**
145
- * Configures action to use property value providers instead of static value to allow changes in runtime
146
- */
147
- withConfiguration(
148
- configuration:
149
- | CommandActionProvidersConfiguration
150
- | (() => CommandActionProvidersConfiguration)
151
- ) {
152
- if (typeof configuration == 'function') {
153
- configuration = configuration();
154
- }
155
-
156
- if (configuration.cooldownProvider)
157
- this.cooldownSettingsProvider = configuration.cooldownProvider;
158
-
159
- if (configuration.chatsWhitelistProvider)
160
- this.whitelistProvider = configuration.chatsWhitelistProvider;
161
-
162
- if (configuration.chatsBlacklistProvider)
163
- this.blacklistProvider = configuration.chatsBlacklistProvider;
164
-
165
- if (configuration.usersWhitelistProvider)
166
- this.allowedUsersProvider = configuration.usersWhitelistProvider;
167
-
168
- if (configuration.isActiveProvider)
169
- this.activeProvider = configuration.isActiveProvider;
170
-
171
- return this;
172
- }
173
-
174
- /** Builds action */
175
- build() {
176
- return new CommandAction(
177
- this.trigger,
178
- this.handler,
179
- this.name,
180
- {
181
- cooldownProvider: this.cooldownSettingsProvider,
182
- isActiveProvider: this.activeProvider,
183
- chatsBlacklistProvider: this.blacklistProvider,
184
- chatsWhitelistProvider: this.whitelistProvider,
185
- usersWhitelistProvider: this.allowedUsersProvider,
186
- maxAllowedSimultaniousExecutions:
187
- this.maxAllowedSimultaniousExecutions
188
- },
189
- this.condition,
190
- this.stateConstructor,
191
- this.readmeFactory
192
- );
193
- }
194
- }
195
-
196
- export type CommandActionProvidersConfiguration = {
197
- cooldownProvider?: CommandActionPropertyProvider<CooldownInfo>;
198
- isActiveProvider?: CommandActionPropertyProvider<boolean>;
199
- chatsBlacklistProvider?: CommandActionPropertyProvider<number[]>;
200
- chatsWhitelistProvider?: CommandActionPropertyProvider<number[]>;
201
- usersWhitelistProvider?: CommandActionPropertyProvider<number[]>;
202
- };
203
-
204
- /**
205
- * Builder for `CommandAction` with state represented by default state (containing only last execution date).
206
- */
207
- export class CommandActionBuilder extends CommandActionBuilderWithState<ActionStateBase> {
208
- /**
209
- * Builder for `CommandAction` with state represented by default state (containing only last execution date).
210
- */
211
- constructor(name: string) {
212
- super(name, () => new ActionStateBase());
213
- }
214
- }
@@ -1,71 +0,0 @@
1
- import { InlineQueryHandler } from '../../types/handlers';
2
- import { Noop } from '../noop';
3
- import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
4
- import { InlineActionPropertyProvider } from '../../types/propertyProvider';
5
-
6
- /**
7
- * Builder for `InlineQueryAction`
8
- */
9
- export class InlineQueryActionBuilder {
10
- private readonly name: string;
11
- private pattern: RegExp = /.+/gi;
12
-
13
- private activeProvider: InlineActionPropertyProvider<boolean> = () => true;
14
- private handler: InlineQueryHandler = Noop.call;
15
-
16
- /**
17
- * Builder for `InlineQueryAction`
18
- * @param name Action name, will be used for logging and storage
19
- */
20
- constructor(name: string) {
21
- this.name = name;
22
- }
23
-
24
- /**
25
- * Defines action pattern to check if action should be executed, if not setup, check will default to true
26
- * @param trigger RegExp to check
27
- */
28
- on(pattern: RegExp) {
29
- this.pattern = pattern;
30
-
31
- return this;
32
- }
33
-
34
- /** Defines action logic itself, will be executed.
35
- * @param handler Callback that will be called
36
- */
37
- do(handler: InlineQueryHandler) {
38
- this.handler = handler;
39
-
40
- return this;
41
- }
42
-
43
- /** If called during building, action is marked as disabled and never checked. */
44
- disabled() {
45
- this.activeProvider = () => false;
46
-
47
- return this;
48
- }
49
-
50
- /**
51
- * Configures action to use property value providers instead of static value to allow changes in runtime
52
- */
53
- withConfiguration(configuration: {
54
- isActiveProvider?: InlineActionPropertyProvider<boolean>;
55
- }) {
56
- if (configuration.isActiveProvider)
57
- this.activeProvider = configuration.isActiveProvider;
58
-
59
- return this;
60
- }
61
-
62
- /** Builds action */
63
- build() {
64
- return new InlineQueryAction(
65
- this.handler,
66
- this.name,
67
- this.activeProvider,
68
- this.pattern
69
- );
70
- }
71
- }