@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.
- package/README.md +141 -12
- package/index.ts +71 -66
- package/package.json +6 -5
- package/src/access-control.ts +65 -0
- package/src/ack-reaction/dynamic-ack-reaction-controller.ts +271 -0
- package/src/ack-reaction/dynamic-ack-reaction-events.ts +123 -0
- package/src/ack-reaction/dynamic-ack-reaction-progress.ts +59 -0
- package/src/ack-reaction-classifier.ts +17 -4
- package/src/ack-reaction-service.ts +66 -19
- package/src/attachment-text-extractor.ts +2 -1
- package/src/card-service.ts +145 -257
- package/src/channel.ts +106 -47
- package/src/config-schema.ts +28 -6
- package/src/config.ts +30 -6
- package/src/connection-manager.ts +16 -5
- package/src/inbound-handler.ts +694 -520
- package/src/media-utils.ts +99 -36
- package/src/message-context-store.ts +787 -0
- package/src/message-utils.ts +221 -42
- package/src/messaging/quoted-context.ts +269 -0
- package/src/messaging/quoted-ref.ts +97 -0
- package/src/onboarding.ts +381 -269
- package/src/reply-strategy-card.ts +225 -0
- package/src/reply-strategy-markdown.ts +55 -0
- package/src/reply-strategy-with-reaction.ts +190 -0
- package/src/reply-strategy.ts +72 -0
- package/src/runtime.ts +5 -7
- package/src/send-service.ts +164 -62
- package/src/targeting/agent-name-matcher.ts +148 -0
- package/src/targeting/agent-routing.ts +181 -0
- package/src/targeting/target-directory-adapter.ts +152 -0
- package/src/targeting/target-directory-store.ts +396 -0
- package/src/targeting/target-input.ts +62 -0
- package/src/types.ts +124 -21
- package/src/quote-journal.ts +0 -242
- 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
|
+
}
|