spectrum-ts 0.8.0 → 0.9.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.
@@ -3,7 +3,7 @@ import { AdvancedIMessage } from '@photon-ai/advanced-imessage';
3
3
  import { IMessageSDK } from '@photon-ai/imessage-kit';
4
4
  import * as z from 'zod';
5
5
  import z__default from 'zod';
6
- import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-DLrsDzV-.js';
6
+ import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-B8g0pvfg.js';
7
7
  import * as zod_v4_core from 'zod/v4/core';
8
8
  import 'hotscript';
9
9
 
@@ -67,15 +67,6 @@ declare const imessage: Platform<PlatformDef<"iMessage", z.ZodUnion<readonly [z.
67
67
  }[] | undefined;
68
68
  };
69
69
  }) => ManagedStream<IMessageMessage>;
70
- }>> & Readonly<{
71
- tapbacks: {
72
- readonly love: "love";
73
- readonly like: "like";
74
- readonly dislike: "dislike";
75
- readonly laugh: "laugh";
76
- readonly emphasize: "emphasize";
77
- readonly question: "question";
78
- };
79
- }>;
70
+ }>> & Readonly<Record<never, never>>;
80
71
 
81
72
  export { imessage };
@@ -1,21 +1,22 @@
1
1
  import {
2
2
  asRichlink
3
- } from "../../chunk-H5XYVRHM.js";
3
+ } from "../../chunk-6ZOLTQDN.js";
4
4
  import {
5
5
  asAttachment,
6
6
  asContact,
7
7
  asCustom,
8
+ asReaction,
8
9
  cloud,
9
10
  fromVCard,
10
11
  mergeStreams,
11
12
  stream,
12
13
  toVCard
13
- } from "../../chunk-ZNUORCLB.js";
14
+ } from "../../chunk-CZIWNTXP.js";
14
15
  import {
15
16
  UnsupportedError,
16
17
  asText,
17
18
  definePlatform
18
- } from "../../chunk-4O6MQC5Z.js";
19
+ } from "../../chunk-PLJI5FTO.js";
19
20
 
20
21
  // src/providers/imessage/index.ts
21
22
  import { createClient as createClient2, directChat } from "@photon-ai/advanced-imessage";
@@ -400,9 +401,47 @@ var isVCardAttachment2 = (mimeType, fileName) => {
400
401
  }
401
402
  return Boolean(fileName?.toLowerCase().endsWith(".vcf"));
402
403
  };
