@llblab/pi-telegram 0.6.3 → 0.7.1

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.
package/lib/updates.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Telegram updates domain helpers
3
+ * Zones: telegram inbound, authorization, routing plans
3
4
  * Owns update extraction, authorization, classification, execution planning, and runtime execution for Telegram updates
4
5
  */
5
6
 
@@ -25,6 +26,19 @@ export type TelegramReactionType =
25
26
  | TelegramReactionTypeEmoji
26
27
  | TelegramReactionTypeNonEmoji;
27
28
 
29
+ export const TELEGRAM_PRIORITY_REACTION_EMOJIS = [
30
+ "👍",
31
+ "⚡",
32
+ "❤",
33
+ "🕊",
34
+ ] as const;
35
+ export const TELEGRAM_REMOVAL_REACTION_EMOJIS = [
36
+ "👎",
37
+ "👻",
38
+ "💔",
39
+ "💩",
40
+ ] as const;
41
+
28
42
  export interface TelegramUpdateDeletion {
29
43
  deleted_business_messages?: { message_ids?: unknown };
30
44
  }
@@ -50,6 +64,23 @@ export function collectTelegramReactionEmojis(
50
64
  );
51
65
  }
52
66
 
67
+ function hasAnyTelegramReactionEmoji(
68
+ emojis: Set<string>,
69
+ candidates: readonly string[],
70
+ ): boolean {
71
+ return candidates.some((emoji) => emojis.has(emoji));
72
+ }
73
+
74
+ function hasAddedTelegramReactionEmoji(
75
+ oldEmojis: Set<string>,
76
+ newEmojis: Set<string>,
77
+ candidates: readonly string[],
78
+ ): boolean {
79
+ return candidates.some(
80
+ (emoji) => !oldEmojis.has(emoji) && newEmojis.has(emoji),
81
+ );
82
+ }
83
+
53
84
  export function extractDeletedTelegramMessageIds(
54
85
  update: TelegramUpdateDeletion,
55
86
  ): number[] {
@@ -579,8 +610,13 @@ export async function handleAuthorizedTelegramReactionUpdate<TContext>(
579
610
  }
580
611
  const oldEmojis = collectTelegramReactionEmojis(reactionUpdate.old_reaction);
581
612
  const newEmojis = collectTelegramReactionEmojis(reactionUpdate.new_reaction);
582
- const dislikeAdded = !oldEmojis.has("👎") && newEmojis.has("👎");
583
- if (dislikeAdded) {
613
+ if (
614
+ hasAddedTelegramReactionEmoji(
615
+ oldEmojis,
616
+ newEmojis,
617
+ TELEGRAM_REMOVAL_REACTION_EMOJIS,
618
+ )
619
+ ) {
584
620
  deps.removePendingMediaGroupMessages([reactionUpdate.message_id]);
585
621
  deps.removeQueuedTelegramTurnsByMessageIds(
586
622
  [reactionUpdate.message_id],
@@ -588,15 +624,28 @@ export async function handleAuthorizedTelegramReactionUpdate<TContext>(
588
624
  );
589
625
  return;
590
626
  }
591
- const likeRemoved = oldEmojis.has("👍") && !newEmojis.has("👍");
592
- if (likeRemoved) {
627
+ const hadPriorityReaction = hasAnyTelegramReactionEmoji(
628
+ oldEmojis,
629
+ TELEGRAM_PRIORITY_REACTION_EMOJIS,
630
+ );
631
+ const hasPriorityReaction = hasAnyTelegramReactionEmoji(
632
+ newEmojis,
633
+ TELEGRAM_PRIORITY_REACTION_EMOJIS,
634
+ );
635
+ if (hadPriorityReaction && !hasPriorityReaction) {
593
636
  deps.clearQueuedTelegramTurnPriorityByMessageId(
594
637
  reactionUpdate.message_id,
595
638
  deps.ctx,
596
639
  );
597
640
  }
598
- const likeAdded = !oldEmojis.has("👍") && newEmojis.has("👍");
599
- if (!likeAdded) return;
641
+ if (
642
+ !hasAddedTelegramReactionEmoji(
643
+ oldEmojis,
644
+ newEmojis,
645
+ TELEGRAM_PRIORITY_REACTION_EMOJIS,
646
+ )
647
+ )
648
+ return;
600
649
  deps.prioritizeQueuedTelegramTurnByMessageId(
601
650
  reactionUpdate.message_id,
602
651
  deps.ctx,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@llblab/pi-telegram",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
- "description": "Better Telegram DM bridge extension for pi",
5
+ "description": "Better Telegram DM bridge extension for π",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "pi-package",
@@ -31,6 +31,9 @@
31
31
  "index.ts",
32
32
  "lib/",
33
33
  "README.md",
34
+ "AGENTS.md",
35
+ "BACKLOG.md",
36
+ "CHANGELOG.md",
34
37
  "docs/",
35
38
  "screenshot.png"
36
39
  ],