@yaoyuanchao/dingtalk 1.4.1 → 1.4.3
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 +37 -17
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -154,26 +154,46 @@ async function extractMessageContent(
|
|
|
154
154
|
|
|
155
155
|
case 'chatRecord': {
|
|
156
156
|
// Chat record collection - contains multiple forwarded messages
|
|
157
|
+
// Structure: content.chatRecord is a JSON string containing an array of messages
|
|
157
158
|
const chatRecordContent = content || (msg as any).chatRecord;
|
|
158
|
-
log?.info?.("[dingtalk] chatRecord message received
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
log?.info?.("[dingtalk] chatRecord message received");
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
// chatRecord is a JSON string, need to parse it
|
|
163
|
+
const chatRecordStr = chatRecordContent?.chatRecord;
|
|
164
|
+
if (chatRecordStr && typeof chatRecordStr === 'string') {
|
|
165
|
+
const records = JSON.parse(chatRecordStr) as Array<{
|
|
166
|
+
senderId?: string;
|
|
167
|
+
senderNick?: string;
|
|
168
|
+
msgType?: string;
|
|
169
|
+
content?: string;
|
|
170
|
+
createAt?: number;
|
|
171
|
+
}>;
|
|
172
|
+
|
|
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
|
+
const formattedRecords = records.map((record, idx) => {
|
|
178
|
+
const sender = record.senderNick || record.senderId || '未知';
|
|
179
|
+
const msgContent = record.content || '[不支持的消息类型]';
|
|
180
|
+
const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
|
|
181
|
+
return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
|
|
182
|
+
});
|
|
183
|
+
const text = `[聊天记录合集 - ${records.length}条消息]\n${formattedRecords.join('\n')}`;
|
|
184
|
+
log?.info?.("[dingtalk] Parsed chatRecord with " + records.length + " messages");
|
|
185
|
+
return {
|
|
186
|
+
text,
|
|
187
|
+
messageType: 'chatRecord',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} catch (e) {
|
|
192
|
+
log?.info?.("[dingtalk] Failed to parse chatRecord: " + (e instanceof Error ? e.message : String(e)));
|
|
173
193
|
}
|
|
174
194
|
|
|
175
|
-
// Fallback if structure is different
|
|
176
|
-
log?.info?.("[dingtalk] chatRecord structure not recognized, full msg: " + JSON.stringify(msg));
|
|
195
|
+
// Fallback if structure is different or parsing failed
|
|
196
|
+
log?.info?.("[dingtalk] chatRecord structure not recognized, full msg: " + JSON.stringify(msg).slice(0, 500));
|
|
177
197
|
return {
|
|
178
198
|
text: '[聊天记录合集]',
|
|
179
199
|
messageType: 'chatRecord',
|