spectrum-ts 0.8.0 → 0.9.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.
@@ -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-OIXH5S65.js";
9
10
  import {
10
11
  UnsupportedError,
11
12
  asText,
12
13
  definePlatform
13
- } from "../../chunk-4O6MQC5Z.js";
14
+ } from "../../chunk-U6WCQVVX.js";
14
15
 
15
16
  // src/providers/whatsapp-business/index.ts
16
17
  import { createClient as createClient2 } from "@photon-ai/whatsapp-business";
@@ -400,8 +401,16 @@ var mapContent = (client, content) => {
400
401
  return asCustom({ whatsapp_type: "sticker", ...content.sticker });
401
402
  case "location":
402
403
  return asCustom({ whatsapp_type: "location", ...content.location });
403
- case "reaction":
404
- return asCustom({ whatsapp_type: "reaction", ...content.reaction });
404
+ case "reaction": {
405
+ const stubTarget = {
406
+ id: content.reaction.messageId,
407
+ content: asCustom({ whatsapp_type: "reaction-target", stub: true })
408
+ };
409
+ return asReaction({
410
+ emoji: content.reaction.emoji,
411
+ target: stubTarget
412
+ });
413
+ }
405
414
  case "interactive":
406
415
  return asCustom({ whatsapp_type: "interactive", ...content.interactive });
407
416
  case "button":
@@ -719,11 +728,11 @@ var whatsappBusiness = definePlatform("WhatsApp Business", {
719
728
  send: async ({ space, content, client }) => {
720
729
  return await send(client, space.id, content);
721
730
  },
722
- reactToMessage: async ({ space, messageId, reaction, client }) => {
731
+ reactToMessage: async ({ space, target, reaction, client }) => {
723
732
  await reactToMessage(
724
733
  client,
725
734
  space.id,
726
- messageId,
735
+ target.id,
727
736
  reaction
728
737
  );
729
738
  },
@@ -88,6 +88,13 @@ 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.ZodCustom<Message, Message>;
95
+ }, z__default.core.$strip>, z__default.ZodObject<{
96
+ type: z__default.ZodLiteral<"group">;
97
+ items: z__default.ZodArray<z__default.ZodCustom<Message, Message>>;
91
98
  }, z__default.core.$strip>], "type">;
92
99
  type Content = z__default.infer<typeof contentSchema>;
93
100
  interface ContentBuilder {
@@ -103,6 +110,13 @@ interface User {
103
110
  interface Space<_Def = unknown> {
104
111
  readonly __platform: string;
105
112
  edit(message: OutboundMessage, newContent: ContentInput): Promise<void>;
113
+ /**
114
+ * Look up a message in this space by its id. Returns `undefined` if the
115
+ * platform has no way to resolve the id (e.g. cache miss with no by-id
116
+ * SDK fallback). Used to materialize a `Message` for APIs that require one,
117
+ * such as `reaction()`.
118
+ */
119
+ getMessage(id: string): Promise<Message | undefined>;
106
120
  readonly id: string;
107
121
  responding<T>(fn: () => T | Promise<T>): Promise<T>;
108
122
  send(content: ContentInput): Promise<OutboundMessage | undefined>;
@@ -154,6 +168,14 @@ type ProviderMessage<TSender extends ResolvedUser = ResolvedUser, TSpace extends
154
168
  timestamp?: Date;
155
169
  } & TExtra;
156
170
  interface SendResult<TSender extends ResolvedUser = ResolvedUser> {
171
+ /**
172
+ * Per-item send receipts returned when the dispatched content was a
173
+ * `group`. Providers that iterate native sends to emulate a group
174
+ * (e.g. iMessage) populate this so the platform build layer can
175
+ * replace the outbound group's placeholder items with real Messages
176
+ * that carry each item's own id.
177
+ */
178
+ groupMembers?: SendResult<TSender>[];
157
179
  id: string;
158
180
  sender?: TSender;
159
181
  timestamp?: Date;
@@ -186,7 +208,7 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
186
208
  }) => Promise<void>;
187
209
  reactToMessage?: (_: {
188
210
  space: _ResolvedSpace & SpaceRef;
189
- messageId: string;
211
+ target: _MessageType;
190
212
  reaction: string;
191
213
  client: _Client;
192
214
  config: z__default.infer<_ConfigSchema>;
@@ -205,6 +227,12 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
205
227
  client: _Client;
206
228
  config: z__default.infer<_ConfigSchema>;
207
229
  }) => Promise<void>;
230
+ getMessage?: (_: {
231
+ space: _ResolvedSpace & SpaceRef;
232
+ messageId: string;
233
+ client: _Client;
234
+ config: z__default.infer<_ConfigSchema>;
235
+ }) => Promise<_MessageType | undefined>;
208
236
  };
209
237
  config: _ConfigSchema;
210
238
  events: _Events;
@@ -255,6 +283,7 @@ interface AnyPlatformDef {
255
283
  reactToMessage?: (_: any) => Promise<void>;
256
284
  replyToMessage?: (_: any) => Promise<SendResult>;
257
285
  editMessage?: (_: any) => Promise<void>;
286
+ getMessage?: (_: any) => Promise<any>;
258
287
  };
259
288
  config: z__default.ZodType<object>;
260
289
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",