openclaw: force webhook transport to use hooks/wake

This commit is contained in:
Dotta
2026-03-06 16:11:11 -06:00
parent 5ab1c18530
commit aa7e069044
4 changed files with 91 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ import {
isTextRequiredResponse,
isWakeCompatibilityRetryableResponse,
isWakeCompatibilityEndpoint,
normalizeWebhookInvocationUrl,
readAndLogResponseText,
redactForLog,
sendJsonRequest,
@@ -92,29 +93,35 @@ async function sendWebhookRequest(params: {
export async function executeWebhook(ctx: AdapterExecutionContext, url: string): Promise<AdapterExecutionResult> {
const { onLog, onMeta, context } = ctx;
const state = buildExecutionState(ctx);
const webhookTarget = normalizeWebhookInvocationUrl(url);
const webhookUrl = webhookTarget.url;
if (onMeta) {
await onMeta({
adapterType: "openclaw",
command: "webhook",
commandArgs: [state.method, url],
commandArgs: [state.method, webhookUrl],
context,
});
}
const headers = { ...state.headers };
if (isOpenResponsesEndpoint(url) && !headers["x-openclaw-session-key"] && !headers["X-OpenClaw-Session-Key"]) {
if (
isOpenResponsesEndpoint(webhookUrl) &&
!headers["x-openclaw-session-key"] &&
!headers["X-OpenClaw-Session-Key"]
) {
headers["x-openclaw-session-key"] = state.sessionKey;
}
const webhookBody = buildWebhookBody({
url,
url: webhookUrl,
state,
context,
configModel: ctx.config.model,
});
const wakeCompatibilityBody = buildWakeCompatibilityPayload(state.wakeText);
const preferWakeCompatibilityBody = isWakeCompatibilityEndpoint(url);
const preferWakeCompatibilityBody = isWakeCompatibilityEndpoint(webhookUrl);
const initialBody = preferWakeCompatibilityBody ? wakeCompatibilityBody : webhookBody;
const outboundHeaderKeys = Object.keys(headers).sort();
@@ -127,7 +134,13 @@ export async function executeWebhook(ctx: AdapterExecutionContext, url: string):
`[openclaw] outbound payload (redacted): ${stringifyForLog(redactForLog(initialBody), 12_000)}\n`,
);
await onLog("stdout", `[openclaw] outbound header keys: ${outboundHeaderKeys.join(", ")}\n`);
await onLog("stdout", `[openclaw] invoking ${state.method} ${url} (transport=webhook)\n`);
if (webhookTarget.normalizedFromOpenResponses) {
await onLog(
"stdout",
`[openclaw] webhook transport normalized /v1/responses endpoint to ${webhookUrl}\n`,
);
}
await onLog("stdout", `[openclaw] invoking ${state.method} ${webhookUrl} (transport=webhook)\n`);
if (preferWakeCompatibilityBody) {
await onLog("stdout", "[openclaw] using wake text payload for /hooks/wake compatibility\n");
@@ -138,7 +151,7 @@ export async function executeWebhook(ctx: AdapterExecutionContext, url: string):
try {
const initialResponse = await sendWebhookRequest({
url,
url: webhookUrl,
method: state.method,
headers,
payload: initialBody,
@@ -157,7 +170,7 @@ export async function executeWebhook(ctx: AdapterExecutionContext, url: string):
);
const retryResponse = await sendWebhookRequest({
url,
url: webhookUrl,
method: state.method,
headers,
payload: wakeCompatibilityBody,
@@ -172,7 +185,7 @@ export async function executeWebhook(ctx: AdapterExecutionContext, url: string):
timedOut: false,
provider: "openclaw",
model: null,
summary: `OpenClaw webhook ${state.method} ${url} (wake compatibility)`,
summary: `OpenClaw webhook ${state.method} ${webhookUrl} (wake compatibility)`,
resultJson: {
status: retryResponse.response.status,
statusText: retryResponse.response.statusText,
@@ -227,7 +240,7 @@ export async function executeWebhook(ctx: AdapterExecutionContext, url: string):
timedOut: false,
provider: "openclaw",
model: null,
summary: `OpenClaw webhook ${state.method} ${url}`,
summary: `OpenClaw webhook ${state.method} ${webhookUrl}`,
resultJson: {
status: initialResponse.response.status,
statusText: initialResponse.response.statusText,