@opentag/dispatcher 0.3.2 → 0.3.3

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.
@@ -17,6 +17,13 @@ export declare function createSlackSourceReceiptSink(input: {
17
17
  reactionsAddUri?: string;
18
18
  timeoutMs?: number;
19
19
  }): SourceReceiptSink;
20
+ export declare function createLarkSourceReceiptSink(input: {
21
+ appId?: string;
22
+ appSecret?: string;
23
+ domain?: "lark" | "feishu";
24
+ client?: LarkReplyClient;
25
+ receivedEmojiType?: string;
26
+ }): SourceReceiptSink;
20
27
  export declare function createLarkCallbackSink(input: {
21
28
  appId?: string;
22
29
  appSecret?: string;
@@ -29,4 +36,5 @@ export declare function createTelegramCallbackSink(input: {
29
36
  fetchImpl?: FetchLike;
30
37
  }): CallbackSink;
31
38
  export declare function createCompositeCallbackSink(sinks: CallbackSink[]): CallbackSink;
39
+ export declare function createCompositeSourceReceiptSink(sinks: SourceReceiptSink[]): SourceReceiptSink;
32
40
  //# sourceMappingURL=callbacks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"callbacks.d.ts","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAIrB,MAAM,eAAe,CAAC;AASvB,OAAO,KAAK,EAA2C,YAAY,EAAiB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE3H,MAAM,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC;AAkErC,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,YAAY,CA+CvG;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,SA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AAG,YAAY,CAuB/E;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,CAmB9F"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/callbacks.ts
2
2
  import {
3
+ addLarkMessageReaction,
3
4
  createLarkReplyClient,
4
5
  patchLarkMessageCard,
5
6
  parseLarkThreadKey,
@@ -15,6 +16,7 @@ import {
15
16
  } from "@opentag/slack";
16
17
  import { createTelegramSendMessageDraftPayload, createTelegramSendMessagePayload, parseTelegramThreadKey } from "@opentag/telegram";
17
18
  var DEFAULT_SLACK_SOURCE_RECEIPT_TIMEOUT_MS = 5e3;
19
+ var DEFAULT_LARK_RECEIVED_REACTION = "OK";
18
20
  function slackUpdateUriFrom(postMessageUri) {
19
21
  return postMessageUri.replace(/\/chat\.postMessage$/, "/chat.update");
20
22
  }
@@ -41,6 +43,12 @@ function slackSourceMessageTarget(receipt) {
41
43
  const messageTs = metadataString(receipt.event.metadata, "messageTs");
42
44
  return channelId && messageTs ? { channelId, messageTs } : null;
43
45
  }
46
+ function larkSourceMessageTarget(receipt) {
47
+ if (receipt.provider !== "lark" || receipt.state !== "received") return null;
48
+ const threadKey = receipt.event.callback.threadKey;
49
+ if (!threadKey) return null;
50
+ return { messageId: parseLarkThreadKey(threadKey).messageId };
51
+ }
44
52
  function isAbortError(error) {
45
53
  return error instanceof Error && error.name === "AbortError";
46
54
  }
@@ -200,6 +208,24 @@ function createSlackSourceReceiptSink(input) {
200
208
  }
201
209
  };
202
210
  }
211
+ function createLarkSourceReceiptSink(input) {
212
+ if (!input.client && Boolean(input.appId) !== Boolean(input.appSecret)) {
213
+ throw new Error("Lark source receipt sink requires both appId and appSecret (or neither).");
214
+ }
215
+ const client = input.client ?? (input.appId && input.appSecret ? createLarkReplyClient({ appId: input.appId, appSecret: input.appSecret, ...input.domain ? { domain: input.domain } : {} }) : void 0);
216
+ const receivedEmojiType = input.receivedEmojiType ?? DEFAULT_LARK_RECEIVED_REACTION;
217
+ return {
218
+ async deliver(receipt) {
219
+ const target = larkSourceMessageTarget(receipt);
220
+ if (!target || !client) return { delivered: false };
221
+ await addLarkMessageReaction(client, {
222
+ messageId: target.messageId,
223
+ emojiType: receivedEmojiType
224
+ });
225
+ return { delivered: true };
226
+ }
227
+ };
228
+ }
203
229
  function createLarkCallbackSink(input) {
204
230
  if (!input.client && Boolean(input.appId) !== Boolean(input.appSecret)) {
205
231
  throw new Error("Lark callback sink requires both appId and appSecret (or neither).");
@@ -314,6 +340,26 @@ function createCompositeCallbackSink(sinks) {
314
340
  }
315
341
  };
316
342
  }
343
+ function createCompositeSourceReceiptSink(sinks) {
344
+ return {
345
+ async deliver(receipt) {
346
+ let delivered = false;
347
+ const failures = [];
348
+ for (const sink of sinks) {
349
+ try {
350
+ const result = await sink.deliver(receipt);
351
+ delivered ||= result.delivered;
352
+ } catch (error) {
353
+ failures.push(error);
354
+ }
355
+ }
356
+ if (!delivered && failures.length > 0) {
357
+ throw new AggregateError(failures, "Composite source receipt delivery failed for every sink.");
358
+ }
359
+ return { delivered };
360
+ }
361
+ };
362
+ }
317
363
 
318
364
  // src/presentation.ts
319
365
  import {
@@ -3482,10 +3528,12 @@ function createDispatcherApp(input) {
3482
3528
  }
3483
3529
  export {
3484
3530
  createCompositeCallbackSink,
3531
+ createCompositeSourceReceiptSink,
3485
3532
  createDefaultCallbackPresentation,
3486
3533
  createDispatcherApp,
3487
3534
  createGitHubCallbackSink,
3488
3535
  createLarkCallbackSink,
3536
+ createLarkSourceReceiptSink,
3489
3537
  createSlackCallbackSink,
3490
3538
  createSlackSourceReceiptSink,
3491
3539
  createTelegramCallbackSink,