@yaoyuanchao/dingtalk 1.4.0 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +46 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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
@@ -152,11 +152,57 @@ async function extractMessageContent(
152
152
  };
153
153
  }
154
154
 
155
+ case 'chatRecord': {
156
+ // Chat record collection - contains multiple forwarded messages
157
+ // Structure: content.chatRecord is a JSON string containing an array of messages
158
+ const chatRecordContent = content || (msg as any).chatRecord;
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)));
189
+ }
190
+
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));
193
+ return {
194
+ text: '[聊天记录合集]',
195
+ messageType: 'chatRecord',
196
+ };
197
+ }
198
+
155
199
  default: {
156
200
  // Fallback: try text.content for unknown message types
157
201
  const text = msg.text?.content?.trim() || '';
158
202
  if (!text) {
159
203
  log?.info?.("[dingtalk] Unknown msgtype: " + msgtype + ", no text content found");
204
+ // Log full message structure for debugging unknown types
205
+ log?.info?.("[dingtalk] Unknown msgtype full structure: " + JSON.stringify(msg).slice(0, 1000));
160
206
  }
161
207
  return {
162
208
  text: text || `[${msgtype}消息]`,