WhatsApp/Signal/Formstack/admin updates

This commit is contained in:
Darren Clarke 2025-11-21 14:55:28 +01:00
parent bcecf61a46
commit d0cc5a21de
451 changed files with 16139 additions and 39623 deletions

View file

@ -1,4 +1,7 @@
import { db } from "@link-stack/bridge-common";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('notify-webhooks');
export interface NotifyWebhooksOptions {
backendId: string;
@ -9,6 +12,11 @@ const notifyWebhooksTask = async (
options: NotifyWebhooksOptions,
): Promise<void> => {
const { backendId, payload } = options;
logger.debug({
backendId,
payloadKeys: Object.keys(payload),
}, 'Processing webhook notification');
const webhooks = await db
.selectFrom("Webhook")
@ -16,16 +24,48 @@ const notifyWebhooksTask = async (
.where("backendId", "=", backendId)
.execute();
logger.debug({ count: webhooks.length, backendId }, 'Found webhooks');
for (const webhook of webhooks) {
const { endpointUrl, httpMethod, headers } = webhook;
const finalHeaders = { "Content-Type": "application/json", ...headers };
console.log({ endpointUrl, httpMethod, headers, finalHeaders });
const result = await fetch(endpointUrl, {
const body = JSON.stringify(payload);
logger.debug({
url: endpointUrl,
method: httpMethod,
headers: finalHeaders,
body: JSON.stringify(payload),
});
console.log(result);
bodyLength: body.length,
headerKeys: Object.keys(finalHeaders),
}, 'Sending webhook');
try {
const result = await fetch(endpointUrl, {
method: httpMethod,
headers: finalHeaders,
body,
});
logger.debug({
url: endpointUrl,
status: result.status,
statusText: result.statusText,
ok: result.ok,
}, 'Webhook response');
if (!result.ok) {
const responseText = await result.text();
logger.error({
url: endpointUrl,
status: result.status,
responseSample: responseText.substring(0, 500),
}, 'Webhook error response');
}
} catch (error) {
logger.error({
url: endpointUrl,
error: error instanceof Error ? error.message : error,
}, 'Webhook request failed');
}
}
};