chz-telegram-bot 0.5.4 → 0.6.8

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 (234) hide show
  1. package/README.md +41 -31
  2. package/dist/builtin/helpAction.d.ts +2 -0
  3. package/dist/builtin/helpAction.d.ts.map +1 -0
  4. package/dist/builtin/helpAction.js +14 -0
  5. package/dist/dtos/chatHistoryMessage.d.ts +35 -0
  6. package/dist/dtos/chatHistoryMessage.d.ts.map +1 -0
  7. package/dist/dtos/chatHistoryMessage.js +32 -0
  8. package/dist/dtos/chatInfo.d.ts +17 -0
  9. package/dist/dtos/chatInfo.d.ts.map +1 -0
  10. package/dist/dtos/chatInfo.js +16 -0
  11. package/dist/dtos/commandTriggerCheckResult.d.ts +24 -0
  12. package/dist/dtos/commandTriggerCheckResult.d.ts.map +1 -0
  13. package/dist/dtos/commandTriggerCheckResult.js +34 -0
  14. package/dist/dtos/cooldownInfo.d.ts +13 -0
  15. package/dist/dtos/cooldownInfo.d.ts.map +1 -0
  16. package/dist/dtos/cooldownInfo.js +12 -0
  17. package/dist/dtos/incomingMessage.d.ts +19 -0
  18. package/dist/dtos/incomingMessage.d.ts.map +1 -0
  19. package/dist/dtos/incomingMessage.js +63 -0
  20. package/dist/dtos/incomingQuery.d.ts +10 -0
  21. package/dist/dtos/incomingQuery.d.ts.map +1 -0
  22. package/dist/dtos/incomingQuery.js +14 -0
  23. package/dist/dtos/messageInfo.d.ts +22 -0
  24. package/dist/dtos/messageInfo.d.ts.map +1 -0
  25. package/dist/dtos/messageInfo.js +20 -0
  26. package/dist/dtos/propertyProviderSets.d.ts +16 -0
  27. package/dist/dtos/propertyProviderSets.d.ts.map +1 -0
  28. package/dist/dtos/propertyProviderSets.js +1 -0
  29. package/dist/dtos/replyInfo.d.ts +6 -0
  30. package/dist/dtos/replyInfo.d.ts.map +1 -0
  31. package/dist/dtos/replyInfo.js +8 -0
  32. package/dist/dtos/responses/delay.d.ts +16 -0
  33. package/dist/dtos/responses/delay.d.ts.map +1 -0
  34. package/dist/dtos/responses/delay.js +15 -0
  35. package/dist/dtos/responses/imageMessage.d.ts +22 -0
  36. package/dist/dtos/responses/imageMessage.d.ts.map +1 -0
  37. package/dist/dtos/responses/imageMessage.js +21 -0
  38. package/dist/dtos/responses/inlineQueryResponse.d.ts +13 -0
  39. package/dist/dtos/responses/inlineQueryResponse.d.ts.map +1 -0
  40. package/dist/dtos/responses/inlineQueryResponse.js +15 -0
  41. package/dist/dtos/responses/reaction.d.ts +16 -0
  42. package/dist/dtos/responses/reaction.d.ts.map +1 -0
  43. package/dist/dtos/responses/reaction.js +17 -0
  44. package/dist/dtos/responses/textMessage.d.ts +23 -0
  45. package/dist/dtos/responses/textMessage.d.ts.map +1 -0
  46. package/dist/dtos/responses/textMessage.js +24 -0
  47. package/dist/dtos/responses/unpin.d.ts +15 -0
  48. package/dist/dtos/responses/unpin.d.ts.map +1 -0
  49. package/dist/dtos/responses/unpin.js +15 -0
  50. package/dist/dtos/responses/videoMessage.d.ts +22 -0
  51. package/dist/dtos/responses/videoMessage.d.ts.map +1 -0
  52. package/dist/dtos/responses/videoMessage.js +21 -0
  53. package/dist/dtos/userInfo.d.ts +12 -0
  54. package/dist/dtos/userInfo.d.ts.map +1 -0
  55. package/dist/dtos/userInfo.js +12 -0
  56. package/dist/entities/actions/commandAction.d.ts +31 -0
  57. package/dist/entities/actions/commandAction.d.ts.map +1 -0
  58. package/dist/entities/actions/commandAction.js +149 -0
  59. package/dist/entities/actions/inlineQueryAction.d.ts +14 -0
  60. package/dist/entities/actions/inlineQueryAction.d.ts.map +1 -0
  61. package/dist/entities/actions/inlineQueryAction.js +51 -0
  62. package/dist/entities/actions/replyCaptureAction.d.ts +15 -0
  63. package/dist/entities/actions/replyCaptureAction.d.ts.map +1 -0
  64. package/dist/entities/actions/replyCaptureAction.js +66 -0
  65. package/dist/entities/actions/scheduledAction.d.ts +24 -0
  66. package/dist/entities/actions/scheduledAction.d.ts.map +1 -0
  67. package/dist/entities/actions/scheduledAction.js +92 -0
  68. package/dist/entities/botInstance.d.ts +36 -0
  69. package/dist/entities/botInstance.d.ts.map +1 -0
  70. package/dist/entities/botInstance.js +39 -0
  71. package/dist/entities/cachedStateFactory.d.ts +7 -0
  72. package/dist/entities/cachedStateFactory.d.ts.map +1 -0
  73. package/dist/entities/cachedStateFactory.js +8 -0
  74. package/dist/entities/context/baseContext.d.ts +39 -0
  75. package/dist/entities/context/baseContext.d.ts.map +1 -0
  76. package/dist/entities/context/baseContext.js +56 -0
  77. package/dist/entities/context/chatContext.d.ts +50 -0
  78. package/dist/entities/context/chatContext.d.ts.map +1 -0
  79. package/dist/entities/context/chatContext.js +65 -0
  80. package/dist/entities/context/inlineQueryContext.d.ts +27 -0
  81. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -0
  82. package/dist/entities/context/inlineQueryContext.js +29 -0
  83. package/dist/entities/context/messageContext.d.ts +92 -0
  84. package/dist/entities/context/messageContext.d.ts.map +1 -0
  85. package/dist/entities/context/messageContext.js +116 -0
  86. package/dist/entities/context/replyContext.d.ts +89 -0
  87. package/dist/entities/context/replyContext.d.ts.map +1 -0
  88. package/dist/entities/context/replyContext.js +124 -0
  89. package/dist/entities/states/actionStateBase.d.ts +6 -0
  90. package/dist/entities/states/actionStateBase.d.ts.map +1 -0
  91. package/dist/entities/states/actionStateBase.js +4 -0
  92. package/dist/entities/taskRecord.d.ts +8 -0
  93. package/dist/entities/taskRecord.d.ts.map +1 -0
  94. package/dist/entities/taskRecord.js +10 -0
  95. package/dist/eslint.config.d.ts +3 -0
  96. package/dist/eslint.config.d.ts.map +1 -0
  97. package/dist/eslint.config.js +51 -0
  98. package/dist/helpers/builders/commandActionBuilder.d.ts +100 -0
  99. package/dist/helpers/builders/commandActionBuilder.d.ts.map +1 -0
  100. package/dist/helpers/builders/commandActionBuilder.js +146 -0
  101. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts +37 -0
  102. package/dist/helpers/builders/inlineQueryActionBuilder.d.ts.map +1 -0
  103. package/dist/helpers/builders/inlineQueryActionBuilder.js +50 -0
  104. package/dist/helpers/builders/scheduledActionBuilder.d.ts +68 -0
  105. package/dist/helpers/builders/scheduledActionBuilder.d.ts.map +1 -0
  106. package/dist/helpers/builders/scheduledActionBuilder.js +95 -0
  107. package/dist/helpers/mapUtils.d.ts +10 -0
  108. package/dist/helpers/mapUtils.d.ts.map +1 -0
  109. package/dist/helpers/mapUtils.js +13 -0
  110. package/dist/helpers/noop.d.ts +9 -0
  111. package/dist/helpers/noop.d.ts.map +1 -0
  112. package/dist/helpers/noop.js +17 -0
  113. package/dist/helpers/objectFromEntries.d.ts +2 -0
  114. package/dist/helpers/objectFromEntries.d.ts.map +1 -0
  115. package/dist/helpers/objectFromEntries.js +3 -0
  116. package/dist/helpers/timeConvertions.d.ts +5 -0
  117. package/dist/helpers/timeConvertions.d.ts.map +1 -0
  118. package/dist/helpers/timeConvertions.js +9 -0
  119. package/dist/helpers/toArray.d.ts +2 -0
  120. package/dist/helpers/toArray.d.ts.map +1 -0
  121. package/dist/helpers/toArray.js +3 -0
  122. package/dist/helpers/traceFactory.d.ts +3 -0
  123. package/dist/helpers/traceFactory.d.ts.map +1 -0
  124. package/dist/helpers/traceFactory.js +3 -0
  125. package/dist/index.d.ts +27 -0
  126. package/dist/index.d.ts.map +1 -0
  127. package/dist/index.js +20 -0
  128. package/dist/main.d.ts +49 -0
  129. package/dist/main.d.ts.map +1 -0
  130. package/dist/main.js +33 -0
  131. package/dist/services/actionProcessingService.d.ts +25 -0
  132. package/dist/services/actionProcessingService.d.ts.map +1 -0
  133. package/dist/services/actionProcessingService.js +50 -0
  134. package/dist/services/actionProcessors/baseProcessor.d.ts +18 -0
  135. package/dist/services/actionProcessors/baseProcessor.d.ts.map +1 -0
  136. package/dist/services/actionProcessors/baseProcessor.js +33 -0
  137. package/dist/services/actionProcessors/commandActionProcessor.d.ts +19 -0
  138. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -0
  139. package/dist/services/actionProcessors/commandActionProcessor.js +130 -0
  140. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +11 -0
  141. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -0
  142. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +69 -0
  143. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts +17 -0
  144. package/dist/services/actionProcessors/scheduledActionProcessor.d.ts.map +1 -0
  145. package/dist/services/actionProcessors/scheduledActionProcessor.js +55 -0
  146. package/dist/services/jsonFileStorage.d.ts +25 -0
  147. package/dist/services/jsonFileStorage.d.ts.map +1 -0
  148. package/dist/services/jsonFileStorage.js +133 -0
  149. package/dist/services/nodeTimeoutScheduler.d.ts +13 -0
  150. package/dist/services/nodeTimeoutScheduler.d.ts.map +1 -0
  151. package/dist/services/nodeTimeoutScheduler.js +50 -0
  152. package/dist/services/responseProcessingQueue.d.ts +12 -0
  153. package/dist/services/responseProcessingQueue.d.ts.map +1 -0
  154. package/dist/services/responseProcessingQueue.js +37 -0
  155. package/dist/services/telegramApi.d.ts +23 -0
  156. package/dist/services/telegramApi.d.ts.map +1 -0
  157. package/dist/services/telegramApi.js +163 -0
  158. package/dist/types/action.d.ts +14 -0
  159. package/dist/types/action.d.ts.map +1 -0
  160. package/dist/types/action.js +1 -0
  161. package/dist/types/actionState.d.ts +5 -0
  162. package/dist/types/actionState.d.ts.map +1 -0
  163. package/dist/types/actionState.js +1 -0
  164. package/dist/types/cachedValueAccessor.d.ts +2 -0
  165. package/dist/types/cachedValueAccessor.d.ts.map +1 -0
  166. package/dist/types/cachedValueAccessor.js +1 -0
  167. package/dist/types/capture.d.ts +24 -0
  168. package/dist/types/capture.d.ts.map +1 -0
  169. package/dist/types/capture.js +1 -0
  170. package/dist/types/commandCondition.d.ts +8 -0
  171. package/dist/types/commandCondition.d.ts.map +1 -0
  172. package/dist/types/commandCondition.js +1 -0
  173. package/dist/types/commandTrigger.d.ts +2 -0
  174. package/dist/types/commandTrigger.d.ts.map +1 -0
  175. package/dist/types/commandTrigger.js +1 -0
  176. package/dist/types/events.d.ts +193 -0
  177. package/dist/types/events.d.ts.map +1 -0
  178. package/dist/types/events.js +69 -0
  179. package/dist/types/externalAliases.d.ts +11 -0
  180. package/dist/types/externalAliases.d.ts.map +1 -0
  181. package/dist/types/externalAliases.js +1 -0
  182. package/dist/types/handlers.d.ts +21 -0
  183. package/dist/types/handlers.d.ts.map +1 -0
  184. package/dist/types/handlers.js +1 -0
  185. package/dist/types/inputFile.d.ts +5 -0
  186. package/dist/types/inputFile.d.ts.map +1 -0
  187. package/dist/types/inputFile.js +1 -0
  188. package/dist/types/logger.d.ts +1 -0
  189. package/dist/types/logger.d.ts.map +1 -0
  190. package/dist/types/logger.js +1 -0
  191. package/dist/types/messageSendingOptions.d.ts +9 -0
  192. package/dist/types/messageSendingOptions.d.ts.map +1 -0
  193. package/dist/types/messageSendingOptions.js +1 -0
  194. package/dist/types/messageTypes.d.ts +20 -0
  195. package/dist/types/messageTypes.d.ts.map +1 -0
  196. package/dist/types/messageTypes.js +18 -0
  197. package/dist/types/propertyProvider.d.ts +8 -0
  198. package/dist/types/propertyProvider.d.ts.map +1 -0
  199. package/dist/types/propertyProvider.js +1 -0
  200. package/dist/types/response.d.ts +39 -0
  201. package/dist/types/response.d.ts.map +1 -0
  202. package/dist/types/response.js +9 -0
  203. package/dist/types/scheduler.d.ts +7 -0
  204. package/dist/types/scheduler.d.ts.map +1 -0
  205. package/dist/types/scheduler.js +1 -0
  206. package/dist/types/storage.d.ts +11 -0
  207. package/dist/types/storage.d.ts.map +1 -0
  208. package/dist/types/storage.js +1 -0
  209. package/dist/types/timeValues.d.ts +15 -0
  210. package/dist/types/timeValues.d.ts.map +1 -0
  211. package/dist/types/timeValues.js +1 -0
  212. package/dist/types/trace.d.ts +6 -0
  213. package/dist/types/trace.d.ts.map +1 -0
  214. package/dist/types/trace.js +1 -0
  215. package/entities/actions/commandAction.ts +11 -3
  216. package/entities/actions/inlineQueryAction.ts +9 -1
  217. package/entities/actions/replyCaptureAction.ts +9 -3
  218. package/entities/actions/scheduledAction.ts +31 -10
  219. package/entities/botInstance.ts +18 -25
  220. package/entities/context/baseContext.ts +9 -4
  221. package/index.ts +1 -1
  222. package/main.ts +1 -10
  223. package/package.json +38 -38
  224. package/services/actionProcessingService.ts +11 -15
  225. package/services/actionProcessors/baseProcessor.ts +9 -9
  226. package/services/actionProcessors/commandActionProcessor.ts +35 -46
  227. package/services/actionProcessors/inlineQueryActionProcessor.ts +24 -20
  228. package/services/actionProcessors/scheduledActionProcessor.ts +5 -10
  229. package/services/jsonFileStorage.ts +27 -1
  230. package/services/nodeTimeoutScheduler.ts +22 -22
  231. package/services/telegramApi.ts +53 -23
  232. package/types/events.ts +285 -0
  233. package/services/jsonLogger.ts +0 -112
  234. package/types/logger.ts +0 -39