403
- var TAPBACK_NAMES = new Set(
404
- Object.values(Reaction).filter((r) => r !== "emoji" && r !== "sticker")
404
+ var EMOJI_TO_TAPBACK = {
405
+ "\u2764\uFE0F": Reaction.love,
406
+ "\u{1F44D}": Reaction.like,
407
+ "\u{1F44E}": Reaction.dislike,
408
+ "\u{1F602}": Reaction.laugh,
409
+ "\u203C\uFE0F": Reaction.emphasize,
410
+ "\u2753": Reaction.question
411
+ };
412
+ var TAPBACK_TO_EMOJI = Object.fromEntries(
413
+ Object.entries(EMOJI_TO_TAPBACK).map(([emoji, kind]) => [kind, emoji])
405
414
  );
415
+ var TAPBACK_CODE_TO_KIND = {
416
+ "2000": Reaction.love,
417
+ "2001": Reaction.like,
418
+ "2002": Reaction.dislike,
419
+ "2003": Reaction.laugh,
420
+ "2004": Reaction.emphasize,
421
+ "2005": Reaction.question,
422
+ "2006": Reaction.emoji,
423
+ "2007": Reaction.sticker
424
+ };
425
+ var isTapbackRemoval = (code) => code.startsWith("3");
426
+ var resolveReactionEmoji = (type, emoji) => {
427
+ if (emoji) {
428
+ return emoji;
429
+ }
430
+ if (!type) {
431
+ return null;
432
+ }
433
+ const kind = TAPBACK_CODE_TO_KIND[type] ?? type;
434
+ return TAPBACK_TO_EMOJI[kind] ?? null;
435
+ };
436
+ var getAssociatedMessageType = (message) => {
437
+ const direct = message.associatedMessageType;
438
+ if (typeof direct === "string") {
439
+ return direct;
440
+ }
441
+ const raw = message._raw;
442
+ const fromRaw = raw?.associatedMessageType;
443
+ return typeof fromRaw === "string" ? fromRaw : void 0;
444
+ };
406
445
  var baseMessage = (event) => ({
407
446
  sender: { id: event.message.sender?.address ?? "" },
408
447
  space: {
@@ -443,9 +482,31 @@ var toRichlinkMessage = (event, base, id) => {
443
482
  };
444
483
  }
445
484
  };
485
+ var PART_PREFIX = /^p:\d+\//;
486
+ var toReactionMessage = (event, base, id, target) => {
487
+ const type = getAssociatedMessageType(event.message);
488
+ if (type && isTapbackRemoval(type)) {
489
+ return [];
490
+ }
491
+ const emoji = resolveReactionEmoji(
492
+ type,
493
+ event.message.associatedMessageEmoji
494
+ );
495
+ if (!emoji) {
496
+ return [];
497
+ }
498
+ const normalizedTarget = target.replace(PART_PREFIX, "");
499
+ return [
500
+ { ...base, id, content: asReaction({ emoji, target: normalizedTarget }) }
501
+ ];
502
+ };
446
503
  var toMessages2 = async (client, event) => {
447
504
  const base = baseMessage(event);
448
505
  const messageGuidStr = event.message.guid;
506
+ const assoc = event.message.associatedMessageGuid;
507
+ if (assoc) {
508
+ return toReactionMessage(event, base, messageGuidStr, assoc);
509
+ }
449
510
  if (getBalloonBundleId(event.message) === URL_BALLOON_BUNDLE_ID) {
450
511
  return [toRichlinkMessage(event, base, messageGuidStr)];
451
512
  }
@@ -655,8 +716,9 @@ var reactToMessage = async (clients, spaceId, msgId, reaction) => {
655
716
  }
656
717
  const chat = chatGuid(spaceId);
657
718
  const msg = messageGuid(msgId);
658
- if (TAPBACK_NAMES.has(reaction)) {
659
- await remote.messages.react(chat, msg, reaction);
719
+ const native = EMOJI_TO_TAPBACK[reaction];
720
+ if (native) {
721
+ await remote.messages.react(chat, msg, native);
660
722
  } else {
661
723
  await remote.messages.reactEmoji(chat, msg, reaction);
662
724
  }
@@ -683,16 +745,6 @@ var spaceSchema = z.object({
683
745
  // src/providers/imessage/index.ts
684
746
  var imessage = definePlatform("iMessage", {
685
747
  config: configSchema,
686
- static: {
687
- tapbacks: {
688
- love: "love",
689
- like: "like",
690
- dislike: "dislike",
691
- laugh: "laugh",
692
- emphasize: "emphasize",
693
- question: "question"
694
- }
695
- },
696
748
  user: {
697
749
  resolve: async ({ input }) => ({ id: input.userID })
698
750
  },
@@ -779,7 +831,7 @@ var imessage = definePlatform("iMessage", {
779
831
  },
780
832
  reactToMessage: async ({ space, messageId, reaction, client }) => {
781
833
  if (isLocal(client)) {
782
- return;
834
+ throw UnsupportedError.action("react", "iMessage (local mode)");
783
835
  }
784
836
  await reactToMessage(client, space.id, messageId, reaction);
785
837
  },
@@ -1,4 +1,4 @@
1
- import { d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-DLrsDzV-.js';
1
+ import { d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-B8g0pvfg.js';
2
2
  import * as node_readline from 'node:readline';
3
3
  import z__default from 'zod';
4
4
  import 'hotscript';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UnsupportedError,
3
3
  definePlatform
4
- } from "../../chunk-4O6MQC5Z.js";
4
+ } from "../../chunk-PLJI5FTO.js";
5
5
 
6
6
  // src/providers/terminal/index.ts
7
7
  import { createInterface } from "readline";
@@ -2,7 +2,7 @@ import { M as ManagedStream } from '../../stream-B55k7W8-.js';
2
2
  import { WhatsAppClient } from '@photon-ai/whatsapp-business';
3
3
  import * as z from 'zod';
4
4
  import z__default from 'zod';
5
- import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-DLrsDzV-.js';
5
+ import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-B8g0pvfg.js';
6
6
  import * as zod_v4_core from 'zod/v4/core';
7
7
  import 'hotscript';
8
8
 
@@ -2,15 +2,16 @@ import {
2
2
  asAttachment,
3
3
  asContact,
4
4
  asCustom,
5
+ asReaction,
5
6
  cloud,
6
7
  mergeStreams,
7
8
  stream
8
- } from "../../chunk-ZNUORCLB.js";
9
+ } from "../../chunk-CZIWNTXP.js";
9
10
  import {
10
11
  UnsupportedError,
11
12
  asText,
12
13
  definePlatform
13
- } from "../../chunk-4O6MQC5Z.js";
14
+ } from "../../chunk-PLJI5FTO.js";
14
15
 
15
16
  // src/providers/whatsapp-business/index.ts
16
17
  import { createClient as createClient2 } from "@photon-ai/whatsapp-business";
@@ -401,7 +402,10 @@ var mapContent = (client, content) => {
401
402
  case "location":
402
403
  return asCustom({ whatsapp_type: "location", ...content.location });
403
404
  case "reaction":
404
- return asCustom({ whatsapp_type: "reaction", ...content.reaction });
405
+ return asReaction({
406
+ emoji: content.reaction.emoji,
407
+ target: content.reaction.messageId
408
+ });
405
409
  case "interactive":
406
410
  return asCustom({ whatsapp_type: "interactive", ...content.interactive });
407
411
  case "button":
@@ -88,6 +88,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
88
88
  read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
89
89
  stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
90
90
  }, z__default.core.$strip>>>>;
91
+ }, z__default.core.$strip>, z__default.ZodObject<{
92
+ type: z__default.ZodLiteral<"reaction">;
93
+ emoji: z__default.ZodString;
94
+ target: z__default.ZodString;
91
95
  }, z__default.core.$strip>], "type">;
92
96
  type Content = z__default.infer<typeof contentSchema>;
93
97
  interface ContentBuilder {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",