chz-telegram-bot 0.1.17 → 0.1.19

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.
@@ -1,5 +1,5 @@
1
- import { Message, Update, User } from 'telegraf/types';
2
- import { MessageTypeValue } from '../types/messageTypes';
1
+ import { User } from 'telegraf/types';
2
+ import { MessageTypeValue, TelegrafContextMessage } from '../types/messageTypes';
3
3
  import { ChatInfo } from './chatInfo';
4
4
  import { TraceId } from '../types/trace';
5
5
  export declare class IncomingMessage {
@@ -9,7 +9,8 @@ export declare class IncomingMessage {
9
9
  readonly text: string;
10
10
  readonly type: MessageTypeValue;
11
11
  readonly traceId: TraceId;
12
+ readonly updateObject: TelegrafContextMessage;
12
13
  private detectMessageType;
13
- constructor(ctxMessage: Update.New & (Update.NonChannel & Message), botName: string);
14
+ constructor(ctxMessage: TelegrafContextMessage, botName: string);
14
15
  }
15
16
  //# sourceMappingURL=incomingMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../dtos/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,eAAe;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,OAAO,CAAC,iBAAiB;gBAmBrB,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,EACtD,OAAO,EAAE,MAAM;CAkBtB"}
1
+ {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../dtos/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAEH,gBAAgB,EAChB,sBAAsB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,qBAAa,eAAe;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;IAE9C,OAAO,CAAC,iBAAiB;gBAmBb,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAkBlE"}
@@ -7,6 +7,8 @@ const chatInfo_1 = require("./chatInfo");
7
7
  const traceFactory_1 = require("../helpers/traceFactory");
8
8
  class IncomingMessage {
9
9
  detectMessageType(message) {
10
+ if ('forward_origin' in message)
11
+ return messageTypes_1.MessageType.Forward;
10
12
  if ('text' in message)
11
13
  return messageTypes_1.MessageType.Text;
12
14
  if ('photo' in message)
@@ -40,6 +42,7 @@ class IncomingMessage {
40
42
  ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
41
43
  : 'DM');
42
44
  this.type = this.detectMessageType(ctxMessage);
45
+ this.updateObject = ctxMessage;
43
46
  }
44
47
  }
45
48
  exports.IncomingMessage = IncomingMessage;
@@ -5,7 +5,7 @@ import { ChatContext } from './chatContext';
5
5
  import { IncomingMessage } from '../../dtos/incomingMessage';
6
6
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
7
7
  import { IActionWithState } from '../../types/statefulAction';
8
- import { MessageTypeValue } from '../../types/messageTypes';
8
+ import { MessageTypeValue, TelegrafContextMessage } from '../../types/messageTypes';
9
9
  import { ILogger } from '../../types/logger';
10
10
  import { IScheduler } from '../../types/scheduler';
11
11
  /**
@@ -26,6 +26,8 @@ export declare class MessageContext<TActionState extends IActionState> extends C
26
26
  fromUserName: string;
27
27
  /** Type of message being received */
28
28
  messageType: MessageTypeValue;
29
+ /** Message object recieved from Telegram */
30
+ messageUpdateObject: TelegrafContextMessage;
29
31
  constructor(storage: IStorageClient, logger: ILogger, scheduler: IScheduler);
30
32
  initializeMessageContext(botName: string, action: IActionWithState<TActionState>, message: IncomingMessage): this;
31
33
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,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,4BAA4B,CAAC;AAC7D,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAG,MAAM,CAAC;IACnB,oDAAoD;IACpD,WAAW,EAAG,MAAM,CAAC;IACrB,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,EAAG,MAAM,CAAC;IACtB,qCAAqC;IACrC,WAAW,EAAG,gBAAgB,CAAC;gBAG3B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,UAAU;IAKzB,wBAAwB,CACpB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACtC,OAAO,EAAE,eAAe;IAqB5B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
1
+ {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAA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O,CAAC,mBAAmB,CAAC;IAe/B;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
@@ -27,6 +27,7 @@ class MessageContext extends chatContext_1.ChatContext {
27
27
  this.fromUserName =
28
28
  (message.from?.first_name ?? 'Unknown user') +
29
29
  (message.from?.last_name ? ` ${message.from.last_name}` : '');
30
+ this.messageUpdateObject = message.updateObject;
30
31
  this.matchResults = [];
31
32
  this.startCooldown = true;
32
33
  return this.initializeChatContext(botName, action, message.chatInfo, message.traceId);
@@ -1,3 +1,4 @@
1
+ import { Message, Update } from 'telegraf/types';
1
2
  export declare const MessageType: {
2
3
  readonly Text: "__msg:Text";
3
4
  readonly Sticker: "__msg:Sticker";
@@ -10,7 +11,9 @@ export declare const MessageType: {
10
11
  readonly Poll: "__msg:Poll";
11
12
  readonly Location: "__msg:Location";
12
13
  readonly Photo: "__msg:Photo";
14
+ readonly Forward: "__msg:Forward";
13
15
  readonly Unknown: "__msg:Unknown";
14
16
  };
15
17
  export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
18
+ export type TelegrafContextMessage = Update.New & (Update.NonChannel & Message);
16
19
  //# sourceMappingURL=messageTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../types/messageTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAad,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
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,WAAW;;;;;;;;;;;;;;CAcd,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"}
@@ -13,5 +13,6 @@ exports.MessageType = {
13
13
  Poll: '__msg:Poll',
14
14
  Location: '__msg:Location',
15
15
  Photo: '__msg:Photo',
16
+ Forward: '__msg:Forward',
16
17
  Unknown: '__msg:Unknown'
17
18
  };
@@ -1,6 +1,10 @@
1
1
  import { Message, Update, User } from 'telegraf/types';
2
2
  import { randomInt } from 'crypto';
3
- import { MessageType, MessageTypeValue } from '../types/messageTypes';
3
+ import {
4
+ MessageType,
5
+ MessageTypeValue,
6
+ TelegrafContextMessage
7
+ } from '../types/messageTypes';
4
8
  import { ChatInfo } from './chatInfo';
5
9
  import { createTrace } from '../helpers/traceFactory';
6
10
  import { TraceId } from '../types/trace';
@@ -13,9 +17,12 @@ export class IncomingMessage {
13
17
  readonly type: MessageTypeValue;
14
18
  readonly traceId: TraceId;
15
19
 
20
+ readonly updateObject: TelegrafContextMessage;
21
+
16
22
  private detectMessageType(
17
23
  message: Update.New & (Update.NonChannel & Message)
18
24
  ) {
25
+ if ('forward_origin' in message) return MessageType.Forward;
19
26
  if ('text' in message) return MessageType.Text;
20
27
  if ('photo' in message) return MessageType.Photo;
21
28
  if ('sticker' in message) return MessageType.Sticker;
@@ -31,10 +38,7 @@ export class IncomingMessage {
31
38
  return MessageType.Unknown;
32
39
  }
33
40
 
34
- constructor(
35
- ctxMessage: Update.New & (Update.NonChannel & Message),
36
- botName: string
37
- ) {
41
+ constructor(ctxMessage: TelegrafContextMessage, botName: string) {
38
42
  this.traceId = createTrace(
39
43
  this,
40
44
  botName,
@@ -50,5 +54,6 @@ export class IncomingMessage {
50
54
  : 'DM'
51
55
  );
52
56
  this.type = this.detectMessageType(ctxMessage);
57
+ this.updateObject = ctxMessage;
53
58
  }
54
59
  }
@@ -14,7 +14,10 @@ import {
14
14
  TextMessageSendingOptions
15
15
  } from '../../types/messageSendingOptions';
16
16
  import { IActionWithState, ActionKey } from '../../types/statefulAction';
17
- import { MessageTypeValue } from '../../types/messageTypes';
17
+ import {
18
+ MessageTypeValue,
19
+ TelegrafContextMessage
20
+ } from '../../types/messageTypes';
18
21
  import { ILogger } from '../../types/logger';
19
22
  import { IScheduler } from '../../types/scheduler';
20
23
  /**
@@ -37,6 +40,8 @@ export class MessageContext<
37
40
  fromUserName!: string;
38
41
  /** Type of message being received */
39
42
  messageType!: MessageTypeValue;
43
+ /** Message object recieved from Telegram */
44
+ messageUpdateObject!: TelegrafContextMessage;
40
45
 
41
46
  constructor(
42
47
  storage: IStorageClient,
@@ -58,6 +63,7 @@ export class MessageContext<
58
63
  this.fromUserName =
59
64
  (message.from?.first_name ?? 'Unknown user') +
60
65
  (message.from?.last_name ? ` ${message.from.last_name}` : '');
66
+ this.messageUpdateObject = message.updateObject;
61
67
 
62
68
  this.matchResults = [];
63
69
  this.startCooldown = true;
package/eslint.config.js CHANGED
@@ -5,6 +5,7 @@ export default tseslint.config(
5
5
  eslint.configs.recommended,
6
6
  ...tseslint.configs.recommended,
7
7
  {
8
+ ignores: ['dist/*'],
8
9
  rules: {
9
10
  '@typescript-eslint/no-unused-vars': [
10
11
  'error',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",
@@ -1,3 +1,5 @@
1
+ import { Message, Update } from 'telegraf/types';
2
+
1
3
  export const MessageType = {
2
4
  Text: '__msg:Text',
3
5
  Sticker: '__msg:Sticker',
@@ -10,7 +12,10 @@ export const MessageType = {
10
12
  Poll: '__msg:Poll',
11
13
  Location: '__msg:Location',
12
14
  Photo: '__msg:Photo',
15
+ Forward: '__msg:Forward',
13
16
  Unknown: '__msg:Unknown'
14
17
  } as const;
15
18
 
16
19
  export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
20
+
21
+ export type TelegrafContextMessage = Update.New & (Update.NonChannel & Message);