@zhin.js/adapter-wechat-mp 1.1.14 → 1.1.16
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/CHANGELOG.md +51 -0
- package/commands/wechat-mp/endpoint/definition.js +4 -4
- package/commands/wechat-mp/endpoint/definition.ts +4 -4
- package/lib/protocol.d.ts +2 -8
- package/lib/protocol.js +6 -2
- package/lib/webhook.d.ts +2 -0
- package/lib/webhook.js +4 -1
- package/package.json +14 -14
- package/schema.json +35 -5
- package/src/protocol.ts +7 -2
- package/src/webhook.ts +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @zhin.js/adapter-wechat-mp
|
|
2
2
|
|
|
3
|
+
## 1.1.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53bc6a0: 适配器配置标签、端点命令和工具反馈支持中英文;复用当前操作语言,保持协议值、用户内容、身份、权限与发送链路不变。Sandbox 展示使用项目语言,QQ 绑定与交互状态保留完整会话身份。
|
|
8
|
+
- 9cade30: 修复国际化调用链遗漏:Agent 审批、管理命令和错误反馈采用可信语言及实际命令前缀;游戏快捷帮助、工具反馈、平台默认卡片和后台通知贯通语言。协议即时回复复用受运行代约束的个人语言查询,业务验证支持不改变审批身份的双语展示元数据。
|
|
9
|
+
|
|
10
|
+
AI 正文、进度与耗尽摘要统一优先遵从用户明确语言要求,再跟随实际输入;个人/项目语言仅作兜底,固定界面文案继续使用配置语言,不增加翻译调用。
|
|
11
|
+
|
|
12
|
+
GitHub 工作区为 Git clone/pull/fetch/ls-remote 显式分隔选项与位置参数,保留仓库和分支校验;顺序写入 Bot 名称和邮箱,避免竞争同一配置文件锁。
|
|
13
|
+
|
|
14
|
+
- dcd4982: Upgrade runtime dependencies to clear security advisories: `undici` (6.29.1 / 8.12.2+), `axios` 1.20.0, and `@modelcontextprotocol/sdk` 1.32.0+ (bringing patched `hono`, `body-parser`, `proxy-addr`, `follow-redirects` and `ip-address` through the lockfile).
|
|
15
|
+
- Updated dependencies [334e92d]
|
|
16
|
+
- Updated dependencies [f3b7c9f]
|
|
17
|
+
- Updated dependencies [658a5fb]
|
|
18
|
+
- Updated dependencies [144a17b]
|
|
19
|
+
- Updated dependencies [18296cf]
|
|
20
|
+
- Updated dependencies [08e64de]
|
|
21
|
+
- Updated dependencies [9cade30]
|
|
22
|
+
- Updated dependencies [53bc6a0]
|
|
23
|
+
- Updated dependencies [7595136]
|
|
24
|
+
- Updated dependencies [66b6404]
|
|
25
|
+
- Updated dependencies [adb4af2]
|
|
26
|
+
- Updated dependencies [69f9ef6]
|
|
27
|
+
- Updated dependencies [17d1301]
|
|
28
|
+
- @zhin.js/adapter@1.1.23
|
|
29
|
+
- @zhin.js/host-http@1.1.10
|
|
30
|
+
- @zhin.js/core@1.1.51
|
|
31
|
+
- @zhin.js/skill@1.1.10
|
|
32
|
+
- @zhin.js/im-contract@1.1.7
|
|
33
|
+
- @zhin.js/feature-kit@1.1.9
|
|
34
|
+
|
|
35
|
+
## 1.1.15
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [f98025b]
|
|
40
|
+
- Updated dependencies [66ec1a5]
|
|
41
|
+
- Updated dependencies [7d68df6]
|
|
42
|
+
- Updated dependencies [bf0fa9f]
|
|
43
|
+
- Updated dependencies [3326db3]
|
|
44
|
+
- Updated dependencies [e91235e]
|
|
45
|
+
- Updated dependencies [6da2bad]
|
|
46
|
+
- Updated dependencies [3781f1c]
|
|
47
|
+
- @zhin.js/core@1.1.50
|
|
48
|
+
- @zhin.js/adapter@1.1.22
|
|
49
|
+
- @zhin.js/im-contract@1.1.6
|
|
50
|
+
- @zhin.js/host-http@1.1.9
|
|
51
|
+
- @zhin.js/feature-kit@1.1.8
|
|
52
|
+
- @zhin.js/skill@1.1.9
|
|
53
|
+
|
|
3
54
|
## 1.1.14
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
|
@@ -10,10 +10,10 @@ export const wechatMpEndpointCommands = createEndpointCommands({
|
|
|
10
10
|
adapterKey: 'wechat-mp',
|
|
11
11
|
adapterDisplayName: 'WeChat MP',
|
|
12
12
|
fields: [
|
|
13
|
-
{ key: 'appId', required: true, env: true, description: '公众号 AppID' },
|
|
14
|
-
{ key: 'appSecret', required: true, env: true, description: '公众号 AppSecret' },
|
|
15
|
-
{ key: 'token', required: true, env: true, description: '服务器配置 token' },
|
|
16
|
-
{ key: 'encodingAESKey', env: true, description: '消息加解密 key' },
|
|
13
|
+
{ key: 'appId', required: true, env: true, description: '公众号 AppID', descriptionI18n: { en: "WeChat Official Account app ID" } },
|
|
14
|
+
{ key: 'appSecret', required: true, env: true, description: '公众号 AppSecret', descriptionI18n: { en: "WeChat Official Account app secret" } },
|
|
15
|
+
{ key: 'token', required: true, env: true, description: '服务器配置 token', descriptionI18n: { en: "Server configuration token" } },
|
|
16
|
+
{ key: 'encodingAESKey', env: true, description: '消息加解密 key', descriptionI18n: { en: "Message encryption key" } },
|
|
17
17
|
],
|
|
18
18
|
running: (use) => use(wechatMpRuntimeStateToken).endpoints.values(),
|
|
19
19
|
describeEntry: (entry) => `appId: ${String(entry.appId)}`,
|
|
@@ -10,10 +10,10 @@ export const wechatMpEndpointCommands = createEndpointCommands({
|
|
|
10
10
|
adapterKey: 'wechat-mp',
|
|
11
11
|
adapterDisplayName: 'WeChat MP',
|
|
12
12
|
fields: [
|
|
13
|
-
{ key: 'appId', required: true, env: true, description: '公众号 AppID' },
|
|
14
|
-
{ key: 'appSecret', required: true, env: true, description: '公众号 AppSecret' },
|
|
15
|
-
{ key: 'token', required: true, env: true, description: '服务器配置 token' },
|
|
16
|
-
{ key: 'encodingAESKey', env: true, description: '消息加解密 key' },
|
|
13
|
+
{ key: 'appId', required: true, env: true, description: '公众号 AppID', descriptionI18n: { en: "WeChat Official Account app ID" } },
|
|
14
|
+
{ key: 'appSecret', required: true, env: true, description: '公众号 AppSecret', descriptionI18n: { en: "WeChat Official Account app secret" } },
|
|
15
|
+
{ key: 'token', required: true, env: true, description: '服务器配置 token', descriptionI18n: { en: "Server configuration token" } },
|
|
16
|
+
{ key: 'encodingAESKey', env: true, description: '消息加解密 key', descriptionI18n: { en: "Message encryption key" } },
|
|
17
17
|
],
|
|
18
18
|
running: (use) => use(wechatMpRuntimeStateToken).endpoints.values(),
|
|
19
19
|
describeEntry: (entry) => `appId: ${String(entry.appId)}`,
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* WeChat Official Account (MP) protocol helpers — no legacy Adapter/Endpoint.
|
|
3
|
-
* Canonicalization is owned by gateway/core before endpoint.send.
|
|
4
|
-
*/
|
|
1
|
+
import { type Locale } from 'zhin.js/i18n';
|
|
5
2
|
import type { IncomingMessage } from 'node:http';
|
|
6
3
|
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
7
4
|
/** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
|
|
@@ -111,10 +108,7 @@ export declare function wechatMpInboundConversation(endpointKey: string, msg: We
|
|
|
111
108
|
export declare function formatInboundId(msg: WeChatMessage): string;
|
|
112
109
|
/** Build inbound text for OutboundMessageService.receive. */
|
|
113
110
|
export declare function formatInboundContent(msg: WeChatMessage): string;
|
|
114
|
-
|
|
115
|
-
* Built-in passive XML for subscribe etc. Empty string = fall through to gateway.
|
|
116
|
-
*/
|
|
117
|
-
export declare function resolveEventPassiveReply(msg: WeChatMessage): string;
|
|
111
|
+
export declare function resolveEventPassiveReply(msg: WeChatMessage, locale?: Locale): string;
|
|
118
112
|
/**
|
|
119
113
|
* Wire-encode an already-rendered outbound payload into客服消息 JSON body.
|
|
120
114
|
*/
|
package/lib/protocol.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createMessages } from 'zhin.js/i18n';
|
|
1
2
|
/**
|
|
2
3
|
* WeChat Official Account (MP) protocol helpers — no legacy Adapter/Endpoint.
|
|
3
4
|
* Canonicalization is owned by gateway/core before endpoint.send.
|
|
@@ -220,11 +221,14 @@ export function formatInboundContent(msg) {
|
|
|
220
221
|
/**
|
|
221
222
|
* Built-in passive XML for subscribe etc. Empty string = fall through to gateway.
|
|
222
223
|
*/
|
|
223
|
-
|
|
224
|
+
const passiveMessages = createMessages({
|
|
225
|
+
subscribed: { 'zh-CN': '感谢关注!', en: 'Thank you for following!' },
|
|
226
|
+
});
|
|
227
|
+
export function resolveEventPassiveReply(msg, locale) {
|
|
224
228
|
if (msg.MsgType !== 'event')
|
|
225
229
|
return '';
|
|
226
230
|
if (msg.Event === 'subscribe') {
|
|
227
|
-
return buildTextReply(msg, '
|
|
231
|
+
return buildTextReply(msg, passiveMessages(locale, 'subscribed'));
|
|
228
232
|
}
|
|
229
233
|
return '';
|
|
230
234
|
}
|
package/lib/webhook.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WeChat MP webhook HTTP: URL verification + inbound message handling.
|
|
3
3
|
*/
|
|
4
4
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
|
+
import type { Locale } from 'zhin.js/i18n';
|
|
5
6
|
import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
|
|
6
7
|
import type { CapabilityId } from 'zhin.js';
|
|
7
8
|
import { type ResolvedWeChatMpConfig, type WeChatMessage } from './protocol.js';
|
|
@@ -10,6 +11,7 @@ export interface WeChatMpWebhookHandler {
|
|
|
10
11
|
readonly isOpen: boolean;
|
|
11
12
|
readonly id: CapabilityId;
|
|
12
13
|
admit(msg: WeChatMessage): void | Promise<unknown>;
|
|
14
|
+
resolveLocale?(senderId: string): Promise<Locale | undefined>;
|
|
13
15
|
/** MsgId 去重缓存(可选;实现见 WeChatMpEndpoint)。 */
|
|
14
16
|
getCachedReply?(msgId: string): string | undefined;
|
|
15
17
|
cacheReply?(msgId: string, replyXML: string): void;
|
package/lib/webhook.js
CHANGED
|
@@ -101,7 +101,10 @@ export async function handleWeChatMpMessage(request, response, url, handler) {
|
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
const locale = wechatMessage.MsgType === 'event' && wechatMessage.Event === 'subscribe'
|
|
105
|
+
? await handler.resolveLocale?.(wechatMessage.FromUserName)
|
|
106
|
+
: undefined;
|
|
107
|
+
let replyXML = resolveEventPassiveReply(wechatMessage, locale);
|
|
105
108
|
if (!replyXML && handler.isOpen) {
|
|
106
109
|
if (config.replyMode === 'passive') {
|
|
107
110
|
replyXML = await collectPassiveReply(handler, wechatMessage);
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-wechat-mp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zhin.js WeChat Official Account adapter for Plugin Runtime (HTTP webhook)",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"axios": "^1.
|
|
9
|
+
"axios": "^1.20.0",
|
|
10
10
|
"xml2js": "^0.6.2",
|
|
11
|
-
"@zhin.js/adapter": "1.1.
|
|
12
|
-
"@zhin.js/core": "1.1.
|
|
13
|
-
"@zhin.js/feature-kit": "1.1.
|
|
14
|
-
"@zhin.js/host-http": "1.1.
|
|
15
|
-
"@zhin.js/im-contract": "1.1.
|
|
11
|
+
"@zhin.js/adapter": "1.1.23",
|
|
12
|
+
"@zhin.js/core": "1.1.51",
|
|
13
|
+
"@zhin.js/feature-kit": "1.1.9",
|
|
14
|
+
"@zhin.js/host-http": "1.1.10",
|
|
15
|
+
"@zhin.js/im-contract": "1.1.7",
|
|
16
16
|
"@zhin.js/logger": "1.1.2",
|
|
17
|
-
"@zhin.js/skill": "1.1.
|
|
17
|
+
"@zhin.js/skill": "1.1.10"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@zhin.js/adapter": "^1.1.
|
|
21
|
-
"@zhin.js/command": "^1.1.
|
|
22
|
-
"@zhin.js/core": "^1.1.
|
|
23
|
-
"@zhin.js/host-http": "^1.1.
|
|
24
|
-
"zhin.js": "^1.1.
|
|
20
|
+
"@zhin.js/adapter": "^1.1.23",
|
|
21
|
+
"@zhin.js/command": "^1.1.11",
|
|
22
|
+
"@zhin.js/core": "^1.1.51",
|
|
23
|
+
"@zhin.js/host-http": "^1.1.10",
|
|
24
|
+
"zhin.js": "^1.1.16"
|
|
25
25
|
},
|
|
26
26
|
"peerDependenciesMeta": {
|
|
27
27
|
"@zhin.js/command": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/xml2js": "^0.4.14",
|
|
37
37
|
"typescript": "^6.0.3",
|
|
38
38
|
"vitest": "^4.1.10",
|
|
39
|
-
"zhin.js": "1.1.
|
|
39
|
+
"zhin.js": "1.1.16"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
42
|
"zhin",
|
package/schema.json
CHANGED
|
@@ -37,7 +37,12 @@
|
|
|
37
37
|
"string",
|
|
38
38
|
"number"
|
|
39
39
|
],
|
|
40
|
-
"description": "框架 master(WeChat OpenID;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
40
|
+
"description": "框架 master(WeChat OpenID;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖",
|
|
41
|
+
"x-i18n": {
|
|
42
|
+
"en": {
|
|
43
|
+
"description": "Framework masters (WeChat OpenID; AI/tool permissions and endpoint management). endpoints[i].master can override this value."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
},
|
|
42
47
|
"trusted": {
|
|
43
48
|
"type": "array",
|
|
@@ -48,7 +53,12 @@
|
|
|
48
53
|
],
|
|
49
54
|
"description": "Trusted WeChat OpenID"
|
|
50
55
|
},
|
|
51
|
-
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
56
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加",
|
|
57
|
+
"x-i18n": {
|
|
58
|
+
"en": {
|
|
59
|
+
"description": "Framework trusted users, below master authority. endpoints[i].trusted can add users."
|
|
60
|
+
}
|
|
61
|
+
}
|
|
52
62
|
},
|
|
53
63
|
"endpoints": {
|
|
54
64
|
"type": "array",
|
|
@@ -63,7 +73,12 @@
|
|
|
63
73
|
"string",
|
|
64
74
|
"number"
|
|
65
75
|
],
|
|
66
|
-
"description": "本 endpoint 的框架 master(WeChat OpenID);覆盖顶层 master"
|
|
76
|
+
"description": "本 endpoint 的框架 master(WeChat OpenID);覆盖顶层 master",
|
|
77
|
+
"x-i18n": {
|
|
78
|
+
"en": {
|
|
79
|
+
"description": "Framework masters for this endpoint (WeChat OpenID), overriding the top-level master list."
|
|
80
|
+
}
|
|
81
|
+
}
|
|
67
82
|
},
|
|
68
83
|
"trusted": {
|
|
69
84
|
"type": "array",
|
|
@@ -74,7 +89,12 @@
|
|
|
74
89
|
],
|
|
75
90
|
"description": "Trusted WeChat OpenID"
|
|
76
91
|
},
|
|
77
|
-
"description": "本 endpoint 的 trusted 列表"
|
|
92
|
+
"description": "本 endpoint 的 trusted 列表",
|
|
93
|
+
"x-i18n": {
|
|
94
|
+
"en": {
|
|
95
|
+
"description": "Trusted users for this endpoint."
|
|
96
|
+
}
|
|
97
|
+
}
|
|
78
98
|
},
|
|
79
99
|
"appId": {
|
|
80
100
|
"type": "string",
|
|
@@ -130,12 +150,22 @@
|
|
|
130
150
|
"appSecret",
|
|
131
151
|
"token"
|
|
132
152
|
]
|
|
153
|
+
},
|
|
154
|
+
"x-i18n": {
|
|
155
|
+
"en": {
|
|
156
|
+
"description": "Multiple accounts: mount multiple endpoints in one plugin instance. Each entry uses the top-level fields; id is required and other fields override defaults."
|
|
157
|
+
}
|
|
133
158
|
}
|
|
134
159
|
},
|
|
135
160
|
"commandPrefix": {
|
|
136
161
|
"type": "string",
|
|
137
162
|
"default": "",
|
|
138
|
-
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
163
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖",
|
|
164
|
+
"x-i18n": {
|
|
165
|
+
"en": {
|
|
166
|
+
"description": "Command prefix. The default empty string allows unprefixed commands; '/' requires a leading slash. Each endpoints[i] can override it."
|
|
167
|
+
}
|
|
168
|
+
}
|
|
139
169
|
}
|
|
140
170
|
},
|
|
141
171
|
"required": [
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createMessages, type Locale } from 'zhin.js/i18n';
|
|
1
2
|
/**
|
|
2
3
|
* WeChat Official Account (MP) protocol helpers — no legacy Adapter/Endpoint.
|
|
3
4
|
* Canonicalization is owned by gateway/core before endpoint.send.
|
|
@@ -366,10 +367,14 @@ export function formatInboundContent(msg: WeChatMessage): string {
|
|
|
366
367
|
/**
|
|
367
368
|
* Built-in passive XML for subscribe etc. Empty string = fall through to gateway.
|
|
368
369
|
*/
|
|
369
|
-
|
|
370
|
+
const passiveMessages = createMessages({
|
|
371
|
+
subscribed: { 'zh-CN': '感谢关注!', en: 'Thank you for following!' },
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
export function resolveEventPassiveReply(msg: WeChatMessage, locale?: Locale): string {
|
|
370
375
|
if (msg.MsgType !== 'event') return '';
|
|
371
376
|
if (msg.Event === 'subscribe') {
|
|
372
|
-
return buildTextReply(msg, '
|
|
377
|
+
return buildTextReply(msg, passiveMessages(locale, 'subscribed'));
|
|
373
378
|
}
|
|
374
379
|
return '';
|
|
375
380
|
}
|
package/src/webhook.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WeChat MP webhook HTTP: URL verification + inbound message handling.
|
|
3
3
|
*/
|
|
4
4
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
|
+
import type { Locale } from 'zhin.js/i18n';
|
|
5
6
|
import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
|
|
6
7
|
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
7
8
|
import type { CapabilityId } from 'zhin.js';
|
|
@@ -36,6 +37,7 @@ export interface WeChatMpWebhookHandler {
|
|
|
36
37
|
readonly isOpen: boolean;
|
|
37
38
|
readonly id: CapabilityId;
|
|
38
39
|
admit(msg: WeChatMessage): void | Promise<unknown>;
|
|
40
|
+
resolveLocale?(senderId: string): Promise<Locale | undefined>;
|
|
39
41
|
/** MsgId 去重缓存(可选;实现见 WeChatMpEndpoint)。 */
|
|
40
42
|
getCachedReply?(msgId: string): string | undefined;
|
|
41
43
|
cacheReply?(msgId: string, replyXML: string): void;
|
|
@@ -172,7 +174,10 @@ export async function handleWeChatMpMessage(
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
const locale = wechatMessage.MsgType === 'event' && wechatMessage.Event === 'subscribe'
|
|
178
|
+
? await handler.resolveLocale?.(wechatMessage.FromUserName)
|
|
179
|
+
: undefined;
|
|
180
|
+
let replyXML = resolveEventPassiveReply(wechatMessage, locale);
|
|
176
181
|
|
|
177
182
|
if (!replyXML && handler.isOpen) {
|
|
178
183
|
if (config.replyMode === 'passive') {
|