chz-telegram-bot 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entities/actionExecutionResult.d.ts +7 -0
- package/dist/entities/actionExecutionResult.d.ts.map +1 -0
- package/dist/entities/{transactionResult.js → actionExecutionResult.js} +3 -2
- package/dist/entities/actions/commandAction.d.ts +4 -4
- package/dist/entities/actions/commandAction.d.ts.map +1 -1
- package/dist/entities/actions/commandAction.js +12 -11
- package/dist/entities/actions/scheduledAction.d.ts +5 -5
- package/dist/entities/actions/scheduledAction.d.ts.map +1 -1
- package/dist/entities/actions/scheduledAction.js +10 -9
- package/dist/entities/{bot.d.ts → botInstance.d.ts} +5 -5
- package/dist/entities/botInstance.d.ts.map +1 -0
- package/dist/entities/{bot.js → botInstance.js} +18 -20
- package/dist/entities/cachedStateFactory.d.ts +1 -1
- package/dist/entities/cachedStateFactory.d.ts.map +1 -1
- package/dist/entities/cachedStateFactory.js +2 -1
- package/dist/entities/commandTriggerCheckResult.d.ts +1 -1
- package/dist/entities/commandTriggerCheckResult.d.ts.map +1 -1
- package/dist/entities/commandTriggerCheckResult.js +2 -1
- package/dist/entities/context/chatContext.d.ts +1 -1
- package/dist/entities/context/chatContext.d.ts.map +1 -1
- package/dist/entities/context/chatContext.js +8 -10
- package/dist/entities/context/messageContext.d.ts +3 -3
- package/dist/entities/context/messageContext.d.ts.map +1 -1
- package/dist/entities/context/messageContext.js +14 -16
- package/dist/entities/incomingMessage.d.ts +1 -1
- package/dist/entities/incomingMessage.d.ts.map +1 -1
- package/dist/entities/incomingMessage.js +2 -1
- package/dist/entities/responses/imageMessage.d.ts +2 -2
- package/dist/entities/responses/imageMessage.d.ts.map +1 -1
- package/dist/entities/responses/imageMessage.js +2 -1
- package/dist/entities/responses/reaction.d.ts +1 -1
- package/dist/entities/responses/reaction.d.ts.map +1 -1
- package/dist/entities/responses/reaction.js +2 -1
- package/dist/entities/responses/textMessage.d.ts +2 -2
- package/dist/entities/responses/textMessage.d.ts.map +1 -1
- package/dist/entities/responses/textMessage.js +2 -1
- package/dist/entities/responses/videoMessage.d.ts +2 -2
- package/dist/entities/responses/videoMessage.d.ts.map +1 -1
- package/dist/entities/responses/videoMessage.js +2 -1
- package/dist/entities/states/actionStateBase.d.ts +2 -2
- package/dist/entities/states/actionStateBase.d.ts.map +1 -1
- package/dist/entities/states/actionStateBase.js +2 -1
- package/dist/entities/taskRecord.d.ts +1 -1
- package/dist/entities/taskRecord.d.ts.map +1 -1
- package/dist/entities/taskRecord.js +2 -1
- package/dist/helpers/builders/commandActionBuilder.d.ts +3 -3
- package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/commandActionBuilder.js +9 -12
- package/dist/helpers/builders/scheduledActionBuilder.d.ts +3 -3
- package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -1
- package/dist/helpers/builders/scheduledActionBuilder.js +8 -10
- package/dist/helpers/noop.d.ts +1 -2
- package/dist/helpers/noop.d.ts.map +1 -1
- package/dist/helpers/noop.js +2 -1
- package/dist/helpers/toArray.d.ts +1 -1
- package/dist/helpers/toArray.d.ts.map +1 -1
- package/dist/helpers/toArray.js +1 -1
- package/dist/main.d.ts +5 -5
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -9
- package/dist/services/jsonFileStorage.d.ts +5 -5
- package/dist/services/jsonFileStorage.d.ts.map +1 -1
- package/dist/services/jsonFileStorage.js +2 -1
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.d.ts.map +1 -1
- package/dist/services/logger.js +3 -2
- package/dist/services/taskScheduler.d.ts +3 -3
- package/dist/services/taskScheduler.d.ts.map +1 -1
- package/dist/services/taskScheduler.js +8 -10
- package/dist/services/telegramApi.d.ts +7 -7
- package/dist/services/telegramApi.d.ts.map +1 -1
- package/dist/services/telegramApi.js +17 -19
- package/dist/types/actionState.d.ts +1 -1
- package/dist/types/actionState.d.ts.map +1 -1
- package/dist/types/actionWithState.d.ts +2 -2
- package/dist/types/actionWithState.d.ts.map +1 -1
- package/dist/types/commandCondition.d.ts +2 -2
- package/dist/types/commandCondition.d.ts.map +1 -1
- package/dist/types/handlers.d.ts +3 -3
- package/dist/types/handlers.d.ts.map +1 -1
- package/dist/types/replyMessage.d.ts +1 -1
- package/dist/types/replyMessage.d.ts.map +1 -1
- package/dist/types/storage.d.ts +4 -4
- package/dist/types/storage.d.ts.map +1 -1
- package/entities/{transactionResult.ts → actionExecutionResult.ts} +2 -2
- package/entities/actions/commandAction.ts +10 -10
- package/entities/actions/scheduledAction.ts +13 -13
- package/entities/{bot.ts → botInstance.ts} +17 -17
- package/entities/cachedStateFactory.ts +1 -1
- package/entities/commandTriggerCheckResult.ts +1 -1
- package/entities/context/chatContext.ts +4 -4
- package/entities/context/messageContext.ts +8 -8
- package/entities/incomingMessage.ts +1 -1
- package/entities/responses/imageMessage.ts +2 -2
- package/entities/responses/reaction.ts +1 -1
- package/entities/responses/textMessage.ts +2 -2
- package/entities/responses/videoMessage.ts +2 -2
- package/entities/states/actionStateBase.ts +2 -2
- package/entities/taskRecord.ts +1 -1
- package/helpers/builders/commandActionBuilder.ts +5 -5
- package/helpers/builders/scheduledActionBuilder.ts +4 -4
- package/helpers/noop.ts +1 -3
- package/helpers/toArray.ts +1 -1
- package/main.ts +9 -9
- package/package.json +1 -1
- package/services/jsonFileStorage.ts +6 -6
- package/services/logger.ts +2 -2
- package/services/taskScheduler.ts +6 -6
- package/services/telegramApi.ts +15 -15
- package/types/actionState.ts +1 -1
- package/types/actionWithState.ts +2 -2
- package/types/commandCondition.ts +2 -2
- package/types/handlers.ts +3 -3
- package/types/replyMessage.ts +1 -1
- package/types/storage.ts +4 -5
- package/dist/entities/bot.d.ts.map +0 -1
- package/dist/entities/transactionResult.d.ts +0 -7
- package/dist/entities/transactionResult.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InputFile } from 'telegraf/types';
|
|
2
|
-
import IReplyMessage from '../../types/replyMessage';
|
|
3
|
-
export
|
|
2
|
+
import { IReplyMessage } from '../../types/replyMessage';
|
|
3
|
+
export declare class VideoMessage implements IReplyMessage<InputFile> {
|
|
4
4
|
content: InputFile;
|
|
5
5
|
chatId: number;
|
|
6
6
|
replyId: number | undefined;
|
|
@@ -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,aAAa,MAAM,0BAA0B,CAAC;
|
|
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,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,qBAAa,YAAa,YAAW,aAAa,CAAC,SAAS,CAAC;IACzD,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;gBAGtB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM;CAO/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VideoMessage = void 0;
|
|
3
4
|
class VideoMessage {
|
|
4
5
|
constructor(video, chatId, replyId, traceId) {
|
|
5
6
|
this.disableWebPreview = false;
|
|
@@ -9,4 +10,4 @@ class VideoMessage {
|
|
|
9
10
|
this.traceId = traceId;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
exports.
|
|
13
|
+
exports.VideoMessage = VideoMessage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import IActionState from '../../types/actionState';
|
|
2
|
-
export
|
|
1
|
+
import { IActionState } from '../../types/actionState';
|
|
2
|
+
export declare class ActionStateBase implements IActionState {
|
|
3
3
|
lastExecutedDate: number;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=actionStateBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionStateBase.d.ts","sourceRoot":"","sources":["../../../entities/states/actionStateBase.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,yBAAyB,CAAC;
|
|
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,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionStateBase = void 0;
|
|
3
4
|
class ActionStateBase {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.lastExecutedDate = 0;
|
|
6
7
|
}
|
|
7
8
|
}
|
|
8
|
-
exports.
|
|
9
|
+
exports.ActionStateBase = ActionStateBase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,
|
|
1
|
+
{"version":3,"file":"taskRecord.d.ts","sourceRoot":"","sources":["../../entities/taskRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;IACvB,QAAQ,EAAE,YAAY,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;CAK3E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskRecord = void 0;
|
|
3
4
|
class TaskRecord {
|
|
4
5
|
constructor(name, taskId, interval) {
|
|
5
6
|
this.name = name;
|
|
@@ -7,4 +8,4 @@ class TaskRecord {
|
|
|
7
8
|
this.interval = interval;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
|
-
exports.
|
|
11
|
+
exports.TaskRecord = TaskRecord;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import CommandAction from '../../entities/actions/commandAction';
|
|
2
|
-
import ActionStateBase from '../../entities/states/actionStateBase';
|
|
3
|
-
import IActionState from '../../types/actionState';
|
|
4
1
|
import { CommandHandler } from '../../types/handlers';
|
|
5
2
|
import { CommandCondition } from '../../types/commandCondition';
|
|
6
3
|
import { Seconds } from '../../types/timeValues';
|
|
4
|
+
import { CommandAction } from '../../entities/actions/commandAction';
|
|
5
|
+
import { ActionStateBase } from '../../entities/states/actionStateBase';
|
|
6
|
+
import { IActionState } from '../../types/actionState';
|
|
7
7
|
export declare class CommandActionBuilderWithState<TActionState extends IActionState> {
|
|
8
8
|
name: string;
|
|
9
9
|
trigger: string | RegExp | Array<string> | Array<RegExp>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"commandActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/commandActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD,qBAAa,6BAA6B,CAAC,YAAY,SAAS,YAAY;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAM;IAE9D,MAAM,UAAQ;IACd,eAAe,EAAE,OAAO,CAAgB;IACxC,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,YAAY,EAAE,MAAM,EAAE,CAAM;IAC5B,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAa;IAClD,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAa;gBAE1C,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY;IAK9D,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAM3D,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAM/B,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC;IAMxC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC;IAM9C,QAAQ;IAMR,QAAQ,CAAC,OAAO,EAAE,OAAO;IAMzB,UAAU,CAAC,MAAM,EAAE,MAAM;IAMzB,KAAK;CAaR;AAED,qBAAa,oBAAqB,SAAQ,6BAA6B,CAAC,eAAe,CAAC;gBACxE,IAAI,EAAE,MAAM;CAG3B"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CommandActionBuilder = exports.CommandActionBuilderWithState = void 0;
|
|
7
|
-
const commandAction_1 =
|
|
8
|
-
const actionStateBase_1 =
|
|
9
|
-
const toArray_1 =
|
|
10
|
-
const noop_1 =
|
|
4
|
+
const commandAction_1 = require("../../entities/actions/commandAction");
|
|
5
|
+
const actionStateBase_1 = require("../../entities/states/actionStateBase");
|
|
6
|
+
const toArray_1 = require("../toArray");
|
|
7
|
+
const noop_1 = require("../noop");
|
|
11
8
|
class CommandActionBuilderWithState {
|
|
12
9
|
constructor(name, stateConstructor) {
|
|
13
10
|
this.trigger = [];
|
|
@@ -15,8 +12,8 @@ class CommandActionBuilderWithState {
|
|
|
15
12
|
this.cooldownSeconds = 0;
|
|
16
13
|
this.blacklist = [];
|
|
17
14
|
this.allowedUsers = [];
|
|
18
|
-
this.handler = noop_1.
|
|
19
|
-
this.condition = noop_1.
|
|
15
|
+
this.handler = noop_1.Noop.call;
|
|
16
|
+
this.condition = noop_1.Noop.true;
|
|
20
17
|
this.name = name;
|
|
21
18
|
this.stateConstructor = stateConstructor;
|
|
22
19
|
}
|
|
@@ -25,7 +22,7 @@ class CommandActionBuilderWithState {
|
|
|
25
22
|
return this;
|
|
26
23
|
}
|
|
27
24
|
from(id) {
|
|
28
|
-
this.allowedUsers = (0, toArray_1.
|
|
25
|
+
this.allowedUsers = (0, toArray_1.toArray)(id);
|
|
29
26
|
return this;
|
|
30
27
|
}
|
|
31
28
|
do(handler) {
|
|
@@ -49,13 +46,13 @@ class CommandActionBuilderWithState {
|
|
|
49
46
|
return this;
|
|
50
47
|
}
|
|
51
48
|
build() {
|
|
52
|
-
return new commandAction_1.
|
|
49
|
+
return new commandAction_1.CommandAction(this.trigger, this.handler, this.name, this.active, this.cooldownSeconds, this.blacklist, this.allowedUsers, this.condition, this.stateConstructor);
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
exports.CommandActionBuilderWithState = CommandActionBuilderWithState;
|
|
56
53
|
class CommandActionBuilder extends CommandActionBuilderWithState {
|
|
57
54
|
constructor(name) {
|
|
58
|
-
super(name, () => new actionStateBase_1.
|
|
55
|
+
super(name, () => new actionStateBase_1.ActionStateBase());
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
exports.CommandActionBuilder = CommandActionBuilder;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import ScheduledAction from '../../entities/actions/scheduledAction';
|
|
2
|
-
import CachedStateFactory from '../../entities/cachedStateFactory';
|
|
1
|
+
import { ScheduledAction } from '../../entities/actions/scheduledAction';
|
|
2
|
+
import { CachedStateFactory } from '../../entities/cachedStateFactory';
|
|
3
3
|
import { ScheduledHandler } from '../../types/handlers';
|
|
4
4
|
import { Hours, HoursOfDay } from '../../types/timeValues';
|
|
5
|
-
export
|
|
5
|
+
export declare class ScheduledActionBuilder {
|
|
6
6
|
active: boolean;
|
|
7
7
|
time: HoursOfDay;
|
|
8
8
|
cachedStateFactories: Map<string, CachedStateFactory>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduledActionBuilder.d.ts","sourceRoot":"","sources":["../../../helpers/builders/scheduledActionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG3D,qBAAa,sBAAsB;IAC/B,MAAM,UAAQ;IACd,IAAI,EAAE,UAAU,CAAK;IACrB,oBAAoB,kCAAyC;IAC7D,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,OAAO,EAAE,gBAAgB,CAAa;IAEtC,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM;IAIxB,OAAO,CAAC,MAAM,EAAE,MAAM;IAMtB,KAAK,CAAC,IAAI,EAAE,UAAU;IAMtB,EAAE,CAAC,OAAO,EAAE,gBAAgB;IAM5B,eAAe,CACX,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,0BAA0B,GAAE,KAAmB;IAUnD,QAAQ;IAMR,KAAK;CAUR"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
3
|
+
exports.ScheduledActionBuilder = void 0;
|
|
4
|
+
const scheduledAction_1 = require("../../entities/actions/scheduledAction");
|
|
5
|
+
const cachedStateFactory_1 = require("../../entities/cachedStateFactory");
|
|
6
|
+
const noop_1 = require("../noop");
|
|
9
7
|
class ScheduledActionBuilder {
|
|
10
8
|
constructor(name) {
|
|
11
9
|
this.active = true;
|
|
12
10
|
this.time = 0;
|
|
13
11
|
this.cachedStateFactories = new Map();
|
|
14
12
|
this.whitelist = [];
|
|
15
|
-
this.handler = noop_1.
|
|
13
|
+
this.handler = noop_1.Noop.call;
|
|
16
14
|
this.name = name;
|
|
17
15
|
}
|
|
18
16
|
allowIn(chatId) {
|
|
@@ -28,7 +26,7 @@ class ScheduledActionBuilder {
|
|
|
28
26
|
return this;
|
|
29
27
|
}
|
|
30
28
|
withSharedCache(key, itemFactory, invalidationTimeoutInHours = 20) {
|
|
31
|
-
this.cachedStateFactories.set(key, new cachedStateFactory_1.
|
|
29
|
+
this.cachedStateFactories.set(key, new cachedStateFactory_1.CachedStateFactory(itemFactory, invalidationTimeoutInHours));
|
|
32
30
|
return this;
|
|
33
31
|
}
|
|
34
32
|
disabled() {
|
|
@@ -36,7 +34,7 @@ class ScheduledActionBuilder {
|
|
|
36
34
|
return this;
|
|
37
35
|
}
|
|
38
36
|
build() {
|
|
39
|
-
return new scheduledAction_1.
|
|
37
|
+
return new scheduledAction_1.ScheduledAction(this.name, this.handler, this.time, this.active, this.whitelist, this.cachedStateFactories);
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
|
-
exports.
|
|
40
|
+
exports.ScheduledActionBuilder = ScheduledActionBuilder;
|
package/dist/helpers/noop.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
declare class Noop {
|
|
1
|
+
export declare class Noop {
|
|
2
2
|
static true<T1>(arg1: T1): Promise<boolean>;
|
|
3
3
|
static false<T1>(arg1: T1): Promise<boolean>;
|
|
4
4
|
static call<T1, T2>(arg1: T1, arg2: T2): Promise<void>;
|
|
5
5
|
}
|
|
6
|
-
export default Noop;
|
|
7
6
|
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../helpers/noop.ts"],"names":[],"mappings":"AACA,qBAAa,IAAI;WACA,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;WAGjB,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;WAGlB,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAE/D"}
|
package/dist/helpers/noop.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Noop = void 0;
|
|
3
4
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
5
|
class Noop {
|
|
5
6
|
static async true(arg1) {
|
|
@@ -10,4 +11,4 @@ class Noop {
|
|
|
10
11
|
}
|
|
11
12
|
static async call(arg1) { }
|
|
12
13
|
}
|
|
13
|
-
exports.
|
|
14
|
+
exports.Noop = Noop;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function toArray<TType>(value: TType | TType[]): TType[];
|
|
2
2
|
//# sourceMappingURL=toArray.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toArray.d.ts","sourceRoot":"","sources":["../../helpers/toArray.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"toArray.d.ts","sourceRoot":"","sources":["../../helpers/toArray.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,WAEpD"}
|
package/dist/helpers/toArray.js
CHANGED
package/dist/main.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import CommandAction from './entities/actions/commandAction
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { IStorageClient } from './types/storage';
|
|
2
|
+
import { CommandAction } from './entities/actions/commandAction';
|
|
3
|
+
import { ScheduledAction } from './entities/actions/scheduledAction';
|
|
4
|
+
import { IActionState } from './types/actionState';
|
|
5
|
+
import { BotInstance } from './entities/botInstance';
|
|
6
6
|
declare function startBot(options: {
|
|
7
7
|
name: string;
|
|
8
8
|
tokenFilePath: string;
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAQrD,iBAAe,QAAQ,CAAC,OAAO,EAAE;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;IACxC,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,wBAcA;AAED,iBAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,iBASrC;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.startBot = startBot;
|
|
7
4
|
exports.stopBots = stopBots;
|
|
8
5
|
const promises_1 = require("fs/promises");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
6
|
+
const logger_1 = require("./services/logger");
|
|
7
|
+
const taskScheduler_1 = require("./services/taskScheduler");
|
|
8
|
+
const botInstance_1 = require("./entities/botInstance");
|
|
12
9
|
const bots = [];
|
|
13
10
|
function log(text) {
|
|
14
|
-
|
|
11
|
+
logger_1.Logger.logWithTraceId('ALL BOTS', 'System:Bot', 'System', text);
|
|
15
12
|
}
|
|
16
13
|
async function startBot(options) {
|
|
17
14
|
const token = await (0, promises_1.readFile)(options.tokenFilePath, 'utf8');
|
|
18
|
-
const bot = new
|
|
15
|
+
const bot = new botInstance_1.BotInstance({
|
|
19
16
|
name: options.name,
|
|
20
17
|
token,
|
|
21
18
|
commands: options.commands,
|
|
@@ -29,7 +26,7 @@ async function startBot(options) {
|
|
|
29
26
|
}
|
|
30
27
|
async function stopBots(reason) {
|
|
31
28
|
log(`Recieved termination code: ${reason}`);
|
|
32
|
-
|
|
29
|
+
taskScheduler_1.Scheduler.stopAll();
|
|
33
30
|
log('Acquiring storage semaphore...');
|
|
34
31
|
log('Stopping bots...');
|
|
35
32
|
for (const bot of bots) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import TransactionResult from '../entities/transactionResult';
|
|
2
|
-
import IActionState from '../types/actionState';
|
|
3
|
-
import IActionWithState from '../types/actionWithState';
|
|
4
1
|
import { Sema as Semaphore } from 'async-sema';
|
|
5
2
|
import { IStorageClient } from '../types/storage';
|
|
6
|
-
|
|
3
|
+
import { ActionExecutionResult } from '../entities/actionExecutionResult';
|
|
4
|
+
import { IActionState } from '../types/actionState';
|
|
5
|
+
import { IActionWithState } from '../types/actionWithState';
|
|
6
|
+
export declare class JsonFileStorage implements IStorageClient {
|
|
7
7
|
semaphore: Semaphore;
|
|
8
8
|
private cache;
|
|
9
9
|
private storagePath;
|
|
@@ -16,7 +16,7 @@ export default class JsonFileStorage implements IStorageClient {
|
|
|
16
16
|
load<TActionState extends IActionState>(key: string): Promise<Record<number, TActionState>>;
|
|
17
17
|
saveMetadata(actions: IActionWithState[], botName: string): Promise<void>;
|
|
18
18
|
getActionState<TActionState extends IActionState>(entity: IActionWithState, chatId: number): Promise<TActionState>;
|
|
19
|
-
saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult:
|
|
19
|
+
saveActionExecutionResult(action: IActionWithState, chatId: number, transactionResult: ActionExecutionResult): Promise<void>;
|
|
20
20
|
close(): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=jsonFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonFileStorage.d.ts","sourceRoot":"","sources":["../../services/jsonFileStorage.ts"],"names":[],"mappings":"
|
|
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;CAG/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonFileStorage = void 0;
|
|
3
4
|
const fs_1 = require("fs");
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
const promises_1 = require("fs/promises");
|
|
@@ -83,4 +84,4 @@ class JsonFileStorage {
|
|
|
83
84
|
await this.semaphore.acquire();
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
exports.
|
|
87
|
+
exports.JsonFileStorage = JsonFileStorage;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
declare class
|
|
1
|
+
declare class JsonLogger {
|
|
2
2
|
logWithTraceId(botName: string, traceId: string | number, chatName: string, text: string): void;
|
|
3
3
|
errorWithTraceId<TData>(botName: string, traceId: string | number, chatName: string, errorObj: string | Error, extraData?: TData | undefined): void;
|
|
4
4
|
}
|
|
5
|
-
declare const
|
|
6
|
-
export
|
|
5
|
+
export declare const Logger: JsonLogger;
|
|
6
|
+
export {};
|
|
7
7
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../services/logger.ts"],"names":[],"mappings":"AAAA,cAAM,
|
|
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,MAAM,GAAG,KAAK,EACxB,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS;CAYpC;AAED,eAAO,MAAM,MAAM,YAAmB,CAAC"}
|
package/dist/services/logger.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class JsonLogger {
|
|
4
5
|
logWithTraceId(botName, traceId, chatName, text) {
|
|
5
6
|
console.log(JSON.stringify({ botName, traceId, chatName, text }));
|
|
6
7
|
}
|
|
@@ -14,4 +15,4 @@ class Logger {
|
|
|
14
15
|
}));
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
exports.
|
|
18
|
+
exports.Logger = new JsonLogger();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import TaskRecord from '../entities/taskRecord';
|
|
1
|
+
import { TaskRecord } from '../entities/taskRecord';
|
|
2
2
|
import { Milliseconds } from '../types/timeValues';
|
|
3
3
|
declare class TaskScheduler {
|
|
4
4
|
activeTasks: TaskRecord[];
|
|
@@ -6,6 +6,6 @@ declare class TaskScheduler {
|
|
|
6
6
|
createTask(name: string, action: () => void, interval: Milliseconds, executeRightAway: boolean, ownerName: string): void;
|
|
7
7
|
createOnetimeTask(name: string, action: () => void, delay: Milliseconds, ownerName: string): void;
|
|
8
8
|
}
|
|
9
|
-
declare const
|
|
10
|
-
export
|
|
9
|
+
export declare const Scheduler: TaskScheduler;
|
|
10
|
+
export {};
|
|
11
11
|
//# sourceMappingURL=taskScheduler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"taskScheduler.d.ts","sourceRoot":"","sources":["../../services/taskScheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAW,MAAM,qBAAqB,CAAC;AAG5D,cAAM,aAAa;IACf,WAAW,EAAE,UAAU,EAAE,CAAM;IAE/B,OAAO;IAMP,UAAU,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM;IAoBrB,iBAAiB,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM;CAoBxB;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
3
|
+
exports.Scheduler = void 0;
|
|
4
|
+
const taskRecord_1 = require("../entities/taskRecord");
|
|
7
5
|
const timeConvertions_1 = require("../helpers/timeConvertions");
|
|
8
|
-
const logger_1 =
|
|
6
|
+
const logger_1 = require("./logger");
|
|
9
7
|
class TaskScheduler {
|
|
10
8
|
constructor() {
|
|
11
9
|
this.activeTasks = [];
|
|
@@ -18,20 +16,20 @@ class TaskScheduler {
|
|
|
18
16
|
createTask(name, action, interval, executeRightAway, ownerName) {
|
|
19
17
|
executeRightAway = executeRightAway ?? false;
|
|
20
18
|
const taskId = setInterval(action, interval);
|
|
21
|
-
const task = new taskRecord_1.
|
|
19
|
+
const task = new taskRecord_1.TaskRecord(name, taskId, interval);
|
|
22
20
|
if (executeRightAway) {
|
|
23
21
|
setTimeout(action, (0, timeConvertions_1.secondsToMilliseconds)(1));
|
|
24
22
|
}
|
|
25
|
-
logger_1.
|
|
23
|
+
logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created task [${taskId}]${name}, that will run every ${interval}ms.`);
|
|
26
24
|
this.activeTasks.push(task);
|
|
27
25
|
}
|
|
28
26
|
createOnetimeTask(name, action, delay, ownerName) {
|
|
29
27
|
const actionWrapper = () => {
|
|
30
|
-
logger_1.
|
|
28
|
+
logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Executing delayed oneshot [${taskId}]${name}`);
|
|
31
29
|
action();
|
|
32
30
|
};
|
|
33
31
|
const taskId = setTimeout(actionWrapper, delay);
|
|
34
|
-
logger_1.
|
|
32
|
+
logger_1.Logger.logWithTraceId(ownerName, `System:TaskScheduler-${ownerName}-${name}`, 'System', `Created oneshot task [${taskId}]${name}, that will run in ${delay}ms.`);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
exports.
|
|
35
|
+
exports.Scheduler = new TaskScheduler();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import MessageContext from '../entities/context/messageContext';
|
|
2
|
-
import ChatContext from '../entities/context/chatContext';
|
|
3
1
|
import { Telegraf } from 'telegraf';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
2
|
+
import { ChatContext } from '../entities/context/chatContext';
|
|
3
|
+
import { MessageContext } from '../entities/context/messageContext';
|
|
4
|
+
import { IReplyMessage } from '../types/replyMessage';
|
|
7
5
|
import { IStorageClient } from '../types/storage';
|
|
8
|
-
|
|
6
|
+
import { Reaction } from '../entities/responses/reaction';
|
|
7
|
+
import { IncomingMessage } from '../entities/incomingMessage';
|
|
8
|
+
export declare class TelegramApiService {
|
|
9
9
|
botName: string;
|
|
10
10
|
telegraf: Telegraf;
|
|
11
11
|
chats: Map<number, string>;
|
|
@@ -17,7 +17,7 @@ export default class TelegramApiService {
|
|
|
17
17
|
private enqueueResponse;
|
|
18
18
|
private enqueueReaction;
|
|
19
19
|
private getInteractions;
|
|
20
|
-
createContextForMessage(incomingMessage: IncomingMessage): MessageContext<import("
|
|
20
|
+
createContextForMessage(incomingMessage: IncomingMessage): MessageContext<import("..").IActionState>;
|
|
21
21
|
createContextForChat(chatId: number, scheduledName: string): ChatContext;
|
|
22
22
|
}
|
|
23
23
|
export interface IBotApiInteractions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAKpE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,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,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAM;IAC5D,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;YAkBf,eAAe;IAgE7B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,eAAe;IAOvB,uBAAuB,CAAC,eAAe,EAAE,eAAe;IAoBxD,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAU7D;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IACzD,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;CACvC"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const chatContext_1 =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
3
|
+
exports.TelegramApiService = void 0;
|
|
4
|
+
const chatContext_1 = require("../entities/context/chatContext");
|
|
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");
|
|
13
9
|
const reverseMap_1 = require("../helpers/reverseMap");
|
|
10
|
+
const taskScheduler_1 = require("./taskScheduler");
|
|
11
|
+
const logger_1 = require("./logger");
|
|
14
12
|
class TelegramApiService {
|
|
15
13
|
constructor(botName, telegraf, storage, chats) {
|
|
16
14
|
this.messageQueue = [];
|
|
@@ -18,7 +16,7 @@ class TelegramApiService {
|
|
|
18
16
|
this.botName = botName;
|
|
19
17
|
this.chats = (0, reverseMap_1.reverseMap)(chats);
|
|
20
18
|
this.storage = storage;
|
|
21
|
-
taskScheduler_1.
|
|
19
|
+
taskScheduler_1.Scheduler.createTask('MessageSending', () => {
|
|
22
20
|
this.dequeueResponse();
|
|
23
21
|
}, 100, false, this.botName);
|
|
24
22
|
}
|
|
@@ -30,7 +28,7 @@ class TelegramApiService {
|
|
|
30
28
|
await this.processResponse(message);
|
|
31
29
|
}
|
|
32
30
|
catch (error) {
|
|
33
|
-
logger_1.
|
|
31
|
+
logger_1.Logger.errorWithTraceId(this.botName, message.traceId, this.chats.get(message.chatId), error, message);
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
async processResponse(response) {
|
|
@@ -44,7 +42,7 @@ class TelegramApiService {
|
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
46
44
|
switch (response.constructor) {
|
|
47
|
-
case textMessage_1.
|
|
45
|
+
case textMessage_1.TextMessage:
|
|
48
46
|
await this.telegraf.telegram.sendMessage(response.chatId, response.content, {
|
|
49
47
|
reply_to_message_id: response.replyId,
|
|
50
48
|
parse_mode: 'MarkdownV2',
|
|
@@ -52,20 +50,20 @@ class TelegramApiService {
|
|
|
52
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
51
|
});
|
|
54
52
|
break;
|
|
55
|
-
case imageMessage_1.
|
|
53
|
+
case imageMessage_1.ImageMessage:
|
|
56
54
|
await this.telegraf.telegram.sendPhoto(response.chatId, response.content, response.replyId
|
|
57
55
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
56
|
{ reply_to_message_id: response.replyId }
|
|
59
57
|
: undefined);
|
|
60
58
|
break;
|
|
61
|
-
case videoMessage_1.
|
|
59
|
+
case videoMessage_1.VideoMessage:
|
|
62
60
|
await this.telegraf.telegram.sendVideo(response.chatId, response.content, response.replyId
|
|
63
61
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
62
|
{ reply_to_message_id: response.replyId }
|
|
65
63
|
: undefined);
|
|
66
64
|
break;
|
|
67
65
|
default:
|
|
68
|
-
logger_1.
|
|
66
|
+
logger_1.Logger.errorWithTraceId(this.botName, response.traceId, this.chats.get(response.chatId), `Unknown message type: ${response.constructor}`, response);
|
|
69
67
|
break;
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -86,10 +84,10 @@ class TelegramApiService {
|
|
|
86
84
|
const lastName = incomingMessage.from?.last_name
|
|
87
85
|
? ` ${incomingMessage.from?.last_name}`
|
|
88
86
|
: '';
|
|
89
|
-
return new messageContext_1.
|
|
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);
|
|
90
88
|
}
|
|
91
89
|
createContextForChat(chatId, scheduledName) {
|
|
92
|
-
return new chatContext_1.
|
|
90
|
+
return new chatContext_1.ChatContext(this.botName, this.getInteractions(), chatId, this.chats.get(chatId), `Scheduled:${scheduledName}:${chatId}`, this.storage);
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
exports.
|
|
93
|
+
exports.TelegramApiService = TelegramApiService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionState.d.ts","sourceRoot":"","sources":["../../types/actionState.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"actionState.d.ts","sourceRoot":"","sources":["../../types/actionState.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC5B"}
|