@yaoyuanchao/dingtalk 1.3.3 → 1.3.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/channel.ts +14 -2
- package/src/monitor.ts +5 -0
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -4,6 +4,18 @@ import { startDingTalkMonitor } from './monitor.js';
|
|
|
4
4
|
import { sendDingTalkRestMessage } from './api.js';
|
|
5
5
|
import { probeDingTalk } from './probe.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Parse outbound `to` address, stripping optional channel prefix.
|
|
9
|
+
* Handles both "dm:id" and "dingtalk:dm:id" formats.
|
|
10
|
+
*/
|
|
11
|
+
function parseOutboundTo(to: string): { type: string; id: string } {
|
|
12
|
+
const parts = to.split(':');
|
|
13
|
+
if (parts[0] === 'dingtalk' && parts.length > 2) {
|
|
14
|
+
parts.shift();
|
|
15
|
+
}
|
|
16
|
+
return { type: parts[0], id: parts.slice(1).join(':') };
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
export const dingtalkPlugin = {
|
|
8
20
|
id: 'dingtalk',
|
|
9
21
|
|
|
@@ -166,7 +178,7 @@ export const dingtalkPlugin = {
|
|
|
166
178
|
|
|
167
179
|
async sendText({ to, text, accountId, cfg }) {
|
|
168
180
|
const account = resolveDingTalkAccount({ cfg, accountId });
|
|
169
|
-
const
|
|
181
|
+
const { type, id } = parseOutboundTo(to);
|
|
170
182
|
|
|
171
183
|
if (type === 'dm') {
|
|
172
184
|
await sendDingTalkRestMessage({
|
|
@@ -204,7 +216,7 @@ export const dingtalkPlugin = {
|
|
|
204
216
|
}
|
|
205
217
|
|
|
206
218
|
const account = resolveDingTalkAccount({ cfg, accountId });
|
|
207
|
-
const
|
|
219
|
+
const { type, id } = parseOutboundTo(to);
|
|
208
220
|
|
|
209
221
|
// Build text message with image URL as markdown image
|
|
210
222
|
const imageMarkdown = ``;
|
package/src/monitor.ts
CHANGED
|
@@ -52,6 +52,11 @@ export async function startDingTalkMonitor(ctx: DingTalkMonitorContext): Promise
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
client.registerCallbackListener(TOPIC_ROBOT, async (downstream: any) => {
|
|
55
|
+
// Immediately ACK to prevent DingTalk from retrying (60s timeout)
|
|
56
|
+
try {
|
|
57
|
+
client.socketResponse(downstream.headers.messageId, { status: 'SUCCESS' });
|
|
58
|
+
} catch (_) { /* best-effort ACK */ }
|
|
59
|
+
|
|
55
60
|
try {
|
|
56
61
|
const data: DingTalkRobotMessage = typeof downstream.data === "string"
|
|
57
62
|
? JSON.parse(downstream.data) : downstream.data;
|