gewe-openclaw 2026.1.29

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Peter Steinberger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # GeWe OpenClaw Plugin
2
+
3
+ 基于 GeWe API + Webhook 回调的 OpenClaw 微信通道插件。
4
+
5
+ ## 安装
6
+
7
+ ### 从 npm 安装
8
+
9
+ ```bash
10
+ openclaw plugins install gewe-openclaw
11
+ ```
12
+
13
+ ### 从本地目录安装
14
+
15
+ ```bash
16
+ openclaw plugins install /path/to/gewe-openclaw
17
+ ```
18
+
19
+ 或使用软链接(便于开发调试):
20
+
21
+ ```bash
22
+ openclaw plugins install --link /path/to/gewe-openclaw
23
+ ```
24
+
25
+ ### 从归档安装
26
+
27
+ OpenClaw 支持本地 `.zip` / `.tgz` / `.tar.gz` / `.tar` 归档:
28
+
29
+ ```bash
30
+ openclaw plugins install ./gewe-openclaw.tgz
31
+ ```
32
+
33
+ > 安装或启用插件后需要重启 Gateway。
34
+
35
+ ## 依赖
36
+
37
+ ### npm 依赖
38
+
39
+ - `zod`
40
+
41
+ ### peer 依赖
42
+
43
+ - `openclaw` (>= 2026.1.29)
44
+
45
+ ### 系统级工具
46
+
47
+ - `ffmpeg` / `ffprobe`(用于视频缩略图与时长)
48
+ - `silk-encoder`(出站语音转 silk)
49
+ - `silk-decoder`(入站语音解码)
50
+
51
+ ### 网络/服务依赖
52
+
53
+ - GeWe API 服务
54
+ - Webhook 回调需要公网可达(可配合 FRP)
55
+ - 媒体对外地址(`mediaPublicUrl`)
56
+
Binary file
package/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+
4
+ import { gewePlugin } from "./src/channel.js";
5
+ import { setGeweRuntime } from "./src/runtime.js";
6
+
7
+ const plugin = {
8
+ id: "gewe",
9
+ name: "GeWe",
10
+ description: "OpenClaw GeWe channel plugin",
11
+ configSchema: emptyPluginConfigSchema(),
12
+ register(api: OpenClawPluginApi) {
13
+ setGeweRuntime(api.runtime);
14
+ api.registerChannel({ plugin: gewePlugin });
15
+ },
16
+ };
17
+
18
+ export default plugin;
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "gewe",
3
+ "channels": [
4
+ "gewe"
5
+ ],
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {}
10
+ }
11
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "gewe-openclaw",
3
+ "version": "2026.1.29",
4
+ "type": "module",
5
+ "description": "OpenClaw GeWe channel plugin",
6
+ "license": "MIT",
7
+ "openclaw": {
8
+ "extensions": [
9
+ "./index.ts"
10
+ ],
11
+ "channel": {
12
+ "id": "gewe",
13
+ "label": "GeWe",
14
+ "selectionLabel": "WeChat (GeWe)",
15
+ "detailLabel": "WeChat (GeWe)",
16
+ "docsPath": "/channels/gewe",
17
+ "docsLabel": "gewe",
18
+ "blurb": "WeChat channel via GeWe API and webhook callbacks.",
19
+ "aliases": [
20
+ "wechat",
21
+ "wx",
22
+ "gewe"
23
+ ],
24
+ "order": 72,
25
+ "quickstartAllowFrom": true
26
+ },
27
+ "install": {
28
+ "npmSpec": "gewe-openclaw",
29
+ "localPath": ".",
30
+ "defaultChoice": "npm"
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "zod": "^4.3.6"
35
+ },
36
+ "peerDependencies": {
37
+ "openclaw": ">=2026.1.29"
38
+ }
39
+ }
@@ -0,0 +1,164 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk";
4
+
5
+ import type { CoreConfig, GeweAccountConfig, GeweAppIdSource, GeweTokenSource } from "./types.js";
6
+
7
+ const DEFAULT_API_BASE_URL = "http://api.geweapi.com";
8
+
9
+ export type ResolvedGeweAccount = {
10
+ accountId: string;
11
+ enabled: boolean;
12
+ name?: string;
13
+ token: string;
14
+ tokenSource: GeweTokenSource;
15
+ appId: string;
16
+ appIdSource: GeweAppIdSource;
17
+ config: GeweAccountConfig;
18
+ };
19
+
20
+ function listConfiguredAccountIds(cfg: CoreConfig): string[] {
21
+ const accounts = cfg.channels?.gewe?.accounts;
22
+ if (!accounts || typeof accounts !== "object") return [];
23
+ const ids = new Set<string>();
24
+ for (const key of Object.keys(accounts)) {
25
+ if (!key) continue;
26
+ ids.add(normalizeAccountId(key));
27
+ }
28
+ return [...ids];
29
+ }
30
+
31
+ export function listGeweAccountIds(cfg: CoreConfig): string[] {
32
+ const ids = listConfiguredAccountIds(cfg);
33
+ if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
34
+ return ids.sort((a, b) => a.localeCompare(b));
35
+ }
36
+
37
+ export function resolveDefaultGeweAccountId(cfg: CoreConfig): string {
38
+ const ids = listGeweAccountIds(cfg);
39
+ if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
40
+ return ids[0] ?? DEFAULT_ACCOUNT_ID;
41
+ }
42
+
43
+ function resolveAccountConfig(cfg: CoreConfig, accountId: string): GeweAccountConfig | undefined {
44
+ const accounts = cfg.channels?.gewe?.accounts;
45
+ if (!accounts || typeof accounts !== "object") return undefined;
46
+ const direct = accounts[accountId] as GeweAccountConfig | undefined;
47
+ if (direct) return direct;
48
+ const normalized = normalizeAccountId(accountId);
49
+ const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
50
+ return matchKey ? (accounts[matchKey] as GeweAccountConfig | undefined) : undefined;
51
+ }
52
+
53
+ function mergeGeweAccountConfig(cfg: CoreConfig, accountId: string): GeweAccountConfig {
54
+ const { accounts: _ignored, ...base } = (cfg.channels?.gewe ?? {}) as GeweAccountConfig & {
55
+ accounts?: unknown;
56
+ };
57
+ const account = resolveAccountConfig(cfg, accountId) ?? {};
58
+ return { ...base, ...account };
59
+ }
60
+
61
+ function resolveToken(
62
+ cfg: CoreConfig,
63
+ accountId: string,
64
+ ): { token: string; source: GeweTokenSource } {
65
+ const merged = mergeGeweAccountConfig(cfg, accountId);
66
+
67
+ const envToken = process.env.GEWE_TOKEN?.trim();
68
+ if (envToken && accountId === DEFAULT_ACCOUNT_ID) {
69
+ return { token: envToken, source: "env" };
70
+ }
71
+
72
+ if (merged.tokenFile) {
73
+ try {
74
+ const fileToken = readFileSync(merged.tokenFile, "utf8").trim();
75
+ if (fileToken) return { token: fileToken, source: "configFile" };
76
+ } catch {
77
+ // ignore read failures
78
+ }
79
+ }
80
+
81
+ if (merged.token?.trim()) {
82
+ return { token: merged.token.trim(), source: "config" };
83
+ }
84
+
85
+ return { token: "", source: "none" };
86
+ }
87
+
88
+ function resolveAppId(
89
+ cfg: CoreConfig,
90
+ accountId: string,
91
+ ): { appId: string; source: GeweAppIdSource } {
92
+ const merged = mergeGeweAccountConfig(cfg, accountId);
93
+
94
+ const envAppId = process.env.GEWE_APP_ID?.trim();
95
+ if (envAppId && accountId === DEFAULT_ACCOUNT_ID) {
96
+ return { appId: envAppId, source: "env" };
97
+ }
98
+
99
+ if (merged.appIdFile) {
100
+ try {
101
+ const fileAppId = readFileSync(merged.appIdFile, "utf8").trim();
102
+ if (fileAppId) return { appId: fileAppId, source: "configFile" };
103
+ } catch {
104
+ // ignore read failures
105
+ }
106
+ }
107
+
108
+ if (merged.appId?.trim()) {
109
+ return { appId: merged.appId.trim(), source: "config" };
110
+ }
111
+
112
+ return { appId: "", source: "none" };
113
+ }
114
+
115
+ export function resolveGeweAccount(params: {
116
+ cfg: CoreConfig;
117
+ accountId?: string | null;
118
+ }): ResolvedGeweAccount {
119
+ const hasExplicitAccountId = Boolean(params.accountId?.trim());
120
+ const baseEnabled = params.cfg.channels?.gewe?.enabled !== false;
121
+
122
+ const resolve = (accountId: string): ResolvedGeweAccount => {
123
+ const merged = mergeGeweAccountConfig(params.cfg, accountId);
124
+ const accountEnabled = merged.enabled !== false;
125
+ const enabled = baseEnabled && accountEnabled;
126
+ const tokenResolution = resolveToken(params.cfg, accountId);
127
+ const appIdResolution = resolveAppId(params.cfg, accountId);
128
+
129
+ if (!merged.apiBaseUrl) {
130
+ merged.apiBaseUrl = DEFAULT_API_BASE_URL;
131
+ } else {
132
+ merged.apiBaseUrl = merged.apiBaseUrl.trim().replace(/\/$/, "");
133
+ }
134
+
135
+ return {
136
+ accountId,
137
+ enabled,
138
+ name: merged.name?.trim() || undefined,
139
+ token: tokenResolution.token,
140
+ tokenSource: tokenResolution.source,
141
+ appId: appIdResolution.appId,
142
+ appIdSource: appIdResolution.source,
143
+ config: merged,
144
+ };
145
+ };
146
+
147
+ const normalized = normalizeAccountId(params.accountId);
148
+ const primary = resolve(normalized);
149
+ if (hasExplicitAccountId) return primary;
150
+ if (primary.tokenSource !== "none" && primary.appIdSource !== "none") return primary;
151
+
152
+ const fallbackId = resolveDefaultGeweAccountId(params.cfg);
153
+ if (fallbackId === primary.accountId) return primary;
154
+ const fallback = resolve(fallbackId);
155
+ if (fallback.tokenSource === "none" || fallback.appIdSource === "none") return primary;
156
+ return fallback;
157
+ }
158
+
159
+ export function listEnabledGeweAccounts(cfg: CoreConfig): ResolvedGeweAccount[] {
160
+ return listGeweAccountIds(cfg)
161
+ .map((accountId) => resolveGeweAccount({ cfg, accountId }))
162
+ .filter((account) => account.enabled);
163
+ }
164
+
package/src/api.ts ADDED
@@ -0,0 +1,53 @@
1
+ export type GeweApiResponse<T> = {
2
+ ret: number;
3
+ msg: string;
4
+ data?: T;
5
+ };
6
+
7
+ export function buildGeweUrl(baseUrl: string, path: string): string {
8
+ const base = baseUrl.replace(/\/$/, "");
9
+ const suffix = path.startsWith("/") ? path : `/${path}`;
10
+ return `${base}${suffix}`;
11
+ }
12
+
13
+ async function readResponseText(res: Response): Promise<string> {
14
+ try {
15
+ return await res.text();
16
+ } catch {
17
+ return "";
18
+ }
19
+ }
20
+
21
+ export async function postGeweJson<T>(params: {
22
+ baseUrl: string;
23
+ token: string;
24
+ path: string;
25
+ body: Record<string, unknown>;
26
+ }): Promise<GeweApiResponse<T>> {
27
+ const url = buildGeweUrl(params.baseUrl, params.path);
28
+ const res = await fetch(url, {
29
+ method: "POST",
30
+ headers: {
31
+ "Content-Type": "application/json",
32
+ "X-GEWE-TOKEN": params.token,
33
+ },
34
+ body: JSON.stringify(params.body),
35
+ });
36
+
37
+ if (!res.ok) {
38
+ const text = await readResponseText(res);
39
+ const detail = text ? `: ${text}` : "";
40
+ throw new Error(`GeWe API request failed (${res.status})${detail}`);
41
+ }
42
+
43
+ const json = (await res.json()) as GeweApiResponse<T>;
44
+ return json;
45
+ }
46
+
47
+ export function assertGeweOk<T>(resp: GeweApiResponse<T>, context: string): T | undefined {
48
+ if (resp.ret !== 200) {
49
+ const msg = resp.msg?.trim() || "unknown error";
50
+ throw new Error(`GeWe API ${context} failed: ${resp.ret} ${msg}`);
51
+ }
52
+ return resp.data;
53
+ }