@eclaw/openclaw-channel 1.2.1 → 1.2.2
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/dist/index.js +12 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,9 +21,16 @@ import { dispatchWebhook } from './webhook-registry.js';
|
|
|
21
21
|
* so no separate port is needed. Set webhookUrl to your OpenClaw public URL
|
|
22
22
|
* (e.g. https://eclaw2.zeabur.app) so E-Claw knows where to push messages.
|
|
23
23
|
*/
|
|
24
|
-
/** Parse JSON body from a raw incoming request
|
|
24
|
+
/** Parse JSON body from a raw incoming request.
|
|
25
|
+
* If the gateway framework already parsed the body (e.g. Express json middleware),
|
|
26
|
+
* skip re-reading the consumed stream to avoid overwriting req.body with {}.
|
|
27
|
+
*/
|
|
25
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
29
|
function parseBody(req) {
|
|
30
|
+
// Gateway already parsed the body — don't overwrite it
|
|
31
|
+
if (req.body && typeof req.body === 'object' && Object.keys(req.body).length > 0) {
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
}
|
|
27
34
|
return new Promise((resolve) => {
|
|
28
35
|
let body = '';
|
|
29
36
|
req.on('data', (chunk) => { body += chunk.toString(); });
|
|
@@ -32,7 +39,10 @@ function parseBody(req) {
|
|
|
32
39
|
req.body = JSON.parse(body);
|
|
33
40
|
}
|
|
34
41
|
catch {
|
|
35
|
-
|
|
42
|
+
// Only set empty fallback if body wasn't pre-parsed
|
|
43
|
+
if (!req.body || typeof req.body !== 'object') {
|
|
44
|
+
req.body = {};
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
resolve();
|
|
38
48
|
});
|