@yaoyuanchao/dingtalk 1.4.6 → 1.4.7

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 +25 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "type": "module",
5
5
  "description": "DingTalk channel plugin for Clawdbot with Stream Mode support",
6
6
  "license": "MIT",
package/src/monitor.ts CHANGED
@@ -199,7 +199,8 @@ async function extractMessageContent(
199
199
  }
200
200
  }
201
201
 
202
- const formattedRecords = records.map((record, idx) => {
202
+ // Process records with async image downloads
203
+ const formattedRecords = await Promise.all(records.map(async (record, idx) => {
203
204
  // Try: senderNick > API resolved name (via staffId or senderId) > fallback
204
205
  let sender = record.senderNick;
205
206
  if (!sender) {
@@ -223,7 +224,28 @@ async function extractMessageContent(
223
224
  break;
224
225
  case 'picture':
225
226
  case 'image':
226
- msgContent = '[图片]';
227
+ // Try to download the image
228
+ if (record.downloadCode && account.clientId && account.clientSecret) {
229
+ try {
230
+ const robotCode = account.robotCode || account.clientId;
231
+ const pictureResult = await downloadPicture(
232
+ account.clientId, account.clientSecret, robotCode!, record.downloadCode,
233
+ );
234
+ if (pictureResult.filePath) {
235
+ msgContent = `[图片: ${pictureResult.filePath}]`;
236
+ log?.info?.("[dingtalk] Downloaded chatRecord picture: " + pictureResult.filePath);
237
+ } else if (pictureResult.error) {
238
+ msgContent = `[图片下载失败: ${pictureResult.error}]`;
239
+ } else {
240
+ msgContent = '[图片]';
241
+ }
242
+ } catch (err) {
243
+ log?.info?.("[dingtalk] Error downloading chatRecord picture: " + err);
244
+ msgContent = '[图片]';
245
+ }
246
+ } else {
247
+ msgContent = '[图片]';
248
+ }
227
249
  break;
228
250
  case 'video':
229
251
  msgContent = '[视频]';
@@ -246,7 +268,7 @@ async function extractMessageContent(
246
268
  }
247
269
  const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
248
270
  return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
249
- });
271
+ }));
250
272
  const text = `[聊天记录合集 - ${records.length}条消息]\n${formattedRecords.join('\n')}`;
251
273
  log?.info?.("[dingtalk] Parsed chatRecord with " + records.length + " messages");
252
274
  return {