chz-telegram-bot 0.0.54 → 0.1.2
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/README.md +214 -0
- package/dist/dtos/responses/delay.d.ts +1 -0
- package/dist/dtos/responses/delay.d.ts.map +1 -1
- package/dist/dtos/responses/delay.js +1 -0
- package/dist/dtos/responses/imageMessage.d.ts +1 -0
- package/dist/dtos/responses/imageMessage.d.ts.map +1 -1
- package/dist/dtos/responses/imageMessage.js +1 -0
- package/dist/dtos/responses/reaction.d.ts +1 -0
- package/dist/dtos/responses/reaction.d.ts.map +1 -1
- package/dist/dtos/responses/reaction.js +1 -0
- package/dist/dtos/responses/textMessage.d.ts +1 -0
- package/dist/dtos/responses/textMessage.d.ts.map +1 -1
- package/dist/dtos/responses/textMessage.js +1 -0
- package/dist/dtos/responses/unpin.d.ts +1 -0
- package/dist/dtos/responses/unpin.d.ts.map +1 -1
- package/dist/dtos/responses/unpin.js +1 -0
- package/dist/dtos/responses/videoMessage.d.ts +1 -0
- package/dist/dtos/responses/videoMessage.d.ts.map +1 -1
- package/dist/dtos/responses/videoMessage.js +1 -0
- package/dist/entities/botInstance.js +2 -2
- package/dist/entities/context/chatContext.d.ts +2 -2
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +2 -2
- package/dist/services/responseProcessingQueue.d.ts +12 -0
- package/dist/services/responseProcessingQueue.d.ts.map +1 -0
- package/dist/services/responseProcessingQueue.js +45 -0
- package/dist/services/telegramApi.d.ts +2 -3
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +22 -25
- package/dist/types/response.d.ts +1 -0
- package/dist/types/response.d.ts.map +1 -1
- package/dtos/responses/delay.ts +1 -0
- package/dtos/responses/imageMessage.ts +1 -0
- package/dtos/responses/reaction.ts +1 -0
- package/dtos/responses/textMessage.ts +1 -0
- package/dtos/responses/unpin.ts +1 -0
- package/dtos/responses/videoMessage.ts +1 -0
- package/entities/botInstance.ts +2 -2
- package/entities/context/chatContext.ts +2 -2
- package/package.json +1 -1
- package/services/responseProcessingQueue.ts +57 -0
- package/services/telegramApi.ts +28 -35
- package/types/response.ts +1 -0
- package/dist/dtos/actionExecutionResult.d.ts +0 -7
- package/dist/dtos/actionExecutionResult.d.ts.map +0 -1
- package/dist/dtos/actionExecutionResult.js +0 -10
- package/dist/entities/actionExecutionResult.d.ts +0 -7
- package/dist/entities/actionExecutionResult.d.ts.map +0 -1
- package/dist/entities/actionExecutionResult.js +0 -10
- package/dist/entities/commandTriggerCheckResult.d.ts +0 -10
- package/dist/entities/commandTriggerCheckResult.d.ts.map +0 -1
- package/dist/entities/commandTriggerCheckResult.js +0 -23
- package/dist/entities/incomingMessage.d.ts +0 -14
- package/dist/entities/incomingMessage.d.ts.map +0 -1
- package/dist/entities/incomingMessage.js +0 -45
- package/dist/entities/responses/delay.d.ts +0 -13
- package/dist/entities/responses/delay.d.ts.map +0 -1
- package/dist/entities/responses/delay.js +0 -14
- package/dist/entities/responses/imageMessage.d.ts +0 -17
- package/dist/entities/responses/imageMessage.d.ts.map +0 -1
- package/dist/entities/responses/imageMessage.js +0 -17
- package/dist/entities/responses/reaction.d.ts +0 -14
- package/dist/entities/responses/reaction.d.ts.map +0 -1
- package/dist/entities/responses/reaction.js +0 -15
- package/dist/entities/responses/textMessage.d.ts +0 -16
- package/dist/entities/responses/textMessage.d.ts.map +0 -1
- package/dist/entities/responses/textMessage.js +0 -17
- package/dist/entities/responses/unpin.d.ts +0 -12
- package/dist/entities/responses/unpin.d.ts.map +0 -1
- package/dist/entities/responses/unpin.js +0 -14
- package/dist/entities/responses/videoMessage.d.ts +0 -17
- package/dist/entities/responses/videoMessage.d.ts.map +0 -1
- package/dist/entities/responses/videoMessage.js +0 -17
- package/dist/helpers/inverseRecord.d.ts +0 -2
- package/dist/helpers/inverseRecord.d.ts.map +0 -1
- package/dist/helpers/inverseRecord.js +0 -6
- package/dist/helpers/reverseMap.d.ts +0 -2
- package/dist/helpers/reverseMap.d.ts.map +0 -1
- package/dist/helpers/reverseMap.js +0 -6
- package/dist/helpers/reverseRecord.d.ts +0 -2
- package/dist/helpers/reverseRecord.d.ts.map +0 -1
- package/dist/helpers/reverseRecord.js +0 -6
- package/dist/services/logger.d.ts +0 -9
- package/dist/services/logger.d.ts.map +0 -1
- package/dist/services/logger.js +0 -28
- package/dist/services/taskScheduler.d.ts +0 -11
- package/dist/services/taskScheduler.d.ts.map +0 -1
- package/dist/services/taskScheduler.js +0 -33
- package/dist/types/daysOfTheWeek.d.ts +0 -10
- package/dist/types/daysOfTheWeek.d.ts.map +0 -1
- package/dist/types/daysOfTheWeek.js +0 -13
- package/dist/types/replyMessage.d.ts +0 -8
- package/dist/types/replyMessage.d.ts.map +0 -1
- package/dist/types/replyMessage.js +0 -2
package/dtos/responses/unpin.ts
CHANGED
package/entities/botInstance.ts
CHANGED
|
@@ -212,7 +212,7 @@ export class BotInstance {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
this.api.flushResponses();
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
private async processMessage(msg: IncomingMessage) {
|
|
@@ -240,6 +240,6 @@ export class BotInstance {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
this.api.flushResponses();
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -145,10 +145,10 @@ export class ChatContext<TActionState extends IActionState> {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Delays next
|
|
148
|
+
* Delays next responses by specified amount of time.
|
|
149
149
|
* @param delay Delay in milliseconds.
|
|
150
150
|
*/
|
|
151
|
-
|
|
151
|
+
wait(delay: Milliseconds) {
|
|
152
152
|
this.responses.push(
|
|
153
153
|
new DelayResponse(delay, this.chatInfo, this.traceId, this.action)
|
|
154
154
|
);
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { setTimeout } from 'timers/promises';
|
|
2
|
+
import { Milliseconds } from '../types/timeValues';
|
|
3
|
+
|
|
4
|
+
export type QueueItem = {
|
|
5
|
+
priority: number;
|
|
6
|
+
callback: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const TELEGRAM_RATELIMIT_DELAY = 35 as Milliseconds;
|
|
10
|
+
|
|
11
|
+
export class ResponseProcessingQueue {
|
|
12
|
+
items: QueueItem[] = [];
|
|
13
|
+
isFlushing = false;
|
|
14
|
+
|
|
15
|
+
enqueue(item: QueueItem) {
|
|
16
|
+
if (
|
|
17
|
+
this.items.length === 0 ||
|
|
18
|
+
item.priority >= this.items[this.items.length - 1]!.priority
|
|
19
|
+
) {
|
|
20
|
+
this.items.push(item);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let insertIndex = this.items.length;
|
|
25
|
+
while (
|
|
26
|
+
insertIndex > 0 &&
|
|
27
|
+
this.items[insertIndex - 1]!.priority > item.priority
|
|
28
|
+
) {
|
|
29
|
+
insertIndex--;
|
|
30
|
+
}
|
|
31
|
+
this.items.splice(insertIndex, 0, item);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async flushReadyItems() {
|
|
35
|
+
if (this.isFlushing) return;
|
|
36
|
+
|
|
37
|
+
this.isFlushing = true;
|
|
38
|
+
|
|
39
|
+
while (this.items.length) {
|
|
40
|
+
if (Date.now() >= this.peek()!.priority) {
|
|
41
|
+
const item = this.items.shift();
|
|
42
|
+
|
|
43
|
+
if (!item) return;
|
|
44
|
+
|
|
45
|
+
await item.callback();
|
|
46
|
+
} else {
|
|
47
|
+
await setTimeout(TELEGRAM_RATELIMIT_DELAY);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.isFlushing = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private peek() {
|
|
55
|
+
return this.items[0];
|
|
56
|
+
}
|
|
57
|
+
}
|
package/services/telegramApi.ts
CHANGED
|
@@ -2,20 +2,16 @@ import { Message } from 'telegraf/types';
|
|
|
2
2
|
import { IStorageClient } from '../types/storage';
|
|
3
3
|
import { BotResponse, IReplyMessage } from '../types/response';
|
|
4
4
|
import { Telegram } from 'telegraf/typings/telegram';
|
|
5
|
-
import { setTimeout } from 'timers/promises';
|
|
6
|
-
import { Milliseconds } from '../types/timeValues';
|
|
7
5
|
import { ILogger } from '../types/logger';
|
|
8
|
-
|
|
9
|
-
const TELEGRAM_RATELIMIT_DELAY = 35 as Milliseconds;
|
|
6
|
+
import { QueueItem, ResponseProcessingQueue } from './responseProcessingQueue';
|
|
10
7
|
|
|
11
8
|
export class TelegramApiService {
|
|
9
|
+
private readonly queue = new ResponseProcessingQueue();
|
|
12
10
|
private readonly telegram: Telegram;
|
|
13
11
|
private readonly storage: IStorageClient;
|
|
14
12
|
private readonly logger: ILogger;
|
|
15
13
|
|
|
16
14
|
private readonly botName: string;
|
|
17
|
-
private readonly messageQueue: BotResponse[] = [];
|
|
18
|
-
isFlushing = false;
|
|
19
15
|
|
|
20
16
|
constructor(
|
|
21
17
|
botName: string,
|
|
@@ -30,36 +26,35 @@ export class TelegramApiService {
|
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
enqueueBatchedResponses(responses: BotResponse[]) {
|
|
29
|
+
let offset = 0;
|
|
33
30
|
for (const response of responses) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
async flushResponses() {
|
|
39
|
-
if (this.isFlushing) return;
|
|
40
|
-
|
|
41
|
-
this.isFlushing = true;
|
|
42
|
-
|
|
43
|
-
while (this.messageQueue.length) {
|
|
44
|
-
const message = this.messageQueue.shift();
|
|
45
|
-
|
|
46
|
-
if (!message) break;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
await this.processResponse(message);
|
|
50
|
-
await setTimeout(TELEGRAM_RATELIMIT_DELAY);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
this.logger.errorWithTraceId(
|
|
53
|
-
this.botName,
|
|
54
|
-
message.traceId,
|
|
55
|
-
message.chatInfo.name,
|
|
56
|
-
error,
|
|
57
|
-
message
|
|
58
|
-
);
|
|
31
|
+
if (response.kind == 'delay') {
|
|
32
|
+
offset += response.delay;
|
|
33
|
+
continue;
|
|
59
34
|
}
|
|
35
|
+
|
|
36
|
+
const queueItem: QueueItem = {
|
|
37
|
+
callback: async () => {
|
|
38
|
+
try {
|
|
39
|
+
await this.processResponse(response);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
this.logger.errorWithTraceId(
|
|
42
|
+
this.botName,
|
|
43
|
+
response.traceId,
|
|
44
|
+
response.chatInfo.name,
|
|
45
|
+
error,
|
|
46
|
+
response
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
priority: response.createdAt + offset
|
|
51
|
+
};
|
|
52
|
+
this.queue.enqueue(queueItem);
|
|
60
53
|
}
|
|
54
|
+
}
|
|
61
55
|
|
|
62
|
-
|
|
56
|
+
flushResponses() {
|
|
57
|
+
this.queue.flushReadyItems();
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
private async pinIfShould<T>(
|
|
@@ -156,9 +151,7 @@ export class TelegramApiService {
|
|
|
156
151
|
);
|
|
157
152
|
break;
|
|
158
153
|
case 'delay':
|
|
159
|
-
|
|
160
|
-
await setTimeout(response.delay - TELEGRAM_RATELIMIT_DELAY);
|
|
161
|
-
}
|
|
154
|
+
break;
|
|
162
155
|
}
|
|
163
156
|
}
|
|
164
157
|
}
|
package/types/response.ts
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IActionState } from '../types/actionState';
|
|
2
|
-
export declare class ActionExecutionResult<TActionState extends IActionState> {
|
|
3
|
-
readonly data: TActionState;
|
|
4
|
-
readonly shouldUpdate: boolean;
|
|
5
|
-
constructor(data: TActionState, shouldUpdate: boolean);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=actionExecutionResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actionExecutionResult.d.ts","sourceRoot":"","sources":["../../dtos/actionExecutionResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,qBAAa,qBAAqB,CAAC,YAAY,SAAS,YAAY;IAChE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;gBAEnB,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO;CAIxD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionExecutionResult = void 0;
|
|
4
|
-
class ActionExecutionResult {
|
|
5
|
-
constructor(data, shouldUpdate) {
|
|
6
|
-
this.data = data;
|
|
7
|
-
this.shouldUpdate = shouldUpdate;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.ActionExecutionResult = ActionExecutionResult;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IActionState } from '../types/actionState';
|
|
2
|
-
export declare class ActionExecutionResult<TActionState extends IActionState> {
|
|
3
|
-
data: TActionState;
|
|
4
|
-
shouldUpdate: boolean;
|
|
5
|
-
constructor(data: TActionState, shouldUpdate: boolean);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=actionExecutionResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actionExecutionResult.d.ts","sourceRoot":"","sources":["../../entities/actionExecutionResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,qBAAa,qBAAqB,CAAC,YAAY,SAAS,YAAY;IAChE,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;gBAEV,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO;CAIxD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionExecutionResult = void 0;
|
|
4
|
-
class ActionExecutionResult {
|
|
5
|
-
constructor(data, shouldUpdate) {
|
|
6
|
-
this.data = data;
|
|
7
|
-
this.shouldUpdate = shouldUpdate;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.ActionExecutionResult = ActionExecutionResult;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class CommandTriggerCheckResult {
|
|
2
|
-
static get DontTriggerAndSkipCooldown(): CommandTriggerCheckResult;
|
|
3
|
-
static get DoNotTrigger(): CommandTriggerCheckResult;
|
|
4
|
-
shouldTrigger: boolean;
|
|
5
|
-
matchResults: RegExpExecArray[];
|
|
6
|
-
skipCooldown: boolean;
|
|
7
|
-
constructor(shouldTrigger: boolean, matchResults: RegExpExecArray[], skipCooldown: boolean);
|
|
8
|
-
mergeWith(other: CommandTriggerCheckResult): this;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=commandTriggerCheckResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commandTriggerCheckResult.d.ts","sourceRoot":"","sources":["../../entities/commandTriggerCheckResult.ts"],"names":[],"mappings":"AAAA,qBAAa,yBAAyB;IAClC,MAAM,KAAK,0BAA0B,8BAEpC;IACD,MAAM,KAAK,YAAY,8BAEtB;IAED,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;gBAGlB,aAAa,EAAE,OAAO,EACtB,YAAY,EAAE,eAAe,EAAE,EAC/B,YAAY,EAAE,OAAO;IAOzB,SAAS,CAAC,KAAK,EAAE,yBAAyB;CAO7C"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandTriggerCheckResult = void 0;
|
|
4
|
-
class CommandTriggerCheckResult {
|
|
5
|
-
static get DontTriggerAndSkipCooldown() {
|
|
6
|
-
return new CommandTriggerCheckResult(false, [], true);
|
|
7
|
-
}
|
|
8
|
-
static get DoNotTrigger() {
|
|
9
|
-
return new CommandTriggerCheckResult(false, [], false);
|
|
10
|
-
}
|
|
11
|
-
constructor(shouldTrigger, matchResults, skipCooldown) {
|
|
12
|
-
this.shouldTrigger = shouldTrigger;
|
|
13
|
-
this.matchResults = matchResults;
|
|
14
|
-
this.skipCooldown = skipCooldown;
|
|
15
|
-
}
|
|
16
|
-
mergeWith(other) {
|
|
17
|
-
this.shouldTrigger = this.shouldTrigger || other.shouldTrigger;
|
|
18
|
-
this.matchResults = this.matchResults.concat(other.matchResults);
|
|
19
|
-
this.skipCooldown = this.skipCooldown || other.skipCooldown;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.CommandTriggerCheckResult = CommandTriggerCheckResult;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Chat, Message, Update, User } from 'telegraf/types';
|
|
2
|
-
import { MessageTypeValue } from '../types/messageTypes';
|
|
3
|
-
export declare class IncomingMessage {
|
|
4
|
-
message_id: number;
|
|
5
|
-
chat: Chat;
|
|
6
|
-
from: User | undefined;
|
|
7
|
-
text: string;
|
|
8
|
-
chatName: string;
|
|
9
|
-
type: MessageTypeValue;
|
|
10
|
-
traceId: number;
|
|
11
|
-
private detectMessageType;
|
|
12
|
-
constructor(ctxMessage: Update.New & (Update.NonChannel & Message));
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=incomingMessage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../entities/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,qBAAa,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,SAA2B;IAElC,OAAO,CAAC,iBAAiB;gBAkBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAWrE"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IncomingMessage = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const messageTypes_1 = require("../types/messageTypes");
|
|
6
|
-
class IncomingMessage {
|
|
7
|
-
detectMessageType(message) {
|
|
8
|
-
if ('text' in message)
|
|
9
|
-
return messageTypes_1.MessageType.Text;
|
|
10
|
-
if ('photo' in message)
|
|
11
|
-
return messageTypes_1.MessageType.Photo;
|
|
12
|
-
if ('sticker' in message)
|
|
13
|
-
return messageTypes_1.MessageType.Sticker;
|
|
14
|
-
if ('animation' in message)
|
|
15
|
-
return messageTypes_1.MessageType.Animation;
|
|
16
|
-
if ('voice' in message)
|
|
17
|
-
return messageTypes_1.MessageType.Voice;
|
|
18
|
-
if ('audio' in message)
|
|
19
|
-
return messageTypes_1.MessageType.Audio;
|
|
20
|
-
if ('document' in message)
|
|
21
|
-
return messageTypes_1.MessageType.Document;
|
|
22
|
-
if ('left_chat_member' in message)
|
|
23
|
-
return messageTypes_1.MessageType.LeftChatMember;
|
|
24
|
-
if ('new_chat_member' in message)
|
|
25
|
-
return messageTypes_1.MessageType.NewChatMember;
|
|
26
|
-
if ('poll' in message)
|
|
27
|
-
return messageTypes_1.MessageType.Poll;
|
|
28
|
-
if ('location' in message)
|
|
29
|
-
return messageTypes_1.MessageType.Location;
|
|
30
|
-
return messageTypes_1.MessageType.Unknown;
|
|
31
|
-
}
|
|
32
|
-
constructor(ctxMessage) {
|
|
33
|
-
this.traceId = (0, crypto_1.randomInt)(10000, 99999);
|
|
34
|
-
this.message_id = ctxMessage.message_id;
|
|
35
|
-
this.chat = ctxMessage.chat;
|
|
36
|
-
this.from = ctxMessage.from;
|
|
37
|
-
this.text = 'text' in ctxMessage ? ctxMessage.text : '';
|
|
38
|
-
this.type = this.detectMessageType(ctxMessage);
|
|
39
|
-
this.chatName =
|
|
40
|
-
'title' in ctxMessage.chat
|
|
41
|
-
? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
|
|
42
|
-
: 'DM';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.IncomingMessage = IncomingMessage;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IActionState } from '../../types/actionState';
|
|
2
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
-
import { IChatResponse } from '../../types/response';
|
|
4
|
-
import { Milliseconds } from '../../types/timeValues';
|
|
5
|
-
export declare class DelayResponse implements IChatResponse {
|
|
6
|
-
kind: "delay";
|
|
7
|
-
chatId: number;
|
|
8
|
-
traceId: number | string;
|
|
9
|
-
delay: Milliseconds;
|
|
10
|
-
action: IActionWithState<IActionState>;
|
|
11
|
-
constructor(delay: Milliseconds, chatId: number, traceId: number | string, action: IActionWithState<IActionState>);
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../entities/responses/delay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,qBAAa,aAAc,YAAW,aAAa;IAC/C,IAAI,UAA0B;IAE9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAO7C"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DelayResponse = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class DelayResponse {
|
|
6
|
-
constructor(delay, chatId, traceId, action) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.delay;
|
|
8
|
-
this.chatId = chatId;
|
|
9
|
-
this.delay = delay;
|
|
10
|
-
this.traceId = traceId;
|
|
11
|
-
this.action = action;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.DelayResponse = DelayResponse;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { InputFile } from 'telegraf/types';
|
|
2
|
-
import { IReplyMessage } from '../../types/response';
|
|
3
|
-
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
-
import { IActionState } from '../../types/actionState';
|
|
6
|
-
export declare class ImageMessage implements IReplyMessage<InputFile> {
|
|
7
|
-
kind: "image";
|
|
8
|
-
content: InputFile;
|
|
9
|
-
chatId: number;
|
|
10
|
-
replyId: number | undefined;
|
|
11
|
-
traceId: string | number;
|
|
12
|
-
disableWebPreview: boolean;
|
|
13
|
-
shouldPin: boolean;
|
|
14
|
-
action: IActionWithState<IActionState>;
|
|
15
|
-
constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState<IActionState>, options?: MessageSendingOptions);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=imageMessage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,qBAAqB;CAStC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageMessage = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class ImageMessage {
|
|
6
|
-
constructor(image, chatId, replyId, traceId, action, options) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.image;
|
|
8
|
-
this.disableWebPreview = false;
|
|
9
|
-
this.content = image;
|
|
10
|
-
this.chatId = chatId;
|
|
11
|
-
this.replyId = replyId;
|
|
12
|
-
this.traceId = traceId;
|
|
13
|
-
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.action = action;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.ImageMessage = ImageMessage;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TelegramEmoji } from 'telegraf/types';
|
|
2
|
-
import { IChatResponse } from '../../types/response';
|
|
3
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
-
import { IActionState } from '../../types/actionState';
|
|
5
|
-
export declare class Reaction implements IChatResponse {
|
|
6
|
-
kind: "react";
|
|
7
|
-
chatId: number;
|
|
8
|
-
messageId: number;
|
|
9
|
-
traceId: number | string;
|
|
10
|
-
emoji: TelegramEmoji;
|
|
11
|
-
action: IActionWithState<IActionState>;
|
|
12
|
-
constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji, action: IActionWithState<IActionState>);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=reaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAQ7C"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Reaction = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class Reaction {
|
|
6
|
-
constructor(traceId, chatId, messageId, emoji, action) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.react;
|
|
8
|
-
this.chatId = chatId;
|
|
9
|
-
this.messageId = messageId;
|
|
10
|
-
this.emoji = emoji;
|
|
11
|
-
this.traceId = traceId;
|
|
12
|
-
this.action = action;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.Reaction = Reaction;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
|
|
2
|
-
import { IReplyMessage } from '../../types/response';
|
|
3
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
4
|
-
import { IActionState } from '../../types/actionState';
|
|
5
|
-
export declare class TextMessage implements IReplyMessage<string> {
|
|
6
|
-
kind: "text";
|
|
7
|
-
content: string;
|
|
8
|
-
chatId: number;
|
|
9
|
-
replyId: number | undefined;
|
|
10
|
-
traceId: string | number;
|
|
11
|
-
disableWebPreview: boolean;
|
|
12
|
-
shouldPin: boolean;
|
|
13
|
-
action: IActionWithState<IActionState>;
|
|
14
|
-
constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number, action: IActionWithState<IActionState>, options?: TextMessageSendingOptions);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=textMessage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"textMessage.d.ts","sourceRoot":"","sources":["../../../entities/responses/textMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,yBAAyB;CAU1C"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextMessage = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class TextMessage {
|
|
6
|
-
constructor(text, chatId, replyId, traceId, action, options) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.text;
|
|
8
|
-
this.content = text;
|
|
9
|
-
this.chatId = chatId;
|
|
10
|
-
this.replyId = replyId;
|
|
11
|
-
this.traceId = traceId;
|
|
12
|
-
this.disableWebPreview = options?.disableWebPreview ?? false;
|
|
13
|
-
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.action = action;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.TextMessage = TextMessage;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IChatResponse } from '../../types/response';
|
|
2
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
3
|
-
import { IActionState } from '../../types/actionState';
|
|
4
|
-
export declare class UnpinResponse implements IChatResponse {
|
|
5
|
-
kind: "unpin";
|
|
6
|
-
messageId: number;
|
|
7
|
-
chatId: number;
|
|
8
|
-
traceId: number | string;
|
|
9
|
-
action: IActionWithState<IActionState>;
|
|
10
|
-
constructor(messageId: number, chatId: number, traceId: number | string, action: IActionWithState<IActionState>);
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=unpin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unpin.d.ts","sourceRoot":"","sources":["../../../entities/responses/unpin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC;CAO7C"}
|
|
@@ -1,14 +0,0 @@
|
|
|
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, action) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.unpin;
|
|
8
|
-
this.messageId = messageId;
|
|
9
|
-
this.chatId = chatId;
|
|
10
|
-
this.traceId = traceId;
|
|
11
|
-
this.action = action;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.UnpinResponse = UnpinResponse;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { InputFile } from 'telegraf/types';
|
|
2
|
-
import { IReplyMessage } from '../../types/response';
|
|
3
|
-
import { MessageSendingOptions } from '../../types/messageSendingOptions';
|
|
4
|
-
import { IActionWithState } from '../../types/actionWithState';
|
|
5
|
-
import { IActionState } from '../../types/actionState';
|
|
6
|
-
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
7
|
-
kind: "video";
|
|
8
|
-
content: InputFile;
|
|
9
|
-
chatId: number;
|
|
10
|
-
replyId: number | undefined;
|
|
11
|
-
traceId: string | number;
|
|
12
|
-
disableWebPreview: boolean;
|
|
13
|
-
shouldPin: boolean;
|
|
14
|
-
action: IActionWithState<IActionState>;
|
|
15
|
-
constructor(video: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState<IActionState>, options?: MessageSendingOptions);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=videoMessage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,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,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGnC,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,CAAC,EAAE,qBAAqB;CAStC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VideoMessage = void 0;
|
|
4
|
-
const response_1 = require("../../types/response");
|
|
5
|
-
class VideoMessage {
|
|
6
|
-
constructor(video, chatId, replyId, traceId, action, options) {
|
|
7
|
-
this.kind = response_1.BotResponseTypes.video;
|
|
8
|
-
this.disableWebPreview = false;
|
|
9
|
-
this.content = video;
|
|
10
|
-
this.chatId = chatId;
|
|
11
|
-
this.replyId = replyId;
|
|
12
|
-
this.traceId = traceId;
|
|
13
|
-
this.shouldPin = options?.pin ?? false;
|
|
14
|
-
this.action = action;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.VideoMessage = VideoMessage;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inverseRecord.d.ts","sourceRoot":"","sources":["../../helpers/inverseRecord.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,WAAW,EACtE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAId,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CACpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reverseMap.d.ts","sourceRoot":"","sources":["../../helpers/reverseMap.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAE1D"}
|