chz-telegram-bot 0.0.45 → 0.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/entities/actionExecutionResult.d.ts +7 -0
  2. package/dist/entities/actionExecutionResult.d.ts.map +1 -0
  3. package/dist/entities/actionExecutionResult.js +10 -0
  4. package/dist/entities/actions/commandAction.d.ts +23 -0
  5. package/dist/entities/actions/commandAction.d.ts.map +1 -0
  6. package/dist/entities/actions/commandAction.js +91 -0
  7. package/dist/entities/actions/scheduledAction.d.ts +24 -0
  8. package/dist/entities/actions/scheduledAction.d.ts.map +1 -0
  9. package/dist/entities/actions/scheduledAction.js +81 -0
  10. package/dist/entities/botInstance.d.ts +31 -0
  11. package/dist/entities/botInstance.d.ts.map +1 -0
  12. package/dist/entities/botInstance.js +107 -0
  13. package/dist/entities/cachedStateFactory.d.ts +7 -0
  14. package/dist/entities/cachedStateFactory.d.ts.map +1 -0
  15. package/dist/entities/cachedStateFactory.js +10 -0
  16. package/dist/entities/commandTriggerCheckResult.d.ts +10 -0
  17. package/dist/entities/commandTriggerCheckResult.d.ts.map +1 -0
  18. package/dist/entities/commandTriggerCheckResult.js +23 -0
  19. package/dist/entities/context/chatContext.d.ts +55 -0
  20. package/dist/entities/context/chatContext.d.ts.map +1 -0
  21. package/dist/entities/context/chatContext.js +70 -0
  22. package/dist/entities/context/messageContext.d.ts +60 -0
  23. package/dist/entities/context/messageContext.d.ts.map +1 -0
  24. package/dist/entities/context/messageContext.js +82 -0
  25. package/dist/entities/incomingMessage.d.ts +14 -0
  26. package/dist/entities/incomingMessage.d.ts.map +1 -0
  27. package/dist/entities/incomingMessage.js +45 -0
  28. package/dist/entities/responses/imageMessage.d.ts +17 -0
  29. package/dist/entities/responses/imageMessage.d.ts.map +1 -0
  30. package/dist/entities/responses/imageMessage.js +17 -0
  31. package/dist/entities/responses/reaction.d.ts +14 -0
  32. package/dist/entities/responses/reaction.d.ts.map +1 -0
  33. package/dist/entities/responses/reaction.js +15 -0
  34. package/dist/entities/responses/textMessage.d.ts +16 -0
  35. package/dist/entities/responses/textMessage.d.ts.map +1 -0
  36. package/dist/entities/responses/textMessage.js +17 -0
  37. package/dist/entities/responses/unpin.d.ts +12 -0
  38. package/dist/entities/responses/unpin.d.ts.map +1 -0
  39. package/dist/entities/responses/unpin.js +14 -0
  40. package/dist/entities/responses/videoMessage.d.ts +17 -0
  41. package/dist/entities/responses/videoMessage.d.ts.map +1 -0
  42. package/dist/entities/responses/videoMessage.js +17 -0
  43. package/dist/entities/states/actionStateBase.d.ts +6 -0
  44. package/dist/entities/states/actionStateBase.d.ts.map +1 -0
  45. package/dist/entities/states/actionStateBase.js +10 -0
  46. package/dist/entities/taskRecord.d.ts +8 -0
  47. package/dist/entities/taskRecord.d.ts.map +1 -0
  48. package/dist/entities/taskRecord.js +11 -0
  49. package/dist/helpers/builders/commandActionBuilder.d.ts +69 -0
  50. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -0
  51. package/dist/helpers/builders/commandActionBuilder.js +96 -0
  52. package/dist/helpers/builders/scheduledActionBuilder.d.ts +60 -0
  53. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -0
  54. package/dist/helpers/builders/scheduledActionBuilder.js +82 -0
  55. package/dist/helpers/inverseRecord.d.ts +2 -0
  56. package/dist/helpers/inverseRecord.d.ts.map +1 -0
  57. package/dist/helpers/inverseRecord.js +6 -0
  58. package/dist/helpers/noop.d.ts +6 -0
  59. package/dist/helpers/noop.d.ts.map +1 -0
  60. package/dist/helpers/noop.js +14 -0
  61. package/dist/helpers/reverseMap.d.ts +2 -0
  62. package/dist/helpers/reverseMap.d.ts.map +1 -0
  63. package/dist/helpers/reverseMap.js +6 -0
  64. package/dist/helpers/reverseRecord.d.ts +2 -0
  65. package/dist/helpers/reverseRecord.d.ts.map +1 -0
  66. package/dist/helpers/reverseRecord.js +6 -0
  67. package/dist/helpers/timeConvertions.d.ts +5 -0
  68. package/dist/helpers/timeConvertions.d.ts.map +1 -0
  69. package/dist/helpers/timeConvertions.js +14 -0
  70. package/dist/helpers/toArray.d.ts +2 -0
  71. package/dist/helpers/toArray.d.ts.map +1 -0
  72. package/dist/helpers/toArray.js +6 -0
  73. package/dist/index.d.ts +10 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +29 -0
  76. package/dist/main.d.ts +35 -0
  77. package/dist/main.d.ts.map +1 -0
  78. package/dist/main.js +43 -0
  79. package/dist/services/jsonFileStorage.d.ts +22 -0
  80. package/dist/services/jsonFileStorage.d.ts.map +1 -0
  81. package/dist/services/jsonFileStorage.js +102 -0
  82. package/dist/services/logger.d.ts +9 -0
  83. package/dist/services/logger.d.ts.map +1 -0
  84. package/dist/services/logger.js +28 -0
  85. package/dist/services/taskScheduler.d.ts +11 -0
  86. package/dist/services/taskScheduler.d.ts.map +1 -0
  87. package/dist/services/taskScheduler.js +33 -0
  88. package/dist/services/telegramApi.d.ts +36 -0
  89. package/dist/services/telegramApi.d.ts.map +1 -0
  90. package/dist/services/telegramApi.js +100 -0
  91. package/dist/types/actionState.d.ts +5 -0
  92. package/dist/types/actionState.d.ts.map +1 -0
  93. package/dist/types/actionState.js +2 -0
  94. package/dist/types/actionWithState.d.ts +9 -0
  95. package/dist/types/actionWithState.d.ts.map +1 -0
  96. package/dist/types/actionWithState.js +2 -0
  97. package/dist/types/cachedValueAccessor.d.ts +2 -0
  98. package/dist/types/cachedValueAccessor.d.ts.map +1 -0
  99. package/dist/types/cachedValueAccessor.js +2 -0
  100. package/dist/types/commandCondition.d.ts +4 -0
  101. package/dist/types/commandCondition.d.ts.map +1 -0
  102. package/dist/types/commandCondition.js +2 -0
  103. package/dist/types/commandTrigger.d.ts +3 -0
  104. package/dist/types/commandTrigger.d.ts.map +1 -0
  105. package/dist/types/commandTrigger.js +2 -0
  106. package/dist/types/daysOfTheWeek.d.ts +10 -0
  107. package/dist/types/daysOfTheWeek.d.ts.map +1 -0
  108. package/dist/types/daysOfTheWeek.js +13 -0
  109. package/dist/types/handlers.d.ts +17 -0
  110. package/dist/types/handlers.d.ts.map +1 -0
  111. package/dist/types/handlers.js +2 -0
  112. package/dist/types/messageSendingOptions.d.ts +7 -0
  113. package/dist/types/messageSendingOptions.d.ts.map +1 -0
  114. package/dist/types/messageSendingOptions.js +2 -0
  115. package/dist/types/messageTypes.d.ts +16 -0
  116. package/dist/types/messageTypes.d.ts.map +1 -0
  117. package/dist/types/messageTypes.js +17 -0
  118. package/dist/types/replyMessage.d.ts +8 -0
  119. package/dist/types/replyMessage.d.ts.map +1 -0
  120. package/dist/types/replyMessage.js +2 -0
  121. package/dist/types/response.d.ts +28 -0
  122. package/dist/types/response.d.ts.map +1 -0
  123. package/dist/types/response.js +10 -0
  124. package/dist/types/storage.d.ts +12 -0
  125. package/dist/types/storage.d.ts.map +1 -0
  126. package/dist/types/storage.js +2 -0
  127. package/dist/types/timeValues.d.ts +11 -0
  128. package/dist/types/timeValues.d.ts.map +1 -0
  129. package/dist/types/timeValues.js +2 -0
  130. package/entities/actionExecutionResult.ts +3 -3
  131. package/entities/actions/commandAction.ts +7 -2
  132. package/entities/actions/scheduledAction.ts +7 -2
  133. package/entities/context/chatContext.ts +4 -3
  134. package/entities/context/messageContext.ts +1 -1
  135. package/entities/responses/imageMessage.ts +3 -2
  136. package/entities/responses/reaction.ts +3 -2
  137. package/entities/responses/textMessage.ts +3 -2
  138. package/entities/responses/unpin.ts +3 -2
  139. package/entities/responses/videoMessage.ts +3 -2
  140. package/package.json +29 -29
  141. package/services/jsonFileStorage.ts +22 -13
  142. package/types/actionWithState.ts +2 -2
  143. package/types/response.ts +2 -1
  144. package/types/storage.ts +9 -6
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,23 @@
1
+ import { CommandHandler } from '../../types/handlers';
2
+ import { CommandCondition } from '../../types/commandCondition';
3
+ import { Seconds } from '../../types/timeValues';
4
+ import { IActionState } from '../../types/actionState';
5
+ import { IActionWithState, ActionKey } from '../../types/actionWithState';
6
+ import { MessageContext } from '../context/messageContext';
7
+ import { CommandTrigger } from '../../types/commandTrigger';
8
+ export declare class CommandAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
9
+ triggers: CommandTrigger[];
10
+ handler: CommandHandler<TActionState>;
11
+ name: string;
12
+ cooldownInSeconds: Seconds;
13
+ active: boolean;
14
+ chatsBlacklist: number[];
15
+ allowedUsers: number[];
16
+ condition: CommandCondition<TActionState>;
17
+ stateConstructor: () => TActionState;
18
+ key: ActionKey;
19
+ constructor(trigger: CommandTrigger | CommandTrigger[], handler: CommandHandler<TActionState>, name: string, active: boolean, cooldown: Seconds, chatsBlacklist: number[], allowedUsers: number[], condition: CommandCondition<TActionState>, stateConstructor: () => TActionState);
20
+ exec(ctx: MessageContext<TActionState>): Promise<void>;
21
+ private checkTrigger;
22
+ }
23
+ //# sourceMappingURL=commandAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,SAAS,CAAC;gBAGX,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY;IAelC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAkD5C,OAAO,CAAC,YAAY;CAwDvB"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CommandAction = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const timeConvertions_1 = require("../../helpers/timeConvertions");
9
+ const toArray_1 = require("../../helpers/toArray");
10
+ const commandTriggerCheckResult_1 = require("../commandTriggerCheckResult");
11
+ const logger_1 = require("../../services/logger");
12
+ const actionExecutionResult_1 = require("../actionExecutionResult");
13
+ class CommandAction {
14
+ constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor) {
15
+ this.triggers = (0, toArray_1.toArray)(trigger);
16
+ this.handler = handler;
17
+ this.name = name;
18
+ this.cooldownInSeconds = cooldown;
19
+ this.active = active;
20
+ this.chatsBlacklist = chatsBlacklist;
21
+ this.allowedUsers = allowedUsers;
22
+ this.condition = condition;
23
+ this.stateConstructor = stateConstructor;
24
+ this.key = `command:${this.name.replace('.', '-')}`;
25
+ }
26
+ async exec(ctx) {
27
+ if (!ctx.isInitialized)
28
+ throw new Error('Context is not initialized');
29
+ if (!this.active || this.chatsBlacklist.includes(ctx.chatId))
30
+ return;
31
+ const isConditionMet = await this.condition(ctx);
32
+ if (!isConditionMet)
33
+ return;
34
+ const state = await ctx.storage.getActionState(this, ctx.chatId);
35
+ const { shouldTrigger, matchResults, skipCooldown } = this.triggers
36
+ .map((x) => this.checkTrigger(ctx, x, state))
37
+ .reduce((acc, curr) => acc.mergeWith(curr), commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger);
38
+ if (!shouldTrigger)
39
+ return;
40
+ logger_1.Logger.logWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, ` - Executing [${this.name}] in ${ctx.chatId}`);
41
+ ctx.matchResults = matchResults;
42
+ await this.handler(ctx, state);
43
+ if (skipCooldown) {
44
+ ctx.startCooldown = false;
45
+ }
46
+ if (ctx.startCooldown) {
47
+ state.lastExecutedDate = (0, moment_1.default)().valueOf();
48
+ }
49
+ ctx.updateActions.forEach((action) => action(state));
50
+ await ctx.storage.saveActionExecutionResult(this, ctx.chatId, new actionExecutionResult_1.ActionExecutionResult(state, ctx.startCooldown && shouldTrigger));
51
+ }
52
+ checkTrigger(ctx, trigger, state) {
53
+ let shouldTrigger = false;
54
+ const matchResults = [];
55
+ if (!ctx.fromUserId)
56
+ return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
57
+ const isUserAllowed = this.allowedUsers.length == 0 ||
58
+ this.allowedUsers.includes(ctx.fromUserId);
59
+ if (!isUserAllowed)
60
+ return commandTriggerCheckResult_1.CommandTriggerCheckResult.DontTriggerAndSkipCooldown;
61
+ const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
62
+ const cooldownInMilliseconds = (0, timeConvertions_1.secondsToMilliseconds)(this.cooldownInSeconds);
63
+ const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
64
+ if (onCooldown)
65
+ return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
66
+ if (trigger == ctx.messageType) {
67
+ shouldTrigger = true;
68
+ }
69
+ else if (typeof trigger == 'string') {
70
+ shouldTrigger = ctx.messageText.toLowerCase() == trigger;
71
+ }
72
+ else {
73
+ trigger.lastIndex = 0;
74
+ const execResult = trigger.exec(ctx.messageText);
75
+ if (execResult != null) {
76
+ matchResults.push(execResult);
77
+ if (trigger.global) {
78
+ while (true) {
79
+ const nextResult = trigger.exec(ctx.messageText);
80
+ if (nextResult == null)
81
+ break;
82
+ matchResults.push(nextResult);
83
+ }
84
+ }
85
+ }
86
+ shouldTrigger = matchResults.length > 0;
87
+ }
88
+ return new commandTriggerCheckResult_1.CommandTriggerCheckResult(shouldTrigger, matchResults, false);
89
+ }
90
+ }
91
+ exports.CommandAction = CommandAction;
@@ -0,0 +1,24 @@
1
+ import { Sema as Semaphore } from 'async-sema';
2
+ import { ScheduledHandler } from '../../types/handlers';
3
+ import { HoursOfDay } from '../../types/timeValues';
4
+ import { IActionState } from '../../types/actionState';
5
+ import { IActionWithState, ActionKey } from '../../types/actionWithState';
6
+ import { CachedStateFactory } from '../cachedStateFactory';
7
+ import { ChatContext } from '../context/chatContext';
8
+ export declare class ScheduledAction<TActionState extends IActionState> implements IActionWithState<TActionState> {
9
+ static locks: Map<string, Semaphore>;
10
+ name: string;
11
+ timeinHours: HoursOfDay;
12
+ active: boolean;
13
+ chatsWhitelist: number[];
14
+ key: ActionKey;
15
+ cachedState: Map<string, unknown>;
16
+ stateConstructor: () => TActionState;
17
+ cachedStateFactories: Map<string, CachedStateFactory>;
18
+ handler: ScheduledHandler<TActionState>;
19
+ constructor(name: string, handler: ScheduledHandler<TActionState>, timeinHours: HoursOfDay, active: boolean, whitelist: number[], cachedStateFactories: Map<string, CachedStateFactory>, stateConstructor: () => TActionState);
20
+ exec(ctx: ChatContext<TActionState>): Promise<void>;
21
+ private getCachedValue;
22
+ private shouldTrigger;
23
+ }
24
+ //# sourceMappingURL=scheduledAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduledAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/scheduledAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,MAAM,CAAC,KAAK,yBAAgC;IAE5C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,GAAG,EAAE,SAAS,CAAC;IAEf,WAAW,uBAA8B;IACzC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACtD,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAGpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,WAAW,EAAE,UAAU,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAYlC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,YAAY,CAAC;YAqC3B,cAAc;IA8C5B,OAAO,CAAC,aAAa;CAaxB"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ScheduledAction = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const async_sema_1 = require("async-sema");
9
+ const timeConvertions_1 = require("../../helpers/timeConvertions");
10
+ const actionExecutionResult_1 = require("../actionExecutionResult");
11
+ const logger_1 = require("../../services/logger");
12
+ const taskScheduler_1 = require("../../services/taskScheduler");
13
+ class ScheduledAction {
14
+ constructor(name, handler, timeinHours, active, whitelist, cachedStateFactories, stateConstructor) {
15
+ this.cachedState = new Map();
16
+ this.name = name;
17
+ this.handler = handler;
18
+ this.timeinHours = timeinHours;
19
+ this.active = active;
20
+ this.chatsWhitelist = whitelist;
21
+ this.cachedStateFactories = cachedStateFactories;
22
+ this.key = `scheduled:${this.name.replace('.', '-')}`;
23
+ this.stateConstructor = stateConstructor;
24
+ }
25
+ async exec(ctx) {
26
+ if (!ctx.isInitialized)
27
+ throw new Error('Context is not initialized');
28
+ if (!this.active || !this.chatsWhitelist.includes(ctx.chatId))
29
+ return;
30
+ const state = await ctx.storage.getActionState(this, ctx.chatId);
31
+ const isAllowedToTrigger = this.shouldTrigger(state);
32
+ if (isAllowedToTrigger) {
33
+ logger_1.Logger.logWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, ` - Executing [${this.name}] in ${ctx.chatId}`);
34
+ await this.handler(ctx, (key) => this.getCachedValue(key, ctx.botName), state);
35
+ state.lastExecutedDate = (0, moment_1.default)().valueOf();
36
+ ctx.updateActions.forEach((action) => action(state));
37
+ await ctx.storage.saveActionExecutionResult(this, ctx.chatId, new actionExecutionResult_1.ActionExecutionResult(state, isAllowedToTrigger));
38
+ }
39
+ }
40
+ async getCachedValue(key, botName) {
41
+ if (!this.cachedStateFactories.has(key)) {
42
+ throw new Error(`No shared cache was set up for the key [${key}] in action '${this.name}'`);
43
+ }
44
+ const semaphoreKey = `${this.key}_cached:${key}`;
45
+ let semaphore;
46
+ if (ScheduledAction.locks.has(semaphoreKey)) {
47
+ semaphore = ScheduledAction.locks.get(semaphoreKey);
48
+ }
49
+ else {
50
+ semaphore = new async_sema_1.Sema(1);
51
+ ScheduledAction.locks.set(semaphoreKey, semaphore);
52
+ }
53
+ await semaphore.acquire();
54
+ try {
55
+ if (this.cachedState.has(key)) {
56
+ return this.cachedState.get(key);
57
+ }
58
+ const cachedItemFactory = this.cachedStateFactories.get(key);
59
+ const value = await cachedItemFactory.getValue();
60
+ this.cachedState.set(key, value);
61
+ taskScheduler_1.Scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), (0, timeConvertions_1.hoursToMilliseconds)(cachedItemFactory.invalidationTimeoutInHours), botName);
62
+ return value;
63
+ }
64
+ finally {
65
+ semaphore.release();
66
+ }
67
+ }
68
+ shouldTrigger(state) {
69
+ const startOfToday = (0, moment_1.default)().startOf('day').valueOf();
70
+ const lastExecutedDate = (0, moment_1.default)(state.lastExecutedDate);
71
+ const currentTime = (0, moment_1.default)();
72
+ const scheduledTime = (0, moment_1.default)()
73
+ .startOf('day')
74
+ .add(this.timeinHours, 'hours');
75
+ const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
76
+ const hasTriggeredToday = lastExecutedDate.isAfter(startOfToday);
77
+ return isAllowedToTrigger && !hasTriggeredToday;
78
+ }
79
+ }
80
+ exports.ScheduledAction = ScheduledAction;
81
+ ScheduledAction.locks = new Map();
@@ -0,0 +1,31 @@
1
+ import { Seconds } from '../types/timeValues';
2
+ import { IStorageClient } from '../types/storage';
3
+ import { IActionState } from '../types/actionState';
4
+ import { CommandAction } from './actions/commandAction';
5
+ import { ScheduledAction } from './actions/scheduledAction';
6
+ export declare class BotInstance {
7
+ name: string;
8
+ private api;
9
+ private telegraf;
10
+ private commands;
11
+ private scheduled;
12
+ private chats;
13
+ storage: IStorageClient;
14
+ constructor(options: {
15
+ name: string;
16
+ token: string;
17
+ commands: CommandAction<IActionState>[];
18
+ scheduled: ScheduledAction<IActionState>[];
19
+ chats: Record<string, number>;
20
+ storageClient?: IStorageClient;
21
+ storagePath?: string;
22
+ scheduledPeriod?: Seconds;
23
+ verboseLoggingForIncomingMessage?: boolean;
24
+ });
25
+ private initializeScheduledProcessing;
26
+ private initializeMessageProcessing;
27
+ stop(code: string): Promise<void>;
28
+ private runScheduled;
29
+ private processMessage;
30
+ }
31
+ //# sourceMappingURL=botInstance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAQ5D,qBAAa,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC9C;IAqCD,OAAO,CAAC,6BAA6B;IA2CrC,OAAO,CAAC,2BAA2B;IAiC7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAwBZ,cAAc;CAqB/B"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BotInstance = void 0;
7
+ const telegraf_1 = require("telegraf");
8
+ const timeConvertions_1 = require("../helpers/timeConvertions");
9
+ const jsonFileStorage_1 = require("../services/jsonFileStorage");
10
+ const telegramApi_1 = require("../services/telegramApi");
11
+ const logger_1 = require("../services/logger");
12
+ const taskScheduler_1 = require("../services/taskScheduler");
13
+ const incomingMessage_1 = require("./incomingMessage");
14
+ const moment_1 = __importDefault(require("moment"));
15
+ const chatContext_1 = require("./context/chatContext");
16
+ const messageContext_1 = require("./context/messageContext");
17
+ class BotInstance {
18
+ constructor(options) {
19
+ this.name = options.name;
20
+ this.commands = options.commands;
21
+ this.scheduled = options.scheduled;
22
+ this.chats = options.chats;
23
+ const actions = [...this.commands, ...this.scheduled];
24
+ logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Start`, 'System', 'Starting bot...');
25
+ this.telegraf = new telegraf_1.Telegraf(options.token);
26
+ this.storage =
27
+ options.storageClient ??
28
+ new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
29
+ this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
30
+ this.initializeMessageProcessing(options.verboseLoggingForIncomingMessage ?? false);
31
+ this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
32
+ this.storage.saveMetadata(actions, this.name);
33
+ this.telegraf.launch();
34
+ }
35
+ initializeScheduledProcessing(period) {
36
+ if (this.scheduled.length > 0) {
37
+ const now = (0, moment_1.default)();
38
+ if (now.minute() == 0 && now.second() == 0) {
39
+ taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
40
+ await this.runScheduled();
41
+ }, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
42
+ return;
43
+ }
44
+ let nextExecutionTime = now.clone().startOf('hour');
45
+ if (now.minute() > 0 || now.second() > 0) {
46
+ nextExecutionTime = nextExecutionTime.add(1, 'hour');
47
+ }
48
+ const delay = nextExecutionTime.diff(now);
49
+ taskScheduler_1.Scheduler.createOnetimeTask('ScheduledProcessing_OneTime', async () => {
50
+ taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
51
+ await this.runScheduled();
52
+ }, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
53
+ }, delay, this.name);
54
+ }
55
+ }
56
+ initializeMessageProcessing(verboseLoggingForIncomingMessage) {
57
+ if (this.commands.length > 0) {
58
+ this.telegraf.on('message', async (ctx) => {
59
+ const msg = new incomingMessage_1.IncomingMessage(ctx.update.message);
60
+ const messageContent = msg.text || `<non-text message: ${msg.type}>`;
61
+ const messageFromName = msg.from?.first_name ?? 'Unknown';
62
+ const messageFromId = msg.from?.id ?? 'Unknown';
63
+ if (verboseLoggingForIncomingMessage) {
64
+ logger_1.Logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatName, ctx.update.message);
65
+ }
66
+ else {
67
+ logger_1.Logger.logWithTraceId(this.name, msg.traceId, msg.chatName, `${messageFromName} (${messageFromId}): ${messageContent}`);
68
+ }
69
+ await this.processMessage(msg);
70
+ });
71
+ }
72
+ }
73
+ async stop(code) {
74
+ logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Stop`, 'System', 'Stopping bot...');
75
+ await this.storage.close();
76
+ this.telegraf.stop(code);
77
+ }
78
+ async runScheduled() {
79
+ const ctx = new chatContext_1.ChatContext();
80
+ for (const [chatName, chatId] of Object.entries(this.chats)) {
81
+ for (const scheduledAction of this.scheduled) {
82
+ this.api.initializeContextForChat(ctx, chatId, scheduledAction);
83
+ try {
84
+ await scheduledAction.exec(ctx);
85
+ }
86
+ catch (error) {
87
+ logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, chatName, error, ctx);
88
+ }
89
+ }
90
+ }
91
+ await this.api.flushResponses();
92
+ }
93
+ async processMessage(msg) {
94
+ const ctx = new messageContext_1.MessageContext();
95
+ for (const commandAction of this.commands) {
96
+ this.api.initializeContextForMessage(ctx, msg, commandAction);
97
+ try {
98
+ await commandAction.exec(ctx);
99
+ }
100
+ catch (error) {
101
+ logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, error, ctx);
102
+ }
103
+ }
104
+ await this.api.flushResponses();
105
+ }
106
+ }
107
+ exports.BotInstance = BotInstance;
@@ -0,0 +1,7 @@
1
+ import { Hours } from '../types/timeValues';
2
+ export declare class CachedStateFactory {
3
+ getValue: () => Promise<unknown>;
4
+ invalidationTimeoutInHours: Hours;
5
+ constructor(itemFactory: () => Promise<unknown>, invalidationTimeout: Hours);
6
+ }
7
+ //# sourceMappingURL=cachedStateFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cachedStateFactory.d.ts","sourceRoot":"","sources":["../../entities/cachedStateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,kBAAkB;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,0BAA0B,EAAE,KAAK,CAAC;gBAG9B,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,mBAAmB,EAAE,KAAK;CAKjC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CachedStateFactory = void 0;
4
+ class CachedStateFactory {
5
+ constructor(itemFactory, invalidationTimeout) {
6
+ this.getValue = itemFactory;
7
+ this.invalidationTimeoutInHours = invalidationTimeout;
8
+ }
9
+ }
10
+ exports.CachedStateFactory = CachedStateFactory;
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,23 @@
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;
@@ -0,0 +1,55 @@
1
+ import { IBotApiInteractions } from '../../services/telegramApi';
2
+ import { IStorageClient } from '../../types/storage';
3
+ import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
4
+ import { IActionWithState } from '../../types/actionWithState';
5
+ import { IActionState } from '../../types/actionState';
6
+ /**
7
+ * Context of action executed in chat.
8
+ */
9
+ export declare class ChatContext<TActionState extends IActionState> {
10
+ protected action: IActionWithState<TActionState>;
11
+ protected interactions: IBotApiInteractions;
12
+ updateActions: Array<(state: TActionState) => void>;
13
+ /** Trace id of a action execution. */
14
+ traceId: number | string;
15
+ /** Name of a bot that executes this action. */
16
+ botName: string;
17
+ /** Id of a chat that action is executed in. */
18
+ chatId: number;
19
+ /** Name of a chat that action is executed in. */
20
+ chatName: string;
21
+ /** Storage client instance for this bot. */
22
+ storage: IStorageClient;
23
+ isInitialized: boolean;
24
+ constructor();
25
+ initializeChatContext(botName: string, action: IActionWithState<TActionState>, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient): this;
26
+ /**
27
+ * Manually update the state of an action.
28
+ * @param stateUpdateAction Function that will modify state.
29
+ */
30
+ updateState(stateUpdateAction: (state: TActionState) => void): void;
31
+ /**
32
+ * Sends text message to chat.
33
+ * @param text Message contents.
34
+ * @param options Message sending option.
35
+ */
36
+ sendTextToChat(text: string, options?: TextMessageSendingOptions): void;
37
+ /**
38
+ * Sends image message to chat.
39
+ * @param name Message contents.
40
+ * @param options Message sending option.
41
+ */
42
+ sendImageToChat(name: string, options?: MessageSendingOptions): void;
43
+ /**
44
+ * Sends video/gif message to chat.
45
+ * @param name Message contents.
46
+ * @param options Message sending option.
47
+ */
48
+ sendVideoToChat(name: string, options?: MessageSendingOptions): void;
49
+ /**
50
+ * Unpins message.
51
+ * @param messageId Message id.
52
+ */
53
+ unpinMessage(messageId: number): void;
54
+ }
55
+ //# sourceMappingURL=chatContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY,SAAS,YAAY;IACtD,SAAS,CAAC,MAAM,EAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAClD,SAAS,CAAC,YAAY,EAAG,mBAAmB,CAAC;IAC7C,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,sCAAsC;IACtC,OAAO,EAAG,MAAM,GAAG,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,+CAA+C;IAC/C,MAAM,EAAG,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAG,MAAM,CAAC;IAClB,4CAA4C;IAC5C,OAAO,EAAG,cAAc,CAAC;IAEzB,aAAa,UAAS;;IAItB,qBAAqB,CACjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,EAAE,cAAc;IAgB3B;;;OAGG;IACH,WAAW,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;IAI5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAahE;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc7D;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;CAKjC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatContext = void 0;
4
+ const path_1 = require("path");
5
+ const imageMessage_1 = require("../responses/imageMessage");
6
+ const textMessage_1 = require("../responses/textMessage");
7
+ const videoMessage_1 = require("../responses/videoMessage");
8
+ const unpin_1 = require("../responses/unpin");
9
+ /**
10
+ * Context of action executed in chat.
11
+ */
12
+ class ChatContext {
13
+ constructor() {
14
+ this.updateActions = [];
15
+ this.isInitialized = false;
16
+ }
17
+ initializeChatContext(botName, action, interactions, chatId, chatName, traceId, storage) {
18
+ this.botName = botName;
19
+ this.action = action;
20
+ this.interactions = interactions;
21
+ this.chatId = chatId;
22
+ this.chatName = chatName;
23
+ this.traceId = traceId;
24
+ this.storage = storage;
25
+ this.updateActions = [];
26
+ this.isInitialized = true;
27
+ return this;
28
+ }
29
+ /**
30
+ * Manually update the state of an action.
31
+ * @param stateUpdateAction Function that will modify state.
32
+ */
33
+ updateState(stateUpdateAction) {
34
+ this.updateActions.push(stateUpdateAction);
35
+ }
36
+ /**
37
+ * Sends text message to chat.
38
+ * @param text Message contents.
39
+ * @param options Message sending option.
40
+ */
41
+ sendTextToChat(text, options) {
42
+ this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.action, options));
43
+ }
44
+ /**
45
+ * Sends image message to chat.
46
+ * @param name Message contents.
47
+ * @param options Message sending option.
48
+ */
49
+ sendImageToChat(name, options) {
50
+ const filePath = `./content/${name}.png`;
51
+ this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
52
+ }
53
+ /**
54
+ * Sends video/gif message to chat.
55
+ * @param name Message contents.
56
+ * @param options Message sending option.
57
+ */
58
+ sendVideoToChat(name, options) {
59
+ const filePath = `./content/${name}.mp4`;
60
+ this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
61
+ }
62
+ /**
63
+ * Unpins message.
64
+ * @param messageId Message id.
65
+ */
66
+ unpinMessage(messageId) {
67
+ this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.action));
68
+ }
69
+ }
70
+ exports.ChatContext = ChatContext;