chz-telegram-bot 0.0.16 → 0.0.18
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/botInstance.js +3 -3
- package/dist/entities/context/chatContext.d.ts +6 -4
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +12 -7
- package/dist/entities/context/messageContext.d.ts +4 -4
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +9 -9
- package/dist/entities/responses/imageMessage.d.ts +5 -2
- package/dist/entities/responses/imageMessage.d.ts.map +1 -1
- package/dist/entities/responses/imageMessage.js +5 -1
- package/dist/entities/responses/reaction.d.ts +5 -2
- package/dist/entities/responses/reaction.d.ts.map +1 -1
- package/dist/entities/responses/reaction.js +4 -1
- package/dist/entities/responses/textMessage.d.ts +5 -2
- package/dist/entities/responses/textMessage.d.ts.map +1 -1
- package/dist/entities/responses/textMessage.js +5 -1
- package/dist/entities/responses/unpin.d.ts +10 -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 +5 -2
- package/dist/entities/responses/videoMessage.d.ts.map +1 -1
- package/dist/entities/responses/videoMessage.js +5 -1
- package/dist/entities/states/actionStateBase.d.ts +1 -0
- package/dist/entities/states/actionStateBase.d.ts.map +1 -1
- package/dist/entities/states/actionStateBase.js +1 -0
- package/dist/services/jsonFileStorage.d.ts +1 -0
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +8 -0
- package/dist/services/logger.d.ts +1 -1
- package/dist/services/logger.d.ts.map +1 -1
- package/dist/services/telegramApi.d.ts +15 -10
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +43 -33
- package/dist/types/actionState.d.ts +1 -0
- package/dist/types/actionState.d.ts.map +1 -1
- package/dist/types/response.d.ts +26 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +10 -0
- package/dist/types/storage.d.ts +1 -0
- package/dist/types/storage.d.ts.map +1 -1
- package/entities/botInstance.ts +3 -3
- package/entities/context/chatContext.ts +31 -6
- package/entities/context/messageContext.ts +29 -8
- package/entities/responses/imageMessage.ts +10 -2
- package/entities/responses/reaction.ts +8 -2
- package/entities/responses/textMessage.ts +10 -2
- package/entities/responses/unpin.ts +22 -0
- package/entities/responses/videoMessage.ts +10 -2
- package/entities/states/actionStateBase.ts +1 -0
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +15 -0
- package/services/logger.ts +1 -1
- package/services/telegramApi.ts +86 -49
- package/types/actionState.ts +1 -0
- package/types/response.ts +34 -0
- package/types/storage.ts +5 -0
- package/types/replyMessage.ts +0 -7
|
@@ -20,7 +20,7 @@ class BotInstance {
|
|
|
20
20
|
this.storage =
|
|
21
21
|
options.storageClient ??
|
|
22
22
|
new jsonFileStorage_1.JsonFileStorage(options.name, options.storagePath);
|
|
23
|
-
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf, this.storage, this.chats);
|
|
23
|
+
this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
|
|
24
24
|
this.telegraf.on('message', async (ctx) => {
|
|
25
25
|
const msg = new incomingMessage_1.IncomingMessage(ctx.update.message);
|
|
26
26
|
const messageContent = msg.text || '<non-text message>';
|
|
@@ -50,7 +50,7 @@ class BotInstance {
|
|
|
50
50
|
async runScheduled() {
|
|
51
51
|
for (const [chatName, chatId] of this.chats.entries()) {
|
|
52
52
|
for (const trig of this.scheduled) {
|
|
53
|
-
const ctx = this.api.createContextForChat(chatId, trig.
|
|
53
|
+
const ctx = this.api.createContextForChat(chatId, trig.key);
|
|
54
54
|
try {
|
|
55
55
|
await trig.exec(ctx);
|
|
56
56
|
}
|
|
@@ -64,7 +64,7 @@ class BotInstance {
|
|
|
64
64
|
async processMessages() {
|
|
65
65
|
const msg = this.messageQueue.pop();
|
|
66
66
|
for (const cmd of this.commands) {
|
|
67
|
-
const ctx = this.api.createContextForMessage(msg);
|
|
67
|
+
const ctx = this.api.createContextForMessage(msg, cmd.key);
|
|
68
68
|
try {
|
|
69
69
|
await cmd.exec(ctx);
|
|
70
70
|
}
|
|
@@ -2,14 +2,16 @@ import { IBotApiInteractions } from '../../services/telegramApi';
|
|
|
2
2
|
import { IStorageClient } from '../../types/storage';
|
|
3
3
|
export declare class ChatContext {
|
|
4
4
|
botName: string;
|
|
5
|
+
actionKey: string;
|
|
5
6
|
interactions: IBotApiInteractions;
|
|
6
7
|
chatId: number;
|
|
7
8
|
chatName: string;
|
|
8
9
|
traceId: number | string;
|
|
9
10
|
storage: IStorageClient;
|
|
10
|
-
constructor(botName: string, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient);
|
|
11
|
-
sendTextToChat(text: string, disableWebPreview?: boolean): void;
|
|
12
|
-
sendImageToChat(name: string): void;
|
|
13
|
-
sendVideoToChat(name: string): void;
|
|
11
|
+
constructor(botName: string, actionKey: string, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient);
|
|
12
|
+
sendTextToChat(text: string, disableWebPreview?: boolean, pinned?: boolean): void;
|
|
13
|
+
sendImageToChat(name: string, pinned?: boolean): void;
|
|
14
|
+
sendVideoToChat(name: string, pinned?: boolean): void;
|
|
15
|
+
unpinMessage(messageId: number): void;
|
|
14
16
|
}
|
|
15
17
|
//# sourceMappingURL=chatContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrD,qBAAa,WAAW;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,mBAAmB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,EAAE,cAAc;IAW3B,cAAc,CACV,IAAI,EAAE,MAAM,EACZ,iBAAiB,CAAC,EAAE,OAAO,EAC3B,MAAM,CAAC,EAAE,OAAO;IAepB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAc9C,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAc9C,YAAY,CAAC,SAAS,EAAE,MAAM;CAUjC"}
|
|
@@ -5,25 +5,30 @@ const path_1 = require("path");
|
|
|
5
5
|
const imageMessage_1 = require("../responses/imageMessage");
|
|
6
6
|
const textMessage_1 = require("../responses/textMessage");
|
|
7
7
|
const videoMessage_1 = require("../responses/videoMessage");
|
|
8
|
+
const unpin_1 = require("../responses/unpin");
|
|
8
9
|
class ChatContext {
|
|
9
|
-
constructor(botName, interactions, chatId, chatName, traceId, storage) {
|
|
10
|
+
constructor(botName, actionKey, interactions, chatId, chatName, traceId, storage) {
|
|
10
11
|
this.botName = botName;
|
|
12
|
+
this.actionKey = actionKey;
|
|
11
13
|
this.interactions = interactions;
|
|
12
14
|
this.chatId = chatId;
|
|
13
15
|
this.chatName = chatName;
|
|
14
16
|
this.traceId = traceId;
|
|
15
17
|
this.storage = storage;
|
|
16
18
|
}
|
|
17
|
-
sendTextToChat(text, disableWebPreview) {
|
|
18
|
-
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, disableWebPreview ?? false));
|
|
19
|
+
sendTextToChat(text, disableWebPreview, pinned) {
|
|
20
|
+
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, disableWebPreview ?? false, pinned ?? false, this.actionKey));
|
|
19
21
|
}
|
|
20
|
-
sendImageToChat(name) {
|
|
22
|
+
sendImageToChat(name, pinned) {
|
|
21
23
|
const filePath = `./content/${name}.png`;
|
|
22
|
-
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId));
|
|
24
|
+
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, pinned ?? false, this.actionKey));
|
|
23
25
|
}
|
|
24
|
-
sendVideoToChat(name) {
|
|
26
|
+
sendVideoToChat(name, pinned) {
|
|
25
27
|
const filePath = `./content/${name}.mp4`;
|
|
26
|
-
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId));
|
|
28
|
+
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, pinned ?? false, this.actionKey));
|
|
29
|
+
}
|
|
30
|
+
unpinMessage(messageId) {
|
|
31
|
+
this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.actionKey));
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
exports.ChatContext = ChatContext;
|
|
@@ -11,12 +11,12 @@ export declare class MessageContext<TActionState extends IActionState> extends C
|
|
|
11
11
|
startCooldown: boolean;
|
|
12
12
|
updateActions: Array<(state: TActionState) => void>;
|
|
13
13
|
fromUserName: string;
|
|
14
|
-
constructor(botName: string, interactions: IBotApiInteractions, chatId: number, chatName: string, messageId: number, messageText: string, fromUserId: number | undefined, traceId: number | string, fromUserName: string, storage: IStorageClient);
|
|
14
|
+
constructor(botName: string, scheduledKey: string, interactions: IBotApiInteractions, chatId: number, chatName: string, messageId: number, messageText: string, fromUserId: number | undefined, traceId: number | string, fromUserName: string, storage: IStorageClient);
|
|
15
15
|
loadStateOf<TAnotherActionState extends IActionState>(commandName: string): Promise<TAnotherActionState>;
|
|
16
16
|
updateState(stateUpdateAction: (state: TActionState) => void): void;
|
|
17
|
-
replyWithText(text: string, disableWebPreview?: boolean): void;
|
|
18
|
-
replyWithImage(name: string): void;
|
|
19
|
-
replyWithVideo(name: string): void;
|
|
17
|
+
replyWithText(text: string, disableWebPreview?: boolean, pinned?: boolean): void;
|
|
18
|
+
replyWithImage(name: string, pinned?: boolean): void;
|
|
19
|
+
replyWithVideo(name: string, pinned?: boolean): void;
|
|
20
20
|
react(emoji: TelegramEmoji): void;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=messageContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAQ;IAC9B,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,YAAY,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,cAAc;
|
|
1
|
+
{"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAQ;IAC9B,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,YAAY,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,cAAc;IAkBrB,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAU/B,WAAW,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;IAM5D,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO;IAczE,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAc7C,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAc7C,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
|
|
@@ -9,8 +9,8 @@ const videoMessage_1 = require("../responses/videoMessage");
|
|
|
9
9
|
const actionStateBase_1 = require("../states/actionStateBase");
|
|
10
10
|
const chatContext_1 = require("./chatContext");
|
|
11
11
|
class MessageContext extends chatContext_1.ChatContext {
|
|
12
|
-
constructor(botName, interactions, chatId, chatName, messageId, messageText, fromUserId, traceId, fromUserName, storage) {
|
|
13
|
-
super(botName, interactions, chatId, chatName, traceId, storage);
|
|
12
|
+
constructor(botName, scheduledKey, interactions, chatId, chatName, messageId, messageText, fromUserId, traceId, fromUserName, storage) {
|
|
13
|
+
super(botName, scheduledKey, interactions, chatId, chatName, traceId, storage);
|
|
14
14
|
this.matchResults = [];
|
|
15
15
|
this.startCooldown = true;
|
|
16
16
|
this.updateActions = [];
|
|
@@ -25,19 +25,19 @@ class MessageContext extends chatContext_1.ChatContext {
|
|
|
25
25
|
updateState(stateUpdateAction) {
|
|
26
26
|
this.updateActions.push(stateUpdateAction);
|
|
27
27
|
}
|
|
28
|
-
replyWithText(text, disableWebPreview) {
|
|
29
|
-
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, disableWebPreview ?? false));
|
|
28
|
+
replyWithText(text, disableWebPreview, pinned) {
|
|
29
|
+
this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, disableWebPreview ?? false, pinned ?? false, this.actionKey));
|
|
30
30
|
}
|
|
31
|
-
replyWithImage(name) {
|
|
31
|
+
replyWithImage(name, pinned) {
|
|
32
32
|
const filePath = `./content/${name}.png`;
|
|
33
|
-
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId));
|
|
33
|
+
this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, pinned ?? false, this.actionKey));
|
|
34
34
|
}
|
|
35
|
-
replyWithVideo(name) {
|
|
35
|
+
replyWithVideo(name, pinned) {
|
|
36
36
|
const filePath = `./content/${name}.mp4`;
|
|
37
|
-
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId));
|
|
37
|
+
this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, pinned ?? false, this.actionKey));
|
|
38
38
|
}
|
|
39
39
|
react(emoji) {
|
|
40
|
-
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji));
|
|
40
|
+
this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.actionKey));
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.MessageContext = MessageContext;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { InputFile } from 'telegraf/types';
|
|
2
|
-
import { IReplyMessage } from '../../types/
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
3
|
export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
4
|
+
kind: "image";
|
|
4
5
|
content: InputFile;
|
|
5
6
|
chatId: number;
|
|
6
7
|
replyId: number | undefined;
|
|
7
8
|
traceId: string | number;
|
|
8
9
|
disableWebPreview: boolean;
|
|
9
|
-
|
|
10
|
+
shouldPin: boolean;
|
|
11
|
+
sourceActionKey: string;
|
|
12
|
+
constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, pinned: boolean, sourceActionKey: string);
|
|
10
13
|
}
|
|
11
14
|
//# sourceMappingURL=imageMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/imageMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"imageMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/imageMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,IAAI,UAA0B;IAE9B,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,UAAS;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;gBAGpB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,MAAM;CAS9B"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImageMessage = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
4
5
|
class ImageMessage {
|
|
5
|
-
constructor(image, chatId, replyId, traceId) {
|
|
6
|
+
constructor(image, chatId, replyId, traceId, pinned, sourceActionKey) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.image;
|
|
6
8
|
this.disableWebPreview = false;
|
|
7
9
|
this.content = image;
|
|
8
10
|
this.chatId = chatId;
|
|
9
11
|
this.replyId = replyId;
|
|
10
12
|
this.traceId = traceId;
|
|
13
|
+
this.shouldPin = pinned;
|
|
14
|
+
this.sourceActionKey = sourceActionKey;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
exports.ImageMessage = ImageMessage;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
-
|
|
2
|
+
import { IChatResponse } from '../../types/response';
|
|
3
|
+
export declare class Reaction implements IChatResponse {
|
|
4
|
+
kind: "react";
|
|
3
5
|
chatId: number;
|
|
4
6
|
messageId: number;
|
|
5
7
|
traceId: number | string;
|
|
6
8
|
emoji: TelegramEmoji;
|
|
7
|
-
|
|
9
|
+
sourceActionKey: string;
|
|
10
|
+
constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji, sourceActionKey: string);
|
|
8
11
|
}
|
|
9
12
|
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../entities/responses/reaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"reaction.d.ts","sourceRoot":"","sources":["../../../entities/responses/reaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,QAAS,YAAW,aAAa;IAC1C,IAAI,UAA0B;IAE9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,EAAE,aAAa,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;gBAGpB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,aAAa,EACpB,eAAe,EAAE,MAAM;CAQ9B"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Reaction = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
4
5
|
class Reaction {
|
|
5
|
-
constructor(traceId, chatId, messageId, emoji) {
|
|
6
|
+
constructor(traceId, chatId, messageId, emoji, sourceActionKey) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.react;
|
|
6
8
|
this.chatId = chatId;
|
|
7
9
|
this.messageId = messageId;
|
|
8
10
|
this.emoji = emoji;
|
|
9
11
|
this.traceId = traceId;
|
|
12
|
+
this.sourceActionKey = sourceActionKey;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
exports.Reaction = Reaction;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { IReplyMessage } from '../../types/
|
|
1
|
+
import { IReplyMessage } from '../../types/response';
|
|
2
2
|
export declare class TextMessage implements IReplyMessage<string> {
|
|
3
|
+
kind: "text";
|
|
3
4
|
content: string;
|
|
4
5
|
chatId: number;
|
|
5
6
|
replyId: number | undefined;
|
|
6
7
|
traceId: string | number;
|
|
7
8
|
disableWebPreview: boolean;
|
|
8
|
-
|
|
9
|
+
shouldPin: boolean;
|
|
10
|
+
sourceActionKey: string;
|
|
11
|
+
constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number, disableWebPreview: boolean, pinned: boolean, sourceActionKey: string);
|
|
9
12
|
}
|
|
10
13
|
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/textMessage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/textMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,WAAY,YAAW,aAAa,CAAC,MAAM,CAAC;IACrD,IAAI,SAAyB;IAE7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;gBAGpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,iBAAiB,EAAE,OAAO,EAC1B,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,MAAM;CAU9B"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TextMessage = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
4
5
|
class TextMessage {
|
|
5
|
-
constructor(text, chatId, replyId, traceId, disableWebPreview) {
|
|
6
|
+
constructor(text, chatId, replyId, traceId, disableWebPreview, pinned, sourceActionKey) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.text;
|
|
6
8
|
this.content = text;
|
|
7
9
|
this.chatId = chatId;
|
|
8
10
|
this.replyId = replyId;
|
|
9
11
|
this.traceId = traceId;
|
|
10
12
|
this.disableWebPreview = disableWebPreview;
|
|
13
|
+
this.shouldPin = pinned;
|
|
14
|
+
this.sourceActionKey = sourceActionKey;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
exports.TextMessage = TextMessage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IChatResponse } from '../../types/response';
|
|
2
|
+
export declare class UnpinResponse implements IChatResponse {
|
|
3
|
+
kind: "unpin";
|
|
4
|
+
messageId: number;
|
|
5
|
+
chatId: number;
|
|
6
|
+
traceId: number | string;
|
|
7
|
+
sourceActionKey: string;
|
|
8
|
+
constructor(messageId: number, chatId: number, traceId: number | string, sourceActionKey: string);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=unpin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpin.d.ts","sourceRoot":"","sources":["../../../entities/responses/unpin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,aAAc,YAAW,aAAa;IAC/C,IAAI,UAA0B;IAE9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;gBAGpB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,eAAe,EAAE,MAAM;CAO9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnpinResponse = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
5
|
+
class UnpinResponse {
|
|
6
|
+
constructor(messageId, chatId, traceId, sourceActionKey) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.unpin;
|
|
8
|
+
this.messageId = messageId;
|
|
9
|
+
this.chatId = chatId;
|
|
10
|
+
this.traceId = traceId;
|
|
11
|
+
this.sourceActionKey = sourceActionKey;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.UnpinResponse = UnpinResponse;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { InputFile } from 'telegraf/types';
|
|
2
|
-
import { IReplyMessage } from '../../types/
|
|
2
|
+
import { IReplyMessage } from '../../types/response';
|
|
3
3
|
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
4
|
+
kind: "video";
|
|
4
5
|
content: InputFile;
|
|
5
6
|
chatId: number;
|
|
6
7
|
replyId: number | undefined;
|
|
7
8
|
traceId: string | number;
|
|
8
9
|
disableWebPreview: boolean;
|
|
9
|
-
|
|
10
|
+
shouldPin: boolean;
|
|
11
|
+
sourceActionKey: string;
|
|
12
|
+
constructor(video: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, pinned: boolean, sourceActionKey: string);
|
|
10
13
|
}
|
|
11
14
|
//# sourceMappingURL=videoMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"videoMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/videoMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"videoMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/videoMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,IAAI,UAA0B;IAE9B,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,iBAAiB,UAAS;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;gBAGpB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,MAAM;CAS9B"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VideoMessage = void 0;
|
|
4
|
+
const response_1 = require("../../types/response");
|
|
4
5
|
class VideoMessage {
|
|
5
|
-
constructor(video, chatId, replyId, traceId) {
|
|
6
|
+
constructor(video, chatId, replyId, traceId, pinned, sourceActionKey) {
|
|
7
|
+
this.kind = response_1.BotResponseTypes.video;
|
|
6
8
|
this.disableWebPreview = false;
|
|
7
9
|
this.content = video;
|
|
8
10
|
this.chatId = chatId;
|
|
9
11
|
this.replyId = replyId;
|
|
10
12
|
this.traceId = traceId;
|
|
13
|
+
this.shouldPin = pinned;
|
|
14
|
+
this.sourceActionKey = sourceActionKey;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
exports.VideoMessage = VideoMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionStateBase.d.ts","sourceRoot":"","sources":["../../../entities/states/actionStateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,qBAAa,eAAgB,YAAW,YAAY;IAChD,gBAAgB,SAAK;CACxB"}
|
|
1
|
+
{"version":3,"file":"actionStateBase.d.ts","sourceRoot":"","sources":["../../../entities/states/actionStateBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,qBAAa,eAAgB,YAAW,YAAY;IAChD,cAAc,EAAE,MAAM,EAAE,CAAM;IAC9B,gBAAgB,SAAK;CACxB"}
|
|
@@ -18,5 +18,6 @@ export declare class JsonFileStorage implements IStorageClient {
|
|
|
18
18
|
getActionState<TActionState extends IActionState>(entity: IActionWithState, chatId: number): Promise<TActionState>;
|
|
19
19
|
saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult: ActionExecutionResult): Promise<void>;
|
|
20
20
|
close(): Promise<void>;
|
|
21
|
+
updateStateFor<TActionState extends IActionState>(sourceActionKey: string, chatId: number, update: (state: TActionState) => Promise<void>): Promise<void>;
|
|
21
22
|
}
|
|
22
23
|
//# sourceMappingURL=jsonFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBAAa,eAAgB,YAAW,cAAc;IAClD,SAAS,YAAoB;IAC7B,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;YAY5B,IAAI;YAUJ,YAAY;YAmBZ,IAAI;IAalB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,MAAM;IAMnD,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM;IAUzD,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM;IASZ,yBAAyB,CAC3B,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB;IAYtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBAAa,eAAgB,YAAW,cAAc;IAClD,SAAS,YAAoB;IAC7B,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;YAY5B,IAAI;YAUJ,YAAY;YAmBZ,IAAI;IAalB,OAAO,CAAC,eAAe;IAOjB,IAAI,CAAC,YAAY,SAAS,YAAY,EAAE,GAAG,EAAE,MAAM;IAMnD,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM;IAUzD,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM;IASZ,yBAAyB,CAC3B,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,qBAAqB;IAYtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,cAAc,CAAC,YAAY,SAAS,YAAY,EAClD,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;CAWrD"}
|
|
@@ -83,5 +83,13 @@ class JsonFileStorage {
|
|
|
83
83
|
async close() {
|
|
84
84
|
await this.semaphore.acquire();
|
|
85
85
|
}
|
|
86
|
+
async updateStateFor(sourceActionKey, chatId, update) {
|
|
87
|
+
await this.lock(async () => {
|
|
88
|
+
const data = await this.loadInternal(sourceActionKey);
|
|
89
|
+
const state = data[chatId];
|
|
90
|
+
await update(state);
|
|
91
|
+
await this.save(data, sourceActionKey);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
86
94
|
}
|
|
87
95
|
exports.JsonFileStorage = JsonFileStorage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare class JsonLogger {
|
|
2
2
|
logWithTraceId(botName: string, traceId: string | number, chatName: string, text: string): void;
|
|
3
|
-
errorWithTraceId<TData>(botName: string, traceId: string | number, chatName: string, errorObj:
|
|
3
|
+
errorWithTraceId<TData>(botName: string, traceId: string | number, chatName: string, errorObj: unknown, extraData?: TData | undefined): void;
|
|
4
4
|
}
|
|
5
5
|
export declare const Logger: JsonLogger;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../services/logger.ts"],"names":[],"mappings":"AAAA,cAAM,UAAU;IACZ,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAKhB,gBAAgB,CAAC,KAAK,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../services/logger.ts"],"names":[],"mappings":"AAAA,cAAM,UAAU;IACZ,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAKhB,gBAAgB,CAAC,KAAK,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS;CAYpC;AAED,eAAO,MAAM,MAAM,YAAmB,CAAC"}
|
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import { Telegraf } from 'telegraf';
|
|
2
1
|
import { ChatContext } from '../entities/context/chatContext';
|
|
3
2
|
import { MessageContext } from '../entities/context/messageContext';
|
|
4
|
-
import { IReplyMessage } from '../types/replyMessage';
|
|
5
3
|
import { IStorageClient } from '../types/storage';
|
|
6
4
|
import { Reaction } from '../entities/responses/reaction';
|
|
7
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';
|
|
8
12
|
export declare class TelegramApiService {
|
|
9
13
|
botName: string;
|
|
10
|
-
|
|
14
|
+
telegram: Telegram;
|
|
11
15
|
chats: Map<number, string>;
|
|
12
|
-
messageQueue: Array<
|
|
16
|
+
messageQueue: Array<BotResponse>;
|
|
13
17
|
storage: IStorageClient;
|
|
14
|
-
constructor(botName: string,
|
|
18
|
+
constructor(botName: string, telegram: Telegram, storage: IStorageClient, chats: Map<string, number>);
|
|
15
19
|
private dequeueResponse;
|
|
20
|
+
private pinIfShould;
|
|
16
21
|
private processResponse;
|
|
17
|
-
private
|
|
18
|
-
private enqueueReaction;
|
|
22
|
+
private enqueue;
|
|
19
23
|
private getInteractions;
|
|
20
|
-
createContextForMessage(incomingMessage: IncomingMessage): MessageContext<import("..").IActionState>;
|
|
21
|
-
createContextForChat(chatId: number,
|
|
24
|
+
createContextForMessage(incomingMessage: IncomingMessage, commandKey: string): MessageContext<import("..").IActionState>;
|
|
25
|
+
createContextForChat(chatId: number, scheduledKey: string): ChatContext;
|
|
22
26
|
}
|
|
23
27
|
export interface IBotApiInteractions {
|
|
24
|
-
respond:
|
|
28
|
+
respond: (response: TextMessage | VideoMessage | ImageMessage) => void;
|
|
25
29
|
react: (reaction: Reaction) => void;
|
|
30
|
+
unpin: (unpinMessage: UnpinResponse) => void;
|
|
26
31
|
}
|
|
27
32
|
//# sourceMappingURL=telegramApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"
|
|
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;AAIlD,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;AAErD,qBAAa,kBAAkB;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,CAAM;IACtC,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;YAkBhB,eAAe;YAmBf,WAAW;YAqBX,eAAe;IA2E7B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,eAAe;IAQvB,uBAAuB,CACnB,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,MAAM;IAsBtB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAW5D;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"}
|
|
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TelegramApiService = void 0;
|
|
4
4
|
const chatContext_1 = require("../entities/context/chatContext");
|
|
5
5
|
const messageContext_1 = require("../entities/context/messageContext");
|
|
6
|
-
const imageMessage_1 = require("../entities/responses/imageMessage");
|
|
7
|
-
const textMessage_1 = require("../entities/responses/textMessage");
|
|
8
|
-
const videoMessage_1 = require("../entities/responses/videoMessage");
|
|
9
6
|
const reverseMap_1 = require("../helpers/reverseMap");
|
|
10
7
|
const taskScheduler_1 = require("./taskScheduler");
|
|
11
8
|
const logger_1 = require("./logger");
|
|
12
9
|
class TelegramApiService {
|
|
13
|
-
constructor(botName,
|
|
10
|
+
constructor(botName, telegram, storage, chats) {
|
|
14
11
|
this.messageQueue = [];
|
|
15
|
-
this.
|
|
12
|
+
this.telegram = telegram;
|
|
16
13
|
this.botName = botName;
|
|
17
14
|
this.chats = (0, reverseMap_1.reverseMap)(chats);
|
|
18
15
|
this.storage = storage;
|
|
@@ -28,66 +25,79 @@ class TelegramApiService {
|
|
|
28
25
|
await this.processResponse(message);
|
|
29
26
|
}
|
|
30
27
|
catch (error) {
|
|
28
|
+
console.dir(error);
|
|
31
29
|
logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats.get(message.chatId), error, message);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
|
-
async
|
|
35
|
-
if (
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
], true);
|
|
42
|
-
return;
|
|
32
|
+
async pinIfShould(response, sentMessage) {
|
|
33
|
+
if (response.shouldPin) {
|
|
34
|
+
await this.telegram.pinChatMessage(response.chatId, sentMessage.message_id, { disable_notification: true });
|
|
35
|
+
await this.storage.updateStateFor(response.sourceActionKey, response.chatId, async (state) => {
|
|
36
|
+
state.pinnedMessages.push(sentMessage.message_id);
|
|
37
|
+
});
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
}
|
|
40
|
+
async processResponse(response) {
|
|
41
|
+
let sentMessage;
|
|
42
|
+
switch (response.kind) {
|
|
43
|
+
case 'text':
|
|
44
|
+
sentMessage = await this.telegram.sendMessage(response.chatId, response.content, {
|
|
47
45
|
reply_to_message_id: response.replyId,
|
|
48
46
|
parse_mode: 'MarkdownV2',
|
|
49
47
|
disable_web_page_preview: response.disableWebPreview
|
|
50
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
49
|
});
|
|
50
|
+
await this.pinIfShould(response, sentMessage);
|
|
52
51
|
break;
|
|
53
|
-
case
|
|
54
|
-
await this.
|
|
52
|
+
case 'image':
|
|
53
|
+
sentMessage = await this.telegram.sendPhoto(response.chatId, response.content, response.replyId
|
|
55
54
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
55
|
{ reply_to_message_id: response.replyId }
|
|
57
56
|
: undefined);
|
|
57
|
+
await this.pinIfShould(response, sentMessage);
|
|
58
58
|
break;
|
|
59
|
-
case
|
|
60
|
-
await this.
|
|
59
|
+
case 'video':
|
|
60
|
+
sentMessage = await this.telegram.sendVideo(response.chatId, response.content, response.replyId
|
|
61
61
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
62
|
{ reply_to_message_id: response.replyId }
|
|
63
63
|
: undefined);
|
|
64
|
+
await this.pinIfShould(response, sentMessage);
|
|
64
65
|
break;
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
case 'react':
|
|
67
|
+
await this.telegram.setMessageReaction(response.chatId, response.messageId, [
|
|
68
|
+
{
|
|
69
|
+
type: 'emoji',
|
|
70
|
+
emoji: response.emoji
|
|
71
|
+
}
|
|
72
|
+
], true);
|
|
73
|
+
return;
|
|
74
|
+
case 'unpin':
|
|
75
|
+
await this.telegram.unpinChatMessage(response.chatId, response.messageId);
|
|
76
|
+
await this.storage.updateStateFor(response.sourceActionKey, response.chatId, async (state) => {
|
|
77
|
+
state.pinnedMessages = state.pinnedMessages.filter((x) => x != response.messageId);
|
|
78
|
+
});
|
|
67
79
|
break;
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
|
-
|
|
71
|
-
this.messageQueue.push(response);
|
|
72
|
-
}
|
|
73
|
-
enqueueReaction(reaction) {
|
|
82
|
+
enqueue(reaction) {
|
|
74
83
|
this.messageQueue.push(reaction);
|
|
75
84
|
}
|
|
76
85
|
getInteractions() {
|
|
77
86
|
return {
|
|
78
|
-
react: (reaction) => this.
|
|
79
|
-
respond: (response) => this.
|
|
87
|
+
react: (reaction) => this.enqueue(reaction),
|
|
88
|
+
respond: (response) => this.enqueue(response),
|
|
89
|
+
unpin: (unpinMessage) => this.enqueue(unpinMessage)
|
|
80
90
|
};
|
|
81
91
|
}
|
|
82
|
-
createContextForMessage(incomingMessage) {
|
|
92
|
+
createContextForMessage(incomingMessage, commandKey) {
|
|
83
93
|
const firstName = incomingMessage.from?.first_name ?? 'Unknown user';
|
|
84
94
|
const lastName = incomingMessage.from?.last_name
|
|
85
95
|
? ` ${incomingMessage.from?.last_name}`
|
|
86
96
|
: '';
|
|
87
|
-
return new messageContext_1.MessageContext(this.botName, this.getInteractions(), incomingMessage.chat.id, incomingMessage.chatName, incomingMessage.message_id, incomingMessage.text, incomingMessage.from?.id, incomingMessage.traceId, firstName + lastName, this.storage);
|
|
97
|
+
return new messageContext_1.MessageContext(this.botName, commandKey, this.getInteractions(), incomingMessage.chat.id, incomingMessage.chatName, incomingMessage.message_id, incomingMessage.text, incomingMessage.from?.id, incomingMessage.traceId, firstName + lastName, this.storage);
|
|
88
98
|
}
|
|
89
|
-
createContextForChat(chatId,
|
|
90
|
-
return new chatContext_1.ChatContext(this.botName, this.getInteractions(), chatId, this.chats.get(chatId), `Scheduled:${
|
|
99
|
+
createContextForChat(chatId, scheduledKey) {
|
|
100
|
+
return new chatContext_1.ChatContext(this.botName, scheduledKey, this.getInteractions(), chatId, this.chats.get(chatId), `Scheduled:${scheduledKey}:${chatId}`, this.storage);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
exports.TelegramApiService = TelegramApiService;
|