openclaw-wechat-channel 0.3.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.mjs +34 -26
  2. package/package.json +1 -4
package/dist/index.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  import { DEFAULT_ACCOUNT_ID, createReplyPrefixContext, emptyPluginConfigSchema } from "openclaw/plugin-sdk";
2
2
  import http from "node:http";
3
- import { H3, defineEventHandler, readBody } from "h3";
4
- import { toNodeHandler } from "h3/node";
5
3
 
6
4
  //#region src/proxy-client.ts
7
5
  var ProxyClient = class {
@@ -280,16 +278,26 @@ async function handleWeChatMessage(params) {
280
278
  //#region src/callback-server.ts
281
279
  async function startCallbackServer(options) {
282
280
  const { port, apiKey, onMessage, abortSignal } = options;
283
- const app = new H3();
284
- app.post("/webhook/wechat", defineEventHandler(async (event) => {
285
- const incomingKey = event.req.headers.get("x-api-key");
286
- if (apiKey && incomingKey !== apiKey) throw createHttpError(401, "Unauthorized");
287
- const message = convertToMessageContext(await readBody(event));
288
- if (message) onMessage(message);
289
- return "OK";
290
- }));
291
- const handler = toNodeHandler(app);
292
- const server = http.createServer(handler);
281
+ const server = http.createServer((req, res) => {
282
+ if ((req.url?.split("?")[0] || "") === "/webhook/wechat" && req.method === "POST") {
283
+ const incomingKey = req.headers["x-api-key"];
284
+ if (apiKey && incomingKey !== apiKey) {
285
+ res.writeHead(401).end("Unauthorized");
286
+ return;
287
+ }
288
+ let body = "";
289
+ req.on("data", (chunk) => body += chunk);
290
+ req.on("end", () => {
291
+ try {
292
+ const message = convertToMessageContext(JSON.parse(body));
293
+ if (message) onMessage(message);
294
+ res.writeHead(200).end("OK");
295
+ } catch {
296
+ res.writeHead(400).end("Bad Request");
297
+ }
298
+ });
299
+ } else res.writeHead(404).end("Not Found");
300
+ });
293
301
  return new Promise((resolve, reject) => {
294
302
  server.listen(port, "0.0.0.0", () => {
295
303
  const addr = server.address();
@@ -312,11 +320,6 @@ async function startCallbackServer(options) {
312
320
  });
313
321
  });
314
322
  }
315
- function createHttpError(statusCode, message) {
316
- const error = new Error(message);
317
- error.statusCode = statusCode;
318
- return error;
319
- }
320
323
  function normalizePayload(payload) {
321
324
  const { messageType, wcId } = payload;
322
325
  if (payload.fromUser) return {
@@ -838,15 +841,20 @@ const wechatPlugin = {
838
841
  runningServers.set(accountId, stop);
839
842
  log?.info(`WeChat account ${accountId} started successfully on port ${port}`);
840
843
  log?.info(`Webhook URL: ${webhookUrl}`);
841
- return { async stop() {
842
- stop();
843
- runningServers.delete(accountId);
844
- setStatus({
845
- accountId,
846
- port,
847
- running: false
848
- });
849
- } };
844
+ await new Promise((resolve) => {
845
+ if (abortSignal?.aborted) {
846
+ resolve();
847
+ return;
848
+ }
849
+ abortSignal?.addEventListener("abort", () => resolve());
850
+ });
851
+ stop();
852
+ runningServers.delete(accountId);
853
+ setStatus({
854
+ accountId,
855
+ port,
856
+ running: false
857
+ });
850
858
  } },
851
859
  outbound: {
852
860
  deliveryMode: "direct",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "openclaw-wechat-channel",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "packageManager": "pnpm@10.30.0",
6
6
  "description": "OpenClaw WeChat channel plugin via Proxy API",
7
7
  "license": "MIT",
@@ -63,9 +63,6 @@
63
63
  "peerDependencies": {
64
64
  "openclaw": ">=2026.2.9"
65
65
  },
66
- "dependencies": {
67
- "h3": "2.0.1-rc.14"
68
- },
69
66
  "devDependencies": {
70
67
  "@antfu/eslint-config": "^7.4.3",
71
68
  "@types/node": "^25.3.0",