chz-telegram-bot 0.0.41 → 0.0.43

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.
@@ -6,7 +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
+ import { MessageTypeValue } from '../../types/messageTypes';
10
10
  /**
11
11
  * Context of action executed in chat, in response to a message
12
12
  */
@@ -24,7 +24,7 @@ export declare class MessageContext<TActionState extends IActionState> extends C
24
24
  /** Name of a user that sent a message that triggered this action. */
25
25
  fromUserName: string;
26
26
  /** Type of message being received */
27
- messageType: (typeof MessageType)[keyof typeof MessageType];
27
+ messageType: MessageTypeValue;
28
28
  constructor(botName: string, action: IActionWithState, interactions: IBotApiInteractions, message: IncomingMessage, storage: IStorageClient);
29
29
  /**
30
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;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,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,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;IAc5D;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa;CAW7B"}
@@ -1,12 +1,12 @@
1
1
  import { Chat, Message, Update, User } from 'telegraf/types';
2
- import { MessageType } from '../types/messageTypes';
2
+ import { MessageTypeValue } from '../types/messageTypes';
3
3
  export declare class IncomingMessage {
4
4
  message_id: number;
5
5
  chat: Chat;
6
6
  from: User | undefined;
7
7
  text: string;
8
8
  chatName: string;
9
- type: (typeof MessageType)[keyof typeof MessageType];
9
+ type: MessageTypeValue;
10
10
  traceId: number;
11
11
  private detectMessageType;
12
12
  constructor(ctxMessage: Update.New & (Update.NonChannel & Message));
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"incomingMessage.d.ts","sourceRoot":"","sources":["../../entities/incomingMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,qBAAa,eAAe;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,SAA2B;IAElC,OAAO,CAAC,iBAAiB;gBAiBb,UAAU,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;CAWrE"}
@@ -5,16 +5,18 @@ const crypto_1 = require("crypto");
5
5
  const messageTypes_1 = require("../types/messageTypes");
6
6
  class IncomingMessage {
7
7
  detectMessageType(message) {
8
+ if ('photo' in message)
9
+ return messageTypes_1.MessageType.Photo;
8
10
  if ('sticker' in message)
9
11
  return messageTypes_1.MessageType.Sticker;
10
12
  if ('animation' in message)
11
13
  return messageTypes_1.MessageType.Animation;
12
- if ('document' in message)
13
- return messageTypes_1.MessageType.Document;
14
14
  if ('voice' in message)
15
15
  return messageTypes_1.MessageType.Voice;
16
16
  if ('audio' in message)
17
17
  return messageTypes_1.MessageType.Audio;
18
+ if ('document' in message)
19
+ return messageTypes_1.MessageType.Document;
18
20
  if ('left_chat_member' in message)
19
21
  return messageTypes_1.MessageType.LeftChatMember;
20
22
  if ('new_chat_member' in message)
package/dist/main.d.ts CHANGED
@@ -24,6 +24,8 @@ declare function startBot(options: {
24
24
  storagePath?: string;
25
25
  /** Period of time between execution of scheduled actions. */
26
26
  scheduledPeriod?: Seconds;
27
+ /** If true, telegram API objects will be logged instead of message content. */
28
+ verboseLoggingForIncomingMessage?: boolean;
27
29
  }): Promise<BotInstance>;
28
30
  /**
29
31
  * Terminates all scheduled tasks, closes storage connections and stops all bots.
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","s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,qBAAqB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ7C;;GAEG;AACH,iBAAe,QAAQ,CAAC,OAAO,EAAE;IAC7B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,2HAA2H;IAC3H,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;IACxC,mGAAmG;IACnG,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;IAC3C,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,qGAAqG;IACrG,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,2KAA2K;IAC3K,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,+EAA+E;IAC/E,gCAAgC,CAAC,EAAE,OAAO,CAAC;CAC9C,wBAiBA;AAED;;GAEG;AACH,iBAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,iBASrC;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC"}
package/dist/main.js CHANGED
@@ -23,7 +23,8 @@ async function startBot(options) {
23
23
  chats: options.chats,
24
24
  storageClient: options.storageClient,
25
25
  storagePath: options.storagePath,
26
- scheduledPeriod: options.scheduledPeriod
26
+ scheduledPeriod: options.scheduledPeriod,
27
+ verboseLoggingForIncomingMessage: options.verboseLoggingForIncomingMessage
27
28
  });
28
29
  bots.push(bot);
29
30
  return bot;
@@ -1,3 +1,3 @@
1
- import { MessageType } from './messageTypes';
2
- export type CommandTrigger = (typeof MessageType)[keyof typeof MessageType] | string | RegExp;
1
+ import { MessageTypeValue } from './messageTypes';
2
+ export type CommandTrigger = MessageTypeValue | string | RegExp;
3
3
  //# sourceMappingURL=commandTrigger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,cAAc,GACpB,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,GAC9C,MAAM,GACN,MAAM,CAAC"}
1
+ {"version":3,"file":"commandTrigger.d.ts","sourceRoot":"","sources":["../../types/commandTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC"}
@@ -9,6 +9,8 @@ export declare const MessageType: {
9
9
  readonly NewChatMember: "__msg:NewChatMember";
10
10
  readonly Poll: "__msg:Poll";
11
11
  readonly Location: "__msg:Location";
12
+ readonly Photo: "__msg:Photo";
12
13
  readonly Unknown: "__msg:Unknown";
13
14
  };
15
+ export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
14
16
  //# 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;;;;;;;;;;;;CAYd,CAAC"}
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"}
@@ -12,5 +12,6 @@ exports.MessageType = {
12
12
  NewChatMember: '__msg:NewChatMember',
13
13
  Poll: '__msg:Poll',
14
14
  Location: '__msg:Location',
15
+ Photo: '__msg:Photo',
15
16
  Unknown: '__msg:Unknown'
16
17
  };
@@ -15,7 +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
+ import { MessageTypeValue } from '../../types/messageTypes';
19
19
 
20
20
  /**
21
21
  * Context of action executed in chat, in response to a message
@@ -36,7 +36,7 @@ export class MessageContext<
36
36
  /** Name of a user that sent a message that triggered this action. */
