@yaoyuanchao/dingtalk 1.7.2 → 1.7.4
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/package.json +1 -1
- package/src/monitor.ts +28 -6
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -308,8 +308,11 @@ export async function startDingTalkMonitor(ctx: DingTalkMonitorContext): Promise
|
|
|
308
308
|
touchActivity(); // Track message activity for heartbeat
|
|
309
309
|
|
|
310
310
|
// Deduplication: skip messages already processed (e.g. re-delivered after reconnect)
|
|
311
|
+
// Check both protocol-level messageId AND business-level msgId, because
|
|
312
|
+
// DingTalk re-delivers with a NEW protocol messageId after reconnect but
|
|
313
|
+
// the same business msgId.
|
|
311
314
|
if (isDuplicateMessage(protocolMsgId)) {
|
|
312
|
-
log?.info?.("[dingtalk] Duplicate message skipped: " + protocolMsgId);
|
|
315
|
+
log?.info?.("[dingtalk] Duplicate message skipped (protocol): " + protocolMsgId);
|
|
313
316
|
return { status: "SUCCESS", message: "OK" };
|
|
314
317
|
}
|
|
315
318
|
markMessageProcessed(protocolMsgId);
|
|
@@ -317,6 +320,15 @@ export async function startDingTalkMonitor(ctx: DingTalkMonitorContext): Promise
|
|
|
317
320
|
try {
|
|
318
321
|
const data: DingTalkRobotMessage = typeof downstream.data === "string"
|
|
319
322
|
? JSON.parse(downstream.data) : downstream.data;
|
|
323
|
+
|
|
324
|
+
// Business-level dedup: same msgId re-delivered with different protocol ID
|
|
325
|
+
const bizMsgId = data.msgId;
|
|
326
|
+
if (bizMsgId && isDuplicateMessage('biz:' + bizMsgId)) {
|
|
327
|
+
log?.info?.("[dingtalk] Duplicate message skipped (bizMsgId): " + bizMsgId);
|
|
328
|
+
return { status: "SUCCESS", message: "OK" };
|
|
329
|
+
}
|
|
330
|
+
if (bizMsgId) markMessageProcessed('biz:' + bizMsgId);
|
|
331
|
+
|
|
320
332
|
setStatus?.({ lastInboundAt: Date.now() });
|
|
321
333
|
await processInboundMessage(data, ctx);
|
|
322
334
|
} catch (err) {
|
|
@@ -1656,6 +1668,7 @@ async function dispatchWithFullPipeline(params: {
|
|
|
1656
1668
|
log, setStatus, onFirstReply } = params;
|
|
1657
1669
|
|
|
1658
1670
|
let firstReplyFired = false;
|
|
1671
|
+
let typingSafetyTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
1659
1672
|
|
|
1660
1673
|
// 1. Resolve agent route via own bindings matching (like official plugin).
|
|
1661
1674
|
// OpenClaw's resolveAgentRoute doesn't handle accountId correctly for multi-account.
|
|
@@ -1751,6 +1764,7 @@ async function dispatchWithFullPipeline(params: {
|
|
|
1751
1764
|
// Recall typing indicator on first delivery
|
|
1752
1765
|
if (!firstReplyFired && onFirstReply) {
|
|
1753
1766
|
firstReplyFired = true;
|
|
1767
|
+
if (typingSafetyTimeout) { clearTimeout(typingSafetyTimeout); typingSafetyTimeout = null; }
|
|
1754
1768
|
await onFirstReply().catch((err) => {
|
|
1755
1769
|
log?.info?.("[dingtalk] onFirstReply error: " + err);
|
|
1756
1770
|
});
|
|
@@ -1778,12 +1792,20 @@ async function dispatchWithFullPipeline(params: {
|
|
|
1778
1792
|
await rt.channel.reply.dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyOptions });
|
|
1779
1793
|
} finally {
|
|
1780
1794
|
markDispatchIdle();
|
|
1781
|
-
//
|
|
1782
|
-
//
|
|
1783
|
-
//
|
|
1784
|
-
//
|
|
1795
|
+
// Don't recall typing immediately — dispatchReplyFromConfig resolves when
|
|
1796
|
+
// dispatch is *initiated*, not when the agent finishes. The agent may still
|
|
1797
|
+
// be doing tool calls for minutes before producing the first text reply.
|
|
1798
|
+
// The deliver callback above handles the normal recall on first delivery.
|
|
1799
|
+
// Set a safety timeout to recall if no delivery ever arrives (edge case).
|
|
1785
1800
|
if (!firstReplyFired && onFirstReply) {
|
|
1786
|
-
|
|
1801
|
+
const TYPING_SAFETY_TIMEOUT_MS = 3 * 60 * 1000; // 3 minutes
|
|
1802
|
+
typingSafetyTimeout = setTimeout(async () => {
|
|
1803
|
+
if (!firstReplyFired && onFirstReply) {
|
|
1804
|
+
firstReplyFired = true;
|
|
1805
|
+
log?.info?.('[dingtalk] Typing safety timeout — recalling after no delivery');
|
|
1806
|
+
await onFirstReply().catch(() => {});
|
|
1807
|
+
}
|
|
1808
|
+
}, TYPING_SAFETY_TIMEOUT_MS);
|
|
1787
1809
|
}
|
|
1788
1810
|
}
|
|
1789
1811
|
|