@codebam/cf-workers-telegram-bot 12.3.0 → 12.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.
@@ -7,8 +7,6 @@ export default class TelegramExecutionContext {
7
7
  private static businessOwners;
8
8
  /** Cache for dead business connections */
9
9
  private static poisonedConnections;
10
- /** Cache for self-response counts to prevent infinite loops */
11
- private static selfResponseCount;
12
10
  /** an instance of the telegram bot */
13
11
  bot: TelegramBot;
14
12
  /** an instance of the telegram update */
@@ -40,6 +38,11 @@ export default class TelegramExecutionContext {
40
38
  * @returns The user ID or undefined if not available
41
39
  */
42
40
  get userId(): number | undefined;
41
+ /**
42
+ * Check if the message sender is a bot
43
+ * @returns True if the sender is a bot
44
+ */
45
+ get isBot(): boolean;
43
46
  /**
44
47
  * Parse arguments from the update
45
48
  * @returns array of argument strings
@@ -5,8 +5,6 @@ export default class TelegramExecutionContext {
5
5
  static businessOwners = new Map();
6
6
  /** Cache for dead business connections */
7
7
  static poisonedConnections = new Set();
8
- /** Cache for self-response counts to prevent infinite loops */
9
- static selfResponseCount = new Map();
10
8
  /** an instance of the telegram bot */
11
9
  bot;
12
10
  /** an instance of the telegram update */
@@ -49,6 +47,16 @@ export default class TelegramExecutionContext {
49
47
  get userId() {
50
48
  return this.update.message?.from?.id ?? this.update.business_message?.from?.id ?? this.update.guest_message?.from?.id;
51
49
  }
50
+ /**
51
+ * Check if the message sender is a bot
52
+ * @returns True if the sender is a bot
53
+ */
54
+ get isBot() {
55
+ return (this.update.message?.from?.is_bot ??
56
+ this.update.business_message?.from?.is_bot ??
57
+ this.update.guest_message?.from?.is_bot ??
58
+ false);
59
+ }
52
60
  /**
53
61
  * Parse arguments from the update
54
62
  * @returns array of argument strings
@@ -75,16 +83,6 @@ export default class TelegramExecutionContext {
75
83
  */
76
84
  async shouldProcess() {
77
85
  if (this.update_type !== 'business_message') {
78
- if (this.userId === this.bot.botId) {
79
- const chatId = this.getChatId();
80
- const count = TelegramExecutionContext.selfResponseCount.get(chatId) || 0;
81
- if (count < this.bot.ttl) {
82
- TelegramExecutionContext.selfResponseCount.set(chatId, count + 1);
83
- return true;
84
- }
85
- return false;
86
- }
87
- TelegramExecutionContext.selfResponseCount.delete(this.getChatId());
88
86
  return true;
89
87
  }
90
88
  const connectionId = this.update.business_message?.business_connection_id?.toString();
@@ -122,16 +120,6 @@ export default class TelegramExecutionContext {
122
120
  console.warn('Failed to fetch business connection info:', e);
123
121
  }
124
122
  }
125
- if (ownerId !== undefined && (this.getChatId() === ownerId.toString() || this.userId === ownerId)) {
126
- const chatId = this.getChatId();
127
- const count = TelegramExecutionContext.selfResponseCount.get(chatId) || 0;
128
- if (count < this.bot.ttl) {
129
- TelegramExecutionContext.selfResponseCount.set(chatId, count + 1);
130
- return true;
131
- }
132
- return false;
133
- }
134
- TelegramExecutionContext.selfResponseCount.delete(this.getChatId());
135
123
  return true;
136
124
  }
137
125
  determineUpdateType() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebam/cf-workers-telegram-bot",
3
- "version": "12.3.0",
3
+ "version": "12.5.0",
4
4
  "description": "serverless telegram bot on cf workers",
5
5
  "main": "./dist/main.js",
6
6
  "module": "./dist/main.js",