@cloudbase/agent-adapter-wx 1.0.1-alpha.25 → 1.0.1-alpha.25-1
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/README.md +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +51 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,7 @@ declare enum WeChatPlatform {
|
|
|
11
11
|
/** 企业微信客服 */
|
|
12
12
|
CUSTOM_SERVICE = "WXCustomerService",
|
|
13
13
|
/** 微信小程序 */
|
|
14
|
-
MINI_APP = "
|
|
14
|
+
MINI_APP = "WXMiniapp",
|
|
15
15
|
/** 微信服务号 */
|
|
16
16
|
SERVICE = "WXService",
|
|
17
17
|
/** 微信订阅号 */
|
|
@@ -127,7 +127,7 @@ interface WeChatWorkCommonInput {
|
|
|
127
127
|
/**
|
|
128
128
|
* Supported trigger sources - 支持的触发源
|
|
129
129
|
*/
|
|
130
|
-
type WeChatTriggerSrc =
|
|
130
|
+
type WeChatTriggerSrc = WeChatPlatform.SUBSCRIPTION | WeChatPlatform.SERVICE | WeChatPlatform.MINI_APP | WeChatPlatform.CUSTOM_SERVICE;
|
|
131
131
|
/**
|
|
132
132
|
* Supported message types - 支持的消息类型
|
|
133
133
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare enum WeChatPlatform {
|
|
|
11
11
|
/** 企业微信客服 */
|
|
12
12
|
CUSTOM_SERVICE = "WXCustomerService",
|
|
13
13
|
/** 微信小程序 */
|
|
14
|
-
MINI_APP = "
|
|
14
|
+
MINI_APP = "WXMiniapp",
|
|
15
15
|
/** 微信服务号 */
|
|
16
16
|
SERVICE = "WXService",
|
|
17
17
|
/** 微信订阅号 */
|
|
@@ -127,7 +127,7 @@ interface WeChatWorkCommonInput {
|
|
|
127
127
|
/**
|
|
128
128
|
* Supported trigger sources - 支持的触发源
|
|
129
129
|
*/
|
|
130
|
-
type WeChatTriggerSrc =
|
|
130
|
+
type WeChatTriggerSrc = WeChatPlatform.SUBSCRIPTION | WeChatPlatform.SERVICE | WeChatPlatform.MINI_APP | WeChatPlatform.CUSTOM_SERVICE;
|
|
131
131
|
/**
|
|
132
132
|
* Supported message types - 支持的消息类型
|
|
133
133
|
*/
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,27 @@ __export(index_exports, {
|
|
|
61
61
|
});
|
|
62
62
|
module.exports = __toCommonJS(index_exports);
|
|
63
63
|
|
|
64
|
+
// src/types.ts
|
|
65
|
+
var WeChatPlatform = /* @__PURE__ */ ((WeChatPlatform2) => {
|
|
66
|
+
WeChatPlatform2["CUSTOM_SERVICE"] = "WXCustomerService";
|
|
67
|
+
WeChatPlatform2["MINI_APP"] = "WXMiniapp";
|
|
68
|
+
WeChatPlatform2["SERVICE"] = "WXService";
|
|
69
|
+
WeChatPlatform2["SUBSCRIPTION"] = "WXSubscription";
|
|
70
|
+
return WeChatPlatform2;
|
|
71
|
+
})(WeChatPlatform || {});
|
|
72
|
+
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
73
|
+
MessageType2["TEXT"] = "text";
|
|
74
|
+
MessageType2["IMAGE"] = "image";
|
|
75
|
+
MessageType2["EVENT"] = "event";
|
|
76
|
+
MessageType2["VOICE"] = "voice";
|
|
77
|
+
return MessageType2;
|
|
78
|
+
})(MessageType || {});
|
|
79
|
+
var WeChatSendMode = /* @__PURE__ */ ((WeChatSendMode2) => {
|
|
80
|
+
WeChatSendMode2["LOCAL"] = "local";
|
|
81
|
+
WeChatSendMode2["AITOOLS"] = "aitools";
|
|
82
|
+
return WeChatSendMode2;
|
|
83
|
+
})(WeChatSendMode || {});
|
|
84
|
+
|
|
64
85
|
// src/wechat-message-handler.ts
|
|
65
86
|
var SUPPORTED_MSG_TYPES = ["text", "voice"];
|
|
66
87
|
function validateMessageType(msgType) {
|
|
@@ -77,21 +98,25 @@ function validateMessageType(msgType) {
|
|
|
77
98
|
function extractMsgType(originMsg) {
|
|
78
99
|
return originMsg.msgType || originMsg.MsgType || "text";
|
|
79
100
|
}
|
|
80
|
-
function extractTriggerSrc(originMsg, defaultSrc = "
|
|
101
|
+
function extractTriggerSrc(originMsg, defaultSrc = "WXService" /* SERVICE */) {
|
|
81
102
|
return originMsg.triggerSrc || defaultSrc;
|
|
82
103
|
}
|
|
83
104
|
function extractTextContent(originMsg, triggerSrc) {
|
|
84
|
-
if ([
|
|
105
|
+
if ([
|
|
106
|
+
"WXSubscription" /* SUBSCRIPTION */,
|
|
107
|
+
"WXService" /* SERVICE */,
|
|
108
|
+
"WXMiniapp" /* MINI_APP */
|
|
109
|
+
].includes(triggerSrc)) {
|
|
85
110
|
return originMsg.Content || originMsg.content || "";
|
|
86
|
-
} else if (triggerSrc === "WXCustomerService") {
|
|
111
|
+
} else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
87
112
|
return originMsg.text?.content || "";
|
|
88
113
|
}
|
|
89
114
|
return "";
|
|
90
115
|
}
|
|
91
116
|
function extractVoiceMediaId(originMsg, triggerSrc) {
|
|
92
|
-
if (["WXSubscription"
|
|
117
|
+
if (["WXSubscription" /* SUBSCRIPTION */, "WXService" /* SERVICE */].includes(triggerSrc)) {
|
|
93
118
|
return originMsg.MediaId || originMsg.mediaId || "";
|
|
94
|
-
} else if (triggerSrc === "WXCustomerService") {
|
|
119
|
+
} else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
95
120
|
return originMsg.voice?.mediaId || "";
|
|
96
121
|
}
|
|
97
122
|
return "";
|
|
@@ -111,17 +136,25 @@ async function getWxChatContent(originMsg, triggerSrc, voiceMessageHandler, botI
|
|
|
111
136
|
return "";
|
|
112
137
|
}
|
|
113
138
|
function extractSender(originMsg, triggerSrc) {
|
|
114
|
-
if ([
|
|
139
|
+
if ([
|
|
140
|
+
"WXSubscription" /* SUBSCRIPTION */,
|
|
141
|
+
"WXService" /* SERVICE */,
|
|
142
|
+
"WXMiniapp" /* MINI_APP */
|
|
143
|
+
].includes(triggerSrc)) {
|
|
115
144
|
return originMsg.FromUserName || originMsg.fromUserName || "";
|
|
116
|
-
} else if (triggerSrc === "WXCustomerService") {
|
|
145
|
+
} else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
117
146
|
return originMsg.externalUserId || "";
|
|
118
147
|
}
|
|
119
148
|
return "";
|
|
120
149
|
}
|
|
121
150
|
function extractConversation(originMsg, triggerSrc) {
|
|
122
|
-
if ([
|
|
151
|
+
if ([
|
|
152
|
+
"WXSubscription" /* SUBSCRIPTION */,
|
|
153
|
+
"WXService" /* SERVICE */,
|
|
154
|
+
"WXMiniapp" /* MINI_APP */
|
|
155
|
+
].includes(triggerSrc)) {
|
|
123
156
|
return originMsg.FromUserName || originMsg.fromUserName || "";
|
|
124
|
-
} else if (triggerSrc === "WXCustomerService") {
|
|
157
|
+
} else if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
125
158
|
return originMsg.externalUserId || "";
|
|
126
159
|
}
|
|
127
160
|
return "";
|
|
@@ -133,13 +166,15 @@ function extractMsgId(originMsg) {
|
|
|
133
166
|
return originMsg.msgId || originMsg.MsgId || Date.now().toString();
|
|
134
167
|
}
|
|
135
168
|
function extractTimestamp(originMsg, triggerSrc) {
|
|
136
|
-
if (triggerSrc === "WXCustomerService") {
|
|
169
|
+
if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
137
170
|
return originMsg.sendTime || Math.floor(Date.now() / 1e3);
|
|
138
171
|
}
|
|
139
172
|
return originMsg.createTime || originMsg.CreateTime || Math.floor(Date.now() / 1e3);
|
|
140
173
|
}
|
|
141
174
|
function needAsyncReply(triggerSrc, wxVerify) {
|
|
142
|
-
if (["
|
|
175
|
+
if (["WXMiniapp" /* MINI_APP */, "WXCustomerService" /* CUSTOM_SERVICE */].includes(
|
|
176
|
+
triggerSrc
|
|
177
|
+
)) {
|
|
143
178
|
return true;
|
|
144
179
|
}
|
|
145
180
|
return wxVerify;
|
|
@@ -147,7 +182,7 @@ function needAsyncReply(triggerSrc, wxVerify) {
|
|
|
147
182
|
function formatWeChatReplyMessage(callbackData, triggerSrc, content) {
|
|
148
183
|
const createTime = Math.floor(Date.now() / 1e3);
|
|
149
184
|
const finalContent = content || "\u62B1\u6B49\u6682\u65F6\u65E0\u6CD5\u5904\u7406\u8FD9\u4E2A\u7C7B\u578B\u7684\u6D88\u606F";
|
|
150
|
-
if (triggerSrc === "WXCustomerService") {
|
|
185
|
+
if (triggerSrc === "WXCustomerService" /* CUSTOM_SERVICE */) {
|
|
151
186
|
return {
|
|
152
187
|
toUserName: callbackData.externalUserId || callbackData.fromUserName,
|
|
153
188
|
fromUserName: callbackData.openKfId,
|
|
@@ -392,27 +427,6 @@ function createWxMessageHandler(createAgent, options) {
|
|
|
392
427
|
};
|
|
393
428
|
}
|
|
394
429
|
|
|
395
|
-
// src/types.ts
|
|
396
|
-
var WeChatPlatform = /* @__PURE__ */ ((WeChatPlatform2) => {
|
|
397
|
-
WeChatPlatform2["CUSTOM_SERVICE"] = "WXCustomerService";
|
|
398
|
-
WeChatPlatform2["MINI_APP"] = "WXMiniApp";
|
|
399
|
-
WeChatPlatform2["SERVICE"] = "WXService";
|
|
400
|
-
WeChatPlatform2["SUBSCRIPTION"] = "WXSubscription";
|
|
401
|
-
return WeChatPlatform2;
|
|
402
|
-
})(WeChatPlatform || {});
|
|
403
|
-
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
404
|
-
MessageType2["TEXT"] = "text";
|
|
405
|
-
MessageType2["IMAGE"] = "image";
|
|
406
|
-
MessageType2["EVENT"] = "event";
|
|
407
|
-
MessageType2["VOICE"] = "voice";
|
|
408
|
-
return MessageType2;
|
|
409
|
-
})(MessageType || {});
|
|
410
|
-
var WeChatSendMode = /* @__PURE__ */ ((WeChatSendMode2) => {
|
|
411
|
-
WeChatSendMode2["LOCAL"] = "local";
|
|
412
|
-
WeChatSendMode2["AITOOLS"] = "aitools";
|
|
413
|
-
return WeChatSendMode2;
|
|
414
|
-
})(WeChatSendMode || {});
|
|
415
|
-
|
|
416
430
|
// src/token-manager.ts
|
|
417
431
|
var TokenManager = class {
|
|
418
432
|
constructor() {
|
|
@@ -560,7 +574,7 @@ var PlatformRouter = class {
|
|
|
560
574
|
switch (config.platform) {
|
|
561
575
|
case "WXCustomerService" /* CUSTOM_SERVICE */:
|
|
562
576
|
return this.sendToCustomService(message, accessToken, config);
|
|
563
|
-
case "
|
|
577
|
+
case "WXMiniapp" /* MINI_APP */:
|
|
564
578
|
return this.sendToMiniApp(message, accessToken);
|
|
565
579
|
case "WXService" /* SERVICE */:
|
|
566
580
|
case "WXSubscription" /* SUBSCRIPTION */:
|
|
@@ -744,7 +758,7 @@ var WeChatHistoryManager = class _WeChatHistoryManager {
|
|
|
744
758
|
await db.createCollection(this.collectionName);
|
|
745
759
|
this.collectionReady = true;
|
|
746
760
|
} catch (error) {
|
|
747
|
-
if (error?.code ===
|
|
761
|
+
if (error?.code === "DATABASE_COLLECTION_ALREADY_EXIST") {
|
|
748
762
|
this.collectionReady = true;
|
|
749
763
|
} else {
|
|
750
764
|
console.error(
|
|
@@ -1039,7 +1053,7 @@ var WeChatAgent = class extends import_client2.AbstractAgent {
|
|
|
1039
1053
|
try {
|
|
1040
1054
|
const needAsyncReply2 = input.forwardedProps?.replay.needAsyncReply ?? true;
|
|
1041
1055
|
if (needAsyncReply2) {
|
|
1042
|
-
const sendMode = this.wechatConfig.sendMode || "
|
|
1056
|
+
const sendMode = this.wechatConfig.sendMode || "aitools" /* AITOOLS */;
|
|
1043
1057
|
if (sendMode === "aitools" /* AITOOLS */) {
|
|
1044
1058
|
await this.sendViaAITools(content, input);
|
|
1045
1059
|
} else {
|
|
@@ -1104,7 +1118,7 @@ var WeChatAgent = class extends import_client2.AbstractAgent {
|
|
|
1104
1118
|
return;
|
|
1105
1119
|
}
|
|
1106
1120
|
const triggerSrc = wxSendmessageInput.triggerSrc || this.wechatConfig.platform;
|
|
1107
|
-
await this.aitools.
|
|
1121
|
+
await this.aitools.sendWxClientMessage(triggerSrc, {
|
|
1108
1122
|
msgType: toWxMsgData.msgType,
|
|
1109
1123
|
touser: toWxMsgData.toUserName,
|
|
1110
1124
|
text: {
|