chz-telegram-bot 0.0.43 → 0.0.45

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 (137) hide show
  1. package/entities/actions/commandAction.ts +2 -0
  2. package/entities/actions/scheduledAction.ts +14 -3
  3. package/entities/botInstance.ts +8 -5
  4. package/entities/context/chatContext.ts +17 -8
  5. package/entities/context/messageContext.ts +21 -14
  6. package/entities/incomingMessage.ts +1 -0
  7. package/package.json +29 -29
  8. package/services/telegramApi.ts +6 -4
  9. package/dist/entities/actionExecutionResult.d.ts +0 -7
  10. package/dist/entities/actionExecutionResult.d.ts.map +0 -1
  11. package/dist/entities/actionExecutionResult.js +0 -10
  12. package/dist/entities/actions/commandAction.d.ts +0 -23
  13. package/dist/entities/actions/commandAction.d.ts.map +0 -1
  14. package/dist/entities/actions/commandAction.js +0 -89
  15. package/dist/entities/actions/scheduledAction.d.ts +0 -24
  16. package/dist/entities/actions/scheduledAction.d.ts.map +0 -1
  17. package/dist/entities/actions/scheduledAction.js +0 -70
  18. package/dist/entities/botInstance.d.ts +0 -31
  19. package/dist/entities/botInstance.d.ts.map +0 -1
  20. package/dist/entities/botInstance.js +0 -103
  21. package/dist/entities/cachedStateFactory.d.ts +0 -7
  22. package/dist/entities/cachedStateFactory.d.ts.map +0 -1
  23. package/dist/entities/cachedStateFactory.js +0 -10
  24. package/dist/entities/commandTriggerCheckResult.d.ts +0 -10
  25. package/dist/entities/commandTriggerCheckResult.d.ts.map +0 -1
  26. package/dist/entities/commandTriggerCheckResult.js +0 -23
  27. package/dist/entities/context/chatContext.d.ts +0 -52
  28. package/dist/entities/context/chatContext.d.ts.map +0 -1
  29. package/dist/entities/context/chatContext.js +0 -64
  30. package/dist/entities/context/messageContext.d.ts +0 -59
  31. package/dist/entities/context/messageContext.d.ts.map +0 -1
  32. package/dist/entities/context/messageContext.js +0 -77
  33. package/dist/entities/incomingMessage.d.ts +0 -14
  34. package/dist/entities/incomingMessage.d.ts.map +0 -1
  35. package/dist/entities/incomingMessage.js +0 -43
  36. package/dist/entities/responses/imageMessage.d.ts +0 -16
  37. package/dist/entities/responses/imageMessage.d.ts.map +0 -1
  38. package/dist/entities/responses/imageMessage.js +0 -17
  39. package/dist/entities/responses/reaction.d.ts +0 -13
  40. package/dist/entities/responses/reaction.d.ts.map +0 -1
  41. package/dist/entities/responses/reaction.js +0 -15
  42. package/dist/entities/responses/textMessage.d.ts +0 -15
  43. package/dist/entities/responses/textMessage.d.ts.map +0 -1
  44. package/dist/entities/responses/textMessage.js +0 -17
  45. package/dist/entities/responses/unpin.d.ts +0 -11
  46. package/dist/entities/responses/unpin.d.ts.map +0 -1
  47. package/dist/entities/responses/unpin.js +0 -14
  48. package/dist/entities/responses/videoMessage.d.ts +0 -16
  49. package/dist/entities/responses/videoMessage.d.ts.map +0 -1
  50. package/dist/entities/responses/videoMessage.js +0 -17
  51. package/dist/entities/states/actionStateBase.d.ts +0 -6
  52. package/dist/entities/states/actionStateBase.d.ts.map +0 -1
  53. package/dist/entities/states/actionStateBase.js +0 -10
  54. package/dist/entities/taskRecord.d.ts +0 -8
  55. package/dist/entities/taskRecord.d.ts.map +0 -1
  56. package/dist/entities/taskRecord.js +0 -11
  57. package/dist/helpers/builders/commandActionBuilder.d.ts +0 -69
  58. package/dist/helpers/builders/commandActionBuilder.d.ts.map +0 -1
  59. package/dist/helpers/builders/commandActionBuilder.js +0 -96
  60. package/dist/helpers/builders/scheduledActionBuilder.d.ts +0 -60
  61. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +0 -1
  62. package/dist/helpers/builders/scheduledActionBuilder.js +0 -82
  63. package/dist/helpers/inverseRecord.d.ts +0 -2
  64. package/dist/helpers/inverseRecord.d.ts.map +0 -1
  65. package/dist/helpers/inverseRecord.js +0 -6
  66. package/dist/helpers/noop.d.ts +0 -6
  67. package/dist/helpers/noop.d.ts.map +0 -1
  68. package/dist/helpers/noop.js +0 -14
  69. package/dist/helpers/reverseMap.d.ts +0 -2
  70. package/dist/helpers/reverseMap.d.ts.map +0 -1
  71. package/dist/helpers/reverseMap.js +0 -6
  72. package/dist/helpers/reverseRecord.d.ts +0 -2
  73. package/dist/helpers/reverseRecord.d.ts.map +0 -1
  74. package/dist/helpers/reverseRecord.js +0 -6
  75. package/dist/helpers/timeConvertions.d.ts +0 -5
  76. package/dist/helpers/timeConvertions.d.ts.map +0 -1
  77. package/dist/helpers/timeConvertions.js +0 -14
  78. package/dist/helpers/toArray.d.ts +0 -2
  79. package/dist/helpers/toArray.d.ts.map +0 -1
  80. package/dist/helpers/toArray.js +0 -6
  81. package/dist/index.d.ts +0 -10
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js +0 -29
  84. package/dist/main.d.ts +0 -35
  85. package/dist/main.d.ts.map +0 -1
  86. package/dist/main.js +0 -43
  87. package/dist/services/jsonFileStorage.d.ts +0 -22
  88. package/dist/services/jsonFileStorage.d.ts.map +0 -1
  89. package/dist/services/jsonFileStorage.js +0 -102
  90. package/dist/services/logger.d.ts +0 -9
  91. package/dist/services/logger.d.ts.map +0 -1
  92. package/dist/services/logger.js +0 -28
  93. package/dist/services/taskScheduler.d.ts +0 -11
  94. package/dist/services/taskScheduler.d.ts.map +0 -1
  95. package/dist/services/taskScheduler.js +0 -33
  96. package/dist/services/telegramApi.d.ts +0 -36
  97. package/dist/services/telegramApi.d.ts.map +0 -1
  98. package/dist/services/telegramApi.js +0 -102
  99. package/dist/types/actionState.d.ts +0 -5
  100. package/dist/types/actionState.d.ts.map +0 -1
  101. package/dist/types/actionState.js +0 -2
  102. package/dist/types/actionWithState.d.ts +0 -9
  103. package/dist/types/actionWithState.d.ts.map +0 -1
  104. package/dist/types/actionWithState.js +0 -2
  105. package/dist/types/cachedValueAccessor.d.ts +0 -2
  106. package/dist/types/cachedValueAccessor.d.ts.map +0 -1
  107. package/dist/types/cachedValueAccessor.js +0 -2
  108. package/dist/types/commandCondition.d.ts +0 -4
  109. package/dist/types/commandCondition.d.ts.map +0 -1
  110. package/dist/types/commandCondition.js +0 -2
  111. package/dist/types/commandTrigger.d.ts +0 -3
  112. package/dist/types/commandTrigger.d.ts.map +0 -1
  113. package/dist/types/commandTrigger.js +0 -2
  114. package/dist/types/daysOfTheWeek.d.ts +0 -10
  115. package/dist/types/daysOfTheWeek.d.ts.map +0 -1
  116. package/dist/types/daysOfTheWeek.js +0 -13
  117. package/dist/types/handlers.d.ts +0 -17
  118. package/dist/types/handlers.d.ts.map +0 -1
  119. package/dist/types/handlers.js +0 -2
  120. package/dist/types/messageSendingOptions.d.ts +0 -7
  121. package/dist/types/messageSendingOptions.d.ts.map +0 -1
  122. package/dist/types/messageSendingOptions.js +0 -2
  123. package/dist/types/messageTypes.d.ts +0 -16
  124. package/dist/types/messageTypes.d.ts.map +0 -1
  125. package/dist/types/messageTypes.js +0 -17
  126. package/dist/types/replyMessage.d.ts +0 -8
  127. package/dist/types/replyMessage.d.ts.map +0 -1
  128. package/dist/types/replyMessage.js +0 -2
  129. package/dist/types/response.d.ts +0 -27
  130. package/dist/types/response.d.ts.map +0 -1
  131. package/dist/types/response.js +0 -10
  132. package/dist/types/storage.d.ts +0 -12
  133. package/dist/types/storage.d.ts.map +0 -1
  134. package/dist/types/storage.js +0 -2
  135. package/dist/types/timeValues.d.ts +0 -11
  136. package/dist/types/timeValues.d.ts.map +0 -1
  137. package/dist/types/timeValues.js +0 -2
