@pawastation/wechat-kf 0.1.2 → 0.2.0
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 +34 -28
- package/README.zh-CN.md +34 -28
- package/dist/index.d.ts +5 -15
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/src/accounts.d.ts +2 -1
- package/dist/src/accounts.js +61 -19
- package/dist/src/accounts.js.map +1 -1
- package/dist/src/api.d.ts +31 -2
- package/dist/src/api.js +41 -13
- package/dist/src/api.js.map +1 -1
- package/dist/src/bot.d.ts +10 -8
- package/dist/src/bot.js +231 -78
- package/dist/src/bot.js.map +1 -1
- package/dist/src/channel.d.ts +7 -106
- package/dist/src/channel.js +208 -71
- package/dist/src/channel.js.map +1 -1
- package/dist/src/config-schema.d.ts +0 -6
- package/dist/src/config-schema.js +2 -7
- package/dist/src/config-schema.js.map +1 -1
- package/dist/src/constants.d.ts +20 -0
- package/dist/src/constants.js +29 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/crypto.js +7 -6
- package/dist/src/crypto.js.map +1 -1
- package/dist/src/monitor.d.ts +27 -14
- package/dist/src/monitor.js +67 -120
- package/dist/src/monitor.js.map +1 -1
- package/dist/src/outbound.d.ts +10 -44
- package/dist/src/outbound.js +277 -92
- package/dist/src/outbound.js.map +1 -1
- package/dist/src/reply-dispatcher.d.ts +2 -6
- package/dist/src/reply-dispatcher.js +131 -32
- package/dist/src/reply-dispatcher.js.map +1 -1
- package/dist/src/runtime.d.ts +1 -119
- package/dist/src/runtime.js +2 -1
- package/dist/src/runtime.js.map +1 -1
- package/dist/src/send-utils.d.ts +13 -0
- package/dist/src/send-utils.js +56 -4
- package/dist/src/send-utils.js.map +1 -1
- package/dist/src/token.js +7 -3
- package/dist/src/token.js.map +1 -1
- package/dist/src/types.d.ts +68 -6
- package/dist/src/webhook.d.ts +16 -16
- package/dist/src/webhook.js +92 -75
- package/dist/src/webhook.js.map +1 -1
- package/dist/src/wechat-kf-directives.d.ts +132 -9
- package/dist/src/wechat-kf-directives.js +535 -24
- package/dist/src/wechat-kf-directives.js.map +1 -1
- package/index.ts +22 -12
- package/openclaw.plugin.json +1 -3
- package/package.json +3 -2
- package/dist/src/chunk-utils.d.ts +0 -18
- package/dist/src/chunk-utils.js +0 -58
- package/dist/src/chunk-utils.js.map +0 -1
package/dist/src/api.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WeCom Customer Service API wrapper
|
|
3
3
|
*/
|
|
4
|
-
import type { WechatKfSendMsgResponse, WechatKfSyncMsgRequest, WechatKfSyncMsgResponse, WechatMediaUploadResponse } from "./types.js";
|
|
4
|
+
import type { WechatKfSendMsgRequest, WechatKfSendMsgResponse, WechatKfSyncMsgRequest, WechatKfSyncMsgResponse, WechatMediaUploadResponse } from "./types.js";
|
|
5
5
|
/** Pull messages from WeChat KF */
|
|
6
6
|
export declare function syncMessages(corpId: string, appSecret: string, params: WechatKfSyncMsgRequest): Promise<WechatKfSyncMsgResponse>;
|
|
7
7
|
/** Send a text message to a WeChat user */
|
|
8
8
|
export declare function sendTextMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, content: string): Promise<WechatKfSendMsgResponse>;
|
|
9
9
|
/** Download media file from WeChat */
|
|
10
|
-
export declare function downloadMedia(corpId: string, appSecret: string, mediaId: string): Promise<
|
|
10
|
+
export declare function downloadMedia(corpId: string, appSecret: string, mediaId: string): Promise<{
|
|
11
|
+
buffer: Buffer;
|
|
12
|
+
contentType: string;
|
|
13
|
+
}>;
|
|
11
14
|
type WechatMediaType = "image" | "voice" | "video" | "file";
|
|
12
15
|
/** Upload media file to WeChat */
|
|
13
16
|
export declare function uploadMedia(corpId: string, appSecret: string, type: WechatMediaType, buffer: Buffer, filename: string): Promise<WechatMediaUploadResponse>;
|
|
@@ -26,4 +29,30 @@ export declare function sendLinkMessage(corpId: string, appSecret: string, toUse
|
|
|
26
29
|
url: string;
|
|
27
30
|
thumb_media_id: string;
|
|
28
31
|
}): Promise<WechatKfSendMsgResponse>;
|
|
32
|
+
/** Send a location message to a WeChat user */
|
|
33
|
+
export declare function sendLocationMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, location: {
|
|
34
|
+
name?: string;
|
|
35
|
+
address?: string;
|
|
36
|
+
latitude: number;
|
|
37
|
+
longitude: number;
|
|
38
|
+
}): Promise<WechatKfSendMsgResponse>;
|
|
39
|
+
/** Send a miniprogram message to a WeChat user */
|
|
40
|
+
export declare function sendMiniprogramMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, miniprogram: {
|
|
41
|
+
appid: string;
|
|
42
|
+
title?: string;
|
|
43
|
+
thumb_media_id: string;
|
|
44
|
+
pagepath: string;
|
|
45
|
+
}): Promise<WechatKfSendMsgResponse>;
|
|
46
|
+
/** Send a menu message to a WeChat user */
|
|
47
|
+
export declare function sendMsgMenuMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, msgmenu: WechatKfSendMsgRequest["msgmenu"]): Promise<WechatKfSendMsgResponse>;
|
|
48
|
+
/** Send a business card message to a WeChat user */
|
|
49
|
+
export declare function sendBusinessCardMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, businessCard: {
|
|
50
|
+
userid: string;
|
|
51
|
+
}): Promise<WechatKfSendMsgResponse>;
|
|
52
|
+
/** Send an acquisition link (获客链接) message to a WeChat user */
|
|
53
|
+
export declare function sendCaLinkMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, caLink: {
|
|
54
|
+
link_url: string;
|
|
55
|
+
}): Promise<WechatKfSendMsgResponse>;
|
|
56
|
+
/** Send a raw message with arbitrary msgtype — for testing undocumented message types. */
|
|
57
|
+
export declare function sendRawMessage(corpId: string, appSecret: string, toUser: string, openKfId: string, msgtype: string, payload: Record<string, unknown>): Promise<WechatKfSendMsgResponse>;
|
|
29
58
|
export {};
|
package/dist/src/api.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* WeCom Customer Service API wrapper
|
|
3
3
|
*/
|
|
4
4
|
import { extname } from "node:path";
|
|
5
|
-
import { API_POST_TIMEOUT_MS, MEDIA_TIMEOUT_MS, TOKEN_EXPIRED_CODES } from "./constants.js";
|
|
5
|
+
import { API_POST_TIMEOUT_MS, logTag, MEDIA_TIMEOUT_MS, TOKEN_EXPIRED_CODES } from "./constants.js";
|
|
6
|
+
import { getSharedContext } from "./monitor.js";
|
|
6
7
|
import { clearAccessToken, getAccessToken } from "./token.js";
|
|
7
8
|
const MIME_MAP = {
|
|
8
9
|
".jpg": "image/jpeg",
|
|
@@ -40,7 +41,7 @@ async function apiPost(path, token, body) {
|
|
|
40
41
|
});
|
|
41
42
|
if (!resp.ok) {
|
|
42
43
|
const text = await resp.text().catch(() => "");
|
|
43
|
-
throw new Error(
|
|
44
|
+
throw new Error(`${logTag()} API ${path} HTTP ${resp.status}: ${text.slice(0, 200)}`);
|
|
44
45
|
}
|
|
45
46
|
return (await resp.json());
|
|
46
47
|
}
|
|
@@ -54,6 +55,7 @@ async function apiPostWithTokenRetry(path, corpId, appSecret, body) {
|
|
|
54
55
|
const data = await apiPost(path, token, body);
|
|
55
56
|
const result = data;
|
|
56
57
|
if (typeof result.errcode === "number" && TOKEN_EXPIRED_CODES.has(result.errcode)) {
|
|
58
|
+
getSharedContext()?.botCtx.log?.info(`${logTag()} token expired (errcode=${result.errcode}), refreshing and retrying ${path}`);
|
|
57
59
|
clearAccessToken(corpId, appSecret);
|
|
58
60
|
token = await getAccessToken(corpId, appSecret);
|
|
59
61
|
return apiPost(path, token, body);
|
|
@@ -64,7 +66,7 @@ async function apiPostWithTokenRetry(path, corpId, appSecret, body) {
|
|
|
64
66
|
export async function syncMessages(corpId, appSecret, params) {
|
|
65
67
|
const data = await apiPostWithTokenRetry("/kf/sync_msg", corpId, appSecret, params);
|
|
66
68
|
if (hasApiError(data.errcode)) {
|
|
67
|
-
throw new Error(
|
|
69
|
+
throw new Error(`${logTag()} sync_msg failed: ${data.errcode} ${data.errmsg}`);
|
|
68
70
|
}
|
|
69
71
|
return data;
|
|
70
72
|
}
|
|
@@ -77,7 +79,7 @@ async function sendMessage(corpId, appSecret, toUser, openKfId, msgtype, payload
|
|
|
77
79
|
};
|
|
78
80
|
const data = await apiPostWithTokenRetry("/kf/send_msg", corpId, appSecret, body);
|
|
79
81
|
if (hasApiError(data.errcode)) {
|
|
80
|
-
throw new Error(
|
|
82
|
+
throw new Error(`${logTag()} send_msg failed: ${data.errcode} ${data.errmsg}`);
|
|
81
83
|
}
|
|
82
84
|
return data;
|
|
83
85
|
}
|
|
@@ -92,31 +94,32 @@ export async function downloadMedia(corpId, appSecret, mediaId) {
|
|
|
92
94
|
signal: AbortSignal.timeout(MEDIA_TIMEOUT_MS),
|
|
93
95
|
});
|
|
94
96
|
if (!resp.ok) {
|
|
95
|
-
throw new Error(
|
|
97
|
+
throw new Error(`${logTag()} download media failed: ${resp.status} ${resp.statusText}`);
|
|
96
98
|
}
|
|
97
99
|
const contentType = resp.headers.get("content-type") ?? "";
|
|
98
100
|
if (contentType.includes("application/json")) {
|
|
99
101
|
const data = (await resp.json());
|
|
100
|
-
return { buffer: Buffer.alloc(0), errcode: data.errcode, errmsg: data.errmsg };
|
|
102
|
+
return { buffer: Buffer.alloc(0), contentType, errcode: data.errcode, errmsg: data.errmsg };
|
|
101
103
|
}
|
|
102
|
-
return { buffer: Buffer.from(await resp.arrayBuffer()) };
|
|
104
|
+
return { buffer: Buffer.from(await resp.arrayBuffer()), contentType };
|
|
103
105
|
};
|
|
104
106
|
let token = await getAccessToken(corpId, appSecret);
|
|
105
107
|
const result = await attemptDownload(token);
|
|
106
108
|
if (result.errcode !== undefined) {
|
|
107
109
|
// Token-expired error: clear and retry once
|
|
108
110
|
if (TOKEN_EXPIRED_CODES.has(result.errcode)) {
|
|
111
|
+
getSharedContext()?.botCtx.log?.info(`${logTag()} token expired (errcode=${result.errcode}), refreshing and retrying media download`);
|
|
109
112
|
clearAccessToken(corpId, appSecret);
|
|
110
113
|
token = await getAccessToken(corpId, appSecret);
|
|
111
114
|
const retry = await attemptDownload(token);
|
|
112
115
|
if (retry.errcode !== undefined) {
|
|
113
|
-
throw new Error(
|
|
116
|
+
throw new Error(`${logTag()} download media failed: ${retry.errcode} ${retry.errmsg}`);
|
|
114
117
|
}
|
|
115
|
-
return retry.buffer;
|
|
118
|
+
return { buffer: retry.buffer, contentType: retry.contentType };
|
|
116
119
|
}
|
|
117
|
-
throw new Error(
|
|
120
|
+
throw new Error(`${logTag()} download media failed: ${result.errcode} ${result.errmsg}`);
|
|
118
121
|
}
|
|
119
|
-
return result.buffer;
|
|
122
|
+
return { buffer: result.buffer, contentType: result.contentType };
|
|
120
123
|
}
|
|
121
124
|
/** Upload media file to WeChat */
|
|
122
125
|
export async function uploadMedia(corpId, appSecret, type, buffer, filename) {
|
|
@@ -133,19 +136,20 @@ export async function uploadMedia(corpId, appSecret, type, buffer, filename) {
|
|
|
133
136
|
});
|
|
134
137
|
if (!resp.ok) {
|
|
135
138
|
const text = await resp.text().catch(() => "");
|
|
136
|
-
throw new Error(
|
|
139
|
+
throw new Error(`${logTag()} upload media HTTP ${resp.status}: ${text.slice(0, 200)}`);
|
|
137
140
|
}
|
|
138
141
|
return (await resp.json());
|
|
139
142
|
};
|
|
140
143
|
let token = await getAccessToken(corpId, appSecret);
|
|
141
144
|
let data = await doUpload(token);
|
|
142
145
|
if (TOKEN_EXPIRED_CODES.has(data.errcode)) {
|
|
146
|
+
getSharedContext()?.botCtx.log?.info(`${logTag()} token expired (errcode=${data.errcode}), refreshing and retrying media upload`);
|
|
143
147
|
clearAccessToken(corpId, appSecret);
|
|
144
148
|
token = await getAccessToken(corpId, appSecret);
|
|
145
149
|
data = await doUpload(token);
|
|
146
150
|
}
|
|
147
151
|
if (hasApiError(data.errcode)) {
|
|
148
|
-
throw new Error(
|
|
152
|
+
throw new Error(`${logTag()} upload media failed: ${data.errcode} ${data.errmsg}`);
|
|
149
153
|
}
|
|
150
154
|
return data;
|
|
151
155
|
}
|
|
@@ -169,4 +173,28 @@ export function sendFileMessage(corpId, appSecret, toUser, openKfId, mediaId) {
|
|
|
169
173
|
export function sendLinkMessage(corpId, appSecret, toUser, openKfId, link) {
|
|
170
174
|
return sendMessage(corpId, appSecret, toUser, openKfId, "link", { link });
|
|
171
175
|
}
|
|
176
|
+
/** Send a location message to a WeChat user */
|
|
177
|
+
export function sendLocationMessage(corpId, appSecret, toUser, openKfId, location) {
|
|
178
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, "location", { location });
|
|
179
|
+
}
|
|
180
|
+
/** Send a miniprogram message to a WeChat user */
|
|
181
|
+
export function sendMiniprogramMessage(corpId, appSecret, toUser, openKfId, miniprogram) {
|
|
182
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, "miniprogram", { miniprogram });
|
|
183
|
+
}
|
|
184
|
+
/** Send a menu message to a WeChat user */
|
|
185
|
+
export function sendMsgMenuMessage(corpId, appSecret, toUser, openKfId, msgmenu) {
|
|
186
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, "msgmenu", { msgmenu });
|
|
187
|
+
}
|
|
188
|
+
/** Send a business card message to a WeChat user */
|
|
189
|
+
export function sendBusinessCardMessage(corpId, appSecret, toUser, openKfId, businessCard) {
|
|
190
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, "business_card", { business_card: businessCard });
|
|
191
|
+
}
|
|
192
|
+
/** Send an acquisition link (获客链接) message to a WeChat user */
|
|
193
|
+
export function sendCaLinkMessage(corpId, appSecret, toUser, openKfId, caLink) {
|
|
194
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, "ca_link", { ca_link: caLink });
|
|
195
|
+
}
|
|
196
|
+
/** Send a raw message with arbitrary msgtype — for testing undocumented message types. */
|
|
197
|
+
export function sendRawMessage(corpId, appSecret, toUser, openKfId, msgtype, payload) {
|
|
198
|
+
return sendMessage(corpId, appSecret, toUser, openKfId, msgtype, payload);
|
|
199
|
+
}
|
|
172
200
|
//# sourceMappingURL=api.js.map
|
package/dist/src/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAS9D,MAAM,QAAQ,GAAG;IACf,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,iBAAiB;CACgB,CAAC;AAE5C,MAAM,IAAI,GAAG,qCAAqC,CAAC;AAEnD;;;;GAIG;AACH,SAAS,WAAW,CAAC,OAA2B;IAC9C,OAAO,CAAC,CAAC,OAAO,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,OAAO,CAAI,IAAY,EAAE,KAAa,EAAE,IAAa;IAClE,MAAM,I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AAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AAClF,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,YAAgC;IAEhC,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;AAC5G,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB,CAC/B,MAAc,EACd,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,MAA4B;IAE5B,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,OAAe,EACf,OAAgC;IAEhC,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAwB,EAAE,OAAO,CAAC,CAAC;AAC7F,CAAC"}
|
package/dist/src/bot.d.ts
CHANGED
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
* - Plugin layer: download media, save via MediaPaths/MediaTypes
|
|
8
8
|
* - OpenClaw runner: handles media understanding (transcription, vision, etc.)
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
error
|
|
15
|
-
|
|
10
|
+
import type { ChannelLogSink, OpenClawConfig } from "openclaw/plugin-sdk";
|
|
11
|
+
import type { ResolvedWechatKfAccount, WechatKfMessage } from "./types.js";
|
|
12
|
+
/** Minimal runtime shape used only for error logging in the reply dispatcher. */
|
|
13
|
+
export type RuntimeErrorLogger = {
|
|
14
|
+
error?: (...args: unknown[]) => void;
|
|
15
|
+
[key: string]: unknown;
|
|
16
16
|
};
|
|
17
17
|
export type BotContext = {
|
|
18
18
|
cfg: OpenClawConfig;
|
|
19
|
-
runtime?:
|
|
19
|
+
runtime?: RuntimeErrorLogger;
|
|
20
20
|
stateDir: string;
|
|
21
|
-
log?:
|
|
21
|
+
log?: ChannelLogSink;
|
|
22
22
|
};
|
|
23
23
|
declare function isDuplicate(msgid: string): boolean;
|
|
24
24
|
/** Exposed for testing only — do not use in production code. */
|
|
@@ -28,8 +28,10 @@ export declare const _testing: {
|
|
|
28
28
|
isDuplicate: typeof isDuplicate;
|
|
29
29
|
DEDUP_MAX_SIZE: number;
|
|
30
30
|
handleEvent: typeof handleEvent;
|
|
31
|
+
drainToLatestCursor: typeof drainToLatestCursor;
|
|
31
32
|
resetState(): void;
|
|
32
33
|
};
|
|
33
34
|
declare function handleEvent(ctx: BotContext, _account: ResolvedWechatKfAccount, msg: WechatKfMessage): Promise<void>;
|
|
35
|
+
declare function drainToLatestCursor(corpId: string, appSecret: string, openKfId: string, syncToken: string, stateDir: string, log?: ChannelLogSink): Promise<void>;
|
|
34
36
|
export declare function handleWebhookEvent(ctx: BotContext, openKfId: string, syncToken: string): Promise<void>;
|
|
35
37
|
export {};
|