@yaoyuanchao/dingtalk 1.4.5 → 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 +54 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.5",
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
@@ -168,6 +168,7 @@ async function extractMessageContent(
168
168
  senderNick?: string;
169
169
  msgType?: string;
170
170
  content?: string;
171
+ downloadCode?: string; // For media messages (picture, video, file)
171
172
  createAt?: number;
172
173
  }>;
173
174
 
@@ -198,7 +199,8 @@ async function extractMessageContent(
198
199
  }
199
200
  }
200
201
 
201
- const formattedRecords = records.map((record, idx) => {
202
+ // Process records with async image downloads
203
+ const formattedRecords = await Promise.all(records.map(async (record, idx) => {
202
204
  // Try: senderNick > API resolved name (via staffId or senderId) > fallback
203
205
  let sender = record.senderNick;
204
206
  if (!sender) {
@@ -214,10 +216,59 @@ async function extractMessageContent(
214
216
  }
215
217
  sender = sender || '未知';
216
218
 
217
- const msgContent = record.content || '[不支持的消息类型]';
219
+ // Handle different message types in chatRecord
220
+ let msgContent: string;
221
+ switch (record.msgType) {
222
+ case 'text':
223
+ msgContent = record.content || '[空消息]';
224
+ break;
225
+ case 'picture':
226
+ case 'image':
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
+ }
249
+ break;
250
+ case 'video':
251
+ msgContent = '[视频]';
252
+ break;
253
+ case 'file':
254
+ msgContent = '[文件]';
255
+ break;
256
+ case 'voice':
257
+ case 'audio':
258
+ msgContent = '[语音]';
259
+ break;
260
+ case 'richText':
261
+ msgContent = record.content || '[富文本消息]';
262
+ break;
263
+ case 'markdown':
264
+ msgContent = record.content || '[Markdown消息]';
265
+ break;
266
+ default:
267
+ msgContent = record.content || `[${record.msgType || '未知'}消息]`;
268
+ }
218
269
  const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
219
270
  return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
220
- });
271
+ }));
221
272
  const text = `[聊天记录合集 - ${records.length}条消息]\n${formattedRecords.join('\n')}`;
222
273
  log?.info?.("[dingtalk] Parsed chatRecord with " + records.length + " messages");
223
274
  return {