chz-telegram-bot 0.1.19 → 0.2.0
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/builtin/helpAction.ts +1 -1
- package/bun.lock +307 -0
- package/dist/builtin/helpAction.js +1 -1
- package/dist/dtos/responses/imageMessage.d.ts +5 -4
- package/dist/dtos/responses/imageMessage.d.ts.map +1 -1
- package/dist/dtos/responses/imageMessage.js +2 -2
- package/dist/dtos/responses/textMessage.d.ts +5 -4
- package/dist/dtos/responses/textMessage.d.ts.map +1 -1
- package/dist/dtos/responses/textMessage.js +2 -2
- package/dist/dtos/responses/videoMessage.d.ts +5 -4
- package/dist/dtos/responses/videoMessage.d.ts.map +1 -1
- package/dist/dtos/responses/videoMessage.js +2 -2
- package/dist/entities/botInstance.d.ts +2 -0
- package/dist/entities/botInstance.d.ts.map +1 -1
- package/dist/entities/botInstance.js +34 -7
- package/dist/entities/context/chatContext.d.ts +25 -21
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +32 -38
- package/dist/entities/context/messageContext.d.ts +60 -28
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +79 -49
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +6 -11
- package/dist/services/responseProcessingQueue.d.ts +0 -1
- package/dist/services/responseProcessingQueue.d.ts.map +1 -1
- package/dist/services/responseProcessingQueue.js +1 -6
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +9 -7
- package/dist/types/messageTypes.d.ts +1 -0
- package/dist/types/messageTypes.d.ts.map +1 -1
- package/dist/types/messageTypes.js +15 -14
- package/dist/types/replyInfo.d.ts +6 -0
- package/dist/types/replyInfo.d.ts.map +1 -0
- package/dist/types/replyInfo.js +10 -0
- package/dist/types/response.d.ts +3 -2
- package/dist/types/response.d.ts.map +1 -1
- package/dtos/responses/imageMessage.ts +6 -5
- package/dtos/responses/textMessage.ts +6 -5
- package/dtos/responses/videoMessage.ts +6 -5
- package/entities/botInstance.ts +65 -10
- package/entities/context/chatContext.ts +58 -72
- package/entities/context/messageContext.ts +133 -88
- package/eslint.config.js +0 -1
- package/package.json +30 -29
- package/services/jsonFileStorage.ts +7 -13
- package/services/responseProcessingQueue.ts +2 -8
- package/services/telegramApi.ts +11 -9
- package/types/messageTypes.ts +15 -13
- package/types/replyInfo.ts +9 -0
- package/types/response.ts +3 -2
|
@@ -8,18 +8,18 @@ import { TextMessage } from '../../dtos/responses/textMessage';
|
|
|
8
8
|
import { VideoMessage } from '../../dtos/responses/videoMessage';
|
|
9
9
|
import { ActionStateBase } from '../states/actionStateBase';
|
|
10
10
|
import { ChatContext } from './chatContext';
|
|
11
|
-
import { IncomingMessage } from '../../dtos/incomingMessage';
|
|
12
11
|
import {
|
|
13
12
|
MessageSendingOptions,
|
|
14
13
|
TextMessageSendingOptions
|
|
15
14
|
} from '../../types/messageSendingOptions';
|
|
16
|
-
import {
|
|
15
|
+
import { ActionKey } from '../../types/statefulAction';
|
|
17
16
|
import {
|
|
18
17
|
MessageTypeValue,
|
|
19
18
|
TelegrafContextMessage
|
|
20
19
|
} from '../../types/messageTypes';
|
|
21
20
|
import { ILogger } from '../../types/logger';
|
|
22
21
|
import { IScheduler } from '../../types/scheduler';
|
|
22
|
+
import { ReplyInfo } from '../../types/replyInfo';
|
|
23
23
|
/**
|
|
24
24
|
* Context of action executed in chat, in response to a message
|
|
25
25
|
*/
|
|
@@ -51,126 +51,171 @@ export class MessageContext<
|
|
|
51
51
|
super(storage, logger, scheduler);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
private replyWithText(
|
|
55
|
+
text: string,
|
|
56
|
+
quote: boolean,
|
|
57
|
+
options?: TextMessageSendingOptions
|
|
58
58
|
) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.fromUserName =
|
|
64
|
-
(message.from?.first_name ?? 'Unknown user') +
|
|
65
|
-
(message.from?.last_name ? ` ${message.from.last_name}` : '');
|
|
66
|
-
this.messageUpdateObject = message.updateObject;
|
|
59
|
+
const quotedPart =
|
|
60
|
+
this.matchResults.length != 0
|
|
61
|
+
? this.matchResults[0][1]
|
|
62
|
+
: this.messageText;
|
|
67
63
|
|
|
68
|
-
this.matchResults = [];
|
|
69
|
-
this.startCooldown = true;
|
|
70
|
-
|
|
71
|
-
return this.initializeChatContext(
|
|
72
|
-
botName,
|
|
73
|
-
action,
|
|
74
|
-
message.chatInfo,
|
|
75
|
-
message.traceId
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
81
|
-
* @param commandName Name of an action to load state of.
|
|
82
|
-
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
83
|
-
*/
|
|
84
|
-
async loadStateOf<TAnotherActionState extends IActionState>(
|
|
85
|
-
commandName: string
|
|
86
|
-
): Promise<TAnotherActionState> {
|
|
87
|
-
const storageKey = `command:${commandName.replace(
|
|
88
|
-
'.',
|
|
89
|
-
'-'
|
|
90
|
-
)}` as ActionKey;
|
|
91
|
-
const allStates = await this.storage.load(storageKey);
|
|
92
|
-
const stateForChat = allStates[this.chatInfo.id];
|
|
93
|
-
|
|
94
|
-
if (!stateForChat) {
|
|
95
|
-
return new ActionStateBase() as TAnotherActionState;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return stateForChat as TAnotherActionState;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Reply with text message to message that triggered this action after action execution is finished.
|
|
103
|
-
* 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.
|
|
104
|
-
* @param text Message contents.
|
|
105
|
-
* @param options Message sending option.
|
|
106
|
-
*/
|
|
107
|
-
replyWithText(text: string, options?: TextMessageSendingOptions) {
|
|
108
64
|
this.responses.push(
|
|
109
65
|
new TextMessage(
|
|
110
66
|
text,
|
|
111
67
|
this.chatInfo,
|
|
112
|
-
this.messageId,
|
|
113
68
|
this.traceId,
|
|
114
69
|
this.action,
|
|
70
|
+
new ReplyInfo(this.messageId, quote ? quotedPart : undefined),
|
|
115
71
|
options
|
|
116
72
|
)
|
|
117
73
|
);
|
|
118
74
|
}
|
|
119
75
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
76
|
+
private replyWithImage(
|
|
77
|
+
name: string,
|
|
78
|
+
quote: boolean,
|
|
79
|
+
options?: MessageSendingOptions
|
|
80
|
+
) {
|
|
81
|
+
const quotedPart =
|
|
82
|
+
this.matchResults.length != 0
|
|
83
|
+
? this.matchResults[0][1]
|
|
84
|
+
: this.messageText;
|
|
85
|
+
|
|
128
86
|
this.responses.push(
|
|
129
87
|
new ImageMessage(
|
|
130
|
-
{ source: resolve(
|
|
88
|
+
{ source: resolve(`./content/${name}.png`) },
|
|
131
89
|
this.chatInfo,
|
|
132
|
-
this.messageId,
|
|
133
90
|
this.traceId,
|
|
134
91
|
this.action,
|
|
92
|
+
new ReplyInfo(this.messageId, quote ? quotedPart : undefined),
|
|
135
93
|
options
|
|
136
94
|
)
|
|
137
95
|
);
|
|
138
96
|
}
|
|
139
97
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
98
|
+
private replyWithVideo(
|
|
99
|
+
name: string,
|
|
100
|
+
quote: boolean,
|
|
101
|
+
options?: MessageSendingOptions
|
|
102
|
+
) {
|
|
103
|
+
const quotedPart =
|
|
104
|
+
this.matchResults.length != 0
|
|
105
|
+
? this.matchResults[0][1]
|
|
106
|
+
: this.messageText;
|
|
107
|
+
|
|
148
108
|
this.responses.push(
|
|
149
109
|
new VideoMessage(
|
|
150
|
-
{ source: resolve(
|
|
110
|
+
{ source: resolve(`./content/${name}.mp4`) },
|
|
151
111
|
this.chatInfo,
|
|
152
|
-
this.messageId,
|
|
153
112
|
this.traceId,
|
|
154
113
|
this.action,
|
|
114
|
+
new ReplyInfo(this.messageId, quote ? quotedPart : undefined),
|
|
155
115
|
options
|
|
156
116
|
)
|
|
157
117
|
);
|
|
158
118
|
}
|
|
159
119
|
|
|
160
120
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @
|
|
121
|
+
* Loads state of another action. Changes to the loaded state will no affect actual state of other action.
|
|
122
|
+
* @param commandName Name of an action to load state of.
|
|
123
|
+
* @template TAnotherActionState - Type of a state that is used by another action.
|
|
164
124
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
125
|
+
async loadStateOf<TAnotherActionState extends IActionState>(
|
|
126
|
+
commandName: string
|
|
127
|
+
): Promise<TAnotherActionState> {
|
|
128
|
+
const storageKey = `command:${commandName.replace(
|
|
129
|
+
'.',
|
|
130
|
+
'-'
|
|
131
|
+
)}` as ActionKey;
|
|
132
|
+
const allStates = await this.storage.load(storageKey);
|
|
133
|
+
const stateForChat = allStates[this.chatInfo.id];
|
|
134
|
+
|
|
135
|
+
if (!stateForChat) {
|
|
136
|
+
return new ActionStateBase() as TAnotherActionState;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return stateForChat as TAnotherActionState;
|
|
175
140
|
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Collection of actions that can be done as a reply to a message that triggered this action
|
|
144
|
+
*/
|
|
145
|
+
reply = {
|
|
146
|
+
/**
|
|
147
|
+
* Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
|
|
148
|
+
* If regex is matched, first match will be quoted
|
|
149
|
+
*/
|
|
150
|
+
andQuote: {
|
|
151
|
+
/**
|
|
152
|
+
* Reply with text message to 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
|
+
* @param text Message contents.
|
|
155
|
+
* @param options Message sending option.
|
|
156
|
+
*/
|
|
157
|
+
withText: (text: string, options?: TextMessageSendingOptions) =>
|
|
158
|
+
this.replyWithText(text, true, options),
|
|
159
|
+
/**
|
|
160
|
+
* Reply with image message to message that triggered this action after action execution is finished.
|
|
161
|
+
* 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.
|
|
162
|
+
* @param text Message contents.
|
|
163
|
+
* @param options Message sending option.
|
|
164
|
+
*/
|
|
165
|
+
withImage: (name: string, options?: MessageSendingOptions) =>
|
|
166
|
+
this.replyWithImage(name, true, options),
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
170
|
+
* 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.
|
|
171
|
+
* @param text Message contents.
|
|
172
|
+
* @param options Message sending option.
|
|
173
|
+
*/
|
|
174
|
+
withVideo: (name: string, options?: MessageSendingOptions) =>
|
|
175
|
+
this.replyWithVideo(name, true, options)
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Reply with text message to message that triggered this action after action execution is finished.
|
|
180
|
+
* 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.
|
|
181
|
+
* @param text Message contents.
|
|
182
|
+
* @param options Message sending option.
|
|
183
|
+
*/
|
|
184
|
+
withText: (text: string, options?: TextMessageSendingOptions) =>
|
|
185
|
+
this.replyWithText(text, false, options),
|
|
186
|
+
/**
|
|
187
|
+
* Reply with image message to message that triggered this action after action execution is finished.
|
|
188
|
+
* 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.
|
|
189
|
+
* @param text Message contents.
|
|
190
|
+
* @param options Message sending option.
|
|
191
|
+
*/
|
|
192
|
+
withImage: (name: string, options?: MessageSendingOptions) =>
|
|
193
|
+
this.replyWithImage(name, false, options),
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Reply with video/gif message to message that triggered this action after action execution is finished.
|
|
197
|
+
* 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.
|
|
198
|
+
* @param text Message contents.
|
|
199
|
+
* @param options Message sending option.
|
|
200
|
+
*/
|
|
201
|
+
withVideo: (name: string, options?: MessageSendingOptions) =>
|
|
202
|
+
this.replyWithVideo(name, false, options),
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* React to the message that triggered this action after action execution is finished.
|
|
206
|
+
* 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.
|
|
207
|
+
* @param emoji Telegram emoji to react with.
|
|
208
|
+
*/
|
|
209
|
+
withReaction: (emoji: TelegramEmoji) => {
|
|
210
|
+
this.responses.push(
|
|
211
|
+
new Reaction(
|
|
212
|
+
this.traceId,
|
|
213
|
+
this.chatInfo,
|
|
214
|
+
this.messageId,
|
|
215
|
+
emoji,
|
|
216
|
+
this.action
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
176
221
|
}
|
package/eslint.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chz-telegram-bot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"async-sema": "^3.1.1",
|
|
7
|
-
"moment": "^2.29.4",
|
|
8
|
-
"telegraf": "^4.16.3"
|
|
9
|
-
},
|
|
10
|
-
"main": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"@eslint/js": "^9.
|
|
14
|
-
"@types/markdown-escape": "^1.1.3",
|
|
15
|
-
"@types/node": "^22.5.5",
|
|
16
|
-
"eslint": "^9.
|
|
17
|
-
"
|
|
18
|
-
"typescript
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "chz-telegram-bot",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"async-sema": "^3.1.1",
|
|
7
|
+
"moment": "^2.29.4",
|
|
8
|
+
"telegraf": "^4.16.3"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@eslint/js": "^9.29.0",
|
|
14
|
+
"@types/markdown-escape": "^1.1.3",
|
|
15
|
+
"@types/node": "^22.5.5",
|
|
16
|
+
"eslint": "^9.29.0",
|
|
17
|
+
"globals": "^16.2.0",
|
|
18
|
+
"typescript": "^5.6.2",
|
|
19
|
+
"typescript-eslint": "^8.34.1"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"lint": "npx eslint && tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"overrides": {
|
|
26
|
+
"telegraf": {
|
|
27
|
+
"node-fetch": "3.3.2"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync, mkdirSync } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import { mkdir, readFile, writeFile } from 'fs/promises';
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
4
3
|
import { Sema as Semaphore } from 'async-sema';
|
|
5
4
|
import { IStorageClient } from '../types/storage';
|
|
6
5
|
import { IActionState } from '../types/actionState';
|
|
@@ -51,11 +50,11 @@ export class JsonFileStorage implements IStorageClient {
|
|
|
51
50
|
) {
|
|
52
51
|
if (!this.cache.has(key)) {
|
|
53
52
|
const targetPath = this.buidPathFromKey(key);
|
|
54
|
-
if (!existsSync(targetPath)) {
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
53
|
|
|
58
|
-
const fileContent = await readFile(targetPath,
|
|
54
|
+
const fileContent = await readFile(targetPath, {
|
|
55
|
+
encoding: 'utf-8',
|
|
56
|
+
flag: 'a+'
|
|
57
|
+
});
|
|
59
58
|
|
|
60
59
|
if (fileContent) {
|
|
61
60
|
const data = JSON.parse(fileContent);
|
|
@@ -74,11 +73,6 @@ export class JsonFileStorage implements IStorageClient {
|
|
|
74
73
|
this.cache.set(key, data);
|
|
75
74
|
|
|
76
75
|
const targetPath = this.buidPathFromKey(key);
|
|
77
|
-
const folderName = dirname(targetPath);
|
|
78
|
-
|
|
79
|
-
if (!existsSync(folderName)) {
|
|
80
|
-
await mkdir(folderName, { recursive: true });
|
|
81
|
-
}
|
|
82
76
|
|
|
83
77
|
await writeFile(targetPath, JSON.stringify(data), { flag: 'w+' });
|
|
84
78
|
}
|
|
@@ -92,7 +86,7 @@ export class JsonFileStorage implements IStorageClient {
|
|
|
92
86
|
|
|
93
87
|
async load<TActionState extends IActionState>(key: ActionKey) {
|
|
94
88
|
return await this.lock(key, async () => {
|
|
95
|
-
return this.loadInternal<TActionState>(key);
|
|
89
|
+
return await this.loadInternal<TActionState>(key);
|
|
96
90
|
});
|
|
97
91
|
}
|
|
98
92
|
|
|
@@ -128,7 +122,7 @@ export class JsonFileStorage implements IStorageClient {
|
|
|
128
122
|
chatId: number,
|
|
129
123
|
state: TActionState
|
|
130
124
|
) {
|
|
131
|
-
await this.lock(action.key, async () => {
|
|
125
|
+
return await this.lock(action.key, async () => {
|
|
132
126
|
const data = await this.loadInternal<TActionState>(action.key);
|
|
133
127
|
|
|
134
128
|
data[chatId] = state;
|
|
@@ -37,10 +37,8 @@ export class ResponseProcessingQueue {
|
|
|
37
37
|
this.isFlushing = true;
|
|
38
38
|
|
|
39
39
|
while (this.items.length) {
|
|
40
|
-
if (Date.now() >= this.
|
|
41
|
-
const item = this.items.shift()
|
|
42
|
-
|
|
43
|
-
if (!item) return;
|
|
40
|
+
if (Date.now() >= this.items[0].priority) {
|
|
41
|
+
const item = this.items.shift()!;
|
|
44
42
|
|
|
45
43
|
await item.callback();
|
|
46
44
|
} else {
|
|
@@ -50,8 +48,4 @@ export class ResponseProcessingQueue {
|
|
|
50
48
|
|
|
51
49
|
this.isFlushing = false;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
private peek() {
|
|
55
|
-
return this.items[0];
|
|
56
|
-
}
|
|
57
51
|
}
|
package/services/telegramApi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from 'telegraf/types';
|
|
2
2
|
import { IStorageClient } from '../types/storage';
|
|
3
|
-
import { BotResponse,
|
|
3
|
+
import { BotResponse, IReplyResponse } from '../types/response';
|
|
4
4
|
import { Telegram } from 'telegraf/typings/telegram';
|
|
5
5
|
import { ILogger } from '../types/logger';
|
|
6
6
|
import { QueueItem, ResponseProcessingQueue } from './responseProcessingQueue';
|
|
@@ -60,7 +60,7 @@ export class TelegramApiService {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
private async pinIfShould<T>(
|
|
63
|
-
response:
|
|
63
|
+
response: IReplyResponse<T>,
|
|
64
64
|
sentMessage: Message
|
|
65
65
|
) {
|
|
66
66
|
if (response.shouldPin) {
|
|
@@ -89,7 +89,7 @@ export class TelegramApiService {
|
|
|
89
89
|
response.chatInfo.id,
|
|
90
90
|
response.content,
|
|
91
91
|
{
|
|
92
|
-
reply_to_message_id: response.
|
|
92
|
+
reply_to_message_id: response.replyInfo?.id,
|
|
93
93
|
parse_mode: 'MarkdownV2',
|
|
94
94
|
disable_web_page_preview: response.disableWebPreview
|
|
95
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -102,9 +102,10 @@ export class TelegramApiService {
|
|
|
102
102
|
sentMessage = await this.telegram.sendPhoto(
|
|
103
103
|
response.chatInfo.id,
|
|
104
104
|
response.content,
|
|
105
|
-
response.
|
|
106
|
-
?
|
|
107
|
-
|
|
105
|
+
response.replyInfo?.id
|
|
106
|
+
? ({
|
|
107
|
+
reply_to_message_id: response.replyInfo?.id // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
} as any)
|
|
108
109
|
: undefined
|
|
109
110
|
);
|
|
110
111
|
|
|
@@ -114,9 +115,10 @@ export class TelegramApiService {
|
|
|
114
115
|
sentMessage = await this.telegram.sendVideo(
|
|
115
116
|
response.chatInfo.id,
|
|
116
117
|
response.content,
|
|
117
|
-
response.
|
|
118
|
-
?
|
|
119
|
-
|
|
118
|
+
response.replyInfo?.id
|
|
119
|
+
? ({
|
|
120
|
+
reply_to_message_id: response.replyInfo?.id // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
121
|
+
} as any)
|
|
120
122
|
: undefined
|
|
121
123
|
);
|
|
122
124
|
|
package/types/messageTypes.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Message, Update } from 'telegraf/types';
|
|
2
2
|
|
|
3
|
+
export const INTERNAL_MESSAGE_TYPE_PREFIX = `__msg:`;
|
|
4
|
+
|
|
3
5
|
export const MessageType = {
|
|
4
|
-
Text:
|
|
5
|
-
Sticker:
|
|
6
|
-
Animation:
|
|
7
|
-
Document:
|
|
8
|
-
Voice:
|
|
9
|
-
Audio:
|
|
10
|
-
LeftChatMember:
|
|
11
|
-
NewChatMember:
|
|
12
|
-
Poll:
|
|
13
|
-
Location:
|
|
14
|
-
Photo:
|
|
15
|
-
Forward:
|
|
16
|
-
Unknown:
|
|
6
|
+
Text: `${INTERNAL_MESSAGE_TYPE_PREFIX}Text`,
|
|
7
|
+
Sticker: `${INTERNAL_MESSAGE_TYPE_PREFIX}Sticker`,
|
|
8
|
+
Animation: `${INTERNAL_MESSAGE_TYPE_PREFIX}Animation`,
|
|
9
|
+
Document: `${INTERNAL_MESSAGE_TYPE_PREFIX}Document`,
|
|
10
|
+
Voice: `${INTERNAL_MESSAGE_TYPE_PREFIX}Voice`,
|
|
11
|
+
Audio: `${INTERNAL_MESSAGE_TYPE_PREFIX}Audio`,
|
|
12
|
+
LeftChatMember: `${INTERNAL_MESSAGE_TYPE_PREFIX}LeftChatMember`,
|
|
13
|
+
NewChatMember: `${INTERNAL_MESSAGE_TYPE_PREFIX}NewChatMember`,
|
|
14
|
+
Poll: `${INTERNAL_MESSAGE_TYPE_PREFIX}Poll`,
|
|
15
|
+
Location: `${INTERNAL_MESSAGE_TYPE_PREFIX}Location`,
|
|
16
|
+
Photo: `${INTERNAL_MESSAGE_TYPE_PREFIX}Photo`,
|
|
17
|
+
Forward: `${INTERNAL_MESSAGE_TYPE_PREFIX}Forward`,
|
|
18
|
+
Unknown: `${INTERNAL_MESSAGE_TYPE_PREFIX}Unknown`
|
|
17
19
|
} as const;
|
|
18
20
|
|
|
19
21
|
export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
|
package/types/response.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { TextMessage } from '../dtos/responses/textMessage';
|
|
|
7
7
|
import { UnpinResponse } from '../dtos/responses/unpin';
|
|
8
8
|
import { VideoMessage } from '../dtos/responses/videoMessage';
|
|
9
9
|
import { IActionState } from './actionState';
|
|
10
|
+
import { ReplyInfo } from './replyInfo';
|
|
10
11
|
import { IActionWithState } from './statefulAction';
|
|
11
12
|
import { TraceId } from './trace';
|
|
12
13
|
|
|
@@ -38,9 +39,9 @@ export interface IChatResponse {
|
|
|
38
39
|
readonly action: IActionWithState<IActionState>;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
export interface
|
|
42
|
+
export interface IReplyResponse<TType> extends IChatResponse {
|
|
42
43
|
readonly content: TType;
|
|
43
|
-
readonly
|
|
44
|
+
readonly replyInfo: ReplyInfo | undefined;
|
|
44
45
|
readonly disableWebPreview: boolean;
|
|
45
46
|
readonly shouldPin: boolean;
|
|
46
47
|
}
|