/**
 * DiscordPublisher ; Discord webhook publisher.
 *
 * Promoted from the Forge-local outreach-publish-post skill Discord branch.
 * Webhook-only ; foreign-server posts (e.g. Starknet builders) stay HITL by
 * design ; an unconfigured webhook returns status="dlq" so the orchestrator
 * does not silently drop the action.
 *
 * @public
 */
export class DiscordPublisher {
    channel = "discord";
    cfg;
    constructor(cfg) {
        this.cfg = cfg;
    }
    async isConfigured() {
        return Boolean(this.cfg.webhookUrl);
    }
    async publish(input) {
        if (!this.cfg.webhookUrl) {
            return {
                status: "dlq",
                channel: "discord",
                reason: "DISCORD_WEBHOOK_URL not set ; Discord posting requires a webhook owned by a server the bot is in ; foreign-server posts remain HITL by design",
            };
        }
        const p = input.payload;
        const message = typeof p["message"] === "string" ? p["message"] : "";
        if (!message) {
            return {
                status: "failed",
                channel: "discord",
                error: "discord platform requires payload.message",
            };
        }
        try {
            const res = await fetch(this.cfg.webhookUrl, {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ content: message }),
                signal: AbortSignal.timeout(15_000),
            });
            if (!res.ok && res.status !== 204) {
                const text = (await res.text().catch(() => "")).slice(0, 256);
                return {
                    status: "failed",
                    channel: "discord",
                    error: `discord webhook ${res.status}: ${text}`,
                };
            }
            // Discord webhooks return 204 with no body ; posted_url not available.
            return {
                status: "published",
                channel: "discord",
                posted_id: `discord-${Date.now()}`,
                posted_at: new Date().toISOString(),
            };
        }
        catch (err) {
            return {
                status: "failed",
                channel: "discord",
                error: err.message,
            };
        }
    }
}
//# sourceMappingURL=discord.js.map