@mocrane/wecom 2026.2.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/LICENSE +21 -0
- package/README.md +0 -0
- package/clawdbot.plugin.json +10 -0
- package/index.ts +28 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +81 -0
- package/src/accounts.ts +72 -0
- package/src/agent/api-client.ts +336 -0
- package/src/agent/handler.ts +566 -0
- package/src/agent/index.ts +12 -0
- package/src/channel.ts +259 -0
- package/src/config/accounts.ts +99 -0
- package/src/config/index.ts +12 -0
- package/src/config/media.ts +14 -0
- package/src/config/network.ts +16 -0
- package/src/config/schema.ts +104 -0
- package/src/config-schema.ts +41 -0
- package/src/crypto/aes.ts +108 -0
- package/src/crypto/index.ts +24 -0
- package/src/crypto/signature.ts +43 -0
- package/src/crypto/xml.ts +49 -0
- package/src/crypto.test.ts +32 -0
- package/src/crypto.ts +176 -0
- package/src/http.ts +102 -0
- package/src/media.test.ts +55 -0
- package/src/media.ts +55 -0
- package/src/monitor/state.queue.test.ts +185 -0
- package/src/monitor/state.ts +514 -0
- package/src/monitor/types.ts +136 -0
- package/src/monitor.active.test.ts +239 -0
- package/src/monitor.integration.test.ts +207 -0
- package/src/monitor.ts +1802 -0
- package/src/monitor.webhook.test.ts +311 -0
- package/src/onboarding.ts +472 -0
- package/src/outbound.test.ts +143 -0
- package/src/outbound.ts +200 -0
- package/src/runtime.ts +14 -0
- package/src/shared/command-auth.ts +101 -0
- package/src/shared/index.ts +5 -0
- package/src/shared/xml-parser.test.ts +30 -0
- package/src/shared/xml-parser.ts +183 -0
- package/src/target.ts +80 -0
- package/src/types/account.ts +76 -0
- package/src/types/config.ts +88 -0
- package/src/types/constants.ts +42 -0
- package/src/types/global.d.ts +9 -0
- package/src/types/index.ts +38 -0
- package/src/types/message.ts +185 -0
- package/src/types.ts +159 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 账号类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { WecomBotConfig, WecomAgentConfig, WecomDmConfig, WecomNetworkConfig } from "./config.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 解析后的 Bot 账号
|
|
9
|
+
*/
|
|
10
|
+
export type ResolvedBotAccount = {
|
|
11
|
+
/** 账号 ID */
|
|
12
|
+
accountId: string;
|
|
13
|
+
/** 是否启用 */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** 是否配置完整 */
|
|
16
|
+
configured: boolean;
|
|
17
|
+
/** 回调 Token */
|
|
18
|
+
token: string;
|
|
19
|
+
/** 回调加密密钥 */
|
|
20
|
+
encodingAESKey: string;
|
|
21
|
+
/** 接收者 ID */
|
|
22
|
+
receiveId: string;
|
|
23
|
+
/** 原始配置 */
|
|
24
|
+
config: WecomBotConfig;
|
|
25
|
+
/** 网络配置(来自 channels.wecom.network) */
|
|
26
|
+
network?: WecomNetworkConfig;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 解析后的 Agent 账号
|
|
31
|
+
*/
|
|
32
|
+
export type ResolvedAgentAccount = {
|
|
33
|
+
/** 账号 ID */
|
|
34
|
+
accountId: string;
|
|
35
|
+
/** 是否启用 */
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
/** 是否配置完整 */
|
|
38
|
+
configured: boolean;
|
|
39
|
+
/** 企业 ID */
|
|
40
|
+
corpId: string;
|
|
41
|
+
/** 应用 Secret */
|
|
42
|
+
corpSecret: string;
|
|
43
|
+
/** 应用 ID (数字) */
|
|
44
|
+
agentId: number;
|
|
45
|
+
/** 回调 Token */
|
|
46
|
+
token: string;
|
|
47
|
+
/** 回调加密密钥 */
|
|
48
|
+
encodingAESKey: string;
|
|
49
|
+
/** 原始配置 */
|
|
50
|
+
config: WecomAgentConfig;
|
|
51
|
+
/** 网络配置(来自 channels.wecom.network) */
|
|
52
|
+
network?: WecomNetworkConfig;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 已解析的模式状态
|
|
57
|
+
*/
|
|
58
|
+
export type ResolvedMode = {
|
|
59
|
+
/** Bot 模式是否已配置 */
|
|
60
|
+
bot: boolean;
|
|
61
|
+
/** Agent 模式是否已配置 */
|
|
62
|
+
agent: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 解析后的 WeCom 账号集合
|
|
67
|
+
*/
|
|
68
|
+
export type ResolvedWecomAccounts = {
|
|
69
|
+
/** Bot 模式账号 */
|
|
70
|
+
bot?: ResolvedBotAccount;
|
|
71
|
+
/** Agent 模式账号 */
|
|
72
|
+
agent?: ResolvedAgentAccount;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Re-export 用于向后兼容
|
|
76
|
+
export type { WecomDmConfig } from "./config.js";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 双模式配置类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** DM 策略配置 - 与其他渠道保持一致,仅用 allowFrom */
|
|
6
|
+
export type WecomDmConfig = {
|
|
7
|
+
/** DM 策略: 'open' 允许所有人, 'pairing' 需要配对, 'allowlist' 仅允许列表, 'disabled' 禁用 */
|
|
8
|
+
policy?: 'open' | 'pairing' | 'allowlist' | 'disabled';
|
|
9
|
+
/** 允许的用户列表,为空表示允许所有人 */
|
|
10
|
+
allowFrom?: Array<string | number>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** 媒体处理配置 */
|
|
14
|
+
export type WecomMediaConfig = {
|
|
15
|
+
tempDir?: string;
|
|
16
|
+
retentionHours?: number;
|
|
17
|
+
cleanupOnStart?: boolean;
|
|
18
|
+
maxBytes?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** 网络配置 */
|
|
22
|
+
export type WecomNetworkConfig = {
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
retries?: number;
|
|
25
|
+
retryDelayMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* 出口代理(用于企业可信 IP 固定出口场景)。
|
|
28
|
+
* 示例: "http://proxy.company.local:3128"
|
|
29
|
+
*/
|
|
30
|
+
egressProxyUrl?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Bot 模式配置 (智能体)
|
|
35
|
+
* 用于接收 JSON 格式回调 + 流式回复
|
|
36
|
+
*/
|
|
37
|
+
export type WecomBotConfig = {
|
|
38
|
+
/** 回调 Token (企微后台生成) */
|
|
39
|
+
token: string;
|
|
40
|
+
/** 回调加密密钥 (企微后台生成) */
|
|
41
|
+
encodingAESKey: string;
|
|
42
|
+
/** 接收者 ID (可选,用于解密校验) */
|
|
43
|
+
receiveId?: string;
|
|
44
|
+
/** 流式消息占位符 */
|
|
45
|
+
streamPlaceholderContent?: string;
|
|
46
|
+
/** 欢迎语 */
|
|
47
|
+
welcomeText?: string;
|
|
48
|
+
/** DM 策略 */
|
|
49
|
+
dm?: WecomDmConfig;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Agent 模式配置 (自建应用)
|
|
54
|
+
* 用于接收 XML 格式回调 + API 主动发送
|
|
55
|
+
*/
|
|
56
|
+
export type WecomAgentConfig = {
|
|
57
|
+
/** 企业 ID */
|
|
58
|
+
corpId: string;
|
|
59
|
+
/** 应用 Secret */
|
|
60
|
+
corpSecret: string;
|
|
61
|
+
/** 应用 ID */
|
|
62
|
+
agentId: number | string;
|
|
63
|
+
/** 回调 Token (企微后台「设置API接收」) */
|
|
64
|
+
token: string;
|
|
65
|
+
/** 回调加密密钥 (企微后台「设置API接收」) */
|
|
66
|
+
encodingAESKey: string;
|
|
67
|
+
/** 欢迎语 */
|
|
68
|
+
welcomeText?: string;
|
|
69
|
+
/** DM 策略 */
|
|
70
|
+
dm?: WecomDmConfig;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 顶层 WeCom 配置
|
|
75
|
+
* 通过 bot / agent 字段隐式指定模式
|
|
76
|
+
*/
|
|
77
|
+
export type WecomConfig = {
|
|
78
|
+
/** 是否启用 */
|
|
79
|
+
enabled?: boolean;
|
|
80
|
+
/** Bot 模式配置 (智能体) */
|
|
81
|
+
bot?: WecomBotConfig;
|
|
82
|
+
/** Agent 模式配置 (自建应用) */
|
|
83
|
+
agent?: WecomAgentConfig;
|
|
84
|
+
/** 媒体处理配置 */
|
|
85
|
+
media?: WecomMediaConfig;
|
|
86
|
+
/** 网络配置 */
|
|
87
|
+
network?: WecomNetworkConfig;
|
|
88
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 双模式常量定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** 固定 Webhook 路径 */
|
|
6
|
+
export const WEBHOOK_PATHS = {
|
|
7
|
+
/** Bot 模式 (智能体) - 兼容原有路径 */
|
|
8
|
+
BOT: "/wecom",
|
|
9
|
+
/** Bot 模式备用路径 */
|
|
10
|
+
BOT_ALT: "/wecom/bot",
|
|
11
|
+
/** Agent 模式 (自建应用) */
|
|
12
|
+
AGENT: "/wecom/agent",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
/** 企业微信 API 端点 */
|
|
16
|
+
export const API_ENDPOINTS = {
|
|
17
|
+
GET_TOKEN: "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
|
|
18
|
+
SEND_MESSAGE: "https://qyapi.weixin.qq.com/cgi-bin/message/send",
|
|
19
|
+
SEND_APPCHAT: "https://qyapi.weixin.qq.com/cgi-bin/appchat/send",
|
|
20
|
+
UPLOAD_MEDIA: "https://qyapi.weixin.qq.com/cgi-bin/media/upload",
|
|
21
|
+
DOWNLOAD_MEDIA: "https://qyapi.weixin.qq.com/cgi-bin/media/get",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
/** 各类限制常量 */
|
|
25
|
+
export const LIMITS = {
|
|
26
|
+
/** 文本消息最大字节数 */
|
|
27
|
+
TEXT_MAX_BYTES: 2048,
|
|
28
|
+
/** Token 刷新缓冲时间 (提前刷新) */
|
|
29
|
+
TOKEN_REFRESH_BUFFER_MS: 60_000,
|
|
30
|
+
/** HTTP 请求超时 */
|
|
31
|
+
REQUEST_TIMEOUT_MS: 15_000,
|
|
32
|
+
/** 最大请求体大小 */
|
|
33
|
+
MAX_REQUEST_BODY_SIZE: 1024 * 1024,
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
/** AES 加密常量 */
|
|
37
|
+
export const CRYPTO = {
|
|
38
|
+
/** PKCS#7 块大小 */
|
|
39
|
+
PKCS7_BLOCK_SIZE: 32,
|
|
40
|
+
/** AES Key 长度 */
|
|
41
|
+
AES_KEY_LENGTH: 32,
|
|
42
|
+
} as const;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 类型统一导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 常量
|
|
6
|
+
export * from "./constants.js";
|
|
7
|
+
|
|
8
|
+
// 配置类型
|
|
9
|
+
export type {
|
|
10
|
+
WecomDmConfig,
|
|
11
|
+
WecomMediaConfig,
|
|
12
|
+
WecomNetworkConfig,
|
|
13
|
+
WecomBotConfig,
|
|
14
|
+
WecomAgentConfig,
|
|
15
|
+
WecomConfig,
|
|
16
|
+
} from "./config.js";
|
|
17
|
+
|
|
18
|
+
// 账号类型
|
|
19
|
+
export type {
|
|
20
|
+
ResolvedBotAccount,
|
|
21
|
+
ResolvedAgentAccount,
|
|
22
|
+
ResolvedMode,
|
|
23
|
+
ResolvedWecomAccounts,
|
|
24
|
+
} from "./account.js";
|
|
25
|
+
|
|
26
|
+
// 消息类型
|
|
27
|
+
export type {
|
|
28
|
+
WecomBotInboundBase,
|
|
29
|
+
WecomBotInboundText,
|
|
30
|
+
WecomBotInboundVoice,
|
|
31
|
+
WecomBotInboundStreamRefresh,
|
|
32
|
+
WecomBotInboundEvent,
|
|
33
|
+
WecomBotInboundMessage,
|
|
34
|
+
WecomAgentInboundMessage,
|
|
35
|
+
WecomInboundQuote,
|
|
36
|
+
WecomTemplateCard,
|
|
37
|
+
WecomOutboundMessage,
|
|
38
|
+
} from "./message.js";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom 消息类型定义
|
|
3
|
+
* Bot 和 Agent 模式共用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bot 模式入站消息基础结构 (JSON)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* **WecomBotInboundBase (Bot 入站消息基类)**
|
|
11
|
+
*
|
|
12
|
+
* Bot 模式下 JSON 格式回调的基础字段。
|
|
13
|
+
* @property msgid 消息 ID
|
|
14
|
+
* @property aibotid 机器人 ID
|
|
15
|
+
* @property chattype 会话类型: "single" | "group"
|
|
16
|
+
* @property chatid 群聊 ID (仅群组时存在)
|
|
17
|
+
* @property response_url 下行回复 URL (用于被动响应转主动推送)
|
|
18
|
+
* @property from 发送者信息
|
|
19
|
+
*/
|
|
20
|
+
export type WecomBotInboundBase = {
|
|
21
|
+
msgid?: string;
|
|
22
|
+
aibotid?: string;
|
|
23
|
+
chattype?: "single" | "group";
|
|
24
|
+
chatid?: string;
|
|
25
|
+
response_url?: string;
|
|
26
|
+
from?: { userid?: string; corpid?: string };
|
|
27
|
+
msgtype?: string;
|
|
28
|
+
/** 附件数量 (部分消息存在) */
|
|
29
|
+
attachment_count?: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type WecomBotInboundText = WecomBotInboundBase & {
|
|
33
|
+
msgtype: "text";
|
|
34
|
+
text?: { content?: string };
|
|
35
|
+
quote?: WecomInboundQuote;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type WecomBotInboundVoice = WecomBotInboundBase & {
|
|
39
|
+
msgtype: "voice";
|
|
40
|
+
voice?: { content?: string };
|
|
41
|
+
quote?: WecomInboundQuote;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type WecomBotInboundStreamRefresh = WecomBotInboundBase & {
|
|
45
|
+
msgtype: "stream";
|
|
46
|
+
stream?: { id?: string };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type WecomBotInboundEvent = WecomBotInboundBase & {
|
|
50
|
+
msgtype: "event";
|
|
51
|
+
create_time?: number;
|
|
52
|
+
event?: {
|
|
53
|
+
eventtype?: string;
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* **WecomInboundQuote (引用消息)**
|
|
60
|
+
*
|
|
61
|
+
* 消息中引用的原始内容(如回复某条消息)。
|
|
62
|
+
* 支持引用文本、图片、混合类型、语音、文件等。
|
|
63
|
+
*/
|
|
64
|
+
export type WecomInboundQuote = {
|
|
65
|
+
msgtype?: "text" | "image" | "mixed" | "voice" | "file";
|
|
66
|
+
/** 引用文本内容 */
|
|
67
|
+
text?: { content?: string };
|
|
68
|
+
/** 引用图片 URL */
|
|
69
|
+
image?: { url?: string };
|
|
70
|
+
/** 引用混合消息 (图文) */
|
|
71
|
+
mixed?: {
|
|
72
|
+
msg_item?: Array<{
|
|
73
|
+
msgtype: "text" | "image";
|
|
74
|
+
text?: { content?: string };
|
|
75
|
+
image?: { url?: string };
|
|
76
|
+
}>;
|
|
77
|
+
};
|
|
78
|
+
/** 引用语音 */
|
|
79
|
+
voice?: { content?: string };
|
|
80
|
+
/** 引用文件 */
|
|
81
|
+
file?: { url?: string };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type WecomBotInboundMessage =
|
|
85
|
+
| WecomBotInboundText
|
|
86
|
+
| WecomBotInboundVoice
|
|
87
|
+
| WecomBotInboundStreamRefresh
|
|
88
|
+
| WecomBotInboundEvent
|
|
89
|
+
| (WecomBotInboundBase & { quote?: WecomInboundQuote } & Record<string, unknown>);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Agent 模式入站消息结构 (解析自 XML)
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* **WecomAgentInboundMessage (Agent 入站消息)**
|
|
96
|
+
*
|
|
97
|
+
* Agent 模式下解析自 XML 的扁平化消息结构。
|
|
98
|
+
* 键名保持 PascalCase (如 `ToUserName`)。
|
|
99
|
+
*/
|
|
100
|
+
export type WecomAgentInboundMessage = {
|
|
101
|
+
ToUserName?: string;
|
|
102
|
+
FromUserName?: string;
|
|
103
|
+
CreateTime?: number;
|
|
104
|
+
MsgType?: string;
|
|
105
|
+
MsgId?: string;
|
|
106
|
+
AgentID?: number;
|
|
107
|
+
// 文本消息
|
|
108
|
+
Content?: string;
|
|
109
|
+
// 图片消息
|
|
110
|
+
PicUrl?: string;
|
|
111
|
+
MediaId?: string;
|
|
112
|
+
// 文件消息
|
|
113
|
+
FileName?: string;
|
|
114
|
+
// 语音消息
|
|
115
|
+
Format?: string;
|
|
116
|
+
Recognition?: string;
|
|
117
|
+
// 视频消息
|
|
118
|
+
ThumbMediaId?: string;
|
|
119
|
+
// 位置消息
|
|
120
|
+
Location_X?: number;
|
|
121
|
+
Location_Y?: number;
|
|
122
|
+
Scale?: number;
|
|
123
|
+
Label?: string;
|
|
124
|
+
// 链接消息
|
|
125
|
+
Title?: string;
|
|
126
|
+
Description?: string;
|
|
127
|
+
Url?: string;
|
|
128
|
+
// 事件消息
|
|
129
|
+
Event?: string;
|
|
130
|
+
EventKey?: string;
|
|
131
|
+
// 群聊
|
|
132
|
+
ChatId?: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 模板卡片类型
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* **WecomTemplateCard (模板卡片)**
|
|
140
|
+
*
|
|
141
|
+
* 复杂的交互式卡片结构。
|
|
142
|
+
* @property card_type 卡片类型: "text_notice" | "news_notice" | "button_interaction" ...
|
|
143
|
+
* @property source 来源信息
|
|
144
|
+
* @property main_title 主标题
|
|
145
|
+
* @property sub_title_text 副标题
|
|
146
|
+
* @property horizontal_content_list 水平排列的键值列表
|
|
147
|
+
* @property button_list 按钮列表
|
|
148
|
+
*/
|
|
149
|
+
export type WecomTemplateCard = {
|
|
150
|
+
card_type: "text_notice" | "news_notice" | "button_interaction" | "vote_interaction" | "multiple_interaction";
|
|
151
|
+
source?: { icon_url?: string; desc?: string; desc_color?: number };
|
|
152
|
+
main_title?: { title?: string; desc?: string };
|
|
153
|
+
task_id?: string;
|
|
154
|
+
button_list?: Array<{ text: string; style?: number; key: string }>;
|
|
155
|
+
sub_title_text?: string;
|
|
156
|
+
horizontal_content_list?: Array<{
|
|
157
|
+
keyname: string;
|
|
158
|
+
value?: string;
|
|
159
|
+
type?: number;
|
|
160
|
+
url?: string;
|
|
161
|
+
userid?: string;
|
|
162
|
+
}>;
|
|
163
|
+
card_action?: { type: number; url?: string; appid?: string; pagepath?: string };
|
|
164
|
+
action_menu?: { desc: string; action_list: Array<{ text: string; key: string }> };
|
|
165
|
+
select_list?: Array<{
|
|
166
|
+
question_key: string;
|
|
167
|
+
title?: string;
|
|
168
|
+
selected_id?: string;
|
|
169
|
+
option_list: Array<{ id: string; text: string }>;
|
|
170
|
+
}>;
|
|
171
|
+
submit_button?: { text: string; key: string };
|
|
172
|
+
checkbox?: {
|
|
173
|
+
question_key: string;
|
|
174
|
+
option_list: Array<{ id: string; text: string; is_checked?: boolean }>;
|
|
175
|
+
mode?: number;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 出站消息类型
|
|
181
|
+
*/
|
|
182
|
+
export type WecomOutboundMessage =
|
|
183
|
+
| { msgtype: "text"; text: { content: string } }
|
|
184
|
+
| { msgtype: "markdown"; markdown: { content: string } }
|
|
185
|
+
| { msgtype: "template_card"; template_card: WecomTemplateCard };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
export type WecomDmConfig = {
|
|
2
|
+
policy?: "pairing" | "allowlist" | "open" | "disabled";
|
|
3
|
+
allowFrom?: Array<string | number>;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type WecomAccountConfig = {
|
|
7
|
+
name?: string;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
|
|
10
|
+
webhookPath?: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
encodingAESKey?: string;
|
|
13
|
+
receiveId?: string;
|
|
14
|
+
|
|
15
|
+
streamPlaceholderContent?: string;
|
|
16
|
+
|
|
17
|
+
dm?: WecomDmConfig;
|
|
18
|
+
welcomeText?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type WecomConfig = WecomAccountConfig & {
|
|
22
|
+
accounts?: Record<string, WecomAccountConfig>;
|
|
23
|
+
defaultAccount?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type ResolvedWecomAccount = {
|
|
27
|
+
accountId: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
configured: boolean;
|
|
31
|
+
token?: string;
|
|
32
|
+
encodingAESKey?: string;
|
|
33
|
+
receiveId: string;
|
|
34
|
+
config: WecomAccountConfig;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type WecomInboundBase = {
|
|
38
|
+
msgid?: string;
|
|
39
|
+
aibotid?: string;
|
|
40
|
+
chattype?: "single" | "group";
|
|
41
|
+
chatid?: string;
|
|
42
|
+
response_url?: string;
|
|
43
|
+
from?: { userid?: string; corpid?: string };
|
|
44
|
+
msgtype?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type WecomInboundText = WecomInboundBase & {
|
|
48
|
+
msgtype: "text";
|
|
49
|
+
text?: { content?: string };
|
|
50
|
+
quote?: unknown;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type WecomInboundVoice = WecomInboundBase & {
|
|
54
|
+
msgtype: "voice";
|
|
55
|
+
voice?: { content?: string };
|
|
56
|
+
quote?: unknown;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type WecomInboundStreamRefresh = WecomInboundBase & {
|
|
60
|
+
msgtype: "stream";
|
|
61
|
+
stream?: { id?: string };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type WecomInboundEvent = WecomInboundBase & {
|
|
65
|
+
msgtype: "event";
|
|
66
|
+
create_time?: number;
|
|
67
|
+
event?: {
|
|
68
|
+
eventtype?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type WecomInboundQuote = {
|
|
74
|
+
msgtype?: "text" | "image" | "mixed" | "voice" | "file";
|
|
75
|
+
text?: { content?: string };
|
|
76
|
+
image?: { url?: string };
|
|
77
|
+
mixed?: {
|
|
78
|
+
msg_item?: Array<{
|
|
79
|
+
msgtype: "text" | "image";
|
|
80
|
+
text?: { content?: string };
|
|
81
|
+
image?: { url?: string };
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
voice?: { content?: string };
|
|
85
|
+
file?: { url?: string };
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type WecomInboundMessage =
|
|
89
|
+
| (WecomInboundText & { quote?: WecomInboundQuote })
|
|
90
|
+
| WecomInboundVoice
|
|
91
|
+
| WecomInboundStreamRefresh
|
|
92
|
+
| WecomInboundEvent
|
|
93
|
+
| (WecomInboundBase & { quote?: WecomInboundQuote } & Record<string, unknown>);
|
|
94
|
+
|
|
95
|
+
export type WecomTemplateCard = {
|
|
96
|
+
card_type: "text_notice" | "news_notice" | "button_interaction" | "vote_interaction" | "multiple_interaction";
|
|
97
|
+
source?: { icon_url?: string; desc?: string; desc_color?: number };
|
|
98
|
+
main_title?: { title?: string; desc?: string };
|
|
99
|
+
task_id?: string;
|
|
100
|
+
button_list?: Array<{ text: string; style?: number; key: string }>;
|
|
101
|
+
sub_title_text?: string;
|
|
102
|
+
horizontal_content_list?: Array<{ keyname: string; value?: string; type?: number; url?: string; userid?: string }>;
|
|
103
|
+
card_action?: { type: number; url?: string; appid?: string; pagepath?: string };
|
|
104
|
+
action_menu?: { desc: string; action_list: Array<{ text: string; key: string }> };
|
|
105
|
+
select_list?: Array<{
|
|
106
|
+
question_key: string;
|
|
107
|
+
title?: string;
|
|
108
|
+
selected_id?: string;
|
|
109
|
+
option_list: Array<{ id: string; text: string }>;
|
|
110
|
+
}>;
|
|
111
|
+
submit_button?: { text: string; key: string };
|
|
112
|
+
checkbox?: {
|
|
113
|
+
question_key: string;
|
|
114
|
+
option_list: Array<{ id: string; text: string; is_checked?: boolean }>;
|
|
115
|
+
mode?: number;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type WecomInboundTemplateCardEvent = WecomInboundBase & {
|
|
120
|
+
msgtype: "event";
|
|
121
|
+
event: {
|
|
122
|
+
eventtype: "template_card_event";
|
|
123
|
+
template_card_event: {
|
|
124
|
+
card_type: string;
|
|
125
|
+
event_key: string;
|
|
126
|
+
task_id: string;
|
|
127
|
+
selected_items?: {
|
|
128
|
+
selected_item: Array<{
|
|
129
|
+
question_key: string;
|
|
130
|
+
option_ids: { option_id: string[] };
|
|
131
|
+
}>;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Template card event payload (button click, checkbox, select)
|
|
140
|
+
*/
|
|
141
|
+
export type WecomTemplateCardEventPayload = {
|
|
142
|
+
card_type: string;
|
|
143
|
+
event_key: string;
|
|
144
|
+
task_id: string;
|
|
145
|
+
response_code?: string;
|
|
146
|
+
selected_items?: {
|
|
147
|
+
question_key?: string;
|
|
148
|
+
option_ids?: string[];
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Outbound message types that can be sent via response_url
|
|
154
|
+
*/
|
|
155
|
+
export type WecomOutboundMessage =
|
|
156
|
+
| { msgtype: "text"; text: { content: string } }
|
|
157
|
+
| { msgtype: "markdown"; markdown: { content: string } }
|
|
158
|
+
| { msgtype: "template_card"; template_card: WecomTemplateCard };
|
|
159
|
+
|