chz-telegram-bot 0.3.30 → 0.5.0

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 (79) hide show
  1. package/README.md +9 -10
  2. package/bun.lock +1 -7
  3. package/dist/dtos/chatHistoryMessage.d.ts +3 -3
  4. package/dist/dtos/chatHistoryMessage.d.ts.map +1 -1
  5. package/dist/dtos/incomingMessage.d.ts +5 -5
  6. package/dist/dtos/incomingMessage.d.ts.map +1 -1
  7. package/dist/dtos/messageInfo.d.ts +4 -3
  8. package/dist/dtos/messageInfo.d.ts.map +1 -1
  9. package/dist/dtos/responses/imageMessage.d.ts +1 -1
  10. package/dist/dtos/responses/imageMessage.d.ts.map +1 -1
  11. package/dist/dtos/responses/inlineQueryResponse.d.ts +3 -3
  12. package/dist/dtos/responses/inlineQueryResponse.d.ts.map +1 -1
  13. package/dist/dtos/responses/reaction.d.ts +1 -1
  14. package/dist/dtos/responses/reaction.d.ts.map +1 -1
  15. package/dist/dtos/responses/videoMessage.d.ts +1 -1
  16. package/dist/dtos/responses/videoMessage.d.ts.map +1 -1
  17. package/dist/entities/botInstance.d.ts +1 -1
  18. package/dist/entities/botInstance.d.ts.map +1 -1
  19. package/dist/entities/botInstance.js +2 -2
  20. package/dist/entities/context/inlineQueryContext.d.ts +3 -3
  21. package/dist/entities/context/inlineQueryContext.d.ts.map +1 -1
  22. package/dist/entities/context/messageContext.d.ts +2 -2
  23. package/dist/entities/context/messageContext.d.ts.map +1 -1
  24. package/dist/entities/context/replyContext.d.ts +2 -2
  25. package/dist/entities/context/replyContext.d.ts.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -0
  29. package/dist/main.d.ts +1 -1
  30. package/dist/main.d.ts.map +1 -1
  31. package/dist/main.js +2 -2
  32. package/dist/services/actionProcessingService.d.ts +2 -2
  33. package/dist/services/actionProcessingService.d.ts.map +1 -1
  34. package/dist/services/actionProcessingService.js +11 -11
  35. package/dist/services/actionProcessors/commandActionProcessor.d.ts +2 -3
  36. package/dist/services/actionProcessors/commandActionProcessor.d.ts.map +1 -1
  37. package/dist/services/actionProcessors/commandActionProcessor.js +7 -7
  38. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts +2 -2
  39. package/dist/services/actionProcessors/inlineQueryActionProcessor.d.ts.map +1 -1
  40. package/dist/services/actionProcessors/inlineQueryActionProcessor.js +4 -4
  41. package/dist/services/jsonLogger.d.ts +1 -1
  42. package/dist/services/jsonLogger.d.ts.map +1 -1
  43. package/dist/services/jsonLogger.js +33 -22
  44. package/dist/services/telegramApi.d.ts +2 -2
  45. package/dist/services/telegramApi.d.ts.map +1 -1
  46. package/dist/services/telegramApi.js +4 -4
  47. package/dist/types/externalAliases.d.ts +11 -0
  48. package/dist/types/externalAliases.d.ts.map +1 -0
  49. package/dist/types/externalAliases.js +2 -0
  50. package/dist/types/inputFile.d.ts +5 -0
  51. package/dist/types/inputFile.d.ts.map +1 -0
  52. package/dist/types/inputFile.js +2 -0
  53. package/dist/types/logger.d.ts +2 -2
  54. package/dist/types/logger.d.ts.map +1 -1
  55. package/dist/types/messageTypes.d.ts +0 -2
  56. package/dist/types/messageTypes.d.ts.map +1 -1
  57. package/dtos/chatHistoryMessage.ts +2 -2
  58. package/dtos/incomingMessage.ts +7 -13
  59. package/dtos/messageInfo.ts +3 -5
  60. package/dtos/responses/imageMessage.ts +1 -1
  61. package/dtos/responses/inlineQueryResponse.ts +3 -3
  62. package/dtos/responses/reaction.ts +1 -1
  63. package/dtos/responses/videoMessage.ts +1 -1
  64. package/entities/botInstance.ts +2 -2
  65. package/entities/context/inlineQueryContext.ts +3 -3
  66. package/entities/context/messageContext.ts +2 -2
  67. package/entities/context/replyContext.ts +2 -2
  68. package/index.ts +1 -0
  69. package/main.ts +2 -2
  70. package/package.json +37 -44
  71. package/services/actionProcessingService.ts +13 -12
  72. package/services/actionProcessors/commandActionProcessor.ts +15 -16
  73. package/services/actionProcessors/inlineQueryActionProcessor.ts +10 -10
  74. package/services/jsonLogger.ts +42 -27
  75. package/services/telegramApi.ts +15 -13
  76. package/types/externalAliases.ts +17 -0
  77. package/types/inputFile.ts +4 -0
  78. package/types/logger.ts +2 -6
  79. package/types/messageTypes.ts +0 -4
