@zhin.js/adapter-wecom 1.1.20 → 1.1.21
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 +29 -0
- package/agents/wecom/skills/wecom/SKILL.md +2 -20
- package/lib/client.d.ts +1 -1
- package/lib/client.js +2 -2
- package/lib/endpoint.js +2 -0
- package/lib/protocol.d.ts +2 -1
- package/lib/self-profile.d.ts +4 -0
- package/lib/self-profile.js +13 -0
- package/package.json +20 -20
- package/schema.json +106 -1
- package/src/client.ts +2 -2
- package/src/endpoint.ts +2 -0
- package/src/protocol.ts +2 -1
- package/src/self-profile.ts +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @zhin.js/adapter-wecom
|
|
2
2
|
|
|
3
|
+
## 1.1.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- af8f803: Use the current Endpoint's platform profile for Agent account identity, with per-field configured fallbacks and scoped, identity-approved profile tools. Keep SOUL first-person and independent of account names. Profile ports preserve the source Client, cancellation, truthful update outcomes and private image authority.
|
|
8
|
+
|
|
9
|
+
Adapter Feature API 2.1 and Tool Feature API 1.1 describe the additive profile requirements; new Core, official adapters and generated plugins declare the corresponding floors. Existing compatible API-2.0/API-1.0 plugins remain accepted by the newer providers. npm releases remain patch.
|
|
10
|
+
|
|
11
|
+
Private IM assets now bind to the full canonical conversation and principal. Existing IM asset records that contain only the earlier lossy hash remain on disk until their original expiry, but cannot be safely rebound; recapture them. No automatic file deletion, platform profile mutation or workspace SOUL rewrite occurs during upgrade.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [b88e988]
|
|
14
|
+
- Updated dependencies [f78eb84]
|
|
15
|
+
- Updated dependencies [c15cef9]
|
|
16
|
+
- Updated dependencies [b0c02a2]
|
|
17
|
+
- Updated dependencies [af8f803]
|
|
18
|
+
- Updated dependencies [26fda97]
|
|
19
|
+
- Updated dependencies [976886c]
|
|
20
|
+
- Updated dependencies [032dc96]
|
|
21
|
+
- @zhin.js/adapter@1.1.27
|
|
22
|
+
- @zhin.js/client@1.1.23
|
|
23
|
+
- @zhin.js/im-contract@1.1.10
|
|
24
|
+
- @zhin.js/core@1.1.55
|
|
25
|
+
- @zhin.js/tool@1.1.14
|
|
26
|
+
- @zhin.js/page@1.1.13
|
|
27
|
+
- @zhin.js/host-http@1.1.13
|
|
28
|
+
- @zhin.js/agent-feature@1.1.12
|
|
29
|
+
- @zhin.js/feature-kit@1.1.11
|
|
30
|
+
- @zhin.js/skill@1.1.12
|
|
31
|
+
|
|
3
32
|
## 1.1.20
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -26,8 +26,6 @@ tools:
|
|
|
26
26
|
|
|
27
27
|
# 企业微信技能
|
|
28
28
|
|
|
29
|
-
企业微信(WeCom)是腾讯面向企业的 IM 平台,具备组织架构(部门树)、应用消息推送等能力。
|
|
30
|
-
|
|
31
29
|
## 核心原则
|
|
32
30
|
|
|
33
31
|
### 组织架构是核心
|
|
@@ -44,25 +42,9 @@ wecom_get_user(user_id) → 获取用户详情
|
|
|
44
42
|
`wecom_send_text` 通过应用消息接口发送文本消息,需要知道接收者的 `userid`。
|
|
45
43
|
群消息通过 webhook 回调自动处理,不需要主动调用发送工具。
|
|
46
44
|
|
|
47
|
-
## 工具分类
|
|
48
|
-
|
|
49
|
-
### 组织架构
|
|
50
|
-
|
|
51
|
-
| 工具 | 用途 | 说明 |
|
|
52
|
-
|------|------|------|
|
|
53
|
-
| `wecom_list_departments` | 部门列表 | 默认从根部门 ID=1 开始 |
|
|
54
|
-
| `wecom_get_dept_users` | 部门用户列表 | 返回简单用户信息 |
|
|
55
|
-
| `wecom_get_user` | 用户详情 | 需要通讯录权限 |
|
|
56
|
-
|
|
57
|
-
### 消息
|
|
58
|
-
|
|
59
|
-
| 工具 | 用途 | 说明 |
|
|
60
|
-
|------|------|------|
|
|
61
|
-
| `wecom_send_text` | 发送文本消息 | 发给指定用户,通过应用消息接口 |
|
|
62
|
-
|
|
63
45
|
## 易错点
|
|
64
46
|
|
|
65
47
|
1. **部门查询从根部门 ID=1 开始**。不知道部门 ID 时先 `list_departments` 获取整棵部门树。
|
|
66
48
|
2. **消息发送需要 userid**,不是用户名或昵称。仅有昵称时先通过 `get_dept_users` 查找。
|
|
67
|
-
3.
|
|
68
|
-
4.
|
|
49
|
+
3. **用户详情查询需要通讯录权限**。
|
|
50
|
+
4. **企业微信不支持机器人撤回消息**,一旦发出无法撤回。
|
package/lib/client.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class WecomClient extends EventEmitter {
|
|
|
59
59
|
recallMessage(messageId: string, { signal }?: EndpointOperationOptions): Promise<void>;
|
|
60
60
|
/** Test / internal: admit a parsed message when open (non-webhook path). */
|
|
61
61
|
admit(msg: WecomMessage): void;
|
|
62
|
-
getApplicationInfo(): Promise<WecomApiResponse>;
|
|
62
|
+
getApplicationInfo(request?: EndpointOperationOptions): Promise<WecomApiResponse>;
|
|
63
63
|
getUserInfo(userId: string): Promise<WecomApiResponse | null>;
|
|
64
64
|
getDepartmentUsers(deptId: number): Promise<unknown[]>;
|
|
65
65
|
getDepartmentList(deptId?: number): Promise<unknown[]>;
|
package/lib/client.js
CHANGED
|
@@ -223,8 +223,8 @@ export class WecomClient extends EventEmitter {
|
|
|
223
223
|
}));
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
async getApplicationInfo() {
|
|
227
|
-
const response = await this.#request('/cgi-bin/agent/get', { params: { agentid: this.config.agentId } });
|
|
226
|
+
async getApplicationInfo(request = {}) {
|
|
227
|
+
const response = await this.#request('/cgi-bin/agent/get', { params: { agentid: this.config.agentId }, signal: request.signal });
|
|
228
228
|
if (response.errcode !== 0)
|
|
229
229
|
throw new Error('WeCom application identity verification failed');
|
|
230
230
|
return response;
|
package/lib/endpoint.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createEndpointSpecification, endpointSpec } from 'zhin.js/adapter';
|
|
2
2
|
import { WecomClient } from './client.js';
|
|
3
|
+
import { createWecomSelfProfile } from './self-profile.js';
|
|
3
4
|
/** Actual protocol Client; framework lifecycle and admission stay in their symbol namespace. */
|
|
4
5
|
export class WecomEndpoint extends WecomClient {
|
|
5
6
|
[endpointSpec] = this.#createSpecification();
|
|
@@ -11,6 +12,7 @@ export class WecomEndpoint extends WecomClient {
|
|
|
11
12
|
send: (request) => this.sendPayload(request),
|
|
12
13
|
name: this.configName(),
|
|
13
14
|
control: this.endpointControl,
|
|
15
|
+
profile: createWecomSelfProfile(this),
|
|
14
16
|
};
|
|
15
17
|
Object.defineProperty(hooks, 'transportState', { get: () => this.transportState });
|
|
16
18
|
return createEndpointSpecification(this, hooks);
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { EndpointProfileConfiguration } from 'zhin.js/adapter';
|
|
1
2
|
import { type Locale } from 'zhin.js/i18n';
|
|
2
3
|
import type { IncomingMessage } from 'node:http';
|
|
3
4
|
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
4
5
|
/** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
|
|
5
|
-
export interface WecomEndpointConfig {
|
|
6
|
+
export interface WecomEndpointConfig extends EndpointProfileConfiguration {
|
|
6
7
|
readonly id: string;
|
|
7
8
|
readonly corpId: string;
|
|
8
9
|
readonly agentId: string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type EndpointProfile } from 'zhin.js/adapter';
|
|
2
|
+
import type { WecomClient } from './client.js';
|
|
3
|
+
/** Enterprise application profile; no member/user profile is impersonated. */
|
|
4
|
+
export declare function createWecomSelfProfile(client: Pick<WecomClient, 'getApplicationInfo'>): EndpointProfile;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createEndpointOperation } from 'zhin.js/adapter';
|
|
2
|
+
/** Enterprise application profile; no member/user profile is impersonated. */
|
|
3
|
+
export function createWecomSelfProfile(client) {
|
|
4
|
+
return Object.freeze({
|
|
5
|
+
writableFields: Object.freeze([]),
|
|
6
|
+
async read({ signal }) {
|
|
7
|
+
const self = await createEndpointOperation({ signal }).prepare(() => client.getApplicationInfo({ signal }));
|
|
8
|
+
return { ...(typeof self.name === 'string' ? { nickname: self.name } : {}),
|
|
9
|
+
...(typeof self.description === 'string' ? { bio: self.description } : {}),
|
|
10
|
+
...(typeof self.square_logo_url === 'string' ? { avatar: self.square_logo_url } : {}) };
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-wecom",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.21",
|
|
4
4
|
"description": "Zhin.js WeCom (企业微信) adapter for Plugin Runtime (HTTP webhook)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,27 +33,27 @@
|
|
|
33
33
|
"directory": "plugins/adapters/wecom"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@zhin.js/adapter": "1.1.
|
|
37
|
-
"@zhin.js/agent-feature": "1.1.
|
|
36
|
+
"@zhin.js/adapter": "1.1.27",
|
|
37
|
+
"@zhin.js/agent-feature": "1.1.12",
|
|
38
|
+
"@zhin.js/client": "1.1.23",
|
|
38
39
|
"@zhin.js/console-contract": "1.1.3",
|
|
39
|
-
"@zhin.js/
|
|
40
|
-
"@zhin.js/
|
|
41
|
-
"@zhin.js/
|
|
40
|
+
"@zhin.js/core": "1.1.55",
|
|
41
|
+
"@zhin.js/feature-kit": "1.1.11",
|
|
42
|
+
"@zhin.js/host-http": "1.1.13",
|
|
43
|
+
"@zhin.js/im-contract": "1.1.10",
|
|
42
44
|
"@zhin.js/logger": "1.1.2",
|
|
43
|
-
"@zhin.js/page": "1.1.
|
|
44
|
-
"@zhin.js/skill": "1.1.
|
|
45
|
-
"@zhin.js/tool": "1.1.
|
|
46
|
-
"@zhin.js/host-http": "1.1.12",
|
|
47
|
-
"@zhin.js/feature-kit": "1.1.10"
|
|
45
|
+
"@zhin.js/page": "1.1.13",
|
|
46
|
+
"@zhin.js/skill": "1.1.12",
|
|
47
|
+
"@zhin.js/tool": "1.1.14"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"zod": "^4.0.0",
|
|
51
|
-
"@zhin.js/adapter": "^1.1.
|
|
52
|
-
"@zhin.js/command": "^1.1.
|
|
53
|
-
"@zhin.js/core": "^1.1.
|
|
54
|
-
"@zhin.js/
|
|
55
|
-
"zhin.js": "^1.1.
|
|
56
|
-
"
|
|
51
|
+
"@zhin.js/adapter": "^1.1.27",
|
|
52
|
+
"@zhin.js/command": "^1.1.13",
|
|
53
|
+
"@zhin.js/core": "^1.1.55",
|
|
54
|
+
"@zhin.js/host-http": "^1.1.13",
|
|
55
|
+
"@zhin.js/permission": "^1.1.11",
|
|
56
|
+
"zhin.js": "^1.1.20"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@zhin.js/command": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"typescript": "^6.0.3",
|
|
72
72
|
"vitest": "^4.1.10",
|
|
73
73
|
"zod": "^4.4.3",
|
|
74
|
-
"zhin.js": "1.1.
|
|
74
|
+
"zhin.js": "1.1.20"
|
|
75
75
|
},
|
|
76
76
|
"files": [
|
|
77
77
|
"adapters",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"features": [
|
|
104
104
|
{
|
|
105
105
|
"package": "@zhin.js/adapter",
|
|
106
|
-
"api": "^2.
|
|
106
|
+
"api": "^2.1.0"
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
109
|
"package": "@zhin.js/command",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
"package": "@zhin.js/tool",
|
|
114
|
-
"api": "^1.
|
|
114
|
+
"api": "^1.1.0"
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
117
|
"package": "@zhin.js/skill",
|
package/schema.json
CHANGED
|
@@ -113,6 +113,27 @@
|
|
|
113
113
|
"description": "WeCom application AgentId (not the application secret)"
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
},
|
|
117
|
+
"nickname": {
|
|
118
|
+
"type": [
|
|
119
|
+
"string",
|
|
120
|
+
"null"
|
|
121
|
+
],
|
|
122
|
+
"description": "账号昵称兜底",
|
|
123
|
+
"x-i18n": {
|
|
124
|
+
"en": {
|
|
125
|
+
"description": "Fallback account nickname"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"profile": {
|
|
130
|
+
"$ref": "#/$defs/selfProfileFallback",
|
|
131
|
+
"description": "账号资料兜底",
|
|
132
|
+
"x-i18n": {
|
|
133
|
+
"en": {
|
|
134
|
+
"description": "Fallback account profile"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
116
137
|
}
|
|
117
138
|
},
|
|
118
139
|
"required": [
|
|
@@ -139,9 +160,93 @@
|
|
|
139
160
|
"description": "Command prefix. The default empty string allows unprefixed commands; '/' requires a leading slash. Each endpoints[i] can override it."
|
|
140
161
|
}
|
|
141
162
|
}
|
|
163
|
+
},
|
|
164
|
+
"nickname": {
|
|
165
|
+
"type": [
|
|
166
|
+
"string",
|
|
167
|
+
"null"
|
|
168
|
+
],
|
|
169
|
+
"description": "账号昵称兜底",
|
|
170
|
+
"x-i18n": {
|
|
171
|
+
"en": {
|
|
172
|
+
"description": "Fallback account nickname"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
"profile": {
|
|
177
|
+
"$ref": "#/$defs/selfProfileFallback",
|
|
178
|
+
"description": "账号资料兜底",
|
|
179
|
+
"x-i18n": {
|
|
180
|
+
"en": {
|
|
181
|
+
"description": "Fallback account profile"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
142
184
|
}
|
|
143
185
|
},
|
|
144
186
|
"required": [
|
|
145
187
|
"endpoints"
|
|
146
|
-
]
|
|
188
|
+
],
|
|
189
|
+
"$defs": {
|
|
190
|
+
"selfProfileFallback": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"additionalProperties": false,
|
|
193
|
+
"properties": {
|
|
194
|
+
"gender": {
|
|
195
|
+
"type": [
|
|
196
|
+
"string",
|
|
197
|
+
"null"
|
|
198
|
+
],
|
|
199
|
+
"enum": [
|
|
200
|
+
"male",
|
|
201
|
+
"female",
|
|
202
|
+
"other",
|
|
203
|
+
"unknown",
|
|
204
|
+
null
|
|
205
|
+
]
|
|
206
|
+
},
|
|
207
|
+
"age": {
|
|
208
|
+
"type": [
|
|
209
|
+
"integer",
|
|
210
|
+
"null"
|
|
211
|
+
],
|
|
212
|
+
"minimum": 0
|
|
213
|
+
},
|
|
214
|
+
"birthday": {
|
|
215
|
+
"type": [
|
|
216
|
+
"string",
|
|
217
|
+
"null"
|
|
218
|
+
],
|
|
219
|
+
"pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$"
|
|
220
|
+
},
|
|
221
|
+
"signature": {
|
|
222
|
+
"type": [
|
|
223
|
+
"string",
|
|
224
|
+
"null"
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
"avatar": {
|
|
228
|
+
"type": [
|
|
229
|
+
"string",
|
|
230
|
+
"null"
|
|
231
|
+
],
|
|
232
|
+
"pattern": "^(https?://[^\\s/?#]+(?:[/?#].*)?|)$"
|
|
233
|
+
},
|
|
234
|
+
"interests": {
|
|
235
|
+
"type": [
|
|
236
|
+
"array",
|
|
237
|
+
"null"
|
|
238
|
+
],
|
|
239
|
+
"items": {
|
|
240
|
+
"type": "string"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"bio": {
|
|
244
|
+
"type": [
|
|
245
|
+
"string",
|
|
246
|
+
"null"
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
147
252
|
}
|
package/src/client.ts
CHANGED
|
@@ -282,8 +282,8 @@ export class WecomClient extends EventEmitter {
|
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
async getApplicationInfo(): Promise<WecomApiResponse> {
|
|
286
|
-
const response = await this.#request('/cgi-bin/agent/get', { params: { agentid: this.config.agentId } });
|
|
285
|
+
async getApplicationInfo(request: EndpointOperationOptions = {}): Promise<WecomApiResponse> {
|
|
286
|
+
const response = await this.#request('/cgi-bin/agent/get', { params: { agentid: this.config.agentId }, signal: request.signal });
|
|
287
287
|
if (response.errcode !== 0) throw new Error('WeCom application identity verification failed');
|
|
288
288
|
return response;
|
|
289
289
|
}
|
package/src/endpoint.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createEndpointSpecification, endpointSpec, type Endpoint } from 'zhin.js/adapter';
|
|
2
2
|
import { WecomClient, type WecomEndpointOptions } from './client.js';
|
|
3
|
+
import { createWecomSelfProfile } from './self-profile.js';
|
|
3
4
|
export type { WecomEndpointOptions } from './client.js';
|
|
4
5
|
export type { WecomFetch } from './client.js';
|
|
5
6
|
|
|
@@ -14,6 +15,7 @@ export class WecomEndpoint extends WecomClient implements Endpoint {
|
|
|
14
15
|
send: (request: import('zhin.js/adapter').EndpointSendRequest) => this.sendPayload(request),
|
|
15
16
|
name: this.configName(),
|
|
16
17
|
control: this.endpointControl,
|
|
18
|
+
profile: createWecomSelfProfile(this),
|
|
17
19
|
};
|
|
18
20
|
Object.defineProperty(hooks, 'transportState', { get: () => this.transportState });
|
|
19
21
|
return createEndpointSpecification(this, hooks);
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EndpointProfileConfiguration } from 'zhin.js/adapter';
|
|
1
2
|
import { createMessages, type Locale } from 'zhin.js/i18n';
|
|
2
3
|
/**
|
|
3
4
|
* WeCom (企业微信) protocol helpers — no legacy Adapter/Endpoint / segment-mapper.
|
|
@@ -9,7 +10,7 @@ import type { IncomingMessage } from 'node:http';
|
|
|
9
10
|
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
10
11
|
|
|
11
12
|
/** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
|
|
12
|
-
export interface WecomEndpointConfig {
|
|
13
|
+
export interface WecomEndpointConfig extends EndpointProfileConfiguration {
|
|
13
14
|
readonly id: string;
|
|
14
15
|
readonly corpId: string;
|
|
15
16
|
readonly agentId: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createEndpointOperation, type EndpointProfile } from 'zhin.js/adapter';
|
|
2
|
+
import type { WecomClient } from './client.js';
|
|
3
|
+
|
|
4
|
+
/** Enterprise application profile; no member/user profile is impersonated. */
|
|
5
|
+
export function createWecomSelfProfile(client: Pick<WecomClient, 'getApplicationInfo'>): EndpointProfile {
|
|
6
|
+
return Object.freeze<EndpointProfile>({
|
|
7
|
+
writableFields: Object.freeze([]),
|
|
8
|
+
async read({ signal }) {
|
|
9
|
+
const self = await createEndpointOperation({ signal }).prepare(() => client.getApplicationInfo({ signal }));
|
|
10
|
+
return { ...(typeof self.name === 'string' ? { nickname: self.name } : {}),
|
|
11
|
+
...(typeof self.description === 'string' ? { bio: self.description } : {}),
|
|
12
|
+
...(typeof self.square_logo_url === 'string' ? { avatar: self.square_logo_url } : {}) };
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|