@yaoyuanchao/dingtalk 1.5.7 → 1.5.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +35 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "type": "module",
5
5
  "description": "DingTalk channel plugin for ClawdBot/OpenClaw with Stream Mode support",
6
6
  "license": "MIT",
package/src/monitor.ts CHANGED
@@ -1181,6 +1181,39 @@ function resolveDeliverText(payload: any, log?: any): string | undefined {
1181
1181
  return text || undefined;
1182
1182
  }
1183
1183
 
1184
+ function buildMarkdownPreviewTitle(text: string, fallback = "Jax"): string {
1185
+ if (!text) return fallback;
1186
+
1187
+ const lines = text
1188
+ .split(/\r?\n/)
1189
+ .map((line) => line.trim())
1190
+ .filter(Boolean);
1191
+
1192
+ for (const raw of lines) {
1193
+ // Skip pure image lines
1194
+ if (/^!\[[^\]]*\]\([^\)]+\)$/.test(raw)) continue;
1195
+
1196
+ let title = raw
1197
+ // Strip common markdown prefixes
1198
+ .replace(/^\s*(#{1,6}|>|[-*+]|\d+\.)\s+/, "")
1199
+ // Convert markdown links/images to plain text
1200
+ .replace(/!\[[^\]]*\]\([^\)]+\)/g, "")
1201
+ .replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1")
1202
+ // Remove inline code fences
1203
+ .replace(/`([^`]*)`/g, "$1")
1204
+ .replace(/\s+/g, " ")
1205
+ .trim();
1206
+
1207
+ if (!title) continue;
1208
+
1209
+ // DingTalk conversation list preview is concise; keep title short.
1210
+ if (title.length > 36) title = title.slice(0, 36);
1211
+ return title;
1212
+ }
1213
+
1214
+ return fallback;
1215
+ }
1216
+
1184
1217
  async function deliverReply(target: any, text: string, log?: any): Promise<void> {
1185
1218
  const now = Date.now();
1186
1219
  const chunkLimit = target.account.config.textChunkLimit ?? 2000;
@@ -1243,7 +1276,8 @@ async function deliverReply(target: any, text: string, log?: any): Promise<void>
1243
1276
  log?.info?.("[dingtalk] Sending text (" + chunk.length + " chars): " + chunk.substring(0, 200));
1244
1277
  let sendResult: { ok: boolean; errcode?: number; errmsg?: string };
1245
1278
  if (isMarkdown) {
1246
- sendResult = await sendMarkdownViaSessionWebhook(target.sessionWebhook, "Reply", chunk);
1279
+ const markdownTitle = buildMarkdownPreviewTitle(chunk, "Jax");
1280
+ sendResult = await sendMarkdownViaSessionWebhook(target.sessionWebhook, markdownTitle, chunk);
1247
1281
  } else {
1248
1282
  sendResult = await sendViaSessionWebhook(target.sessionWebhook, chunk);
1249
1283
  }