@yaoyuanchao/dingtalk 1.4.12 → 1.4.13

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/channel.ts +44 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yaoyuanchao/dingtalk",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "type": "module",
5
5
  "description": "DingTalk channel plugin for Clawdbot with Stream Mode support",
6
6
  "license": "MIT",
package/src/channel.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { getDingTalkRuntime } from './runtime.js';
2
2
  import { resolveDingTalkAccount } from './accounts.js';
3
3
  import { startDingTalkMonitor } from './monitor.js';
4
- import { sendDingTalkRestMessage } from './api.js';
4
+ import { sendDingTalkRestMessage, uploadMediaFile, sendFileMessage, textToMarkdownFile } from './api.js';
5
5
  import { probeDingTalk } from './probe.js';
6
6
 
7
7
  /**
@@ -187,6 +187,49 @@ export const dingtalkPlugin = {
187
187
  const account = resolveDingTalkAccount({ cfg, accountId });
188
188
  const { type, id } = parseOutboundTo(to);
189
189
 
190
+ // Check longTextMode config
191
+ const longTextMode = account.config?.longTextMode ?? 'chunk';
192
+ const longTextThreshold = account.config?.longTextThreshold ?? 4000;
193
+
194
+ // If longTextMode is 'file' and text exceeds threshold, send as file
195
+ if (longTextMode === 'file' && text.length > longTextThreshold) {
196
+ console.log(`[dingtalk] Outbound text exceeds threshold (${text.length} > ${longTextThreshold}), sending as file`);
197
+
198
+ const { buffer, fileName } = textToMarkdownFile(text, 'AI Response');
199
+
200
+ // Upload file
201
+ const uploadResult = await uploadMediaFile({
202
+ clientId: account.clientId,
203
+ clientSecret: account.clientSecret,
204
+ robotCode: account.robotCode || account.clientId,
205
+ fileBuffer: buffer,
206
+ fileName,
207
+ fileType: 'file',
208
+ });
209
+
210
+ if (uploadResult.mediaId) {
211
+ // Send file message
212
+ const sendResult = await sendFileMessage({
213
+ clientId: account.clientId,
214
+ clientSecret: account.clientSecret,
215
+ robotCode: account.robotCode || account.clientId,
216
+ userId: type === 'dm' ? id : undefined,
217
+ conversationId: type === 'group' ? id : undefined,
218
+ mediaId: uploadResult.mediaId,
219
+ fileName,
220
+ });
221
+
222
+ if (sendResult.ok) {
223
+ console.log(`[dingtalk] File sent successfully via outbound: ${fileName}`);
224
+ return { channel: 'dingtalk', ok: true };
225
+ }
226
+ console.log(`[dingtalk] File send failed, falling back to text: ${sendResult.error}`);
227
+ } else {
228
+ console.log(`[dingtalk] File upload failed, falling back to text: ${uploadResult.error}`);
229
+ }
230
+ // Fall through to text sending if file send fails
231
+ }
232
+
190
233
  if (type === 'dm') {
191
234
  await sendDingTalkRestMessage({
192
235
  clientId: account.clientId,