@wu529778790/open-im 1.10.7-beta.3 → 1.10.7-beta.5
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/dist/constants.d.ts
CHANGED
|
@@ -36,3 +36,5 @@ export declare const MAX_FEISHU_MESSAGE_LENGTH = 4000;
|
|
|
36
36
|
export declare const MAX_STREAMING_CONTENT_LENGTH = 25000;
|
|
37
37
|
export declare const MAX_WEWORK_MESSAGE_LENGTH = 2048;
|
|
38
38
|
export declare const MAX_DINGTALK_MESSAGE_LENGTH = 2048;
|
|
39
|
+
/** WeChat KF (微信客服) 单条消息最大字符数 */
|
|
40
|
+
export declare const MAX_WORKBUDDY_MESSAGE_LENGTH = 2000;
|
package/dist/constants.js
CHANGED
|
@@ -66,3 +66,5 @@ export const MAX_FEISHU_MESSAGE_LENGTH = 4000;
|
|
|
66
66
|
export const MAX_STREAMING_CONTENT_LENGTH = 25000;
|
|
67
67
|
export const MAX_WEWORK_MESSAGE_LENGTH = 2048;
|
|
68
68
|
export const MAX_DINGTALK_MESSAGE_LENGTH = 2048;
|
|
69
|
+
/** WeChat KF (微信客服) 单条消息最大字符数 */
|
|
70
|
+
export const MAX_WORKBUDDY_MESSAGE_LENGTH = 2000;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { WorkBuddyCentrifugeClient } from './centrifuge-client.js';
|
|
5
5
|
/**
|
|
6
|
-
* Send text reply to WeChat KF
|
|
6
|
+
* Send text reply to WeChat KF, splitting long messages automatically.
|
|
7
7
|
*/
|
|
8
8
|
export declare function sendTextReply(_client: WorkBuddyCentrifugeClient | null, chatId: string, text: string, msgId: string): Promise<void>;
|
|
9
9
|
/**
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WorkBuddy Message Sender - Send responses to WeChat KF
|
|
3
3
|
*/
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { createLogger } from '../logger.js';
|
|
5
|
-
import { toReplyPlainText } from '../shared/utils.js';
|
|
6
|
+
import { splitLongContent, toReplyPlainText } from '../shared/utils.js';
|
|
7
|
+
import { MAX_WORKBUDDY_MESSAGE_LENGTH } from '../constants.js';
|
|
6
8
|
import { getCentrifugeClient } from './client.js';
|
|
7
9
|
const log = createLogger('WorkBuddySender');
|
|
8
10
|
/**
|
|
9
|
-
* Send text reply to WeChat KF
|
|
11
|
+
* Send text reply to WeChat KF, splitting long messages automatically.
|
|
10
12
|
*/
|
|
11
13
|
export async function sendTextReply(_client, chatId, text, msgId) {
|
|
12
14
|
const client = _client ?? getCentrifugeClient();
|
|
@@ -14,13 +16,32 @@ export async function sendTextReply(_client, chatId, text, msgId) {
|
|
|
14
16
|
log.warn('WorkBuddy client not available, cannot send reply');
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const plainText = toReplyPlainText(text);
|
|
20
|
+
const parts = splitLongContent(plainText, MAX_WORKBUDDY_MESSAGE_LENGTH);
|
|
21
|
+
if (parts.length === 1) {
|
|
22
|
+
log.info(`Sending WorkBuddy reply to chatId=${chatId}, msgId=${msgId}, len=${plainText.length}`);
|
|
23
|
+
await client.sendPromptResponse({
|
|
24
|
+
session_id: chatId,
|
|
25
|
+
prompt_id: msgId,
|
|
26
|
+
content: [{ type: 'text', text: plainText }],
|
|
27
|
+
stop_reason: 'end_turn',
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
log.info(`Sending WorkBuddy reply in ${parts.length} parts to chatId=${chatId}, msgId=${msgId}, totalLen=${plainText.length}`);
|
|
32
|
+
for (let i = 0; i < parts.length; i++) {
|
|
33
|
+
const partText = i === 0
|
|
34
|
+
? `${parts[i]}\n\n_(1/${parts.length})_`
|
|
35
|
+
: `_(续 ${i + 1}/${parts.length})_\n\n${parts[i]}`;
|
|
36
|
+
const partMsgId = i === 0 ? msgId : randomUUID();
|
|
37
|
+
await client.sendPromptResponse({
|
|
38
|
+
session_id: chatId,
|
|
39
|
+
prompt_id: partMsgId,
|
|
40
|
+
content: [{ type: 'text', text: partText }],
|
|
41
|
+
stop_reason: 'end_turn',
|
|
42
|
+
});
|
|
43
|
+
log.info(`WorkBuddy part ${i + 1}/${parts.length} sent, msgId=${partMsgId}`);
|
|
44
|
+
}
|
|
24
45
|
}
|
|
25
46
|
/**
|
|
26
47
|
* Send error response to WeChat KF
|