@yaoyuanchao/dingtalk 1.4.1 → 1.4.2
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 +33 -17
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -154,26 +154,42 @@ 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
|
+
const formattedRecords = records.map((record, idx) => {
|
|
175
|
+
const msgContent = record.content || '[不支持的消息类型]';
|
|
176
|
+
const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
|
|
177
|
+
return `[${idx + 1}]${time ? ` (${time})` : ''}: ${msgContent}`;
|
|
178
|
+
});
|
|
179
|
+
const text = `[聊天记录合集 - ${records.length}条消息]\n${formattedRecords.join('\n')}`;
|
|
180
|
+
log?.info?.("[dingtalk] Parsed chatRecord with " + records.length + " messages");
|
|
181
|
+
return {
|
|
182
|
+
text,
|
|
183
|
+
messageType: 'chatRecord',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
log?.info?.("[dingtalk] Failed to parse chatRecord: " + (e instanceof Error ? e.message : String(e)));
|
|
173
189
|
}
|
|
174
190
|
|
|
175
|
-
// Fallback if structure is different
|
|
176
|
-
log?.info?.("[dingtalk] chatRecord structure not recognized, full msg: " + JSON.stringify(msg));
|
|
191
|
+
// Fallback if structure is different or parsing failed
|
|
192
|
+
log?.info?.("[dingtalk] chatRecord structure not recognized, full msg: " + JSON.stringify(msg).slice(0, 500));
|
|
177
193
|
return {
|
|
178
194
|
text: '[聊天记录合集]',
|
|
179
195
|
messageType: 'chatRecord',
|