import { sleepSeconds } from './sleep.ts'; import { WEBHOOK_ENDPOINT } from 'astro:env/server'; export enum WebhookAction { Strike = 'strike' } export type WebhookActionType = { [WebhookAction.Strike]: { users: string[]; totalWeight: number; }; }[T]; export async function sendWebhook(action: T, data: WebhookActionType) { if (!WEBHOOK_ENDPOINT || !/^https?:\/\/.+$/.test(WEBHOOK_ENDPOINT)) return; while (true) { try { const response = await fetch(WEBHOOK_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-webhook-action': action }, body: JSON.stringify(data) }); if (response.status === 200) return; } catch (_) {} await sleepSeconds(60); } }