@@ -21,7 +21,7 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
21
21
  x,
22
22
  []
23
23
  ]));
24
- initialize(api, telegraf, commands, verboseLoggingForIncomingMessage, botInfo) {
24
+ initialize(api, telegram, commands, verboseLoggingForIncomingMessage, botInfo) {
25
25
  this.botInfo = botInfo;
26
26
  this.initializeDependencies(api);
27
27
  for (const msgType of Object.values(messageTypes_1.MessageType)) {
@@ -38,16 +38,16 @@ class CommandActionProcessor extends baseProcessor_1.BaseActionProcessor {
38
38
  cmd.triggers.includes(messageTypes_1.MessageType.Any));
39
39
  }
40
40
  if (commands.length > 0) {
41
- telegraf.on('message', (ctx) => {
42
- const msg = new incomingMessage_1.IncomingMessage(ctx.update.message, this.botName, (0, mapUtils_1.getOrSetIfNotExists)(this.chatHistory, ctx.chat.id, []));
43
- const logger = this.logger.createScope(this.botName, msg.traceId, msg.chatInfo.name);
41
+ telegram.on('message', ({ message }) => {
42
+ const internalMessage = new incomingMessage_1.IncomingMessage(message, this.botName, (0, mapUtils_1.getOrSetIfNotExists)(this.chatHistory, message.chat.id, []));
43
+ const logger = this.logger.createScope(this.botName, internalMessage.traceId, internalMessage.chatInfo.name);
44
44
  if (verboseLoggingForIncomingMessage) {
45
- logger.logObjectWithTraceId(ctx.update.message);
45
+ logger.logObjectWithTraceId(message);
46
46
  }
47
47
  else {
48
- logger.logWithTraceId(`${msg.from?.first_name ?? 'Unknown'} (${msg.from?.id ?? 'Unknown'}): ${msg.text || msg.type}`);
48
+ logger.logWithTraceId(`${internalMessage.from?.first_name ?? 'Unknown'} (${internalMessage.from?.id ?? 'Unknown'}): ${internalMessage.text || internalMessage.type}`);
49
49
  }
50
- void this.processMessage(msg);
50
+ void this.processMessage(internalMessage);
51
51
  });
52
52
  }
53
53
  }
@@ -1,11 +1,11 @@
1
- import { Telegraf } from 'telegraf';
2
1
  import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
2
+ import { TelegramBot } from '../../types/externalAliases';
3
3
  import { Milliseconds } from '../../types/timeValues';
4
4
  import { TelegramApiService } from '../telegramApi';
5
5
  import { BaseActionProcessor } from './baseProcessor';
6
6
  export declare class InlineQueryActionProcessor extends BaseActionProcessor {
7
7
  private inlineQueries;
8
- initialize(api: TelegramApiService, telegraf: Telegraf, inlineQueries: InlineQueryAction[], period: Milliseconds): void;
8
+ initialize(api: TelegramApiService, telegram: TelegramBot, inlineQueries: InlineQueryAction[], period: Milliseconds): void;
9
9
  private initializeInlineQueryContext;
10
10
  }
11
11
  //# sourceMappingURL=inlineQueryActionProcessor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,0BAA2B,SAAQ,mBAAmB;IAC/D,OAAO,CAAC,aAAa,CAAuB;IAE5C,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IAuGxB,OAAO,CAAC,4BAA4B;CAqBvC"}
1
+ {"version":3,"file":"inlineQueryActionProcessor.d.ts","sourceRoot":"","sources":["../../../services/actionProcessors/inlineQueryActionProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,qBAAa,0BAA2B,SAAQ,mBAAmB;IAC/D,OAAO,CAAC,aAAa,CAAuB;IAE5C,UAAU,CACN,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,WAAW,EACrB,aAAa,EAAE,iBAAiB,EAAE,EAClC,MAAM,EAAE,YAAY;IAuGxB,OAAO,CAAC,4BAA4B;CAqBvC"}
@@ -7,16 +7,16 @@ const traceFactory_1 = require("../../helpers/traceFactory");
7
7
  const baseProcessor_1 = require("./baseProcessor");
8
8
  class InlineQueryActionProcessor extends baseProcessor_1.BaseActionProcessor {
9
9
  inlineQueries;
10
- initialize(api, telegraf, inlineQueries, period) {
10
+ initialize(api, telegram, inlineQueries, period) {
11
11
  this.initializeDependencies(api);
12
12
  this.inlineQueries = inlineQueries;
13
13
  let pendingInlineQueries = [];
14
14
  const queriesInProcessing = new Map();
15
15
  if (this.inlineQueries.length > 0) {
16
- telegraf.on('inline_query', (ctx) => {
17
- const query = new incomingQuery_1.IncomingInlineQuery(ctx.inlineQuery.id, ctx.inlineQuery.query, ctx.inlineQuery.from.id, (0, traceFactory_1.createTrace)('InlineQuery', this.botName, ctx.inlineQuery.id));
16
+ telegram.on('inline_query', ({ inlineQuery }) => {
17
+ const query = new incomingQuery_1.IncomingInlineQuery(inlineQuery.id, inlineQuery.query, inlineQuery.from.id, (0, traceFactory_1.createTrace)('InlineQuery', this.botName, inlineQuery.id));
18
18
  const logger = this.logger.createScope(this.botName, query.traceId, 'Query');
19
- logger.logWithTraceId(`${ctx.inlineQuery.from.username ?? 'Unknown'} (${ctx.inlineQuery.from.id}): Query for ${ctx.inlineQuery.query}`);
19
+ logger.logWithTraceId(`${inlineQuery.from.username ?? 'Unknown'} (${inlineQuery.from.id}): Query for ${inlineQuery.query}`);
20
20
  const queryBeingProcessed = queriesInProcessing.get(query.userId);
21
21
  if (queryBeingProcessed) {
22
22
  logger.logWithTraceId(`Aborting query ${queryBeingProcessed.queryId} (${queryBeingProcessed.query}): new query recieved from ${query.userId}`);
@@ -4,7 +4,7 @@ export declare class JsonLogger implements ILogger {
4
4
  private serializeError;
5
5
  private getCircularReplacer;
6
6
  createScope(botName: string, traceId: TraceId, chatName: string): IScopedLogger;
7
- logObjectWithTraceId(botName: string, traceId: TraceId, chatName: string, data: any): void;
7
+ logObjectWithTraceId(botName: string, traceId: TraceId, chatName: string, data: unknown): void;
8
8
  logWithTraceId(botName: string, traceId: TraceId, chatName: string, text: string): void;
9
9
  errorWithTraceId(botName: string, traceId: TraceId, chatName: string, errorObj: unknown, extraData?: unknown): void;
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,mBAAmB;IAmB3B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,GAAG;IAQb,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;CAe1B"}
1
+ {"version":3,"file":"jsonLogger.d.ts","sourceRoot":"","sources":["../../services/jsonLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,UAAW,YAAW,OAAO;IACtC,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,mBAAmB;IAc3B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAiBtD,aAAa;IAGtB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO;IAoBjB,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;IAOhB,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO;CAe1B"}
@@ -3,27 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonLogger = void 0;
4
4
  class JsonLogger {
5
5
  serializeError(error) {
6
- const plainObject = {};
7
- Object.getOwnPropertyNames(error).forEach(function (key) {
8
- plainObject[key] = error[key];
9
- });
10
- return JSON.stringify(plainObject);
6
+ if (error instanceof Error) {
7
+ const plainObject = {
8
+ name: error.name,
9
+ message: error.message,
10
+ stack: error.stack
11
+ };
12
+ for (const [key, value] of Object.entries(error)) {
13
+ plainObject[key] = value;
14
+ }
15
+ return JSON.stringify(plainObject);
16
+ }
17
+ return JSON.stringify({ error });
11
18
  }
12
19
  getCircularReplacer() {
13
- const ancestors = [];
14
- return function (_, value) {
15
- if (typeof value !== 'object' || value === null) {
16
- return value;
17
- }
18
- // `this` is the object that value is contained in,
19
- // i.e., its direct parent.
20
- while (ancestors.length > 0 && ancestors.at(-1) !== this) {
21
- ancestors.pop();
20
+ const cache = new Set();
21
+ return (_, value) => {
22
+ if (typeof value === 'object' && value !== null) {
23
+ if (cache.has(value)) {
24
+ return;
25
+ }
26
+ cache.add(value);
22
27
  }
23
- if (ancestors.includes(value)) {
24
- return '[Circular]';
25
- }
26
- ancestors.push(value);
27
28
  return value;
28
29
  };
29
30
  }
@@ -41,10 +42,20 @@ class JsonLogger {
41
42
  };
42
43
  }
43
44
  logObjectWithTraceId(botName, traceId, chatName, data) {
44
- data.botName = botName;
45
- data.traceId = traceId;
46
- data.chatName = chatName;
47
- console.log(data);
45
+ const enrichedData = typeof data == 'object'
46
+ ? {
47
+ ...data,
48
+ botName,
49
+ traceId,
50
+ chatName
51
+ }
52
+ : {
53
+ botName,
54
+ traceId,
55
+ chatName,
56
+ data
57
+ };
58
+ console.log(enrichedData);
48
59
  }
49
60
  logWithTraceId(botName, traceId, chatName, text) {
50
61
  console.log(`{"botName":"${botName}","traceId":"${traceId}","chatName":"${chatName}","text":"${text}"}`);
@@ -1,10 +1,10 @@
1
1
  import { IStorageClient } from '../types/storage';
2
2
  import { BotResponse } from '../types/response';
3
- import { Telegram } from 'telegraf/typings/telegram';
4
3
  import { ILogger } from '../types/logger';
5
4
  import { IReplyCapture } from '../types/capture';
6
5
  import { TraceId } from '../types/trace';
7
6
  import { ChatInfo } from '../dtos/chatInfo';
7
+ import { TelegramApiClient } from '../types/externalAliases';
8
8
  export declare const TELEGRAM_ERROR_QUOTE_INVALID = "QUOTE_TEXT_INVALID";
9
9
  export declare class TelegramApiService {
10
10
  private readonly queue;
@@ -13,7 +13,7 @@ export declare class TelegramApiService {
13
13
  private readonly logger;
14
14
  private readonly captureRegistrationCallback;
15
15
  private readonly botName;
16
- constructor(botName: string, telegram: Telegram, storage: IStorageClient, logger: ILogger, captureRegistrationCallback: (capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId) => void);
16
+ constructor(botName: string, telegram: TelegramApiClient, storage: IStorageClient, logger: ILogger, captureRegistrationCallback: (capture: IReplyCapture, parentMessageId: number, chatInfo: ChatInfo, traceId: TraceId) => void);
17
17
  enqueueBatchedResponses(responses: BotResponse[]): void;
18
18
  flushResponses(): void;
19
19
  private pinIfShould;
@@ -1 +1 @@
1
- {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAKlC;IAEV,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG7B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,2BAA2B,EAAE,CACzB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,KACf,IAAI;IASb,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAsDhD,cAAc;YAIA,WAAW;YAkBX,eAAe;CAsGhC"}
1
+ {"version":3,"file":"telegramApi.d.ts","sourceRoot":"","sources":["../../services/telegramApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAmB,MAAM,0BAA0B,CAAC;AAE9E,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAKlC;IAEV,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAG7B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,2BAA2B,EAAE,CACzB,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,KACf,IAAI;IASb,uBAAuB,CAAC,SAAS,EAAE,WAAW,EAAE;IAwDhD,cAAc;YAIA,WAAW;YAqBX,eAAe;CAqGhC"}
@@ -57,11 +57,11 @@ class TelegramApiService {
57
57
  flushResponses() {
58
58
  void this.queue.flushReadyItems();
59
59
  }
60
- async pinIfShould(response, sentMessage) {
60
+ async pinIfShould(response, message) {
61
61
  if (response.shouldPin) {
62
- await this.telegram.pinChatMessage(response.chatInfo.id, sentMessage.message_id, { disable_notification: true });
62
+ await this.telegram.pinChatMessage(response.chatInfo.id, message.message_id, { disable_notification: true });
63
63
  await this.storage.updateStateFor(response.action, response.chatInfo.id, (state) => {
64
- state.pinnedMessages.push(sentMessage.message_id);
64
+ state.pinnedMessages.push(message.message_id);
65
65
  });
66
66
  }
67
67
  }
@@ -108,7 +108,7 @@ class TelegramApiService {
108
108
  type: 'emoji',
109
109
  emoji: response.emoji
110
110
  }
111
- ], true);
111
+ ]);
112
112
  return;
113
113
  case 'unpin':
114
114
  await this.telegram.unpinChatMessage(response.chatInfo.id, response.messageId);
@@ -0,0 +1,11 @@
1
+ import { User, Message, InlineQueryResult, TelegramEmoji as Emoji, UserFromGetMe } from 'telegraf/typings/core/types/typegram';
2
+ import { Telegraf } from 'telegraf';
3
+ import Telegram from 'telegraf/typings/telegram';
4
+ export type TelegramUser = User;
5
+ export type TelegramMessage = Message;
6
+ export type TelegramInlineQueryResult = InlineQueryResult;
7
+ export type TelegramEmoji = Emoji;
8
+ export type TelegramApiClient = Telegram;
9
+ export type BotInfo = UserFromGetMe;
10
+ export type TelegramBot = Telegraf;
11
+ //# sourceMappingURL=externalAliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalAliases.d.ts","sourceRoot":"","sources":["../../types/externalAliases.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,OAAO,EACP,iBAAiB,EACjB,aAAa,IAAI,KAAK,EACtB,aAAa,EAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,QAAQ,MAAM,2BAA2B,CAAC;AAEjD,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC;AAChC,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC;AACtC,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC;AAClC,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC;AACpC,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface InputFile {
2
+ source: string;
3
+ filename?: string;
4
+ }
5
+ //# sourceMappingURL=inputFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputFile.d.ts","sourceRoot":"","sources":["../../types/inputFile.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,12 @@
1
1
  import { TraceId } from './trace';
2
2
  export interface IScopedLogger {
3
- logObjectWithTraceId(data: any): void;
3
+ logObjectWithTraceId(data: unknown): void;
4
4
  logWithTraceId(text: string): void;
5
5
  errorWithTraceId(errorObj: unknown, extraData?: unknown): void;
6
6
  }
7
7
  export interface ILogger {
8
8
  createScope(botName: string, traceId: TraceId, chatName: string): IScopedLogger;
9
- logObjectWithTraceId(botName: string, traceId: TraceId, chatName: string, data: any): void;
9
+ logObjectWithTraceId(botName: string, traceId: TraceId, chatName: string, data: unknown): void;
10
10
  logWithTraceId(botName: string, traceId: TraceId, chatName: string, text: string): void;
11
11
  errorWithTraceId(botName: string, traceId: TraceId, chatName: string, errorObj: unknown, extraData?: unknown): void;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../types/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,aAAa;IAC1B,oBAAoB,CAEhB,IAAI,EAAE,GAAG,GACV,IAAI,CAAC;IAER,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAClE;AAED,MAAM,WAAW,OAAO;IACpB,WAAW,CACP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GACjB,aAAa,CAAC;IAEjB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAEhB,IAAI,EAAE,GAAG,GACV,IAAI,CAAC;IAER,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACb,IAAI,CAAC;IAER,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO,GACpB,IAAI,CAAC;CACX"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../types/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,aAAa;IAC1B,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAE1C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAClE;AAED,MAAM,WAAW,OAAO;IACpB,WAAW,CACP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GACjB,aAAa,CAAC;IAEjB,oBAAoB,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACd,IAAI,CAAC;IAER,cAAc,CACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACb,IAAI,CAAC;IAER,gBAAgB,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO,GACpB,IAAI,CAAC;CACX"}
@@ -1,4 +1,3 @@
1
- import { Message, Update } from 'telegraf/types';
2
1
  export declare const INTERNAL_MESSAGE_TYPE_PREFIX = "__msg:";
3
2
  export declare const MessageType: {
4
3
  readonly Any: "__msg:Any";
@@ -18,5 +17,4 @@ export declare const MessageType: {
18
17
  readonly Unknown: "__msg:Unknown";
19
18
  };
20
19
  export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
21
- export type TelegrafContextMessage = Update.New & (Update.NonChannel & Message);
22
20
  //# sourceMappingURL=messageTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../types/messageTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,4BAA4B,WAAW,CAAC;AAErD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;CAgBd,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE9E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../types/messageTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,WAAW,CAAC;AAErD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;CAgBd,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
@@ -1,11 +1,11 @@
1
- import { User } from 'telegraf/types';
1
+ import { TelegramUser } from '../types/externalAliases';
2
2
  import { MessageTypeValue } from '../types/messageTypes';
3
3
  import { TraceId } from '../types/trace';
4
4
 
5
5
  export class ChatHistoryMessage {
6
6
  constructor(
7
7
  readonly id: number,
8
- readonly from: User | undefined,
8
+ readonly from: TelegramUser | undefined,
9
9
  readonly text: string,
10
10
  readonly type: MessageTypeValue,
11
11
  readonly traceId: TraceId,
@@ -1,29 +1,23 @@
1
- import { Message, Update, User } from 'telegraf/types';
2
1
  import { randomInt } from 'crypto';
3
- import {
4
- MessageType,
5
- MessageTypeValue,
6
- TelegrafContextMessage
7
- } from '../types/messageTypes';
2
+ import { MessageType, MessageTypeValue } from '../types/messageTypes';
8
3
  import { ChatInfo } from './chatInfo';
9
4
  import { createTrace } from '../helpers/traceFactory';
10
5
  import { TraceId } from '../types/trace';
11
6
  import { ChatHistoryMessage } from './chatHistoryMessage';
7
+ import { TelegramMessage, TelegramUser } from '../types/externalAliases';
12
8
 
13
9
  export class IncomingMessage {
14
10
  readonly messageId: number;
15
11
  readonly chatInfo: ChatInfo;
16
- readonly from: User | undefined;
12
+ readonly from: TelegramUser | undefined;
17
13
  readonly text: string;
18
14
  readonly type: MessageTypeValue;
19
15
  readonly traceId: TraceId;
20
16
  readonly replyToMessageId: number | undefined;
21
17
 
22
- readonly updateObject: TelegrafContextMessage;
18
+ readonly updateObject: TelegramMessage;
23
19
 
24
- private detectMessageType(
25
- message: Update.New & (Update.NonChannel & Message)
26
- ) {
20
+ private detectMessageType(message: TelegramMessage) {
27
21
  if ('forward_origin' in message) return MessageType.Forward;
28
22
  if ('text' in message) return MessageType.Text;
29
23
  if ('video' in message) return MessageType.Video;
@@ -42,7 +36,7 @@ export class IncomingMessage {
42
36
  }
43
37
 
44
38
  constructor(
45
- ctxMessage: TelegrafContextMessage,
39
+ ctxMessage: TelegramMessage,
46
40
  botName: string,
47
41
  history: ChatHistoryMessage[]
48
42
  ) {
@@ -69,7 +63,7 @@ export class IncomingMessage {
69
63
  this.updateObject = ctxMessage;
70
64
  }
71
65
 
72
- private getMessageText(ctxMessage: TelegrafContextMessage) {
66
+ private getMessageText(ctxMessage: TelegramMessage) {
73
67
  if ('text' in ctxMessage) return ctxMessage.text;
74
68
 
75
69
  return 'caption' in ctxMessage ? ctxMessage.caption ?? '' : '';
@@ -1,7 +1,5 @@
1
- import {
2
- MessageTypeValue,
3
- TelegrafContextMessage
4
- } from '../types/messageTypes';
1
+ import { TelegramMessage } from '../types/externalAliases';
2
+ import { MessageTypeValue } from '../types/messageTypes';
5
3
 
6
4
  export class MessageInfo {
7
5
  constructor(
@@ -12,6 +10,6 @@ export class MessageInfo {
12
10
  /** Type of message being received */
13
11
  readonly type: MessageTypeValue,
14
12
  /** Message object recieved from Telegram */
15
- readonly telegramUpdateObject: TelegrafContextMessage
13
+ readonly telegramUpdateObject: TelegramMessage
16
14
  ) {}
17
15
  }
@@ -1,4 +1,3 @@
1
- import { InputFile } from 'telegraf/types';
2
1
  import {
3
2
  BotResponseTypes,
4
3
  IReplyResponseWithContent
@@ -9,6 +8,7 @@ import { ChatInfo } from '../chatInfo';
9
8
  import { TraceId } from '../../types/trace';
10
9
  import { ReplyInfo } from '../replyInfo';
11
10
  import { IReplyCapture } from '../../types/capture';
11
+ import { InputFile } from '../../types/inputFile';
12
12
 
13
13
  export class ImageMessage implements IReplyResponseWithContent<InputFile> {
14
14
  readonly kind = BotResponseTypes.image;
@@ -1,5 +1,5 @@
1
- import { InlineQueryResult } from 'telegraf/types';
2
1
  import { InlineQueryAction } from '../../entities/actions/inlineQueryAction';
2
+ import { TelegramInlineQueryResult } from '../../types/externalAliases';
3
3
  import { BotResponseTypes } from '../../types/response';
4
4
  import { TraceId } from '../../types/trace';
5
5
 
@@ -10,10 +10,10 @@ export class InlineQueryResponse {
10
10
  readonly queryId: string;
11
11
  readonly traceId: TraceId;
12
12
  readonly action: InlineQueryAction;
13
- readonly queryResults: InlineQueryResult[];
13
+ readonly queryResults: TelegramInlineQueryResult[];
14
14
 
15
15
  constructor(
16
- queryResult: InlineQueryResult[],
16
+ queryResult: TelegramInlineQueryResult[],
17
17
  queryId: string,
18
18
  traceId: TraceId,
19
19
  action: InlineQueryAction
@@ -1,8 +1,8 @@
1
- import { TelegramEmoji } from 'telegraf/types';
2
1
  import { BotResponseTypes, IChatResponse } from '../../types/response';
3
2
  import { IAction } from '../../types/action';
4
3
  import { ChatInfo } from '../chatInfo';
5
4
  import { TraceId } from '../../types/trace';
5
+ import { TelegramEmoji } from '../../types/externalAliases';
6
6
 
7
7
  export class Reaction implements IChatResponse {
8
8
  readonly kind = BotResponseTypes.react;
@@ -1,4 +1,3 @@
1
- import { InputFile } from 'telegraf/types';
2
1
  import {
3
2
  BotResponseTypes,
4
3
  IReplyResponseWithContent
@@ -9,6 +8,7 @@ import { ChatInfo } from '../chatInfo';
9
8
  import { TraceId } from '../../types/trace';
10
9
  import { ReplyInfo } from '../replyInfo';
11
10
  import { IReplyCapture } from '../../types/capture';
11
+ import { InputFile } from '../../types/inputFile';
12
12
 
13
13
  export class VideoMessage implements IReplyResponseWithContent<InputFile> {
14
14
  readonly kind = BotResponseTypes.video;
@@ -83,7 +83,7 @@ export class BotInstance {
83
83
  );
84
84
  }
85
85
 
86
- async stop(code: string) {
86
+ async stop() {
87
87
  this.logger.logWithTraceId(
88
88
  this.name,
89
89
  createTrace(this, this.name, 'Stop'),
@@ -93,6 +93,6 @@ export class BotInstance {
93
93
 
94
94
  this.scheduler.stopAll();
95
95
  await this.storage.close();
96
- this.actionProcessingService.stop(code);
96
+ await this.actionProcessingService.stop();
97
97
  }
98
98
  }
@@ -1,4 +1,3 @@
1
- import { InlineQueryResult } from 'telegraf/types';
2
1
  import { BotResponse } from '../../types/response';
3
2
  import { InlineQueryAction } from '../actions/inlineQueryAction';
4
3
  import { InlineQueryResponse } from '../../dtos/responses/inlineQueryResponse';
@@ -6,6 +5,7 @@ import {
6
5
  BaseContextInternal,
7
6
  BaseContextPropertiesToOmit
8
7
  } from './baseContext';
8
+ import { TelegramInlineQueryResult } from '../../types/externalAliases';
9
9
 
10
10
  export type InlineQueryContext = Omit<
11
11
  InlineQueryContextInternal,
@@ -13,7 +13,7 @@ export type InlineQueryContext = Omit<
13
13
  >;
14
14
 
15
15
  export class InlineQueryContextInternal extends BaseContextInternal<InlineQueryAction> {
16
- queryResults: InlineQueryResult[] = [];
16
+ queryResults: TelegramInlineQueryResult[] = [];
17
17
  /**
18
18
  * Abort signal to be utilized in query handler.
19
19
  * Signal will be aborted if new query comes from the same user.
@@ -42,7 +42,7 @@ export class InlineQueryContextInternal extends BaseContextInternal<InlineQueryA
42
42
  * This result will be shown to user as a response to inline query.
43
43
  * @param queryResult Inline query result to be shown to user.
44
44
  */
45
- showInlineQueryResult(queryResult: InlineQueryResult) {
45
+ showInlineQueryResult(queryResult: TelegramInlineQueryResult) {
46
46
  this.queryResults.push(queryResult);
47
47
  }
48
48
  }
@@ -1,5 +1,4 @@
1
1
  import { resolve } from 'path';
2
- import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
3
2
  import { IActionState } from '../../types/actionState';
4
3
  import { ImageMessage } from '../../dtos/responses/imageMessage';
5
4
  import { Reaction } from '../../dtos/responses/reaction';
@@ -16,6 +15,7 @@ import { Seconds } from '../../types/timeValues';
16
15
  import { BaseContextPropertiesToOmit } from './baseContext';
17
16
  import { MessageInfo } from '../../dtos/messageInfo';
18
17
  import { UserInfo } from '../../dtos/userInfo';
18
+ import { BotInfo, TelegramEmoji } from '../../types/externalAliases';
19
19
 
20
20
  export type MessageContext<TActionState extends IActionState> = Omit<
21
21
  MessageContextInternal<TActionState>,
@@ -37,7 +37,7 @@ export class MessageContextInternal<
37
37
  /** Indicates if cooldown should be started after action is executed. Set to `true` by default. */
38
38
  startCooldown: boolean = true;
39
39
  /** Bot info from Telegram */
40
- botInfo!: UserFromGetMe;
40
+ botInfo!: BotInfo;
41
41
  customCooldown: Seconds | undefined;
42
42
 
43
43
  private getQuotePart(quote: boolean | string) {
@@ -1,4 +1,3 @@
1
- import { TelegramEmoji, UserFromGetMe } from 'telegraf/types';
2
1
  import { ReplyInfo } from '../../dtos/replyInfo';
3
2
  import { ImageMessage } from '../../dtos/responses/imageMessage';
4
3
  import { Reaction } from '../../dtos/responses/reaction';
@@ -17,6 +16,7 @@ import {
17
16
  } from './baseContext';
18
17
  import { UserInfo } from '../../dtos/userInfo';
19
18
  import { MessageInfo } from '../../dtos/messageInfo';
19
+ import { TelegramUser, TelegramEmoji } from '../../types/externalAliases';
20
20
 
21
21
  export type ReplyContext<TActionState extends IActionState> = Omit<
22
22
  ReplyContextInternal<TActionState>,
@@ -38,7 +38,7 @@ export class ReplyContextInternal<
38
38
  /** Information about the message that triggered this action */
39
39
  messageInfo!: MessageInfo;
40
40
  /** Bot info from Telegram */
41
- botInfo!: UserFromGetMe;
41
+ botInfo!: TelegramUser;
42
42
 
43
43
  isInitialized = false;
44
44
 
package/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './entities/states/actionStateBase';
7
7
  export * from './types/messageTypes';
8
8
  export * from './helpers/timeConvertions';
9
9
  export * from './types/action';
10
+ export * from './types/externalAliases';
10
11
  export { CommandAction } from './entities/actions/commandAction';
11
12
  export { InlineQueryAction } from './entities/actions/inlineQueryAction';
12
13
  export { ReplyCaptureAction } from './entities/actions/replyCaptureAction';
package/main.ts CHANGED
@@ -73,9 +73,9 @@ class BotOrchestrator {
73
73
  /**
74
74
  * Terminates all scheduled tasks, closes storage connections and stops all bots.
75
75
  */
76
- async stopBots(reason: string) {
76
+ async stopBots() {
77
77
  for (const bot of this.bots) {
78
- await bot.stop(reason);
78
+ await bot.stop();
79
79
  }
80
80
  }
81
81
  }