chz-telegram-bot 0.0.46 → 0.0.48
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/actionExecutionResult.d.ts +3 -3
- package/dist/entities/actionExecutionResult.d.ts.map +1 -1
- 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 +6 -4
- package/dist/entities/actions/scheduledAction.d.ts +2 -2
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +4 -2
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +4 -2
- package/dist/entities/context/chatContext.d.ts +21 -9
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +24 -10
- package/dist/entities/context/messageContext.d.ts +9 -6
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +14 -10
- package/dist/entities/responses/delay.d.ts +13 -0
- package/dist/entities/responses/delay.d.ts.map +1 -0
- package/dist/entities/responses/delay.js +14 -0
- package/dist/entities/responses/imageMessage.d.ts +3 -2
- package/dist/entities/responses/imageMessage.d.ts.map +1 -1
- package/dist/entities/responses/reaction.d.ts +3 -2
- package/dist/entities/responses/reaction.d.ts.map +1 -1
- package/dist/entities/responses/textMessage.d.ts +3 -2
- package/dist/entities/responses/textMessage.d.ts.map +1 -1
- package/dist/entities/responses/unpin.d.ts +3 -2
- package/dist/entities/responses/unpin.d.ts.map +1 -1
- package/dist/entities/responses/videoMessage.d.ts +3 -2
- package/dist/entities/responses/videoMessage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.d.ts +5 -5
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +1 -1
- package/dist/services/telegramApi.d.ts +1 -12
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +7 -10
- package/dist/types/actionWithState.d.ts +2 -2
- package/dist/types/actionWithState.d.ts.map +1 -1
- package/dist/types/response.d.ts +5 -2
- package/dist/types/response.d.ts.map +1 -1
- package/dist/types/response.js +2 -1
- package/dist/types/storage.d.ts +4 -4
- package/dist/types/storage.d.ts.map +1 -1
- package/entities/actionExecutionResult.ts +3 -3
- package/entities/actions/commandAction.ts +12 -5
- package/entities/actions/scheduledAction.ts +11 -3
- package/entities/botInstance.ts +4 -2
- package/entities/context/chatContext.ts +32 -15
- package/entities/context/messageContext.ts +13 -13
- package/entities/responses/delay.ts +25 -0
- package/entities/responses/imageMessage.ts +3 -2
- package/entities/responses/reaction.ts +3 -2
- package/entities/responses/textMessage.ts +3 -2
- package/entities/responses/unpin.ts +3 -2
- package/entities/responses/videoMessage.ts +3 -2
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +22 -13
- package/services/telegramApi.ts +5 -23
- package/types/actionWithState.ts +2 -2
- package/types/response.ts +6 -2
- package/types/storage.ts +9 -6
|
@@ -7,16 +7,16 @@ export declare class JsonFileStorage implements IStorageClient {
|
|
|
7
7
|
private cache;
|
|
8
8
|
private storagePath;
|
|
9
9
|
private botName;
|
|
10
|
-
constructor(botName: string, actions: IActionWithState[], path?: string);
|
|
10
|
+
constructor(botName: string, actions: IActionWithState<IActionState>[], path?: string);
|
|
11
11
|
private lock;
|
|
12
12
|
private loadInternal;
|
|
13
13
|
private save;
|
|
14
14
|
private buidPathFromKey;
|
|
15
15
|
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
16
|
-
saveMetadata(actions: IActionWithState[], botName: string): Promise<void>;
|
|
17
|
-
getActionState<TActionState extends IActionState>(action: IActionWithState
|
|
18
|
-
saveActionExecutionResult(action: IActionWithState
|
|
16
|
+
saveMetadata(actions: IActionWithState<IActionState>[], botName: string): Promise<void>;
|
|
17
|
+
getActionState<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number): Promise<TActionState>;
|
|
18
|
+
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, transactionResult: ActionExecutionResult<TActionState>): Promise<void>;
|
|
19
19
|
close(): Promise<void>;
|
|
20
|
-
updateStateFor<TActionState extends IActionState>(action: IActionWithState
|
|
20
|
+
updateStateFor<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=jsonFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEvE,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAGpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,IAAI,CAAC,EAAE,MAAM;YAiBH,IAAI;YAgBJ,YAAY;YAqBZ,IAAI;IAgBlB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,SAAS;IAMtD,YAAY,CACd,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,OAAO,EAAE,MAAM;IAWb,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM;IAYZ,yBAAyB,CAAC,YAAY,SAAS,YAAY,EAC7D,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAYpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAcrD"}
|
|
@@ -48,7 +48,7 @@ class JsonFileStorage {
|
|
|
48
48
|
return (this.cache.get(key) ?? {});
|
|
49
49
|
}
|
|
50
50
|
async save(data, key) {
|
|
51
|
-
this.cache.
|
|
51
|
+
this.cache.set(key, data);
|
|
52
52
|
const targetPath = this.buidPathFromKey(key);
|
|
53
53
|
const folderName = (0, path_1.dirname)(targetPath);
|
|
54
54
|
if (!(0, fs_1.existsSync)(folderName)) {
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { ChatContext } from '../entities/context/chatContext';
|
|
2
2
|
import { MessageContext } from '../entities/context/messageContext';
|
|
3
3
|
import { IStorageClient } from '../types/storage';
|
|
4
|
-
import { Reaction } from '../entities/responses/reaction';
|
|
5
4
|
import { IncomingMessage } from '../entities/incomingMessage';
|
|
6
5
|
import { BotResponse } from '../types/response';
|
|
7
|
-
import { UnpinResponse } from '../entities/responses/unpin';
|
|
8
|
-
import { TextMessage } from '../entities/responses/textMessage';
|
|
9
|
-
import { VideoMessage } from '../entities/responses/videoMessage';
|
|
10
|
-
import { ImageMessage } from '../entities/responses/imageMessage';
|
|
11
6
|
import { Telegram } from 'telegraf/typings/telegram';
|
|
12
7
|
import { ScheduledAction } from '../entities/actions/scheduledAction';
|
|
13
8
|
import { IActionState } from '../types/actionState';
|
|
@@ -19,18 +14,12 @@ export declare class TelegramApiService {
|
|
|
19
14
|
telegram: Telegram;
|
|
20
15
|
chats: Record<number, string>;
|
|
21
16
|
storage: IStorageClient;
|
|
22
|
-
interactions: IBotApiInteractions;
|
|
23
17
|
constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Record<string, number>);
|
|
18
|
+
enqueueBatchedResponses(responses: BotResponse[]): void;
|
|
24
19
|
flushResponses(): Promise<void>;
|
|
25
20
|
private pinIfShould;
|
|
26
21
|
private processResponse;
|
|
27
|
-
private enqueue;
|
|
28
22
|
initializeContextForMessage<TActionState extends IActionState>(ctx: MessageContext<TActionState>, incomingMessage: IncomingMessage, command: CommandAction<TActionState>): MessageContext<TActionState>;
|
|
29
23
|
initializeContextForChat<TActionState extends IActionState>(ctx: ChatContext<TActionState>, chatId: number, scheduledAction: ScheduledAction<TActionState>): ChatContext<TActionState>;
|
|
30
24
|
}
|
|
31
|
-
export interface IBotApiInteractions {
|
|
32
|
-
respond: (response: TextMessage | VideoMessage | ImageMessage) => void;
|
|
33
|
-
react: (reaction: Reaction) => void;
|
|
34
|
-
unpin: (unpinMessage: UnpinResponse) => void;
|
|
35
|
-
}
|
|
36
25
|
//# sourceMappingURL=telegramApi.d.ts.map
|
|
@@ -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,
|
|
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,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,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;AAIlE,qBAAa,kBAAkB;IAC3B,UAAU,UAAS;IACnB,YAAY,EAAE,WAAW,EAAE,CAAM;IAEjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQjC,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAM1C,cAAc;YA2BN,WAAW;YAqBX,eAAe;IA2E7B,2BAA2B,CAAC,YAAY,SAAS,YAAY,EACzD,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,EACjC,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC;IAUxC,wBAAwB,CAAC,YAAY,SAAS,YAAY,EACtD,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,eAAe,CAAC,YAAY,CAAC;CAWrD"}
|
|
@@ -13,11 +13,11 @@ class TelegramApiService {
|
|
|
13
13
|
this.botName = botName;
|
|
14
14
|
this.chats = (0, inverseRecord_1.inverseRecord)(chats);
|
|
15
15
|
this.storage = storage;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
}
|
|
17
|
+
enqueueBatchedResponses(responses) {
|
|
18
|
+
for (const response of responses) {
|
|
19
|
+
this.messageQueue.push(response);
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
22
|
async flushResponses() {
|
|
23
23
|
if (this.isFlushing)
|
|
@@ -87,14 +87,11 @@ class TelegramApiService {
|
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
enqueue(response) {
|
|
91
|
-
this.messageQueue.push(response);
|
|
92
|
-
}
|
|
93
90
|
initializeContextForMessage(ctx, incomingMessage, command) {
|
|
94
|
-
return ctx.initializeMessageContext(this.botName, command,
|
|
91
|
+
return ctx.initializeMessageContext(this.botName, command, incomingMessage, this.storage);
|
|
95
92
|
}
|
|
96
93
|
initializeContextForChat(ctx, chatId, scheduledAction) {
|
|
97
|
-
return ctx.initializeChatContext(this.botName, scheduledAction,
|
|
94
|
+
return ctx.initializeChatContext(this.botName, scheduledAction, chatId, this.chats[chatId], `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
exports.TelegramApiService = TelegramApiService;
|
|
@@ -2,8 +2,8 @@ import { IActionState } from './actionState';
|
|
|
2
2
|
export type ActionKey = string & {
|
|
3
3
|
__brand: 'actionKey';
|
|
4
4
|
};
|
|
5
|
-
export interface IActionWithState {
|
|
5
|
+
export interface IActionWithState<TActionState extends IActionState> {
|
|
6
6
|
key: ActionKey;
|
|
7
|
-
stateConstructor: () =>
|
|
7
|
+
stateConstructor: () => TActionState;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=actionWithState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB;
|
|
1
|
+
{"version":3,"file":"actionWithState.d.ts","sourceRoot":"","sources":["../../types/actionWithState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,YAAY,SAAS,YAAY;IAC/D,GAAG,EAAE,SAAS,CAAC;IACf,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACxC"}
|
package/dist/types/response.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { DelayResponse } from '../entities/responses/delay';
|
|
1
2
|
import { ImageMessage } from '../entities/responses/imageMessage';
|
|
2
3
|
import { Reaction } from '../entities/responses/reaction';
|
|
3
4
|
import { TextMessage } from '../entities/responses/textMessage';
|
|
4
5
|
import { UnpinResponse } from '../entities/responses/unpin';
|
|
5
6
|
import { VideoMessage } from '../entities/responses/videoMessage';
|
|
7
|
+
import { IActionState } from './actionState';
|
|
6
8
|
import { IActionWithState } from './actionWithState';
|
|
7
9
|
export declare const BotResponseTypes: {
|
|
8
10
|
readonly unpin: "unpin";
|
|
@@ -10,13 +12,14 @@ export declare const BotResponseTypes: {
|
|
|
10
12
|
readonly image: "image";
|
|
11
13
|
readonly video: "video";
|
|
12
14
|
readonly react: "react";
|
|
15
|
+
readonly delay: "delay";
|
|
13
16
|
};
|
|
14
|
-
export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | ImageMessage;
|
|
17
|
+
export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | DelayResponse | ImageMessage;
|
|
15
18
|
export interface IChatResponse {
|
|
16
19
|
kind: keyof typeof BotResponseTypes;
|
|
17
20
|
chatId: number;
|
|
18
21
|
traceId: number | string;
|
|
19
|
-
action: IActionWithState
|
|
22
|
+
action: IActionWithState<IActionState>;
|
|
20
23
|
}
|
|
21
24
|
export interface IReplyMessage<TType> extends IChatResponse {
|
|
22
25
|
content: TType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../types/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAEX,MAAM,MAAM,WAAW,GACjB,aAAa,GACb,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,aAAa,GACb,YAAY,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,OAAO,gBAAgB,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa,CAAC,KAAK,CAAE,SAAQ,aAAa;IACvD,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/types/response.js
CHANGED
package/dist/types/storage.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
|
2
2
|
import { IActionState } from './actionState';
|
|
3
3
|
import { ActionKey, IActionWithState } from './actionWithState';
|
|
4
4
|
export interface IStorageClient {
|
|
5
|
-
updateStateFor<TActionState extends IActionState>(action: IActionWithState
|
|
5
|
+
updateStateFor<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
6
6
|
close(): Promise<void>;
|
|
7
7
|
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
8
|
-
saveMetadata(actions: IActionWithState[], botName: string): Promise<void>;
|
|
9
|
-
getActionState<TActionState extends IActionState>(action: IActionWithState
|
|
10
|
-
saveActionExecutionResult(action: IActionWithState
|
|
8
|
+
saveMetadata<TActionState extends IActionState>(actions: IActionWithState<TActionState>[], botName: string): Promise<void>;
|
|
9
|
+
getActionState<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number): Promise<TActionState>;
|
|
10
|
+
saveActionExecutionResult<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, transactionResult: ActionExecutionResult<TActionState>): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../types/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,YAAY,SAAS,YAAY,EAClC,GAAG,EAAE,SAAS,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,YAAY,CAAC,YAAY,SAAS,YAAY,EAC1C,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EAAE,EACzC,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,CAAC,YAAY,SAAS,YAAY,EAC5C,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,yBAAyB,CAAC,YAAY,SAAS,YAAY,EACvD,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB,CAAC,YAAY,CAAC,GACvD,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IActionState } from '../types/actionState';
|
|
2
2
|
|
|
3
|
-
export class ActionExecutionResult {
|
|
4
|
-
data:
|
|
3
|
+
export class ActionExecutionResult<TActionState extends IActionState> {
|
|
4
|
+
data: TActionState;
|
|
5
5
|
shouldUpdate: boolean;
|
|
6
6
|
|
|
7
|
-
constructor(data:
|
|
7
|
+
constructor(data: TActionState, shouldUpdate: boolean) {
|
|
8
8
|
this.data = data;
|
|
9
9
|
this.shouldUpdate = shouldUpdate;
|
|
10
10
|
}
|
|
@@ -13,7 +13,7 @@ import { ActionExecutionResult } from '../actionExecutionResult';
|
|
|
13
13
|
import { CommandTrigger } from '../../types/commandTrigger';
|
|
14
14
|
|
|
15
15
|
export class CommandAction<TActionState extends IActionState>
|
|
16
|
-
implements IActionWithState
|
|
16
|
+
implements IActionWithState<TActionState>
|
|
17
17
|
{
|
|
18
18
|
triggers: CommandTrigger[];
|
|
19
19
|
handler: CommandHandler<TActionState>;
|
|
@@ -51,13 +51,16 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async exec(ctx: MessageContext<TActionState>) {
|
|
54
|
-
if (!ctx.isInitialized)
|
|
54
|
+
if (!ctx.isInitialized)
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Context for ${this.key} is not initialized or already consumed`
|
|
57
|
+
);
|
|
55
58
|
|
|
56
|
-
if (!this.active || this.chatsBlacklist.includes(ctx.chatId)) return;
|
|
59
|
+
if (!this.active || this.chatsBlacklist.includes(ctx.chatId)) return [];
|
|
57
60
|
|
|
58
61
|
const isConditionMet = await this.condition(ctx);
|
|
59
62
|
|
|
60
|
-
if (!isConditionMet) return;
|
|
63
|
+
if (!isConditionMet) return [];
|
|
61
64
|
|
|
62
65
|
const state = await ctx.storage.getActionState<TActionState>(
|
|
63
66
|
this,
|
|
@@ -71,7 +74,7 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
71
74
|
CommandTriggerCheckResult.DoNotTrigger
|
|
72
75
|
);
|
|
73
76
|
|
|
74
|
-
if (!shouldTrigger) return;
|
|
77
|
+
if (!shouldTrigger) return [];
|
|
75
78
|
|
|
76
79
|
Logger.logWithTraceId(
|
|
77
80
|
ctx.botName,
|
|
@@ -98,6 +101,10 @@ export class CommandAction<TActionState extends IActionState>
|
|
|
98
101
|
ctx.chatId,
|
|
99
102
|
new ActionExecutionResult(state, ctx.startCooldown && shouldTrigger)
|
|
100
103
|
);
|
|
104
|
+
|
|
105
|
+
ctx.isInitialized = false;
|
|
106
|
+
|
|
107
|
+
return ctx.responses;
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
private checkTrigger(
|
|
@@ -12,7 +12,7 @@ import { Logger } from '../../services/logger';
|
|
|
12
12
|
import { Scheduler } from '../../services/taskScheduler';
|
|
13
13
|
|
|
14
14
|
export class ScheduledAction<TActionState extends IActionState>
|
|
15
|
-
implements IActionWithState
|
|
15
|
+
implements IActionWithState<TActionState>
|
|
16
16
|
{
|
|
17
17
|
static locks = new Map<string, Semaphore>();
|
|
18
18
|
|
|
@@ -47,9 +47,13 @@ export class ScheduledAction<TActionState extends IActionState>
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async exec(ctx: ChatContext<TActionState>) {
|
|
50
|
-
if (!ctx.isInitialized)
|
|
50
|
+
if (!ctx.isInitialized)
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Context for ${this.key} is not initialized or already consumed`
|
|
53
|
+
);
|
|
51
54
|
|
|
52
|
-
if (!this.active || !this.chatsWhitelist.includes(ctx.chatId))
|
|
55
|
+
if (!this.active || !this.chatsWhitelist.includes(ctx.chatId))
|
|
56
|
+
return [];
|
|
53
57
|
|
|
54
58
|
const state = await ctx.storage.getActionState<TActionState>(
|
|
55
59
|
this,
|
|
@@ -81,6 +85,10 @@ export class ScheduledAction<TActionState extends IActionState>
|
|
|
81
85
|
new ActionExecutionResult(state, isAllowedToTrigger)
|
|
82
86
|
);
|
|
83
87
|
}
|
|
88
|
+
|
|
89
|
+
ctx.isInitialized = false;
|
|
90
|
+
|
|
91
|
+
return ctx.responses;
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
private async getCachedValue<TResult>(
|
package/entities/botInstance.ts
CHANGED
|
@@ -169,7 +169,8 @@ export class BotInstance {
|
|
|
169
169
|
this.api.initializeContextForChat(ctx, chatId, scheduledAction);
|
|
170
170
|
|
|
171
171
|
try {
|
|
172
|
-
await scheduledAction.exec(ctx);
|
|
172
|
+
const responses = await scheduledAction.exec(ctx);
|
|
173
|
+
this.api.enqueueBatchedResponses(responses);
|
|
173
174
|
} catch (error) {
|
|
174
175
|
Logger.errorWithTraceId(
|
|
175
176
|
ctx.botName,
|
|
@@ -192,7 +193,8 @@ export class BotInstance {
|
|
|
192
193
|
this.api.initializeContextForMessage(ctx, msg, commandAction);
|
|
193
194
|
|
|
194
195
|
try {
|
|
195
|
-
await commandAction.exec(ctx);
|
|
196
|
+
const responses = await commandAction.exec(ctx);
|
|
197
|
+
this.api.enqueueBatchedResponses(responses);
|
|
196
198
|
} catch (error) {
|
|
197
199
|
Logger.errorWithTraceId(
|
|
198
200
|
ctx.botName,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import { IBotApiInteractions } from '../../services/telegramApi';
|
|
3
2
|
import { IStorageClient } from '../../types/storage';
|
|
4
3
|
import { ImageMessage } from '../responses/imageMessage';
|
|
5
4
|
import { TextMessage } from '../responses/textMessage';
|
|
@@ -10,13 +9,16 @@ import {
|
|
|
10
9
|
TextMessageSendingOptions
|
|
11
10
|
} from '../../types/messageSendingOptions';
|
|
12
11
|
import { IActionWithState } from '../../types/actionWithState';
|
|
12
|
+
import { IActionState } from '../../types/actionState';
|
|
13
|
+
import { BotResponse } from '../../types/response';
|
|
14
|
+
import { Milliseconds } from '../../types/timeValues';
|
|
15
|
+
import { DelayResponse } from '../responses/delay';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Context of action executed in chat.
|
|
16
19
|
*/
|
|
17
|
-
export class ChatContext<TActionState> {
|
|
18
|
-
protected action!: IActionWithState
|
|
19
|
-
protected interactions!: IBotApiInteractions;
|
|
20
|
+
export class ChatContext<TActionState extends IActionState> {
|
|
21
|
+
protected action!: IActionWithState<TActionState>;
|
|
20
22
|
updateActions: Array<(state: TActionState) => void> = [];
|
|
21
23
|
/** Trace id of a action execution. */
|
|
22
24
|
traceId!: number | string;
|
|
@@ -28,6 +30,8 @@ export class ChatContext<TActionState> {
|
|
|
28
30
|
chatName!: string;
|
|
29
31
|
/** Storage client instance for this bot. */
|
|
30
32
|
storage!: IStorageClient;
|
|
33
|
+
/** Ordered collection of responses to be processed */
|
|
34
|
+
responses: BotResponse[] = [];
|
|
31
35
|
|
|
32
36
|
isInitialized = false;
|
|
33
37
|
|
|
@@ -35,8 +39,7 @@ export class ChatContext<TActionState> {
|
|
|
35
39
|
|
|
36
40
|
initializeChatContext(
|
|
37
41
|
botName: string,
|
|
38
|
-
action: IActionWithState
|
|
39
|
-
interactions: IBotApiInteractions,
|
|
42
|
+
action: IActionWithState<TActionState>,
|
|
40
43
|
chatId: number,
|
|
41
44
|
chatName: string,
|
|
42
45
|
traceId: number | string,
|
|
@@ -44,7 +47,6 @@ export class ChatContext<TActionState> {
|
|
|
44
47
|
) {
|
|
45
48
|
this.botName = botName;
|
|
46
49
|
this.action = action;
|
|
47
|
-
this.interactions = interactions;
|
|
48
50
|
this.chatId = chatId;
|
|
49
51
|
this.chatName = chatName;
|
|
50
52
|
this.traceId = traceId;
|
|
@@ -52,6 +54,7 @@ export class ChatContext<TActionState> {
|
|
|
52
54
|
|
|
53
55
|
this.updateActions = [];
|
|
54
56
|
this.isInitialized = true;
|
|
57
|
+
this.responses = [];
|
|
55
58
|
|
|
56
59
|
return this;
|
|
57
60
|
}
|
|
@@ -65,12 +68,13 @@ export class ChatContext<TActionState> {
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
|
-
* Sends text message to chat.
|
|
71
|
+
* Sends text message to chat after action execution is finished.
|
|
72
|
+
* 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.
|
|
69
73
|
* @param text Message contents.
|
|
70
74
|
* @param options Message sending option.
|
|
71
75
|
*/
|
|
72
76
|
sendTextToChat(text: string, options?: TextMessageSendingOptions) {
|
|
73
|
-
this.
|
|
77
|
+
this.responses.push(
|
|
74
78
|
new TextMessage(
|
|
75
79
|
text,
|
|
76
80
|
this.chatId,
|
|
@@ -83,13 +87,14 @@ export class ChatContext<TActionState> {
|
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
/**
|
|
86
|
-
* Sends image message to chat.
|
|
90
|
+
* Sends image message to chat after action execution is finished.
|
|
91
|
+
* 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.
|
|
87
92
|
* @param name Message contents.
|
|
88
93
|
* @param options Message sending option.
|
|
89
94
|
*/
|
|
90
95
|
sendImageToChat(name: string, options?: MessageSendingOptions) {
|
|
91
96
|
const filePath = `./content/${name}.png`;
|
|
92
|
-
this.
|
|
97
|
+
this.responses.push(
|
|
93
98
|
new ImageMessage(
|
|
94
99
|
{ source: resolve(filePath) },
|
|
95
100
|
this.chatId,
|
|
@@ -102,13 +107,14 @@ export class ChatContext<TActionState> {
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
/**
|
|
105
|
-
* Sends video/gif message to chat.
|
|
110
|
+
* Sends video/gif message to chat after action execution is finished.
|
|
111
|
+
* 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.
|
|
106
112
|
* @param name Message contents.
|
|
107
113
|
* @param options Message sending option.
|
|
108
114
|
*/
|
|
109
115
|
sendVideoToChat(name: string, options?: MessageSendingOptions) {
|
|
110
116
|
const filePath = `./content/${name}.mp4`;
|
|
111
|
-
this.
|
|
117
|
+
this.responses.push(
|
|
112
118
|
new VideoMessage(
|
|
113
119
|
{ source: resolve(filePath) },
|
|
114
120
|
this.chatId,
|
|
@@ -121,12 +127,23 @@ export class ChatContext<TActionState> {
|
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
/**
|
|
124
|
-
* Unpins message.
|
|
130
|
+
* Unpins message after action execution is finished.
|
|
131
|
+
* 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.
|
|
125
132
|
* @param messageId Message id.
|
|
126
133
|
*/
|
|
127
134
|
unpinMessage(messageId: number) {
|
|
128
|
-
this.
|
|
135
|
+
this.responses.push(
|
|
129
136
|
new UnpinResponse(messageId, this.chatId, this.traceId, this.action)
|
|
130
137
|
);
|
|
131
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Delays next response by specified amount of time.
|
|
142
|
+
* @param delay Delay in milliseconds.
|
|
143
|
+
*/
|
|
144
|
+
delayNextResponse(delay: Milliseconds) {
|
|
145
|
+
this.responses.push(
|
|
146
|
+
new DelayResponse(delay, this.chatId, this.traceId, this.action)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
132
149
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import { IBotApiInteractions } from '../../services/telegramApi';
|
|
3
2
|
import { TelegramEmoji } from 'telegraf/types';
|
|
4
3
|
import { IStorageClient } from '../../types/storage';
|
|
5
4
|
import { IActionState } from '../../types/actionState';
|
|
@@ -16,7 +15,6 @@ import {
|
|
|
16
15
|
} from '../../types/messageSendingOptions';
|
|
17
16
|
import { IActionWithState, ActionKey } from '../../types/actionWithState';
|
|
18
17
|
import { MessageTypeValue } from '../../types/messageTypes';
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Context of action executed in chat, in response to a message
|
|
22
20
|
*/
|
|
@@ -44,8 +42,7 @@ export class MessageContext<
|
|
|
44
42
|
|
|
45
43
|
initializeMessageContext(
|
|
46
44
|
botName: string,
|
|
47
|
-
action: IActionWithState
|
|
48
|
-
interactions: IBotApiInteractions,
|
|
45
|
+
action: IActionWithState<TActionState>,
|
|
49
46
|
message: IncomingMessage,
|
|
50
47
|
storage: IStorageClient
|
|
51
48
|
) {
|
|
@@ -63,7 +60,6 @@ export class MessageContext<
|
|
|
63
60
|
return this.initializeChatContext(
|
|
64
61
|
botName,
|
|
65
62
|
action,
|
|
66
|
-
interactions,
|
|
67
63
|
message.chat.id,
|
|
68
64
|
message.chatName,
|
|
69
65
|
message.traceId,
|
|
@@ -94,12 +90,13 @@ export class MessageContext<
|
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
/**
|
|
97
|
-
* Reply with text message to message that triggered this action.
|
|
93
|
+
* Reply with text message to message that triggered this action after action execution is finished.
|
|
94
|
+
* 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.
|
|
98
95
|
* @param text Message contents.
|
|
99
96
|
* @param options Message sending option.
|
|
100
97
|
*/
|
|
101
98
|
replyWithText(text: string, options?: TextMessageSendingOptions) {
|
|
102
|
-
this.
|
|
99
|
+
this.responses.push(
|
|
103
100
|
new TextMessage(
|
|
104
101
|
text,
|
|
105
102
|
this.chatId,
|
|
@@ -112,13 +109,14 @@ export class MessageContext<
|
|
|
112
109
|
}
|
|
113
110
|
|
|
114
111
|
/**
|
|
115
|
-
* Reply with image message to message that triggered this action.
|
|
112
|
+
* Reply with image message to message that triggered this action after action execution is finished.
|
|
113
|
+
* 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.
|
|
116
114
|
* @param text Message contents.
|
|
117
115
|
* @param options Message sending option.
|
|
118
116
|
*/
|
|
119
117
|
replyWithImage(name: string, options?: MessageSendingOptions) {
|
|
120
118
|
const filePath = `./content/${name}.png`;
|
|
121
|
-
this.
|
|
119
|
+
this.responses.push(
|
|
122
120
|
new ImageMessage(
|
|
123
121
|
{ source: resolve(filePath) },
|
|
124
122
|
this.chatId,
|
|
@@ -131,13 +129,14 @@ export class MessageContext<
|
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
/**
|
|
134
|
-
* Reply with video/gif message to message that triggered this action.
|
|
132
|
+
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
133
|
+
* 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.
|
|
135
134
|
* @param text Message contents.
|
|
136
135
|
* @param options Message sending option.
|
|
137
136
|
*/
|
|
138
137
|
replyWithVideo(name: string, options?: MessageSendingOptions) {
|
|
139
138
|
const filePath = `./content/${name}.mp4`;
|
|
140
|
-
this.
|
|
139
|
+
this.responses.push(
|
|
141
140
|
new VideoMessage(
|
|
142
141
|
{ source: resolve(filePath) },
|
|
143
142
|
this.chatId,
|
|
@@ -150,11 +149,12 @@ export class MessageContext<
|
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
|
-
* React to the message that triggered this action.
|
|
152
|
+
* React to the message that triggered this action after action execution is finished.
|
|
153
|
+
* 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.
|
|
154
154
|
* @param emoji Telegram emoji to react with.
|
|
155
155
|
*/
|
|
156
156
|
react(emoji: TelegramEmoji) {
|
|
157
|
-
this.
|
|
157
|
+
this.responses.push(
|
|
158
158
|
new Reaction(
|
|
159
159
|
this.traceId,
|
|
160
160
|
this.chatId,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IActionState } from '../../types/actionState';
|
|
2
|
+
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
+
import { BotResponseTypes, IChatResponse } from '../../types/response';
|
|
4
|
+
import { Milliseconds } from '../../types/timeValues';
|
|
5
|
+
|
|
6
|
+
export class DelayResponse implements IChatResponse {
|
|
7
|
+
kind = BotResponseTypes.delay;
|
|
8
|
+
|
|
9
|
+
chatId: number;
|
|
10
|
+
traceId: number | string;
|
|
11
|
+
delay: Milliseconds;
|
|
12
|
+
action: IActionWithState<IActionState>;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
delay: Milliseconds,
|
|
16
|
+
chatId: number,
|
|
17
|
+
traceId: number | string,
|
|
18
|
+
action: IActionWithState<IActionState>
|
|
19
|
+
) {
|
|
20
|
+
this.chatId = chatId;
|
|
21
|
+
this.delay = delay;
|
|
22
|
+
this.traceId = traceId;
|
|
23
|
+
this.action = action;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -2,6 +2,7 @@ import { InputFile } from 'telegraf/types';
|
|
|
2
2
|
import { BotResponseTypes, IReplyMessage } from '../../types/response';
|
|
3
3
|
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
4
|
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
+
import { IActionState } from '../../types/actionState';
|
|
5
6
|
|
|
6
7
|
export class ImageMessage implements IReplyMessage<InputFile> {
|
|
7
8
|
kind = BotResponseTypes.image;
|
|
@@ -12,14 +13,14 @@ export class ImageMessage implements IReplyMessage<InputFile> {
|
|
|
12
13
|
traceId: string | number;
|
|
13
14
|
disableWebPreview = false;
|
|
14
15
|
shouldPin: boolean;
|
|
15
|
-
action: IActionWithState
|
|
16
|
+
action: IActionWithState<IActionState>;
|
|
16
17
|
|
|
17
18
|
constructor(
|
|
18
19
|
image: InputFile,
|
|
19
20
|
chatId: number,
|
|
20
21
|
replyId: number | undefined,
|
|
21
22
|
traceId: number | string,
|
|
22
|
-
action: IActionWithState
|
|
23
|
+
action: IActionWithState<IActionState>,
|
|
23
24
|
options?: MessageSendingOptions
|
|
24
25
|
) {
|
|
25
26
|
this.content = image;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TelegramEmoji } from 'telegraf/types';
|
|
2
2
|
import { BotResponseTypes, IChatResponse } from '../../types/response';
|
|
3
3
|
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
import { IActionState } from '../../types/actionState';
|
|
4
5
|
|
|
5
6
|
export class Reaction implements IChatResponse {
|
|
6
7
|
kind = BotResponseTypes.react;
|
|
@@ -9,14 +10,14 @@ export class Reaction implements IChatResponse {
|
|
|
9
10
|
messageId: number;
|
|
10
11
|
traceId: number | string;
|
|
11
12
|
emoji: TelegramEmoji;
|
|
12
|
-
action: IActionWithState
|
|
13
|
+
action: IActionWithState<IActionState>;
|
|
13
14
|
|
|
14
15
|
constructor(
|
|
15
16
|
traceId: number | string,
|
|
16
17
|
chatId: number,
|
|
17
18
|
messageId: number,
|
|
18
19
|
emoji: TelegramEmoji,
|
|
19
|
-
action: IActionWithState
|
|
20
|
+
action: IActionWithState<IActionState>
|
|
20
21
|
) {
|
|
21
22
|
this.chatId = chatId;
|
|
22
23
|
this.messageId = messageId;
|