37
37
  fromUserName: string;
38
38
  /** Type of message being received */
39
- messageType: (typeof MessageType)[keyof typeof MessageType];
39
+ messageType: MessageTypeValue;
40
40
 
41
41
  constructor(
42
42
  botName: string,
@@ -1,6 +1,6 @@
1
1
  import { Chat, Message, Update, User } from 'telegraf/types';
2
2
  import { randomInt } from 'crypto';
3
- import { MessageType } from '../types/messageTypes';
3
+ import { MessageType, MessageTypeValue } from '../types/messageTypes';
4
4
 
5
5
  export class IncomingMessage {
6
6
  message_id: number;
@@ -8,17 +8,18 @@ export class IncomingMessage {
8
8
  from: User | undefined;
9
9
  text: string;
10
10
  chatName: string;
11
- type: (typeof MessageType)[keyof typeof MessageType];
11
+ type: MessageTypeValue;
12
12
  traceId = randomInt(10000, 99999);
13
13
 
14
14
  private detectMessageType(
15
15
  message: Update.New & (Update.NonChannel & Message)
16
16
  ) {
17
+ if ('photo' in message) return MessageType.Photo;
17
18
  if ('sticker' in message) return MessageType.Sticker;
18
19
  if ('animation' in message) return MessageType.Animation;
19
- if ('document' in message) return MessageType.Document;
20
20
  if ('voice' in message) return MessageType.Voice;
21
21
  if ('audio' in message) return MessageType.Audio;
22
+ if ('document' in message) return MessageType.Document;
22
23
  if ('left_chat_member' in message) return MessageType.LeftChatMember;
23
24
  if ('new_chat_member' in message) return MessageType.NewChatMember;
24
25
  if ('poll' in message) return MessageType.Poll;
package/main.ts CHANGED
@@ -34,6 +34,8 @@ async function startBot(options: {
34
34
  storagePath?: string;
35
35
  /** Period of time between execution of scheduled actions. */
36
36
  scheduledPeriod?: Seconds;
37
+ /** If true, telegram API objects will be logged instead of message content. */
38
+ verboseLoggingForIncomingMessage?: boolean;
37
39
  }) {
38
40
  const token = await readFile(options.tokenFilePath, 'utf8');
39
41
  const bot = new BotInstance({
@@ -44,7 +46,9 @@ async function startBot(options: {
44
46
  chats: options.chats,
45
47
  storageClient: options.storageClient,
46
48
  storagePath: options.storagePath,
47
- scheduledPeriod: options.scheduledPeriod
49
+ scheduledPeriod: options.scheduledPeriod,
50
+ verboseLoggingForIncomingMessage:
51
+ options.verboseLoggingForIncomingMessage
48
52
  });
49
53
  bots.push(bot);
50
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chz-telegram-bot",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "async-sema": "^3.1.1",
@@ -1,6 +1,3 @@
1
- import { MessageType } from './messageTypes';
1
+ import { MessageTypeValue } from './messageTypes';
2
2
 
3
- export type CommandTrigger =
4
- | (typeof MessageType)[keyof typeof MessageType]
5
- | string
6
- | RegExp;
3
+ export type CommandTrigger = MessageTypeValue | string | RegExp;
@@ -9,5 +9,8 @@ export const MessageType = {
9
9
  NewChatMember: '__msg:NewChatMember',
10
10
  Poll: '__msg:Poll',
11
11
  Location: '__msg:Location',
12
+ Photo: '__msg:Photo',
12
13
  Unknown: '__msg:Unknown'
13
14
  } as const;
15
+
16
+ export type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];