@openclaw/zalo 2026.2.12 → 2026.2.13
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/monitor.ts +17 -35
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import type { OpenClawConfig, MarkdownTableMode } from "openclaw/plugin-sdk";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createReplyPrefixOptions,
|
|
5
|
+
readJsonBodyWithLimit,
|
|
6
|
+
requestBodyErrorToText,
|
|
7
|
+
} from "openclaw/plugin-sdk";
|
|
4
8
|
import type { ResolvedZaloAccount } from "./accounts.js";
|
|
5
9
|
import {
|
|
6
10
|
ZaloApiError,
|
|
@@ -61,37 +65,6 @@ function isSenderAllowed(senderId: string, allowFrom: string[]): boolean {
|
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
async function readJsonBody(req: IncomingMessage, maxBytes: number) {
|
|
65
|
-
const chunks: Buffer[] = [];
|
|
66
|
-
let total = 0;
|
|
67
|
-
return await new Promise<{ ok: boolean; value?: unknown; error?: string }>((resolve) => {
|
|
68
|
-
req.on("data", (chunk: Buffer) => {
|
|
69
|
-
total += chunk.length;
|
|
70
|
-
if (total > maxBytes) {
|
|
71
|
-
resolve({ ok: false, error: "payload too large" });
|
|
72
|
-
req.destroy();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
chunks.push(chunk);
|
|
76
|
-
});
|
|
77
|
-
req.on("end", () => {
|
|
78
|
-
try {
|
|
79
|
-
const raw = Buffer.concat(chunks).toString("utf8");
|
|
80
|
-
if (!raw.trim()) {
|
|
81
|
-
resolve({ ok: false, error: "empty payload" });
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
resolve({ ok: true, value: JSON.parse(raw) as unknown });
|
|
85
|
-
} catch (err) {
|
|
86
|
-
resolve({ ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
req.on("error", (err) => {
|
|
90
|
-
resolve({ ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
68
|
type WebhookTarget = {
|
|
96
69
|
token: string;
|
|
97
70
|
account: ResolvedZaloAccount;
|
|
@@ -177,10 +150,19 @@ export async function handleZaloWebhookRequest(
|
|
|
177
150
|
return true;
|
|
178
151
|
}
|
|
179
152
|
|
|
180
|
-
const body = await
|
|
153
|
+
const body = await readJsonBodyWithLimit(req, {
|
|
154
|
+
maxBytes: 1024 * 1024,
|
|
155
|
+
timeoutMs: 30_000,
|
|
156
|
+
emptyObjectOnEmpty: false,
|
|
157
|
+
});
|
|
181
158
|
if (!body.ok) {
|
|
182
|
-
res.statusCode =
|
|
183
|
-
|
|
159
|
+
res.statusCode =
|
|
160
|
+
body.code === "PAYLOAD_TOO_LARGE" ? 413 : body.code === "REQUEST_BODY_TIMEOUT" ? 408 : 400;
|
|
161
|
+
res.end(
|
|
162
|
+
body.code === "REQUEST_BODY_TIMEOUT"
|
|
163
|
+
? requestBodyErrorToText("REQUEST_BODY_TIMEOUT")
|
|
164
|
+
: body.error,
|
|
165
|
+
);
|
|
184
166
|
return true;
|
|
185
167
|
}
|
|
186
168
|
|