@yaoyuanchao/dingtalk 1.4.4 → 1.4.5
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 +22 -8
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -164,6 +164,7 @@ async function extractMessageContent(
|
|
|
164
164
|
if (chatRecordStr && typeof chatRecordStr === 'string') {
|
|
165
165
|
const records = JSON.parse(chatRecordStr) as Array<{
|
|
166
166
|
senderId?: string;
|
|
167
|
+
senderStaffId?: string; // Non-encrypted userId (available when app is published)
|
|
167
168
|
senderNick?: string;
|
|
168
169
|
msgType?: string;
|
|
169
170
|
content?: string;
|
|
@@ -171,16 +172,21 @@ async function extractMessageContent(
|
|
|
171
172
|
}>;
|
|
172
173
|
|
|
173
174
|
if (Array.isArray(records) && records.length > 0) {
|
|
174
|
-
// Debug: log first record structure
|
|
175
|
-
|
|
175
|
+
// Debug: log first record structure with all keys
|
|
176
|
+
const firstRecord = records[0];
|
|
177
|
+
log?.info?.("[dingtalk] chatRecord first record keys: " + Object.keys(firstRecord).join(', '));
|
|
178
|
+
log?.info?.("[dingtalk] chatRecord first record: " + JSON.stringify(firstRecord));
|
|
176
179
|
|
|
177
|
-
// Collect unique
|
|
180
|
+
// Collect unique userIds for batch lookup
|
|
181
|
+
// Prefer senderStaffId (non-encrypted) over senderId
|
|
178
182
|
const senderIds = [...new Set(
|
|
179
183
|
records
|
|
180
|
-
.map(r => r.senderId)
|
|
181
|
-
.filter((id): id is string => !!id
|
|
184
|
+
.map(r => r.senderStaffId || (r.senderId && !r.senderId.startsWith('$:') ? r.senderId : null))
|
|
185
|
+
.filter((id): id is string => !!id)
|
|
182
186
|
)].slice(0, 10); // Limit to 10 users
|
|
183
187
|
|
|
188
|
+
log?.info?.("[dingtalk] chatRecord senderIds for lookup: " + JSON.stringify(senderIds));
|
|
189
|
+
|
|
184
190
|
// Try to resolve sender names via API
|
|
185
191
|
let senderNameMap = new Map<string, string>();
|
|
186
192
|
if (senderIds.length > 0 && account.clientId && account.clientSecret) {
|
|
@@ -193,10 +199,18 @@ async function extractMessageContent(
|
|
|
193
199
|
}
|
|
194
200
|
|
|
195
201
|
const formattedRecords = records.map((record, idx) => {
|
|
196
|
-
// Try: senderNick
|
|
202
|
+
// Try: senderNick > API resolved name (via staffId or senderId) > fallback
|
|
197
203
|
let sender = record.senderNick;
|
|
198
|
-
if (!sender
|
|
199
|
-
|
|
204
|
+
if (!sender) {
|
|
205
|
+
// Try to get name from API lookup
|
|
206
|
+
const lookupId = record.senderStaffId || record.senderId;
|
|
207
|
+
if (lookupId) {
|
|
208
|
+
sender = senderNameMap.get(lookupId);
|
|
209
|
+
}
|
|
210
|
+
// Fallback for encrypted IDs
|
|
211
|
+
if (!sender && record.senderId?.startsWith('$:')) {
|
|
212
|
+
sender = '成员';
|
|
213
|
+
}
|
|
200
214
|
}
|
|
201
215
|
sender = sender || '未知';
|
|
202
216
|
|