chz-telegram-bot 0.0.45 → 0.0.47
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 +7 -0
- package/dist/entities/actionExecutionResult.d.ts.map +1 -0
- package/dist/entities/actionExecutionResult.js +10 -0
- package/dist/entities/actions/commandAction.d.ts +23 -0
- package/dist/entities/actions/commandAction.d.ts.map +1 -0
- package/dist/entities/actions/commandAction.js +91 -0
- package/dist/entities/actions/scheduledAction.d.ts +24 -0
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -0
- package/dist/entities/actions/scheduledAction.js +81 -0
- package/dist/entities/botInstance.d.ts +31 -0
- package/dist/entities/botInstance.d.ts.map +1 -0
- package/dist/entities/botInstance.js +107 -0
- package/dist/entities/cachedStateFactory.d.ts +7 -0
- package/dist/entities/cachedStateFactory.d.ts.map +1 -0
- package/dist/entities/cachedStateFactory.js +10 -0
- package/dist/entities/commandTriggerCheckResult.d.ts +10 -0
- package/dist/entities/commandTriggerCheckResult.d.ts.map +1 -0
- package/dist/entities/commandTriggerCheckResult.js +23 -0
- package/dist/entities/context/chatContext.d.ts +55 -0
- package/dist/entities/context/chatContext.d.ts.map +1 -0
- package/dist/entities/context/chatContext.js +70 -0
- package/dist/entities/context/messageContext.d.ts +60 -0
- package/dist/entities/context/messageContext.d.ts.map +1 -0
- package/dist/entities/context/messageContext.js +82 -0
- package/dist/entities/incomingMessage.d.ts +14 -0
- package/dist/entities/incomingMessage.d.ts.map +1 -0
- package/dist/entities/incomingMessage.js +45 -0
- package/dist/entities/responses/imageMessage.d.ts +17 -0
- package/dist/entities/responses/imageMessage.d.ts.map +1 -0
- package/dist/entities/responses/imageMessage.js +17 -0
- package/dist/entities/responses/reaction.d.ts +14 -0
- package/dist/entities/responses/reaction.d.ts.map +1 -0
- package/dist/entities/responses/reaction.js +15 -0
- package/dist/entities/responses/textMessage.d.ts +16 -0
- package/dist/entities/responses/textMessage.d.ts.map +1 -0
- package/dist/entities/responses/textMessage.js +17 -0
- package/dist/entities/responses/unpin.d.ts +12 -0
- package/dist/entities/responses/unpin.d.ts.map +1 -0
- package/dist/entities/responses/unpin.js +14 -0
- package/dist/entities/responses/videoMessage.d.ts +17 -0
- package/dist/entities/responses/videoMessage.d.ts.map +1 -0
- package/dist/entities/responses/videoMessage.js +17 -0
- package/dist/entities/states/actionStateBase.d.ts +6 -0
- package/dist/entities/states/actionStateBase.d.ts.map +1 -0
- package/dist/entities/states/actionStateBase.js +10 -0
- package/dist/entities/taskRecord.d.ts +8 -0
- package/dist/entities/taskRecord.d.ts.map +1 -0
- package/dist/entities/taskRecord.js +11 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts +69 -0
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/commandActionBuilder.js +96 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +60 -0
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -0
- package/dist/helpers/builders/scheduledActionBuilder.js +82 -0
- package/dist/helpers/inverseRecord.d.ts +2 -0
- package/dist/helpers/inverseRecord.d.ts.map +1 -0
- package/dist/helpers/inverseRecord.js +6 -0
- package/dist/helpers/noop.d.ts +6 -0
- package/dist/helpers/noop.d.ts.map +1 -0
- package/dist/helpers/noop.js +14 -0
- package/dist/helpers/reverseMap.d.ts +2 -0
- package/dist/helpers/reverseMap.d.ts.map +1 -0
- package/dist/helpers/reverseMap.js +6 -0
- package/dist/helpers/reverseRecord.d.ts +2 -0
- package/dist/helpers/reverseRecord.d.ts.map +1 -0
- package/dist/helpers/reverseRecord.js +6 -0
- package/dist/helpers/timeConvertions.d.ts +5 -0
- package/dist/helpers/timeConvertions.d.ts.map +1 -0
- package/dist/helpers/timeConvertions.js +14 -0
- package/dist/helpers/toArray.d.ts +2 -0
- package/dist/helpers/toArray.d.ts.map +1 -0
- package/dist/helpers/toArray.js +6 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/main.d.ts +35 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +43 -0
- package/dist/services/jsonFileStorage.d.ts +22 -0
- package/dist/services/jsonFileStorage.d.ts.map +1 -0
- package/dist/services/jsonFileStorage.js +102 -0
- package/dist/services/logger.d.ts +9 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +28 -0
- package/dist/services/taskScheduler.d.ts +11 -0
- package/dist/services/taskScheduler.d.ts.map +1 -0
- package/dist/services/taskScheduler.js +33 -0
- package/dist/services/telegramApi.d.ts +36 -0
- package/dist/services/telegramApi.d.ts.map +1 -0
- package/dist/services/telegramApi.js +100 -0
- package/dist/types/actionState.d.ts +5 -0
- package/dist/types/actionState.d.ts.map +1 -0
- package/dist/types/actionState.js +2 -0
- package/dist/types/actionWithState.d.ts +9 -0
- package/dist/types/actionWithState.d.ts.map +1 -0
- package/dist/types/actionWithState.js +2 -0
- package/dist/types/cachedValueAccessor.d.ts +2 -0
- package/dist/types/cachedValueAccessor.d.ts.map +1 -0
- package/dist/types/cachedValueAccessor.js +2 -0
- package/dist/types/commandCondition.d.ts +4 -0
- package/dist/types/commandCondition.d.ts.map +1 -0
- package/dist/types/commandCondition.js +2 -0
- package/dist/types/commandTrigger.d.ts +3 -0
- package/dist/types/commandTrigger.d.ts.map +1 -0
- package/dist/types/commandTrigger.js +2 -0
- package/dist/types/daysOfTheWeek.d.ts +10 -0
- package/dist/types/daysOfTheWeek.d.ts.map +1 -0
- package/dist/types/daysOfTheWeek.js +13 -0
- package/dist/types/handlers.d.ts +17 -0
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/handlers.js +2 -0
- package/dist/types/messageSendingOptions.d.ts +7 -0
- package/dist/types/messageSendingOptions.d.ts.map +1 -0
- package/dist/types/messageSendingOptions.js +2 -0
- package/dist/types/messageTypes.d.ts +16 -0
- package/dist/types/messageTypes.d.ts.map +1 -0
- package/dist/types/messageTypes.js +17 -0
- package/dist/types/replyMessage.d.ts +8 -0
- package/dist/types/replyMessage.d.ts.map +1 -0
- package/dist/types/replyMessage.js +2 -0
- package/dist/types/response.d.ts +28 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +10 -0
- package/dist/types/storage.d.ts +12 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +2 -0
- package/dist/types/timeValues.d.ts +11 -0
- package/dist/types/timeValues.d.ts.map +1 -0
- package/dist/types/timeValues.js +2 -0
- package/entities/actionExecutionResult.ts +3 -3
- package/entities/actions/commandAction.ts +7 -2
- package/entities/actions/scheduledAction.ts +7 -2
- package/entities/context/chatContext.ts +4 -3
- package/entities/context/messageContext.ts +1 -1
- 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 +29 -29
- package/services/jsonFileStorage.ts +22 -13
- package/types/actionWithState.ts +2 -2
- package/types/response.ts +2 -1
- package/types/storage.ts +9 -6
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChatContext } from '../entities/context/chatContext';
|
|
2
|
+
import { MessageContext } from '../entities/context/messageContext';
|
|
3
|
+
import { IStorageClient } from '../types/storage';
|
|
4
|
+
import { Reaction } from '../entities/responses/reaction';
|
|
5
|
+
import { IncomingMessage } from '../entities/incomingMessage';
|
|
6
|
+
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
|
+
import { Telegram } from 'telegraf/typings/telegram';
|
|
12
|
+
import { ScheduledAction } from '../entities/actions/scheduledAction';
|
|
13
|
+
import { IActionState } from '../types/actionState';
|
|
14
|
+
import { CommandAction } from '../entities/actions/commandAction';
|
|
15
|
+
export declare class TelegramApiService {
|
|
16
|
+
isFlushing: boolean;
|
|
17
|
+
messageQueue: BotResponse[];
|
|
18
|
+
botName: string;
|
|
19
|
+
telegram: Telegram;
|
|
20
|
+
chats: Record<number, string>;
|
|
21
|
+
storage: IStorageClient;
|
|
22
|
+
interactions: IBotApiInteractions;
|
|
23
|
+
constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Record<string, number>);
|
|
24
|
+
flushResponses(): Promise<void>;
|
|
25
|
+
private pinIfShould;
|
|
26
|
+
private processResponse;
|
|
27
|
+
private enqueue;
|
|
28
|
+
initializeContextForMessage<TActionState extends IActionState>(ctx: MessageContext<TActionState>, incomingMessage: IncomingMessage, command: CommandAction<TActionState>): MessageContext<TActionState>;
|
|
29
|
+
initializeContextForChat<TActionState extends IActionState>(ctx: ChatContext<TActionState>, chatId: number, scheduledAction: ScheduledAction<TActionState>): ChatContext<TActionState>;
|
|
30
|
+
}
|
|
31
|
+
export interface IBotApiInteractions {
|
|
32
|
+
respond: (response: TextMessage | VideoMessage | ImageMessage) => void;
|
|
33
|
+
react: (reaction: Reaction) => void;
|
|
34
|
+
unpin: (unpinMessage: UnpinResponse) => void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=telegramApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;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;IACxB,YAAY,EAAE,mBAAmB,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAc3B,cAAc;YA2BN,WAAW;YAqBX,eAAe;IA2E7B,OAAO,CAAC,OAAO;IAIf,2BAA2B,CAAC,YAAY,SAAS,YAAY,EACzD,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,EACjC,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC;IAWxC,wBAAwB,CAAC,YAAY,SAAS,YAAY,EACtD,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,eAAe,CAAC,YAAY,CAAC;CAYrD;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,KAAK,IAAI,CAAC;IACvE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramApiService = void 0;
|
|
4
|
+
const inverseRecord_1 = require("../helpers/inverseRecord");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const promises_1 = require("timers/promises");
|
|
7
|
+
const TELEGRAM_RATELIMIT_DELAY = 35;
|
|
8
|
+
class TelegramApiService {
|
|
9
|
+
constructor(botName, telegram, storage, chats) {
|
|
10
|
+
this.isFlushing = false;
|
|
11
|
+
this.messageQueue = [];
|
|
12
|
+
this.telegram = telegram;
|
|
13
|
+
this.botName = botName;
|
|
14
|
+
this.chats = (0, inverseRecord_1.inverseRecord)(chats);
|
|
15
|
+
this.storage = storage;
|
|
16
|
+
this.interactions = {
|
|
17
|
+
react: (reaction) => this.enqueue(reaction),
|
|
18
|
+
respond: (response) => this.enqueue(response),
|
|
19
|
+
unpin: (unpinMessage) => this.enqueue(unpinMessage)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async flushResponses() {
|
|
23
|
+
if (this.isFlushing)
|
|
24
|
+
return;
|
|
25
|
+
this.isFlushing = true;
|
|
26
|
+
while (this.messageQueue.length) {
|
|
27
|
+
const message = this.messageQueue.pop();
|
|
28
|
+
if (!message)
|
|
29
|
+
break;
|
|
30
|
+
try {
|
|
31
|
+
await this.processResponse(message);
|
|
32
|
+
await (0, promises_1.setTimeout)(TELEGRAM_RATELIMIT_DELAY);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats[message.chatId], error, message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this.isFlushing = false;
|
|
39
|
+
}
|
|
40
|
+
async pinIfShould(response, sentMessage) {
|
|
41
|
+
if (response.shouldPin) {
|
|
42
|
+
await this.telegram.pinChatMessage(response.chatId, sentMessage.message_id, { disable_notification: true });
|
|
43
|
+
await this.storage.updateStateFor(response.action, response.chatId, async (state) => {
|
|
44
|
+
state.pinnedMessages.push(sentMessage.message_id);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async processResponse(response) {
|
|
49
|
+
let sentMessage;
|
|
50
|
+
switch (response.kind) {
|
|
51
|
+
case 'text':
|
|
52
|
+
sentMessage = await this.telegram.sendMessage(response.chatId, response.content, {
|
|
53
|
+
reply_to_message_id: response.replyId,
|
|
54
|
+
parse_mode: 'MarkdownV2',
|
|
55
|
+
disable_web_page_preview: response.disableWebPreview
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
});
|
|
58
|
+
await this.pinIfShould(response, sentMessage);
|
|
59
|
+
break;
|
|
60
|
+
case 'image':
|
|
61
|
+
sentMessage = await this.telegram.sendPhoto(response.chatId, response.content, response.replyId
|
|
62
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
{ reply_to_message_id: response.replyId }
|
|
64
|
+
: undefined);
|
|
65
|
+
await this.pinIfShould(response, sentMessage);
|
|
66
|
+
break;
|
|
67
|
+
case 'video':
|
|
68
|
+
sentMessage = await this.telegram.sendVideo(response.chatId, response.content, response.replyId
|
|
69
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
{ reply_to_message_id: response.replyId }
|
|
71
|
+
: undefined);
|
|
72
|
+
await this.pinIfShould(response, sentMessage);
|
|
73
|
+
break;
|
|
74
|
+
case 'react':
|
|
75
|
+
await this.telegram.setMessageReaction(response.chatId, response.messageId, [
|
|
76
|
+
{
|
|
77
|
+
type: 'emoji',
|
|
78
|
+
emoji: response.emoji
|
|
79
|
+
}
|
|
80
|
+
], true);
|
|
81
|
+
return;
|
|
82
|
+
case 'unpin':
|
|
83
|
+
await this.telegram.unpinChatMessage(response.chatId, response.messageId);
|
|
84
|
+
await this.storage.updateStateFor(response.action, response.chatId, async (state) => {
|
|
85
|
+
state.pinnedMessages = state.pinnedMessages.filter((x) => x != response.messageId);
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
enqueue(response) {
|
|
91
|
+
this.messageQueue.push(response);
|
|
92
|
+
}
|
|
93
|
+
initializeContextForMessage(ctx, incomingMessage, command) {
|
|
94
|
+
return ctx.initializeMessageContext(this.botName, command, this.interactions, incomingMessage, this.storage);
|
|
95
|
+
}
|
|
96
|
+
initializeContextForChat(ctx, chatId, scheduledAction) {
|
|
97
|
+
return ctx.initializeChatContext(this.botName, scheduledAction, this.interactions, chatId, this.chats[chatId], `Scheduled:${scheduledAction.key}:${chatId}`, this.storage);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.TelegramApiService = TelegramApiService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionState.d.ts","sourceRoot":"","sources":["../../types/actionState.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IActionState } from './actionState';
|
|
2
|
+
export type ActionKey = string & {
|
|
3
|
+
__brand: 'actionKey';
|
|
4
|
+
};
|
|
5
|
+
export interface IActionWithState<TActionState extends IActionState> {
|
|
6
|
+
key: ActionKey;
|
|
7
|
+
stateConstructor: () => TActionState;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=actionWithState.d.ts.map
|
|
@@ -0,0 +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,CAAC,YAAY,SAAS,YAAY;IAC/D,GAAG,EAAE,SAAS,CAAC;IACf,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cachedValueAccessor.d.ts","sourceRoot":"","sources":["../../types/cachedValueAccessor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MessageContext } from '../entities/context/messageContext';
|
|
2
|
+
import { IActionState } from './actionState';
|
|
3
|
+
export type CommandCondition<TActionState extends IActionState> = (ctx: MessageContext<TActionState>) => Promise<boolean>;
|
|
4
|
+
//# sourceMappingURL=commandCondition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandCondition.d.ts","sourceRoot":"","sources":["../../types/commandCondition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI,CAC9D,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC,KAChC,OAAO,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daysOfTheWeek.d.ts","sourceRoot":"","sources":["../../types/daysOfTheWeek.ts"],"names":[],"mappings":"AAAA,oBAAY,GAAG;IACX,MAAM,IAAI;IACV,MAAM,IAAI;IACV,OAAO,IAAI;IACX,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,QAAQ,IAAI;CACf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Day = void 0;
|
|
4
|
+
var Day;
|
|
5
|
+
(function (Day) {
|
|
6
|
+
Day[Day["Sunday"] = 0] = "Sunday";
|
|
7
|
+
Day[Day["Monday"] = 1] = "Monday";
|
|
8
|
+
Day[Day["Tuesday"] = 2] = "Tuesday";
|
|
9
|
+
Day[Day["Wednesday"] = 3] = "Wednesday";
|
|
10
|
+
Day[Day["Thursday"] = 4] = "Thursday";
|
|
11
|
+
Day[Day["Friday"] = 5] = "Friday";
|
|
12
|
+
Day[Day["Saturday"] = 6] = "Saturday";
|
|
13
|
+
})(Day || (exports.Day = Day = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChatContext } from '../entities/context/chatContext';
|
|
2
|
+
import { MessageContext } from '../entities/context/messageContext';
|
|
3
|
+
import { IActionState } from './actionState';
|
|
4
|
+
import { CachedValueAccessor } from './cachedValueAccessor';
|
|
5
|
+
export type CommandHandler<TActionState extends IActionState> = (
|
|
6
|
+
/** Context of action executed in chat, in response to a message. */
|
|
7
|
+
ctx: MessageContext<TActionState>,
|
|
8
|
+
/** State of an action being executed. */
|
|
9
|
+
state: TActionState) => Promise<void>;
|
|
10
|
+
export type ScheduledHandler<TActionState extends IActionState> = (
|
|
11
|
+
/** Context of action executed in chat. */
|
|
12
|
+
ctx: ChatContext<TActionState>,
|
|
13
|
+
/** Function that will attempt to get value from cache. If there is no value found, corresponding cached state factory will be called. */
|
|
14
|
+
getCached: CachedValueAccessor,
|
|
15
|
+
/** State of an action being executed. */
|
|
16
|
+
state: TActionState) => Promise<void>;
|
|
17
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../types/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,YAAY,IAAI;AAC5D,oEAAoE;AACpE,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;AACjC,yCAAyC;AACzC,KAAK,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,gBAAgB,CAAC,YAAY,SAAS,YAAY,IAAI;AAC9D,0CAA0C;AAC1C,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC;AAC9B,yIAAyI;AACzI,SAAS,EAAE,mBAAmB;AAC9B,yCAAyC;AACzC,KAAK,EAAE,YAAY,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageSendingOptions.d.ts","sourceRoot":"","sources":["../../types/messageSendingOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IAClC,GAAG,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,yBAA0B,SAAQ,qBAAqB;IACpE,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const MessageType: {
|
|
2
|
+
readonly Text: "__msg:Text";
|
|
3
|
+
readonly Sticker: "__msg:Sticker";
|
|
4
|
+
readonly Animation: "__msg:Animation";
|
|
5
|
+
readonly Document: "__msg:Document";
|
|
6
|
+
readonly Voice: "__msg:Voice";
|
|
7
|
+
readonly Audio: "__msg:Audio";
|
|
8
|
+
readonly LeftChatMember: "__msg:LeftChatMember";
|
|
9
|
+
readonly NewChatMember: "__msg:NewChatMember";
|
|
10
|
+
readonly Poll: "__msg:Poll";
|
|
11
|
+
readonly Location: "__msg:Location";
|
|
12
|
+
readonly Photo: "__msg:Photo";
|
|
13
|
+
readonly Unknown: "__msg:Unknown";
|
|
14
|
+
};
|
|
15
|
+
export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
|
|
16
|
+
//# sourceMappingURL=messageTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../types/messageTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAad,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageType = void 0;
|
|
4
|
+
exports.MessageType = {
|
|
5
|
+
Text: '__msg:Text',
|
|
6
|
+
Sticker: '__msg:Sticker',
|
|
7
|
+
Animation: '__msg:Animation',
|
|
8
|
+
Document: '__msg:Document',
|
|
9
|
+
Voice: '__msg:Voice',
|
|
10
|
+
Audio: '__msg:Audio',
|
|
11
|
+
LeftChatMember: '__msg:LeftChatMember',
|
|
12
|
+
NewChatMember: '__msg:NewChatMember',
|
|
13
|
+
Poll: '__msg:Poll',
|
|
14
|
+
Location: '__msg:Location',
|
|
15
|
+
Photo: '__msg:Photo',
|
|
16
|
+
Unknown: '__msg:Unknown'
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replyMessage.d.ts","sourceRoot":"","sources":["../../types/replyMessage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,KAAK;IAChC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC9B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ImageMessage } from '../entities/responses/imageMessage';
|
|
2
|
+
import { Reaction } from '../entities/responses/reaction';
|
|
3
|
+
import { TextMessage } from '../entities/responses/textMessage';
|
|
4
|
+
import { UnpinResponse } from '../entities/responses/unpin';
|
|
5
|
+
import { VideoMessage } from '../entities/responses/videoMessage';
|
|
6
|
+
import { IActionState } from './actionState';
|
|
7
|
+
import { IActionWithState } from './actionWithState';
|
|
8
|
+
export declare const BotResponseTypes: {
|
|
9
|
+
readonly unpin: "unpin";
|
|
10
|
+
readonly text: "text";
|
|
11
|
+
readonly image: "image";
|
|
12
|
+
readonly video: "video";
|
|
13
|
+
readonly react: "react";
|
|
14
|
+
};
|
|
15
|
+
export type BotResponse = UnpinResponse | Reaction | TextMessage | VideoMessage | ImageMessage;
|
|
16
|
+
export interface IChatResponse {
|
|
17
|
+
kind: keyof typeof BotResponseTypes;
|
|
18
|
+
chatId: number;
|
|
19
|
+
traceId: number | string;
|
|
20
|
+
action: IActionWithState<IActionState>;
|
|
21
|
+
}
|
|
22
|
+
export interface IReplyMessage<TType> extends IChatResponse {
|
|
23
|
+
content: TType;
|
|
24
|
+
replyId: number | undefined;
|
|
25
|
+
disableWebPreview: boolean;
|
|
26
|
+
shouldPin: boolean;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +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,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX,MAAM,MAAM,WAAW,GACjB,aAAa,GACb,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
2
|
+
import { IActionState } from './actionState';
|
|
3
|
+
import { ActionKey, IActionWithState } from './actionWithState';
|
|
4
|
+
export interface IStorageClient {
|
|
5
|
+
updateStateFor<TActionState extends IActionState>(action: IActionWithState<TActionState>, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
6
|
+
close(): Promise<void>;
|
|
7
|
+
load<TActionState extends IActionState>(key: ActionKey): Promise<Record<number, TActionState>>;
|
|
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
|
+
}
|
|
12
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Milliseconds = number & {
|
|
2
|
+
__brand: 'ms';
|
|
3
|
+
};
|
|
4
|
+
export type Seconds = number & {
|
|
5
|
+
__brand: 's';
|
|
6
|
+
};
|
|
7
|
+
export type Hours = number & {
|
|
8
|
+
__brand: 'h';
|
|
9
|
+
};
|
|
10
|
+
export type HoursOfDay = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23;
|
|
11
|
+
//# sourceMappingURL=timeValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeValues.d.ts","sourceRoot":"","sources":["../../types/timeValues.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAChD,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,UAAU,GAChB,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,CAAC,GACD,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,GACF,EAAE,CAAC"}
|
|
@@ -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,7 +51,10 @@ 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
59
|
if (!this.active || this.chatsBlacklist.includes(ctx.chatId)) return;
|
|
57
60
|
|
|
@@ -98,6 +101,8 @@ 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;
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
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,7 +47,10 @@ 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
55
|
if (!this.active || !this.chatsWhitelist.includes(ctx.chatId)) return;
|
|
53
56
|
|
|
@@ -81,6 +84,8 @@ export class ScheduledAction<TActionState extends IActionState>
|
|
|
81
84
|
new ActionExecutionResult(state, isAllowedToTrigger)
|
|
82
85
|
);
|
|
83
86
|
}
|
|
87
|
+
|
|
88
|
+
ctx.isInitialized = false;
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
private async getCachedValue<TResult>(
|
|
@@ -10,12 +10,13 @@ import {
|
|
|
10
10
|
TextMessageSendingOptions
|
|
11
11
|
} from '../../types/messageSendingOptions';
|
|
12
12
|
import { IActionWithState } from '../../types/actionWithState';
|
|
13
|
+
import { IActionState } from '../../types/actionState';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Context of action executed in chat.
|
|
16
17
|
*/
|
|
17
|
-
export class ChatContext<TActionState> {
|
|
18
|
-
protected action!: IActionWithState
|
|
18
|
+
export class ChatContext<TActionState extends IActionState> {
|
|
19
|
+
protected action!: IActionWithState<TActionState>;
|
|
19
20
|
protected interactions!: IBotApiInteractions;
|
|
20
21
|
updateActions: Array<(state: TActionState) => void> = [];
|
|
21
22
|
/** Trace id of a action execution. */
|
|
@@ -35,7 +36,7 @@ export class ChatContext<TActionState> {
|
|
|
35
36
|
|
|
36
37
|
initializeChatContext(
|
|
37
38
|
botName: string,
|
|
38
|
-
action: IActionWithState
|
|
39
|
+
action: IActionWithState<TActionState>,
|
|
39
40
|
interactions: IBotApiInteractions,
|
|
40
41
|
chatId: number,
|
|
41
42
|
chatName: string,
|
|
@@ -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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
2
|
import { BotResponseTypes, IReplyMessage } from '../../types/response';
|
|
3
3
|
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
+
import { IActionState } from '../../types/actionState';
|
|
4
5
|
|
|
5
6
|
export class TextMessage implements IReplyMessage<string> {
|
|
6
7
|
kind = BotResponseTypes.text;
|
|
@@ -11,14 +12,14 @@ export class TextMessage implements IReplyMessage<string> {
|
|
|
11
12
|
traceId: string | number;
|
|
12
13
|
disableWebPreview: boolean;
|
|
13
14
|
shouldPin: boolean;
|
|
14
|
-
action: IActionWithState
|
|
15
|
+
action: IActionWithState<IActionState>;
|
|
15
16
|
|
|
16
17
|
constructor(
|
|
17
18
|
text: string,
|
|
18
19
|
chatId: number,
|
|
19
20
|
replyId: number | undefined,
|
|
20
21
|
traceId: string | number,
|
|
21
|
-
action: IActionWithState
|
|
22
|
+
action: IActionWithState<IActionState>,
|
|
22
23
|
options?: TextMessageSendingOptions
|
|
23
24
|
) {
|
|
24
25
|
this.content = text;
|