@yaoyuanchao/dingtalk 1.4.2 → 1.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +29 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
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
@@ -171,10 +171,38 @@ async function extractMessageContent(
171
171
  }>;
172
172
 
173
173
  if (Array.isArray(records) && records.length > 0) {
174
+ // Debug: log first record structure to understand available fields
175
+ log?.info?.("[dingtalk] chatRecord first record structure: " + JSON.stringify(records[0]));
176
+
177
+ // Collect unique senderIds for batch lookup
178
+ const senderIds = [...new Set(
179
+ records
180
+ .map(r => r.senderId)
181
+ .filter((id): id is string => !!id && !id.startsWith('$:')) // Skip encrypted IDs
182
+ )].slice(0, 10); // Limit to 10 users
183
+
184
+ // Try to resolve sender names via API
185
+ let senderNameMap = new Map<string, string>();
186
+ if (senderIds.length > 0 && account.clientId && account.clientSecret) {
187
+ try {
188
+ senderNameMap = await batchGetUserInfo(account.clientId, account.clientSecret, senderIds, 3000);
189
+ log?.info?.("[dingtalk] Resolved " + senderNameMap.size + " sender names from API");
190
+ } catch (err) {
191
+ log?.info?.("[dingtalk] Failed to resolve sender names: " + err);
192
+ }
193
+ }
194
+
174
195
  const formattedRecords = records.map((record, idx) => {
196
+ // Try: senderNick from record > API resolved name > senderId > '未知'
197
+ let sender = record.senderNick;
198
+ if (!sender && record.senderId) {
199
+ sender = senderNameMap.get(record.senderId) || (record.senderId.startsWith('$:') ? '成员' : record.senderId);
200
+ }
201
+ sender = sender || '未知';
202
+
175
203
  const msgContent = record.content || '[不支持的消息类型]';
176
204
  const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
177
- return `[${idx + 1}]${time ? ` (${time})` : ''}: ${msgContent}`;
205
+ return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
178
206
  });
179
207
  const text = `[聊天记录合集 - ${records.length}条消息]\n${formattedRecords.join('\n')}`;
180
208
  log?.info?.("[dingtalk] Parsed chatRecord with " + records.length + " messages");