@soimy/dingtalk 3.3.0 → 3.4.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.
Files changed (36) hide show
  1. package/README.md +141 -12
  2. package/index.ts +71 -66
  3. package/package.json +6 -5
  4. package/src/access-control.ts +65 -0
  5. package/src/ack-reaction/dynamic-ack-reaction-controller.ts +271 -0
  6. package/src/ack-reaction/dynamic-ack-reaction-events.ts +123 -0
  7. package/src/ack-reaction/dynamic-ack-reaction-progress.ts +59 -0
  8. package/src/ack-reaction-classifier.ts +17 -4
  9. package/src/ack-reaction-service.ts +66 -19
  10. package/src/attachment-text-extractor.ts +2 -1
  11. package/src/card-service.ts +145 -257
  12. package/src/channel.ts +106 -47
  13. package/src/config-schema.ts +28 -6
  14. package/src/config.ts +30 -6
  15. package/src/connection-manager.ts +16 -5
  16. package/src/inbound-handler.ts +694 -520
  17. package/src/media-utils.ts +99 -36
  18. package/src/message-context-store.ts +787 -0
  19. package/src/message-utils.ts +221 -42
  20. package/src/messaging/quoted-context.ts +269 -0
  21. package/src/messaging/quoted-ref.ts +97 -0
  22. package/src/onboarding.ts +381 -269
  23. package/src/reply-strategy-card.ts +225 -0
  24. package/src/reply-strategy-markdown.ts +55 -0
  25. package/src/reply-strategy-with-reaction.ts +190 -0
  26. package/src/reply-strategy.ts +72 -0
  27. package/src/runtime.ts +5 -7
  28. package/src/send-service.ts +164 -62
  29. package/src/targeting/agent-name-matcher.ts +148 -0
  30. package/src/targeting/agent-routing.ts +181 -0
  31. package/src/targeting/target-directory-adapter.ts +152 -0
  32. package/src/targeting/target-directory-store.ts +396 -0
  33. package/src/targeting/target-input.ts +62 -0
  34. package/src/types.ts +124 -21
  35. package/src/quote-journal.ts +0 -242
  36. package/src/quoted-msg-cache.ts +0 -226
@@ -0,0 +1,97 @@
1
+ import {
2
+ resolveByQuotedRef,
3
+ type MessageRecord,
4
+ } from "../message-context-store";
5
+ import type { DingTalkInboundMessage, Logger, MessageContent, QuotedRef } from "../types";
6
+
7
+ function firstTrimmedString(...candidates: Array<string | undefined>): string | undefined {
8
+ for (const candidate of candidates) {
9
+ if (typeof candidate === "string" && candidate.trim()) {
10
+ return candidate.trim();
11
+ }
12
+ }
13
+ return undefined;
14
+ }
15
+
16
+ function firstFiniteNumber(...candidates: Array<number | undefined>): number | undefined {
17
+ for (const candidate of candidates) {
18
+ if (typeof candidate === "number" && Number.isFinite(candidate)) {
19
+ return candidate;
20
+ }
21
+ }
22
+ return undefined;
23
+ }
24
+
25
+ export function buildInboundQuotedRef(
26
+ data: DingTalkInboundMessage,
27
+ content: MessageContent,
28
+ ): QuotedRef | undefined {
29
+ const repliedMsg = data.text?.repliedMsg;
30
+ const repliedMsgId = firstTrimmedString(repliedMsg?.msgId, data.originalMsgId, content.quoted?.msgId);
31
+ const fallbackCreatedAt = firstFiniteNumber(
32
+ repliedMsg?.createdAt,
33
+ content.quoted?.cardCreatedAt,
34
+ content.quoted?.fileCreatedAt,
35
+ );
36
+ const isOutboundQuoted =
37
+ firstTrimmedString(data.originalProcessQueryKey) !== undefined ||
38
+ repliedMsg?.senderId === data.chatbotUserId ||
39
+ content.quoted?.isQuotedCard === true;
40
+ if (isOutboundQuoted) {
41
+ const processQueryKey = firstTrimmedString(data.originalProcessQueryKey, content.quoted?.processQueryKey);
42
+ if (processQueryKey) {
43
+ return {
44
+ targetDirection: "outbound",
45
+ key: "processQueryKey",
46
+ value: processQueryKey,
47
+ fallbackCreatedAt,
48
+ };
49
+ }
50
+ if (!fallbackCreatedAt) {
51
+ return undefined;
52
+ }
53
+ return {
54
+ targetDirection: "outbound",
55
+ fallbackCreatedAt,
56
+ };
57
+ }
58
+ if (!repliedMsgId) {
59
+ return undefined;
60
+ }
61
+ return {
62
+ targetDirection: "inbound",
63
+ key: "msgId",
64
+ value: repliedMsgId,
65
+ };
66
+ }
67
+
68
+ export function createReplyQuotedRef(msgId: string | undefined): QuotedRef | undefined {
69
+ const value = firstTrimmedString(msgId);
70
+ if (!value) {
71
+ return undefined;
72
+ }
73
+ return {
74
+ targetDirection: "inbound",
75
+ key: "msgId",
76
+ value,
77
+ };
78
+ }
79
+
80
+ export function resolveQuotedRecord(params: {
81
+ storePath?: string;
82
+ accountId: string;
83
+ conversationId: string | null;
84
+ quotedRef?: QuotedRef;
85
+ log?: Logger;
86
+ }): MessageRecord | null {
87
+ if (!params.quotedRef) {
88
+ return null;
89
+ }
90
+ return resolveByQuotedRef({
91
+ storePath: params.storePath,
92
+ accountId: params.accountId,
93
+ conversationId: params.conversationId,
94
+ quotedRef: params.quotedRef,
95
+ log: params.log,
96
+ });
97
+ }