@@ -1,103 +0,0 @@
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
- class BotInstance {
16
- constructor(options) {
17
- this.name = options.name;
18
- this.commands = options.commands;
19
- this.scheduled = options.scheduled;
20
- this.chats = options.chats;
21
- const actions = [...this.commands, ...this.scheduled];
22
- logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Start`, 'System', 'Starting bot...');
23
- this.telegraf = new telegraf_1.Telegraf(options.token);
24
- this.storage =
25
- options.storageClient ??
26
- new jsonFileStorage_1.JsonFileStorage(options.name, actions, options.storagePath);
27
- this.api = new telegramApi_1.TelegramApiService(this.name, this.telegraf.telegram, this.storage, this.chats);
28
- this.initializeMessageProcessing(options.verboseLoggingForIncomingMessage ?? false);
29
- this.initializeScheduledProcessing(options.scheduledPeriod ?? (0, timeConvertions_1.hoursToSeconds)(1));
30
- this.storage.saveMetadata(actions, this.name);
31
- this.telegraf.launch();
32
- }
33
- initializeScheduledProcessing(period) {
34
- if (this.scheduled.length > 0) {
35
- const now = (0, moment_1.default)();
36
- if (now.minute() == 0 && now.second() == 0) {
37
- taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
38
- await this.runScheduled();
39
- }, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
40
- return;
41
- }
42
- let nextExecutionTime = now.clone().startOf('hour');
43
- if (now.minute() > 0 || now.second() > 0) {
44
- nextExecutionTime = nextExecutionTime.add(1, 'hour');
45
- }
46
- const delay = nextExecutionTime.diff(now);
47
- taskScheduler_1.Scheduler.createOnetimeTask('ScheduledProcessing_OneTime', async () => {
48
- taskScheduler_1.Scheduler.createTask('ScheduledProcessing', async () => {
49
- await this.runScheduled();
50
- }, (0, timeConvertions_1.secondsToMilliseconds)(period), true, this.name);
51
- }, delay, this.name);
52
- }
53
- }
54
- initializeMessageProcessing(verboseLoggingForIncomingMessage) {
55
- if (this.commands.length > 0) {
56
- this.telegraf.on('message', async (ctx) => {
57
- const msg = new incomingMessage_1.IncomingMessage(ctx.update.message);
58
- const messageContent = msg.text || `<non-text message: ${msg.type}>`;
59
- const messageFromName = msg.from?.first_name ?? 'Unknown';
60
- const messageFromId = msg.from?.id ?? 'Unknown';
61
- if (verboseLoggingForIncomingMessage) {
62
- logger_1.Logger.logObjectWithTraceId(this.name, msg.traceId, msg.chatName, ctx.update.message);
63
- }
64
- else {
65
- logger_1.Logger.logWithTraceId(this.name, msg.traceId, msg.chatName, `${messageFromName} (${messageFromId}): ${messageContent}`);
66
- }
67
- await this.processMessage(msg);
68
- });
69
- }
70
- }
71
- async stop(code) {
72
- logger_1.Logger.logWithTraceId(this.name, `System:Bot-${this.name}-Stop`, 'System', 'Stopping bot...');
73
- await this.storage.close();
74
- this.telegraf.stop(code);
75
- }
76
- async runScheduled() {
77
- for (const [chatName, chatId] of Object.entries(this.chats)) {
78
- for (const scheduledAction of this.scheduled) {
79
- const ctx = this.api.createContextForChat(chatId, scheduledAction);
80
- try {
81
- await scheduledAction.exec(ctx);
82
- }
83
- catch (error) {
84
- logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, chatName, error, ctx);
85
- }
86
- }
87
- }
88
- await this.api.flushResponses();
89
- }
90
- async processMessage(msg) {
91
- for (const commandAction of this.commands) {
92
- const ctx = this.api.createContextForMessage(msg, commandAction);
93
- try {
94
- await commandAction.exec(ctx);
95
- }
96
- catch (error) {
97
- logger_1.Logger.errorWithTraceId(ctx.botName, ctx.traceId, ctx.chatName, error, ctx);
98
- }
99
- }
100
- await this.api.flushResponses();
101
- }
102
- }
103
- exports.BotInstance = BotInstance;
@@ -1,7 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
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;
@@ -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,52 +0,0 @@
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
- /**
6
- * Context of action executed in chat.
7
- */
8
- export declare class ChatContext<TActionState> {
9
- protected action: IActionWithState;
10
- protected interactions: IBotApiInteractions;
11
- updateActions: Array<(state: TActionState) => void>;
12
- /** Trace id of a action execution. */
13
- traceId: number | string;
14
- /** Name of a bot that executes this action. */
15
- botName: string;
16
- /** Id of a chat that action is executed in. */
17
- chatId: number;
18
- /** Name of a chat that action is executed in. */
19
- chatName: string;
20
- /** Storage client instance for this bot. */
21
- storage: IStorageClient;
22
- constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, chatId: number, chatName: string, traceId: number | string, storage: IStorageClient);
23
- /**
24
- * Manually update the state of an action.
25
- * @param stateUpdateAction Function that will modify state.
26
- */
27
- updateState(stateUpdateAction: (state: TActionState) => void): void;
28
- /**
29
- * Sends text message to chat.
30
- * @param text Message contents.
31
- * @param options Message sending option.
32
- */
33
- sendTextToChat(text: string, options?: TextMessageSendingOptions): void;
34
- /**
35
- * Sends image message to chat.
36
- * @param name Message contents.
37
- * @param options Message sending option.
38
- */
39
- sendImageToChat(name: string, options?: MessageSendingOptions): void;
40
- /**
41
- * Sends video/gif message to chat.
42
- * @param name Message contents.
43
- * @param options Message sending option.
44
- */
45
- sendVideoToChat(name: string, options?: MessageSendingOptions): void;
46
- /**
47
- * Unpins message.
48
- * @param messageId Message id.
49
- */
50
- unpinMessage(messageId: number): void;
51
- }
52
- //# sourceMappingURL=chatContext.d.ts.map
@@ -1 +0,0 @@
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;AAE/D;;GAEG;AACH,qBAAa,WAAW,CAAC,YAAY;IACjC,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC;IACnC,SAAS,CAAC,YAAY,EAAE,mBAAmB,CAAC;IAC5C,aAAa,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CAAM;IACzD,sCAAsC;IACtC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE,cAAc,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,mBAAmB,EACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,EAAE,cAAc;IAW3B;;;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"}
@@ -1,64 +0,0 @@
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(botName, action, interactions, chatId, chatName, traceId, storage) {
14
- this.updateActions = [];
15
- this.botName = botName;
16
- this.action = action;
17
- this.interactions = interactions;
18
- this.chatId = chatId;
19
- this.chatName = chatName;
20
- this.traceId = traceId;
21
- this.storage = storage;
22
- }
23
- /**
24
- * Manually update the state of an action.
25
- * @param stateUpdateAction Function that will modify state.
26
- */
27
- updateState(stateUpdateAction) {
28
- this.updateActions.push(stateUpdateAction);
29
- }
30
- /**
31
- * Sends text message to chat.
32
- * @param text Message contents.
33
- * @param options Message sending option.
34
- */
35
- sendTextToChat(text, options) {
36
- this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, undefined, this.traceId, this.action, options));
37
- }
38
- /**
39
- * Sends image message to chat.
40
- * @param name Message contents.
41
- * @param options Message sending option.
42
- */
43
- sendImageToChat(name, options) {
44
- const filePath = `./content/${name}.png`;
45
- this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
46
- }
47
- /**
48
- * Sends video/gif message to chat.
49
- * @param name Message contents.
50
- * @param options Message sending option.
51
- */
52
- sendVideoToChat(name, options) {
53
- const filePath = `./content/${name}.mp4`;
54
- this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, undefined, this.traceId, this.action, options));
55
- }
56
- /**
57
- * Unpins message.
58
- * @param messageId Message id.
59
- */
60
- unpinMessage(messageId) {
61
- this.interactions.unpin(new unpin_1.UnpinResponse(messageId, this.chatId, this.traceId, this.action));
62
- }
63
- }
64
- exports.ChatContext = ChatContext;
@@ -1,59 +0,0 @@
1
- import { IBotApiInteractions } from '../../services/telegramApi';
2
- import { TelegramEmoji } from 'telegraf/types';
3
- import { IStorageClient } from '../../types/storage';
4
- import { IActionState } from '../../types/actionState';
5
- import { ChatContext } from './chatContext';
6
- import { IncomingMessage } from '../incomingMessage';
7
- import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
8
- import { IActionWithState } from '../../types/actionWithState';
9
- import { MessageTypeValue } from '../../types/messageTypes';
10
- /**
11
- * Context of action executed in chat, in response to a message
12
- */
13
- export declare class MessageContext<TActionState extends IActionState> extends ChatContext<TActionState> {
14
- /** Id of a message that triggered this action. */
15
- messageId: number;
16
- /** Text of a message that triggered this action. */
17
- messageText: string;
18
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
19
- matchResults: RegExpMatchArray[];
20
- /** Id of a user that sent a message that triggered this action. */
21
- fromUserId: number | undefined;
22
- /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
23
- startCooldown: boolean;
24
- /** Name of a user that sent a message that triggered this action. */
25
- fromUserName: string;
26
- /** Type of message being received */
27
- messageType: MessageTypeValue;
28
- constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, message: IncomingMessage, storage: IStorageClient);
29
- /**
30
- * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
31
- * @param commandName Name of an action to load state of.
32
- * @template TAnotherActionState - Type of a state that is used by another action.
33
- */
34
- loadStateOf<TAnotherActionState extends IActionState>(commandName: string): Promise<TAnotherActionState>;
35
- /**
36
- * Reply with text message to message that triggered this action.
37
- * @param text Message contents.
38
- * @param options Message sending option.
39
- */
40
- replyWithText(text: string, options?: TextMessageSendingOptions): void;
41
- /**
42
- * Reply with image message to message that triggered this action.
43
- * @param text Message contents.
44
- * @param options Message sending option.
45
- */
46
- replyWithImage(name: string, options?: MessageSendingOptions): void;
47
- /**
48
- * Reply with video/gif message to message that triggered this action.
49
- * @param text Message contents.
50
- * @param options Message sending option.
51
- */
52
- replyWithVideo(name: string, options?: MessageSendingOptions): void;
53
- /**
54
- * React to the message that triggered this action.
55
- * @param emoji Telegram emoji to react with.
56
- */
57
- react(emoji: TelegramEmoji): void;
58
- }
59
- //# sourceMappingURL=messageContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,WAAW,EAAE,gBAAgB,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,cAAc;IAqB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageContext = void 0;
4
- const path_1 = require("path");
5
- const imageMessage_1 = require("../responses/imageMessage");
6
- const reaction_1 = require("../responses/reaction");
7
- const textMessage_1 = require("../responses/textMessage");
8
- const videoMessage_1 = require("../responses/videoMessage");
9
- const actionStateBase_1 = require("../states/actionStateBase");
10
- const chatContext_1 = require("./chatContext");
11
- /**
12
- * Context of action executed in chat, in response to a message
13
- */
14
- class MessageContext extends chatContext_1.ChatContext {
15
- constructor(botName, action, interactions, message, storage) {
16
- super(botName, action, interactions, message.chat.id, message.chatName, message.traceId, storage);
17
- /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
18
- this.matchResults = [];
19
- /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
20
- this.startCooldown = true;
21
- this.messageId = message.message_id;
22
- this.messageText = message.text ?? '';
23
- this.messageType = message.type;
24
- this.fromUserId = message.from?.id;
25
- this.fromUserName =
26
- (message.from?.first_name ?? 'Unknown user') +
27
- (message.from?.last_name ? ` ${message.from.last_name}` : '');
28
- }
29
- /**
30
- * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
31
- * @param commandName Name of an action to load state of.
32
- * @template TAnotherActionState - Type of a state that is used by another action.
33
- */
34
- async loadStateOf(commandName) {
35
- const storageKey = `command:${commandName.replace('.', '-')}`;
36
- const allStates = await this.storage.load(storageKey);
37
- const stateForChat = allStates[this.chatId];
38
- if (!stateForChat) {
39
- return new actionStateBase_1.ActionStateBase();
40
- }
41
- return stateForChat;
42
- }
43
- /**
44
- * Reply with text message to message that triggered this action.
45
- * @param text Message contents.
46
- * @param options Message sending option.
47
- */
48
- replyWithText(text, options) {
49
- this.interactions.respond(new textMessage_1.TextMessage(text, this.chatId, this.messageId, this.traceId, this.action, options));
50
- }
51
- /**
52
- * Reply with image message to message that triggered this action.
53
- * @param text Message contents.
54
- * @param options Message sending option.
55
- */
56
- replyWithImage(name, options) {
57
- const filePath = `./content/${name}.png`;
58
- this.interactions.respond(new imageMessage_1.ImageMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
59
- }
60
- /**
61
- * Reply with video/gif message to message that triggered this action.
62
- * @param text Message contents.
63
- * @param options Message sending option.
64
- */
65
- replyWithVideo(name, options) {
66
- const filePath = `./content/${name}.mp4`;
67
- this.interactions.respond(new videoMessage_1.VideoMessage({ source: (0, path_1.resolve)(filePath) }, this.chatId, this.messageId, this.traceId, this.action, options));
68
- }
69
- /**
70
- * React to the message that triggered this action.
71
- * @param emoji Telegram emoji to react with.
72
- */
73
- react(emoji) {
74
- this.interactions.react(new reaction_1.Reaction(this.traceId, this.chatId, this.messageId, emoji, this.action));
75
- }
76
- }
77
- exports.MessageContext = MessageContext;
@@ -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;gBAiBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAWrE"}
@@ -1,43 +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 ('photo' in message)
9
- return messageTypes_1.MessageType.Photo;
10
- if ('sticker' in message)
11
- return messageTypes_1.MessageType.Sticker;
12
- if ('animation' in message)
13
- return messageTypes_1.MessageType.Animation;
14
- if ('voice' in message)
15
- return messageTypes_1.MessageType.Voice;
16
- if ('audio' in message)
17
- return messageTypes_1.MessageType.Audio;
18
- if ('document' in message)
19
- return messageTypes_1.MessageType.Document;
20
- if ('left_chat_member' in message)
21
- return messageTypes_1.MessageType.LeftChatMember;
22
- if ('new_chat_member' in message)
23
- return messageTypes_1.MessageType.NewChatMember;
24
- if ('poll' in message)
25
- return messageTypes_1.MessageType.Poll;
26
- if ('location' in message)
27
- return messageTypes_1.MessageType.Location;
28
- return messageTypes_1.MessageType.Unknown;
29
- }
30
- constructor(ctxMessage) {
31
- this.traceId = (0, crypto_1.randomInt)(10000, 99999);
32
- this.message_id = ctxMessage.message_id;
33
- this.chat = ctxMessage.chat;
34
- this.from = ctxMessage.from;
35
- this.text = 'text' in ctxMessage ? ctxMessage.text : '';
36
- this.type = this.detectMessageType(ctxMessage);
37
- this.chatName =
38
- 'title' in ctxMessage.chat
39
- ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
40
- : 'DM';
41
- }
42
- }
43
- exports.IncomingMessage = IncomingMessage;
@@ -1,16 +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
- export declare class ImageMessage implements IReplyMessage<InputFile> {
6
- kind: "image";
7
- content: InputFile;
8
- chatId: number;
9
- replyId: number | undefined;
10
- traceId: string | number;
11
- disableWebPreview: boolean;
12
- shouldPin: boolean;
13
- action: IActionWithState;
14
- constructor(image: InputFile, chatId: number, replyId: number | undefined, traceId: number | string, action: IActionWithState, options?: MessageSendingOptions);
15
- }
16
- //# 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;AAE/D,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;gBAGrB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,EACxB,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,13 +0,0 @@
1
- import { TelegramEmoji } from 'telegraf/types';
2
- import { IChatResponse } from '../../types/response';
3
- import { IActionWithState } from '../../types/actionWithState';
4
- export declare class Reaction implements IChatResponse {
5
- kind: "react";
6
- chatId: number;
7
- messageId: number;
8
- traceId: number | string;
9
- emoji: TelegramEmoji;
10
- action: IActionWithState;
11
- constructor(traceId: number | string, chatId: number, messageId: number, emoji: TelegramEmoji, action: IActionWithState);
12
- }
13
- //# 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;AAE/D,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;gBAGrB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,gBAAgB;CAQ/B"}
@@ -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,15 +0,0 @@
1
- import { TextMessageSendingOptions } from '../../types/messageSendingOptions';
2
- import { IReplyMessage } from '../../types/response';
3
- import { IActionWithState } from '../../types/actionWithState';
4
- export declare class TextMessage implements IReplyMessage<string> {
5
- kind: "text";
6
- content: string;
7
- chatId: number;
8
- replyId: number | undefined;
9
- traceId: string | number;
10
- disableWebPreview: boolean;
11
- shouldPin: boolean;
12
- action: IActionWithState;
13
- constructor(text: string, chatId: number, replyId: number | undefined, traceId: string | number, action: IActionWithState, options?: TextMessageSendingOptions);
14
- }
15
- //# 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;AAE/D,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;gBAGrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB,EACxB,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,11 +0,0 @@
1
- import { IChatResponse } from '../../types/response';
2
- import { IActionWithState } from '../../types/actionWithState';
3
- export declare class UnpinResponse implements IChatResponse {
4
- kind: "unpin";
5
- messageId: number;
6
- chatId: number;
7
- traceId: number | string;
8
- action: IActionWithState;
9
- constructor(messageId: number, chatId: number, traceId: number | string, action: IActionWithState);
10
- }
11
- //# 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;AAE/D,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;gBAGrB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,gBAAgB;CAO/B"}
@@ -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;