@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +37 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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
@@ -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, raw structure: " + JSON.stringify(chatRecordContent));
159
-
160
- if (chatRecordContent?.recordList && Array.isArray(chatRecordContent.recordList)) {
161
- // Parse recordList into readable text
162
- const records = chatRecordContent.recordList.map((record: any, idx: number) => {
163
- const sender = record.senderNick || record.senderName || '未知用户';
164
- const msgContent = record.text || record.content || '[不支持的消息类型]';
165
- const time = record.createAt ? new Date(record.createAt).toLocaleString('zh-CN') : '';
166
- return `[${idx + 1}] ${sender}${time ? ` (${time})` : ''}: ${msgContent}`;
167
- });
168
- const text = `[聊天记录合集 - ${records.length}条消息]\n${records.join('\n')}`;
169
- return {
170
- text,
171
- messageType: 'chatRecord',
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',