@yaoqi10012/wechat-kf 0.3.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/LICENSE +21 -0
- package/dist/accounts.d.ts +38 -0
- package/dist/accounts.js +247 -0
- package/dist/accounts.js.map +1 -0
- package/dist/api.d.ts +58 -0
- package/dist/api.js +200 -0
- package/dist/api.js.map +1 -0
- package/dist/bot.d.ts +37 -0
- package/dist/bot.js +672 -0
- package/dist/bot.js.map +1 -0
- package/dist/channel.d.ts +14 -0
- package/dist/channel.js +320 -0
- package/dist/channel.js.map +1 -0
- package/dist/config-schema.d.ts +56 -0
- package/dist/config-schema.js +39 -0
- package/dist/config-schema.js.map +1 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.js +51 -0
- package/dist/constants.js.map +1 -0
- package/dist/crypto.d.ts +18 -0
- package/dist/crypto.js +81 -0
- package/dist/crypto.js.map +1 -0
- package/dist/fs-utils.d.ts +7 -0
- package/dist/fs-utils.js +13 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/monitor.d.ts +31 -0
- package/dist/monitor.js +80 -0
- package/dist/monitor.js.map +1 -0
- package/dist/outbound.d.ts +32 -0
- package/dist/outbound.js +411 -0
- package/dist/outbound.js.map +1 -0
- package/dist/reply-dispatcher.d.ts +36 -0
- package/dist/reply-dispatcher.js +216 -0
- package/dist/reply-dispatcher.js.map +1 -0
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +23 -0
- package/dist/runtime.js.map +1 -0
- package/dist/send-utils.d.ts +52 -0
- package/dist/send-utils.js +217 -0
- package/dist/send-utils.js.map +1 -0
- package/dist/token.d.ts +8 -0
- package/dist/token.js +61 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +236 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/unicode-format.d.ts +26 -0
- package/dist/unicode-format.js +157 -0
- package/dist/unicode-format.js.map +1 -0
- package/dist/webhook.d.ts +22 -0
- package/dist/webhook.js +148 -0
- package/dist/webhook.js.map +1 -0
- package/dist/wechat-kf-directives.d.ts +157 -0
- package/dist/wechat-kf-directives.js +576 -0
- package/dist/wechat-kf-directives.js.map +1 -0
- package/openclaw.plugin.json +31 -0
- package/package.json +92 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeChat KF directive parser
|
|
3
|
+
*
|
|
4
|
+
* Parses [[wechat_*: ...]] directives embedded in agent text replies.
|
|
5
|
+
* The framework doesn't recognize these directives, so the text arrives
|
|
6
|
+
* intact for plugin-level interception.
|
|
7
|
+
*
|
|
8
|
+
* Supported directives:
|
|
9
|
+
* [[wechat_link: title | desc | url | thumbUrl]]
|
|
10
|
+
* [[wechat_location: name | address | lat | lng]]
|
|
11
|
+
* [[wechat_miniprogram: appid | title | pagepath | thumbUrl]]
|
|
12
|
+
* [[wechat_menu: header | Option1, Option2, Option3 | footer]]
|
|
13
|
+
* [[wechat_business_card: USERID]]
|
|
14
|
+
* [[wechat_ca_link: https://work.weixin.qq.com/ca/...]]
|
|
15
|
+
*/
|
|
16
|
+
export type WechatLinkDirective = {
|
|
17
|
+
title: string;
|
|
18
|
+
desc?: string;
|
|
19
|
+
url: string;
|
|
20
|
+
thumbUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
export type WechatLocationDirective = {
|
|
23
|
+
name: string;
|
|
24
|
+
address?: string;
|
|
25
|
+
latitude: number;
|
|
26
|
+
longitude: number;
|
|
27
|
+
};
|
|
28
|
+
export type WechatMenuItemDirective = {
|
|
29
|
+
type: "click";
|
|
30
|
+
id?: string;
|
|
31
|
+
content: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "view";
|
|
34
|
+
url: string;
|
|
35
|
+
content: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: "miniprogram";
|
|
38
|
+
appid: string;
|
|
39
|
+
pagepath: string;
|
|
40
|
+
content: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: "text";
|
|
43
|
+
content: string;
|
|
44
|
+
noNewline?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type WechatMenuDirective = {
|
|
47
|
+
headContent?: string;
|
|
48
|
+
items: WechatMenuItemDirective[];
|
|
49
|
+
tailContent?: string;
|
|
50
|
+
};
|
|
51
|
+
export type WechatMiniprogramDirective = {
|
|
52
|
+
appid: string;
|
|
53
|
+
title: string;
|
|
54
|
+
pagepath: string;
|
|
55
|
+
thumbUrl?: string;
|
|
56
|
+
};
|
|
57
|
+
export type WechatBusinessCardDirective = {
|
|
58
|
+
userid: string;
|
|
59
|
+
};
|
|
60
|
+
export type WechatCaLinkDirective = {
|
|
61
|
+
link_url: string;
|
|
62
|
+
};
|
|
63
|
+
export type WechatRawDirective = {
|
|
64
|
+
msgtype: string;
|
|
65
|
+
payload: Record<string, unknown>;
|
|
66
|
+
};
|
|
67
|
+
export type WechatDirectiveResult = {
|
|
68
|
+
text: string;
|
|
69
|
+
link?: WechatLinkDirective;
|
|
70
|
+
location?: WechatLocationDirective;
|
|
71
|
+
miniprogram?: WechatMiniprogramDirective;
|
|
72
|
+
menu?: WechatMenuDirective;
|
|
73
|
+
businessCard?: WechatBusinessCardDirective;
|
|
74
|
+
caLink?: WechatCaLinkDirective;
|
|
75
|
+
raw?: WechatRawDirective;
|
|
76
|
+
};
|
|
77
|
+
export type ProtectedRange = {
|
|
78
|
+
start: number;
|
|
79
|
+
end: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Scan text left-to-right and collect ranges that should be treated as
|
|
83
|
+
* "protected" — i.e. directive syntax inside them must be ignored.
|
|
84
|
+
*
|
|
85
|
+
* Three zone types (checked in priority order):
|
|
86
|
+
* 1. Fenced code blocks (``` or ~~~, with optional 0-3 leading spaces + lang tag)
|
|
87
|
+
* 2. Inline code spans (backtick sequences, matching equal-length closer)
|
|
88
|
+
* 3. Blockquote lines (line starting with optional whitespace + `>`)
|
|
89
|
+
*/
|
|
90
|
+
export declare function findProtectedRanges(text: string): ProtectedRange[];
|
|
91
|
+
/**
|
|
92
|
+
* Quick check whether text contains a `[[wechat_link:...]]` directive
|
|
93
|
+
* outside of markdown code blocks, inline code, and blockquotes.
|
|
94
|
+
*/
|
|
95
|
+
export declare function hasWechatLinkDirective(text: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Extract the first `[[wechat_link:...]]` directive from text.
|
|
98
|
+
*
|
|
99
|
+
* Returns the remaining text (with directive stripped and trimmed)
|
|
100
|
+
* plus the parsed link fields. If parsing fails (e.g. invalid URL),
|
|
101
|
+
* returns the original text unchanged with no link.
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseWechatLinkDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
104
|
+
export declare function parseWechatLocationDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
105
|
+
export declare function parseWechatMiniprogramDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
106
|
+
export declare function parseWechatMenuDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
107
|
+
/**
|
|
108
|
+
* Convert a parsed WechatMenuDirective into the API `msgmenu` payload.
|
|
109
|
+
*
|
|
110
|
+
* Click items get auto-incrementing IDs (only among click items that lack
|
|
111
|
+
* an explicit `id`). Explicit IDs are preserved as-is.
|
|
112
|
+
*/
|
|
113
|
+
export declare function buildMsgMenuPayload(menu: WechatMenuDirective): {
|
|
114
|
+
head_content?: string;
|
|
115
|
+
list: Array<{
|
|
116
|
+
type: "click";
|
|
117
|
+
click: {
|
|
118
|
+
id: string;
|
|
119
|
+
content: string;
|
|
120
|
+
};
|
|
121
|
+
} | {
|
|
122
|
+
type: "view";
|
|
123
|
+
view: {
|
|
124
|
+
url: string;
|
|
125
|
+
content: string;
|
|
126
|
+
};
|
|
127
|
+
} | {
|
|
128
|
+
type: "miniprogram";
|
|
129
|
+
miniprogram: {
|
|
130
|
+
appid: string;
|
|
131
|
+
pagepath: string;
|
|
132
|
+
content: string;
|
|
133
|
+
};
|
|
134
|
+
} | {
|
|
135
|
+
type: "text";
|
|
136
|
+
text: {
|
|
137
|
+
content: string;
|
|
138
|
+
no_newline?: number;
|
|
139
|
+
};
|
|
140
|
+
}>;
|
|
141
|
+
tail_content?: string;
|
|
142
|
+
};
|
|
143
|
+
export declare function parseWechatBusinessCardDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
144
|
+
export declare function parseWechatCaLinkDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
145
|
+
export declare function parseWechatRawDirective(text: string, protectedRanges?: ProtectedRange[]): WechatDirectiveResult;
|
|
146
|
+
/**
|
|
147
|
+
* Quick check whether text contains any `[[wechat_*:...]]` directive
|
|
148
|
+
* outside of markdown code blocks, inline code, and blockquotes.
|
|
149
|
+
*/
|
|
150
|
+
export declare function hasWechatDirective(text: string): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Parse the first matching directive from text.
|
|
153
|
+
* Tries parsers in order: link → location → miniprogram → menu → business_card → ca_link → raw.
|
|
154
|
+
* Returns the first successful parse result.
|
|
155
|
+
* Directives inside markdown code blocks, inline code, or blockquotes are ignored.
|
|
156
|
+
*/
|
|
157
|
+
export declare function parseWechatDirective(text: string): WechatDirectiveResult;
|