@yaoyuanchao/dingtalk 1.4.3 → 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.
- package/package.json +1 -1
- package/src/monitor.ts +25 -1
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -174,8 +174,32 @@ async function extractMessageContent(
|
|
|
174
174
|
// Debug: log first record structure to understand available fields
|
|
175
175
|
log?.info?.("[dingtalk] chatRecord first record structure: " + JSON.stringify(records[0]));
|
|
176
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
|
+
|
|
177
195
|
const formattedRecords = records.map((record, idx) => {
|
|
178
|
-
|
|
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
|
+
|
|
179
203
|
const msgContent = record.content || '[不支持的消息类型]';
|
|
180
204
|
const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
|
|
181
205
|
return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
|