@@ -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;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,qBAAa,eAAe,CAAC,YAAY,SAAS,YAAY,CAC1D,YAAW,gBAAgB,CAAC,YAAY,CAAC;IAEzC,MAAM,CAAC,QAAQ,CAAC,KAAK,yBAAgC;IAErD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA8C;IAClF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2C;IAC1E,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAErC;IAEF,QAAQ,CAAC,WAAW,uBAA8B;IAClD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,YAAY,CAAC;IAC9C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;gBAG7C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACvC,SAAS,EAAE,wBAAwB,EACnC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACrD,gBAAgB,EAAE,MAAM,YAAY;IAclC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,CAAC;YAgDnC,cAAc;IA2D5B,OAAO,CAAC,uBAAuB;CAgBlC"}
@@ -0,0 +1,92 @@
1
+ import moment from 'moment';
2
+ import { Sema as Semaphore } from 'async-sema';
3
+ import { hoursToMilliseconds } from '../../helpers/timeConvertions';
4
+ import { Noop } from '../../helpers/noop';
5
+ import { getOrSetIfNotExists, getOrThrow } from '../../helpers/mapUtils';
6
+ import { BotEventType } from '../../types/events';
7
+ export class ScheduledAction {
8
+ static locks = new Map();
9
+ name;
10
+ key;
11
+ timeinHoursProvider;
12
+ activeProvider;
13
+ chatsWhitelistProvider;
14
+ cachedState = new Map();
15
+ stateConstructor;
16
+ cachedStateFactories;
17
+ handler;
18
+ constructor(name, handler, providers, cachedStateFactories, stateConstructor) {
19
+ this.name = name;
20
+ this.key = `scheduled:${this.name.replace('.', '-')}`;
21
+ this.timeinHoursProvider = providers.timeinHoursProvider;
22
+ this.activeProvider = providers.isActiveProvider;
23
+ this.chatsWhitelistProvider = providers.chatsWhitelistProvider;
24
+ this.cachedStateFactories = cachedStateFactories;
25
+ this.stateConstructor = stateConstructor;
26
+ this.handler = handler;
27
+ }
28
+ async exec(ctx) {
29
+ if (!ctx.isInitialized)
30
+ throw new Error(`Context for ${this.key} is not initialized or already consumed`);
31
+ if (!this.activeProvider(ctx) ||
32
+ !this.chatsWhitelistProvider(ctx).includes(ctx.chatInfo.id))
33
+ return Noop.NoResponse;
34
+ const state = await ctx.storage.getActionState(this, ctx.chatInfo.id);
35
+ const isAllowedToTrigger = this.checkIfShouldBeExecuted(state, ctx);
36
+ if (!isAllowedToTrigger)
37
+ return Noop.NoResponse;
38
+ ctx.eventEmitter.emit(BotEventType.scheduledActionExecuting, {
39
+ action: this,
40
+ ctx,
41
+ state
42
+ });
43
+ await this.handler(ctx, (key) => this.getCachedValue(key, ctx), state);
44
+ state.lastExecutedDate = moment().valueOf();
45
+ await ctx.storage.saveActionExecutionResult(this, ctx.chatInfo.id, state);
46
+ ctx.eventEmitter.emit(BotEventType.scheduledActionExecuted, {
47
+ action: this,
48
+ ctx,
49
+ state
50
+ });
51
+ return ctx.responses;
52
+ }
53
+ async getCachedValue(key, ctx) {
54
+ const cachedItemFactory = getOrThrow(this.cachedStateFactories, key, `No shared cache was set up for the key [${key}] in action '${this.name}'`);
55
+ const semaphoreKey = `${this.key}_cached:${key}`;
56
+ const semaphore = getOrSetIfNotExists(ScheduledAction.locks, semaphoreKey, new Semaphore(1));
57
+ await semaphore.acquire();
58
+ try {
59
+ if (this.cachedState.has(key)) {
60
+ return this.cachedState.get(key);
61
+ }
62
+ ctx.eventEmitter.emit(BotEventType.scheduledActionCacheValueCreating, {
63
+ action: this,
64
+ ctx,
65
+ key
66
+ });
67
+ const value = await cachedItemFactory.getValue();
68
+ this.cachedState.set(key, value);
69
+ ctx.scheduler.createOnetimeTask(`Drop cached value [${this.name} : ${key}]`, () => this.cachedState.delete(key), hoursToMilliseconds(cachedItemFactory.invalidationTimeoutInHours), ctx.botName);
70
+ return value;
71
+ }
72
+ finally {
73
+ ctx.eventEmitter.emit(BotEventType.scheduledActionCacheValueReturned, {
74
+ action: this,
75
+ ctx,
76
+ key
77
+ });
78
+ semaphore.release();
79
+ }
80
+ }
81
+ checkIfShouldBeExecuted(state, ctx) {
82
+ const startOfToday = moment().startOf('day').valueOf();
83
+ const lastExecutedDate = moment(state.lastExecutedDate);
84
+ const currentTime = moment();
85
+ const scheduledTime = moment()
86
+ .startOf('day')
87
+ .add(this.timeinHoursProvider(ctx), 'hours');
88
+ const isAllowedToTrigger = currentTime.isSameOrAfter(scheduledTime);
89
+ const hasTriggeredToday = lastExecutedDate.isAfter(startOfToday);
90
+ return isAllowedToTrigger && !hasTriggeredToday;
91
+ }
92
+ }
@@ -0,0 +1,36 @@
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
+ import { IScheduler } from '../types/scheduler';
7
+ import { InlineQueryAction } from './actions/inlineQueryAction';
8
+ import { TypedEventEmitter } from '../types/events';
9
+ export declare class BotInstance {
10
+ private readonly storage;
11
+ private readonly scheduler;
12
+ private readonly actionProcessingService;
13
+ readonly name: string;
14
+ readonly eventEmitter: TypedEventEmitter;
15
+ constructor(options: {
16
+ name: string;
17
+ actions: {
18
+ commands: CommandAction<IActionState>[];
19
+ scheduled: ScheduledAction<IActionState>[];
20
+ inlineQueries: InlineQueryAction[];
21
+ };
22
+ chats: Record<string, number>;
23
+ storagePath?: string;
24
+ services?: {
25
+ storageClient?: IStorageClient;
26
+ scheduler?: IScheduler;
27
+ };
28
+ });
29
+ start(token: string, actions: {
30
+ commands: CommandAction<IActionState>[];
31
+ scheduled: ScheduledAction<IActionState>[];
32
+ inlineQueries: InlineQueryAction[];
33
+ }, scheduledPeriod?: Seconds): Promise<void>;
34
+ stop(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=botInstance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAgB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElE,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IACvC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA0B;IAElE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,oBAA2B;gBAEpC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE;YACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;SACtC,CAAC;QACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE;YACP,aAAa,CAAC,EAAE,cAAc,CAAC;YAC/B,SAAS,CAAC,EAAE,UAAU,CAAC;SAC1B,CAAC;KACL;IA4BK,KAAK,CACP,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACL,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACtC,EACD,eAAe,CAAC,EAAE,OAAO;IAavB,IAAI;CASb"}
@@ -0,0 +1,39 @@
1
+ import { JsonFileStorage } from '../services/jsonFileStorage';
2
+ import { NodeTimeoutScheduler } from '../services/nodeTimeoutScheduler';
3
+ import { ActionProcessingService } from '../services/actionProcessingService';
4
+ import { BotEventType, TypedEventEmitter } from '../types/events';
5
+ export class BotInstance {
6
+ storage;
7
+ scheduler;
8
+ actionProcessingService;
9
+ name;
10
+ eventEmitter = new TypedEventEmitter();
11
+ constructor(options) {
12
+ const actions = [
13
+ ...options.actions.commands,
14
+ ...options.actions.scheduled
15
+ ];
16
+ this.name = options.name;
17
+ this.scheduler =
18
+ options.services?.scheduler ??
19
+ new NodeTimeoutScheduler(this.eventEmitter);
20
+ this.storage =
21
+ options.services?.storageClient ??
22
+ new JsonFileStorage(options.name, actions, this.eventEmitter, options.storagePath);
23
+ this.actionProcessingService = new ActionProcessingService(this.name, options.chats, this.storage, this.scheduler, this.eventEmitter);
24
+ }
25
+ async start(token, actions, scheduledPeriod) {
26
+ this.eventEmitter.emit(BotEventType.botStarting, {
27
+ botName: this.name
28
+ });
29
+ await this.actionProcessingService.initialize(token, actions, scheduledPeriod);
30
+ }
31
+ async stop() {
32
+ this.eventEmitter.emit(BotEventType.botStopping, {
33
+ botName: this.name
34
+ });
35
+ this.scheduler.stopAll();
36
+ await this.storage.close();
37
+ this.actionProcessingService.stop();
38
+ }
39
+ }
@@ -0,0 +1,7 @@
1
+ import { Hours } from '../types/timeValues';
2
+ export declare class CachedStateFactory {
3
+ readonly getValue: () => Promise<unknown>;
4
+ readonly 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,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,0BAA0B,EAAE,KAAK,CAAC;gBAGvC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACnC,mBAAmB,EAAE,KAAK;CAKjC"}
@@ -0,0 +1,8 @@
1
+ export class CachedStateFactory {
2
+ getValue;
3
+ invalidationTimeoutInHours;
4
+ constructor(itemFactory, invalidationTimeout) {
5
+ this.getValue = itemFactory;
6
+ this.invalidationTimeoutInHours = invalidationTimeout;
7
+ }
8
+ }
@@ -0,0 +1,39 @@
1
+ import { ChatInfo } from '../../dtos/chatInfo';
2
+ import { IAction, IActionWithState } from '../../types/action';
3
+ import { IActionState } from '../../types/actionState';
4
+ import { ICaptureController } from '../../types/capture';
5
+ import { TypedEventEmitter } from '../../types/events';
6
+ import { BotResponse, IReplyResponse } from '../../types/response';
7
+ import { IScheduler } from '../../types/scheduler';
8
+ import { IStorageClient } from '../../types/storage';
9
+ import { TraceId } from '../../types/trace';
10
+ export type BaseContextPropertiesToOmit = 'action' | 'isInitialized' | 'storage' | 'scheduler' | 'eventEmitter' | 'responses' | 'traceId';
11
+ export declare abstract class BaseContextInternal<TAction extends IAction> {
12
+ isInitialized: boolean;
13
+ private _responses;
14
+ action: TAction;
15
+ /** Storage client instance for the bot executing this action. */
16
+ readonly storage: IStorageClient;
17
+ /** Scheduler instance for the bot executing this action */
18
+ readonly scheduler: IScheduler;
19
+ readonly eventEmitter: TypedEventEmitter;
20
+ /** Trace id of a action execution. */
21
+ traceId: TraceId;
22
+ /** Name of a bot that executes this action. */
23
+ botName: string;
24
+ /** Chat information. */
25
+ chatInfo: ChatInfo;
26
+ get actionKey(): import("../..").ActionKey;
27
+ /** Ordered collection of responses to be processed */
28
+ get responses(): BotResponse[];
29
+ set responses(value: BotResponse[]);
30
+ constructor(storage: IStorageClient, scheduler: IScheduler, eventEmitter: TypedEventEmitter);
31
+ protected createCaptureController(response: IReplyResponse): ICaptureController;
32
+ /**
33
+ * Loads state of another action for current chat.
34
+ * @param action Action to load state of.
35
+ * @template TAnotherActionState - Type of a state that is used by another action.
36
+ */
37
+ loadStateOf<TAnotherActionState extends IActionState>(action: IActionWithState<TAnotherActionState>): Promise<Readonly<TAnotherActionState>>;
38
+ }
39
+ //# sourceMappingURL=baseContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseContext.d.ts","sourceRoot":"","sources":["../../../entities/context/baseContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,MAAM,MAAM,2BAA2B,GACjC,QAAQ,GACR,eAAe,GACf,SAAS,GACT,WAAW,GACX,cAAc,GACd,WAAW,GACX,SAAS,CAAC;AAEhB,8BAAsB,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC7D,aAAa,UAAS;IACtB,OAAO,CAAC,UAAU,CAAqB;IAEvC,MAAM,EAAG,OAAO,CAAC;IAEjB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,sCAAsC;IACtC,OAAO,EAAG,OAAO,CAAC;IAClB,+CAA+C;IAC/C,OAAO,EAAG,MAAM,CAAC;IACjB,wBAAwB;IACxB,QAAQ,EAAG,QAAQ,CAAC;IACpB,IAAI,SAAS,8BAEZ;IAED,uDAAuD;IACvD,IAAW,SAAS,IAAI,WAAW,EAAE,CAEpC;IACD,IAAW,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,EAExC;gBAGG,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,UAAU,EACrB,YAAY,EAAE,iBAAiB;IAOnC,SAAS,CAAC,uBAAuB,CAC7B,QAAQ,EAAE,cAAc,GACzB,kBAAkB;IAmBrB;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,MAAM,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;CAWpD"}
@@ -0,0 +1,56 @@
1
+ export class BaseContextInternal {
2
+ isInitialized = false;
3
+ _responses = [];
4
+ action;
5
+ /** Storage client instance for the bot executing this action. */
6
+ storage;
7
+ /** Scheduler instance for the bot executing this action */
8
+ scheduler;
9
+ eventEmitter;
10
+ /** Trace id of a action execution. */
11
+ traceId;
12
+ /** Name of a bot that executes this action. */
13
+ botName;
14
+ /** Chat information. */
15
+ chatInfo;
16
+ get actionKey() {
17
+ return this.action.key;
18
+ }
19
+ /** Ordered collection of responses to be processed */
20
+ get responses() {
21
+ return this._responses;
22
+ }
23
+ set responses(value) {
24
+ this._responses = value;
25
+ }
26
+ constructor(storage, scheduler, eventEmitter) {
27
+ this.storage = storage;
28
+ this.scheduler = scheduler;
29
+ this.eventEmitter = eventEmitter;
30
+ }
31
+ createCaptureController(response) {
32
+ return {
33
+ captureReplies: (trigger, handler, abortController) => {
34
+ response.captures.push({
35
+ trigger,
36
+ handler,
37
+ abortController: abortController ?? new AbortController(),
38
+ action: this.action
39
+ });
40
+ }
41
+ };
42
+ }
43
+ /**
44
+ * Loads state of another action for current chat.
45
+ * @param action Action to load state of.
46
+ * @template TAnotherActionState - Type of a state that is used by another action.
47
+ */
48
+ async loadStateOf(action) {
49
+ const allStates = await this.storage.load(action.key);
50
+ const stateForChat = allStates[this.chatInfo.id];
51
+ if (!stateForChat) {
52
+ return Object.freeze(action.stateConstructor());
53
+ }
54
+ return Object.freeze(stateForChat);
55
+ }
56
+ }
@@ -0,0 +1,50 @@
1
+ import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
2
+ import { IActionWithState } from '../../types/action';
3
+ import { IActionState } from '../../types/actionState';
4
+ import { Milliseconds } from '../../types/timeValues';
5
+ import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
6
+ import { ScheduledAction } from '../actions/scheduledAction';
7
+ export type ChatContext<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> = Omit<ChatContextInternal<TActionState, TAction>, BaseContextPropertiesToOmit>;
8
+ /**
9
+ * Context of action executed in chat.
10
+ */
11
+ export declare class ChatContextInternal<TActionState extends IActionState, TAction extends IActionWithState<TActionState> = ScheduledAction<TActionState>> extends BaseContextInternal<TAction> {
12
+ /**
13
+ * Collection of actions that send something to chat as a standalone message.
14
+ */
15
+ send: {
16
+ /**
17
+ * Sends text message to chat after action execution is finished.
18
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
19
+ * @param text Message contents.
20
+ * @param options Message sending option.
21
+ */
22
+ text: (text: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
23
+ /**
24
+ * Sends image message to chat after action execution is finished.
25
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
26
+ * @param name Message contents.
27
+ * @param options Message sending option.
28
+ */
29
+ image: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
30
+ /**
31
+ * Sends video/gif message to chat after action execution is finished.
32
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
33
+ * @param name Message contents.
34
+ * @param options Message sending option.
35
+ */
36
+ video: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
37
+ };
38
+ /**
39
+ * Unpins message after action execution is finished.
40
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
41
+ * @param messageId Message id.
42
+ */
43
+ unpinMessage(messageId: number): void;
44
+ /**
45
+ * Delays next responses by specified amount of time.
46
+ * @param delay Delay in milliseconds.
47
+ */
48
+ wait(delay: Milliseconds): void;
49
+ }
50
+ //# sourceMappingURL=chatContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatContext.d.ts","sourceRoot":"","sources":["../../../entities/context/chatContext.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,WAAW,CACnB,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,IAC9E,IAAI,CACJ,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC,EAC1C,2BAA2B,CAC9B,CAAC;AAEF;;GAEG;AACH,qBAAa,mBAAmB,CAC5B,YAAY,SAAS,YAAY,EACjC,OAAO,SAAS,gBAAgB,CAAC,YAAY,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAChF,SAAQ,mBAAmB,CAAC,OAAO,CAAC;IAClC;;OAEG;IACH,IAAI;QACA;;;;;WAKG;qBACU,MAAM,YAAY,yBAAyB;QAexD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;QAerD;;;;;WAKG;sBACW,MAAM,YAAY,qBAAqB;MAcvD;IAEF;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;IAW9B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,YAAY;CAK3B"}
@@ -0,0 +1,65 @@
1
+ import { resolve } from 'path';
2
+ import { ImageMessage } from '../../dtos/responses/imageMessage';
3
+ import { TextMessage } from '../../dtos/responses/textMessage';
4
+ import { VideoMessage } from '../../dtos/responses/videoMessage';
5
+ import { UnpinResponse } from '../../dtos/responses/unpin';
6
+ import { DelayResponse } from '../../dtos/responses/delay';
7
+ import { BaseContextInternal } from './baseContext';
8
+ /**
9
+ * Context of action executed in chat.
10
+ */
11
+ export class ChatContextInternal extends BaseContextInternal {
12
+ /**
13
+ * Collection of actions that send something to chat as a standalone message.
14
+ */
15
+ send = {
16
+ /**
17
+ * Sends text message to chat after action execution is finished.
18
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
19
+ * @param text Message contents.
20
+ * @param options Message sending option.
21
+ */
22
+ text: (text, options) => {
23
+ const response = new TextMessage(text, this.chatInfo, this.traceId, this.action, undefined, options);
24
+ this.responses.push(response);
25
+ return this.createCaptureController(response);
26
+ },
27
+ /**
28
+ * Sends image message to chat after action execution is finished.
29
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
30
+ * @param name Message contents.
31
+ * @param options Message sending option.
32
+ */
33
+ image: (name, options) => {
34
+ const response = new ImageMessage({ source: resolve(`./content/${name}.png`) }, this.chatInfo, this.traceId, this.action, undefined, options);
35
+ this.responses.push(response);
36
+ return this.createCaptureController(response);
37
+ },
38
+ /**
39
+ * Sends video/gif message to chat after action execution is finished.
40
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
41
+ * @param name Message contents.
42
+ * @param options Message sending option.
43
+ */
44
+ video: (name, options) => {
45
+ const response = new VideoMessage({ source: resolve(`./content/${name}.mp4`) }, this.chatInfo, this.traceId, this.action, undefined, options);
46
+ this.responses.push(response);
47
+ return this.createCaptureController(response);
48
+ }
49
+ };
50
+ /**
51
+ * Unpins message after action execution is finished.
52
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
53
+ * @param messageId Message id.
54
+ */
55
+ unpinMessage(messageId) {
56
+ this.responses.push(new UnpinResponse(messageId, this.chatInfo, this.traceId, this.action));
57
+ }
58
+ /**
59
+ * Delays next responses by specified amount of time.
60
+ * @param delay Delay in milliseconds.
61
+ */
62
+ wait(delay) {
63
+ this.responses.push(new DelayResponse(delay, this.chatInfo, this.traceId, this.action));
64
+ }
65
+ }
@@ -0,0 +1,27 @@
1
+ import { BotResponse } from '../../types/response';
2
+ import { InlineQueryAction } from '../actions/inlineQueryAction';
3
+ import { BaseContextInternal, BaseContextPropertiesToOmit } from './baseContext';
4
+ import { TelegramInlineQueryResult } from '../../types/externalAliases';
5
+ export type InlineQueryContext = Omit<InlineQueryContextInternal, BaseContextPropertiesToOmit | 'queryResults' | 'queryId'>;
6
+ export declare class InlineQueryContextInternal extends BaseContextInternal<InlineQueryAction> {
7
+ queryResults: TelegramInlineQueryResult[];
8
+ /**
9
+ * Abort signal to be utilized in query handler.
10
+ * Signal will be aborted if new query comes from the same user.
11
+ */
12
+ abortSignal: AbortSignal;
13
+ /** Ordered collection of responses to be processed */
14
+ get responses(): BotResponse[];
15
+ /** Inline query text */
16
+ queryText: string;
17
+ /** Internal query id */
18
+ queryId: string;
19
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
20
+ matchResults: RegExpMatchArray[];
21
+ /**
22
+ * This result will be shown to user as a response to inline query.
23
+ * @param queryResult Inline query result to be shown to user.
24
+ */
25
+ showInlineQueryResult(queryResult: TelegramInlineQueryResult): void;
26
+ }
27
+ //# sourceMappingURL=inlineQueryContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inlineQueryContext.d.ts","sourceRoot":"","sources":["../../../entities/context/inlineQueryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EACH,mBAAmB,EACnB,2BAA2B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACjC,0BAA0B,EAC1B,2BAA2B,GAAG,cAAc,GAAG,SAAS,CAC3D,CAAC;AAEF,qBAAa,0BAA2B,SAAQ,mBAAmB,CAAC,iBAAiB,CAAC;IAClF,YAAY,EAAE,yBAAyB,EAAE,CAAM;IAC/C;;;OAGG;IACH,WAAW,EAAG,WAAW,CAAC;IAE1B,uDAAuD;IACvD,IAAI,SAAS,IAAI,WAAW,EAAE,CAS7B;IACD,wBAAwB;IACxB,SAAS,EAAG,MAAM,CAAC;IACnB,wBAAwB;IACxB,OAAO,EAAG,MAAM,CAAC;IACjB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IAEtC;;;OAGG;IACH,qBAAqB,CAAC,WAAW,EAAE,yBAAyB;CAG/D"}
@@ -0,0 +1,29 @@
1
+ import { InlineQueryResponse } from '../../dtos/responses/inlineQueryResponse';
2
+ import { BaseContextInternal } from './baseContext';
3
+ export class InlineQueryContextInternal extends BaseContextInternal {
4
+ queryResults = [];
5
+ /**
6
+ * Abort signal to be utilized in query handler.
7
+ * Signal will be aborted if new query comes from the same user.
8
+ */
9
+ abortSignal;
10
+ /** Ordered collection of responses to be processed */
11
+ get responses() {
12
+ return [
13
+ new InlineQueryResponse(this.queryResults, this.queryId, this.traceId, this.action)
14
+ ];
15
+ }
16
+ /** Inline query text */
17
+ queryText;
18
+ /** Internal query id */
19
+ queryId;
20
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
21
+ matchResults = [];
22
+ /**
23
+ * This result will be shown to user as a response to inline query.
24
+ * @param queryResult Inline query result to be shown to user.
25
+ */
26
+ showInlineQueryResult(queryResult) {
27
+ this.queryResults.push(queryResult);
28
+ }
29
+ }
@@ -0,0 +1,92 @@
1
+ import { IActionState } from '../../types/actionState';
2
+ import { ChatContextInternal } from './chatContext';
3
+ import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
4
+ import { CommandAction } from '../actions/commandAction';
5
+ import { Seconds } from '../../types/timeValues';
6
+ import { BaseContextPropertiesToOmit } from './baseContext';
7
+ import { MessageInfo } from '../../dtos/messageInfo';
8
+ import { UserInfo } from '../../dtos/userInfo';
9
+ import { BotInfo, TelegramEmoji } from '../../types/externalAliases';
10
+ export type MessageContext<TActionState extends IActionState> = Omit<MessageContextInternal<TActionState>, BaseContextPropertiesToOmit | 'startCooldown' | 'customCooldown'>;
11
+ /**
12
+ * Context of action executed in chat, in response to a message
13
+ */
14
+ export declare class MessageContextInternal<TActionState extends IActionState> extends ChatContextInternal<TActionState, CommandAction<TActionState>> {
15
+ /** Information about the user that triggered this action */
16
+ userInfo: UserInfo;
17
+ /** Information about the message that triggered this action */
18
+ messageInfo: MessageInfo;
19
+ /** Collection of Regexp match results on a message that triggered this action. Will be empty if trigger is not a Regexp. */
20
+ matchResults: RegExpMatchArray[];
21
+ /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
22
+ startCooldown: boolean;
23
+ /** Bot info from Telegram */
24
+ botInfo: BotInfo;
25
+ customCooldown: Seconds | undefined;
26
+ private getQuotePart;
27
+ private replyWithText;
28
+ private replyWithImage;
29
+ private replyWithVideo;
30
+ skipCooldown(): void;
31
+ startCustomCooldown(customCooldown: Seconds): void;
32
+ /**
33
+ * Collection of actions that can be done as a reply to a message that triggered this action
34
+ */
35
+ reply: {
36
+ /**
37
+ * Collection of actions that can be done as a reply to a message, quoting the part that triggered this action
38
+ * If regex is matched, first match will be quoted
39
+ */
40
+ andQuote: {
41
+ /**
42
+ * Reply with text message to message that triggered this action after action execution is finished.
43
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
44
+ * @param text Message contents.
45
+ * @param options Message sending option.
46
+ */
47
+ withText: (text: string, quote?: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
48
+ /**
49
+ * Reply with image message to message that triggered this action after action execution is finished.
50
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
51
+ * @param text Message contents.
52
+ * @param options Message sending option.
53
+ */
54
+ withImage: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
55
+ /**
56
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
57
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
58
+ * @param text Message contents.
59
+ * @param options Message sending option.
60
+ */
61
+ withVideo: (name: string, quote?: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
62
+ };
63
+ /**
64
+ * Reply with text message to message that triggered this action after action execution is finished.
65
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
66
+ * @param text Message contents.
67
+ * @param options Message sending option.
68
+ */
69
+ withText: (text: string, options?: TextMessageSendingOptions) => import("../..").ICaptureController;
70
+ /**
71
+ * Reply with image message to message that triggered this action after action execution is finished.
72
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
73
+ * @param text Message contents.
74
+ * @param options Message sending option.
75
+ */
76
+ withImage: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
77
+ /**
78
+ * Reply with video/gif message to message that triggered this action after action execution is finished.
79
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
80
+ * @param text Message contents.
81
+ * @param options Message sending option.
82
+ */
83
+ withVideo: (name: string, options?: MessageSendingOptions) => import("../..").ICaptureController;
84
+ /**
85
+ * React to the message that triggered this action after action execution is finished.
86
+ * If multiple responses are sent, they will be sent in the order they were added, with delay of at least 35ms as per Telegram rate-limit.
87
+ * @param emoji Telegram emoji to react with.
88
+ */
89
+ withReaction: (emoji: TelegramEmoji) => void;
90
+ };
91
+ }
92
+ //# sourceMappingURL=messageContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,YAAY,IAAI,IAAI,CAChE,sBAAsB,CAAC,YAAY,CAAC,EACpC,2BAA2B,GAAG,eAAe,GAAG,gBAAgB,CACnE,CAAC;AAEF;;GAEG;AACH,qBAAa,sBAAsB,CAC/B,YAAY,SAAS,YAAY,CACnC,SAAQ,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACpE,4DAA4D;IAC5D,QAAQ,EAAG,QAAQ,CAAC;IACpB,+DAA+D;IAC/D,WAAW,EAAG,WAAW,CAAC;IAC1B,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,6BAA6B;IAC7B,OAAO,EAAG,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,cAAc;IAqBtB,YAAY;IAIZ,mBAAmB,CAAC,cAAc,EAAE,OAAO;IAK3C;;OAEG;IACH,KAAK;QACD;;;WAGG;;YAEC;;;;;eAKG;6BAEO,MAAM,UACJ,MAAM,YACJ,yBAAyB;YAEvC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;YAGnC;;;;;eAKG;8BAEO,MAAM,UACJ,MAAM,YACJ,qBAAqB;;QAIvC;;;;;WAKG;yBACc,MAAM,YAAY,yBAAyB;QAE5D;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;;WAKG;0BACe,MAAM,YAAY,qBAAqB;QAGzD;;;;WAIG;8BACmB,aAAa;MAWrC;CACL"}