chz-telegram-bot 0.0.36 → 0.0.38

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 +1 @@
1
- {"version":3,"file":"commandAction.d.ts","sourceRoot":"","sources":["../../../entities/actions/commandAction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAkB,MAAM,4BAA4B,CAAC;AAE5E,qBAAa,aAAa,CAAC,YAAY,SAAS,YAAY,CACxD,YAAW,gBAAgB;IAE3B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,EAAE,MAAM,YAAY,CAAC;IACrC,GAAG,EAAE,SAAS,CAAC;gBAGX,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,EAC1C,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EA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,EAAE,MAAM,EAAE,EACxB,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,gBAAgB,CAAC,YAAY,CAAC,EACzC,gBAAgB,EAAE,MAAM,YAAY;IAelC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,YAAY,CAAC;IAgD5C,OAAO,CAAC,YAAY;CAwDvB"}
@@ -10,7 +10,6 @@ const toArray_1 = require("../../helpers/toArray");
10
10
  const commandTriggerCheckResult_1 = require("../commandTriggerCheckResult");
11
11
  const logger_1 = require("../../services/logger");
12
12
  const actionExecutionResult_1 = require("../actionExecutionResult");
13
- const commandTrigger_1 = require("../../types/commandTrigger");
14
13
  class CommandAction {
15
14
  constructor(trigger, handler, name, active, cooldown, chatsBlacklist, allowedUsers, condition, stateConstructor) {
16
15
  this.triggers = (0, toArray_1.toArray)(trigger);
@@ -62,8 +61,8 @@ class CommandAction {
62
61
  const onCooldown = (0, moment_1.default)().diff(lastExecutedDate) < cooldownInMilliseconds;
63
62
  if (onCooldown)
64
63
  return commandTriggerCheckResult_1.CommandTriggerCheckResult.DoNotTrigger;
65
- if (trigger == commandTrigger_1.NonTextMessage.Any) {
66
- shouldTrigger = ctx.messageText == '';
64
+ if (trigger == ctx.messageType) {
65
+ shouldTrigger = true;
67
66
  }
68
67
  else if (typeof trigger == 'string') {
69
68
  shouldTrigger = ctx.messageText.toLowerCase() == trigger;
@@ -1 +1 @@
1
- {"version":3,"file":"botInstance.d.ts","sourceRoot":"","sources":["../../entities/botInstance.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,qBAAa,WAAW;IACpB,IAAI,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AK,CAAyB;IACtC,OAAO,EAAE,cAAc,CAAC;gBAEZ,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,cAAc,CAAC;QAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC7B;IAmCD,OAAO,CAAC,6BAA6B;IA2CrC,OAAO,CAAC,2BAA2B;IAsB7B,IAAI,CAAC,IAAI,EAAE,MAAM;YAYT,YAAY;YAyBZ,cAAc;CAmB/B"}
@@ -54,8 +54,9 @@ class BotInstance {
54
54
  initializeMessageProcessing() {
55
55
  if (this.commands.length > 0) {
56
56
  this.telegraf.on('message', async (ctx) => {
57
+ console.dir(ctx.update);
57
58
  const msg = new incomingMessage_1.IncomingMessage(ctx.update.message);
58
- const messageContent = msg.text || '<non-text message>';
59
+ const messageContent = msg.text || `<non-text message: ${msg.type}>`;
59
60
  const messageFromName = msg.from?.first_name ?? 'Unknown';
60
61
  const messageFromId = msg.from?.id ?? 'Unknown';
61
62
  logger_1.Logger.logWithTraceId(this.name, msg.traceId, msg.chatName, `${messageFromName} (${messageFromId}): ${messageContent}`);
@@ -6,6 +6,7 @@ import { ChatContext } from './chatContext';
6
6
  import { IncomingMessage } from '../incomingMessage';
7
7
  import { MessageSendingOptions, TextMessageSendingOptions } from '../../types/messageSendingOptions';
8
8
  import { IActionWithState } from '../../types/actionWithState';
9
+ import { MessageType } from '../../types/messageTypes';
9
10
  /**
10
11
  * Context of action executed in chat, in response to a message
11
12
  */
@@ -22,6 +23,8 @@ export declare class MessageContext<TActionState extends IActionState> extends C
22
23
  startCooldown: boolean;
23
24
  /** Name of a user that sent a message that triggered this action. */
24
25
  fromUserName: string;
26
+ /** Type of message being received */
27
+ messageType: (typeof MessageType)[keyof typeof MessageType];
25
28
  constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, message: IncomingMessage, storage: IStorageClient);
26
29
  /**
27
30
  * Loads state of another action. Changes to the loaded state will no affect actual state of other action.
@@ -1 +1 @@
1
- {"version":3,"file":"messageContext.d.ts","sourceRoot":"","sources":["../../../entities/context/messageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAa,MAAM,6BAA6B,CAAC;AAE1E;;GAEG;AACH,qBAAa,cAAc,CACvB,YAAY,SAAS,YAAY,CACnC,SAAQ,WAAW,CAAC,YAAY,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,4HAA4H;IAC5H,YAAY,EAAE,gBAAgB,EAAE,CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,eAAe,EACxB,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CAAM;IACtC,mEAAmE;IACnE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAQ;IAC9B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,WAAW,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;gBAGxD,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,cAAc;IAqB3B;;;;OAIG;IACG,WAAW,CAAC,mBAAmB,SAAS,YAAY,EACtD,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAe/B;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa/D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
@@ -20,6 +20,7 @@ class MessageContext extends chatContext_1.ChatContext {
20
20
  this.startCooldown = true;
21
21
  this.messageId = message.message_id;
22
22
  this.messageText = message.text ?? '';
23
+ this.messageType = message.type;
23
24
  this.fromUserId = message.from?.id;
24
25
  this.fromUserName =
25
26
  (message.from?.first_name ?? 'Unknown user') +
@@ -1,16 +1,14 @@
1
- import { Chat, User } from 'telegraf/types';
1
+ import { Chat, Message, Update, User } from 'telegraf/types';
2
+ import { MessageType } from '../types/messageTypes';
2
3
  export declare class IncomingMessage {
3
4
  message_id: number;
4
5
  chat: Chat;
5
6
  from: User | undefined;
6
7
  text: string;
7
8
  chatName: string;
9
+ type: (typeof MessageType)[keyof typeof MessageType];
8
10
  traceId: number;
9
- constructor(ctxMessage: {
10
- message_id: number;
11
- chat: Chat;
12
- from?: User;
13
- text?: string;
14
- });
11
+ private detectMessageType;
12
+ constructor(ctxMessage: Update.New & (Update.NonChannel & Message));
15
13
  }
16
14
  //# sourceMappingURL=incomingMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../entities/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG5C,qBAAa,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,SAA2B;gBAEtB,UAAU,EAAE;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,IAAI,CAAC;QACX,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;KACjB;CAUJ"}
1
+ {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../entities/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,qBAAa,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;IACrD,OAAO,SAA2B;IAElC,OAAO,CAAC,iBAAiB;gBAgBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAWrE"}
@@ -2,13 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IncomingMessage = void 0;
4
4
  const crypto_1 = require("crypto");
5
+ const messageTypes_1 = require("../types/messageTypes");
5
6
  class IncomingMessage {
7
+ detectMessageType(message) {
8
+ if ('sticker' in message)
9
+ return messageTypes_1.MessageType.Sticker;
10
+ if ('animation' in message)
11
+ return messageTypes_1.MessageType.Animation;
12
+ if ('document' in message)
13
+ return messageTypes_1.MessageType.Document;
14
+ if ('voice' in message)
15
+ return messageTypes_1.MessageType.Voice;
16
+ if ('audio' in message)
17
+ return messageTypes_1.MessageType.Audio;
18
+ if ('left_chat_member' in message)
19
+ return messageTypes_1.MessageType.LeftChatMember;
20
+ if ('new_chat_member' in message)
21
+ return messageTypes_1.MessageType.NewChatMember;
22
+ if ('poll' in message)
23
+ return messageTypes_1.MessageType.Poll;
24
+ if ('location' in message)
25
+ return messageTypes_1.MessageType.Location;
26
+ return messageTypes_1.MessageType.Unknown;
27
+ }
6
28
  constructor(ctxMessage) {
7
29
  this.traceId = (0, crypto_1.randomInt)(10000, 99999);
8
30
  this.message_id = ctxMessage.message_id;
9
31
  this.chat = ctxMessage.chat;
10
32
  this.from = ctxMessage.from;
11
- this.text = ctxMessage.text || '';
33
+ this.text = 'text' in ctxMessage ? ctxMessage.text : '';
34
+ this.type = this.detectMessageType(ctxMessage);
12
35
  this.chatName =
13
36
  'title' in ctxMessage.chat
14
37
  ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
@@ -1,5 +1,2 @@
1
- export declare enum NonTextMessage {
2
- Any = 0
3
- }
4
- export type CommandTrigger = string | RegExp | NonTextMessage.Any;
1
+ export type CommandTrigger = string | RegExp;
5
2
  //# sourceMappingURL=commandTrigger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACtB,GAAG,IAAA;CACN;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC"}
1
+ {"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,CAAC"}
@@ -1,7 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NonTextMessage = void 0;
4
- var NonTextMessage;
5
- (function (NonTextMessage) {
6
- NonTextMessage[NonTextMessage["Any"] = 0] = "Any";
7
- })(NonTextMessage || (exports.NonTextMessage = NonTextMessage = {}));
@@ -0,0 +1,14 @@
1
+ export declare const MessageType: {
2
+ readonly Text: "__msg:Text";
3
+ readonly Sticker: "__msg:Sticker";
4
+ readonly Animation: "__msg:Animation";
5
+ readonly Document: "__msg:Document";
6
+ readonly Voice: "__msg:Voice";
7
+ readonly Audio: "__msg:Audio";
8
+ readonly LeftChatMember: "__msg:LeftChatMember";
9
+ readonly NewChatMember: "__msg:NewChatMember";
10
+ readonly Poll: "__msg:Poll";
11
+ readonly Location: "__msg:Location";
12
+ readonly Unknown: "__msg:Unknown";
13
+ };
14
+ //# sourceMappingURL=messageTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../types/messageTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;;;;CAYd,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageType = void 0;
4
+ exports.MessageType = {
5
+ Text: '__msg:Text',
6
+ Sticker: '__msg:Sticker',
7
+ Animation: '__msg:Animation',
8
+ Document: '__msg:Document',
9
+ Voice: '__msg:Voice',
10
+ Audio: '__msg:Audio',
11
+ LeftChatMember: '__msg:LeftChatMember',
12
+ NewChatMember: '__msg:NewChatMember',
13
+ Poll: '__msg:Poll',
14
+ Location: '__msg:Location',
15
+ Unknown: '__msg:Unknown'
16
+ };
@@ -10,7 +10,7 @@ import { CommandTriggerCheckResult } from '../commandTriggerCheckResult';
10
10
  import { MessageContext } from '../context/messageContext';
11
11
  import { Logger } from '../../services/logger';
12
12
  import { ActionExecutionResult } from '../actionExecutionResult';
13
- import { CommandTrigger, NonTextMessage } from '../../types/commandTrigger';
13
+ import { CommandTrigger } from '../../types/commandTrigger';
14
14
 
15
15
  export class CommandAction<TActionState extends IActionState>
16
16
  implements IActionWithState
@@ -125,8 +125,8 @@ export class CommandAction<TActionState extends IActionState>
125
125
 
126
126
  if (onCooldown) return CommandTriggerCheckResult.DoNotTrigger;
127
127
 
128
- if (trigger == NonTextMessage.Any) {
129
- shouldTrigger = ctx.messageText == '';
128
+ if (trigger == ctx.messageType) {
129
+ shouldTrigger = true;
130
130
  } else if (typeof trigger == 'string') {
131
131
  shouldTrigger = ctx.messageText.toLowerCase() == trigger;
132
132
  } else {
@@ -111,13 +111,13 @@ export class BotInstance {
111
111
  );
112
112
  }
113
113
  }
114
-
115
114
  private initializeMessageProcessing() {
116
115
  if (this.commands.length > 0) {
117
116
  this.telegraf.on('message', async (ctx) => {
118
117
  console.dir(ctx.update);
119
118
  const msg = new IncomingMessage(ctx.update.message);
120
- const messageContent = msg.text || '<non-text message>';
119
+ const messageContent =
120
+ msg.text || `<non-text message: ${msg.type}>`;
121
121
 
122
122
  const messageFromName = msg.from?.first_name ?? 'Unknown';
123
123
  const messageFromId = msg.from?.id ?? 'Unknown';
@@ -15,6 +15,7 @@ import {
15
15
  TextMessageSendingOptions
16
16
  } from '../../types/messageSendingOptions';
17
17
  import { IActionWithState, ActionKey } from '../../types/actionWithState';
18
+ import { MessageType } from '../../types/messageTypes';
18
19
 
19
20
  /**
20
21
  * Context of action executed in chat, in response to a message
@@ -34,6 +35,8 @@ export class MessageContext<
34
35
  startCooldown: boolean = true;
35
36
  /** Name of a user that sent a message that triggered this action. */
36
37
  fromUserName: string;
38
+ /** Type of message being received */
39
+ messageType: (typeof MessageType)[keyof typeof MessageType];
37
40
 
38
41
  constructor(
39
42
  botName: string,
@@ -54,6 +57,7 @@ export class MessageContext<
54
57
 
55
58
  this.messageId = message.message_id;
56
59
  this.messageText = message.text ?? '';
60
+ this.messageType = message.type;
57
61
  this.fromUserId = message.from?.id;
58
62
  this.fromUserName =
59
63
  (message.from?.first_name ?? 'Unknown user') +
@@ -1,5 +1,6 @@
1
- import { Chat, User } from 'telegraf/types';
1
+ import { Chat, Message, Update, User } from 'telegraf/types';
2
2
  import { randomInt } from 'crypto';
3
+ import { MessageType } from '../types/messageTypes';
3
4
 
4
5
  export class IncomingMessage {
5
6
  message_id: number;
@@ -7,18 +8,31 @@ export class IncomingMessage {
7
8
  from: User | undefined;
8
9
  text: string;
9
10
  chatName: string;
11
+ type: (typeof MessageType)[keyof typeof MessageType];
10
12
  traceId = randomInt(10000, 99999);
11
13
 
12
- constructor(ctxMessage: {
13
- message_id: number;
14
- chat: Chat;
15
- from?: User;
16
- text?: string;
17
- }) {
14
+ private detectMessageType(
15
+ message: Update.New & (Update.NonChannel & Message)
16
+ ) {
17
+ if ('sticker' in message) return MessageType.Sticker;
18
+ if ('animation' in message) return MessageType.Animation;
19
+ if ('document' in message) return MessageType.Document;
20
+ if ('voice' in message) return MessageType.Voice;
21
+ if ('audio' in message) return MessageType.Audio;
22
+ if ('left_chat_member' in message) return MessageType.LeftChatMember;
23
+ if ('new_chat_member' in message) return MessageType.NewChatMember;
24
+ if ('poll' in message) return MessageType.Poll;
25
+ if ('location' in message) return MessageType.Location;
26
+
27
+ return MessageType.Unknown;
28
+ }
29
+
30
+ constructor(ctxMessage: Update.New & (Update.NonChannel & Message)) {
18
31
  this.message_id = ctxMessage.message_id;
19
32
  this.chat = ctxMessage.chat;
20
33
  this.from = ctxMessage.from;
21
- this.text = ctxMessage.text || '';
34
+ this.text = 'text' in ctxMessage ? ctxMessage.text : '';
35
+ this.type = this.detectMessageType(ctxMessage);
22
36
  this.chatName =
23
37
  'title' in ctxMessage.chat
24
38
  ? ctxMessage.chat.title + ' ' + ctxMessage.chat.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",
@@ -1,5 +1 @@
1
- export enum NonTextMessage {
2
- Any
3
- }
4
-
5
- export type CommandTrigger = string | RegExp | NonTextMessage.Any;
1
+ export type CommandTrigger = string | RegExp;
@@ -0,0 +1,13 @@
1
+ export const MessageType = {
2
+ Text: '__msg:Text',
3
+ Sticker: '__msg:Sticker',
4
+ Animation: '__msg:Animation',
5
+ Document: '__msg:Document',
6
+ Voice: '__msg:Voice',
7
+ Audio: '__msg:Audio',
8
+ LeftChatMember: '__msg:LeftChatMember',
9
+ NewChatMember: '__msg:NewChatMember',
10
+ Poll: '__msg:Poll',
11
+ Location: '__msg:Location',
12
+ Unknown: '__msg:Unknown'
13
+ } as const;