More groups WIP
This commit is contained in:
parent
f20cd5a53c
commit
7be5cb1478
8 changed files with 488 additions and 261 deletions
|
|
@ -9,6 +9,12 @@ const notifyWebhooksTask = async (
|
|||
options: NotifyWebhooksOptions,
|
||||
): Promise<void> => {
|
||||
const { backendId, payload } = options;
|
||||
|
||||
console.log(`[notify-webhooks] Processing webhook notification:`, {
|
||||
backendId,
|
||||
payloadKeys: Object.keys(payload),
|
||||
payload: JSON.stringify(payload, null, 2),
|
||||
});
|
||||
|
||||
const webhooks = await db
|
||||
.selectFrom("Webhook")
|
||||
|
|
@ -16,14 +22,49 @@ const notifyWebhooksTask = async (
|
|||
.where("backendId", "=", backendId)
|
||||
.execute();
|
||||
|
||||
console.log(`[notify-webhooks] Found ${webhooks.length} webhooks for backend ${backendId}`);
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
const { endpointUrl, httpMethod, headers } = webhook;
|
||||
const finalHeaders = { "Content-Type": "application/json", ...headers };
|
||||
const result = await fetch(endpointUrl, {
|
||||
const body = JSON.stringify(payload);
|
||||
|
||||
console.log(`[notify-webhooks] Sending webhook:`, {
|
||||
url: endpointUrl,
|
||||
method: httpMethod,
|
||||
headers: finalHeaders,
|
||||
body: JSON.stringify(payload),
|
||||
bodyLength: body.length,
|
||||
headers: Object.keys(finalHeaders),
|
||||
payload: body,
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await fetch(endpointUrl, {
|
||||
method: httpMethod,
|
||||
headers: finalHeaders,
|
||||
body,
|
||||
});
|
||||
|
||||
console.log(`[notify-webhooks] Webhook response:`, {
|
||||
url: endpointUrl,
|
||||
status: result.status,
|
||||
statusText: result.statusText,
|
||||
ok: result.ok,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
const responseText = await result.text();
|
||||
console.error(`[notify-webhooks] Webhook error response:`, {
|
||||
url: endpointUrl,
|
||||
status: result.status,
|
||||
response: responseText.substring(0, 500), // First 500 chars
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[notify-webhooks] Webhook request failed:`, {
|
||||
url: endpointUrl,
|
||||
error: error instanceof Error ? error.message : error,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue