import { d as defineEventHandler, s as setResponseStatus, t as toWebRequest, e as setResponseHeader, h as useNitroApp, j as createLogger } from '../../../../index.mjs';
import '@anthropic-ai/claude-agent-sdk';
import '@octokit/webhooks';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:process';
import 'consola';
import '@octokit/graphql';
import 'zod';
import '@octokit/auth-app';
import 'node:os';
import '@libsql/client';
import 'liquidjs';
import 'js-yaml';
import 'node:child_process';
import '@chat-adapter/github';
import '@chat-adapter/slack';
import 'chat';
import 'chat-adapter-asana';
import 'better-auth';
import 'better-auth/plugins';
import 'bun:sqlite';
import 'better-auth/db/migration';
import 'node:url';
import '@iconify/utils';
import 'rou3';

const log = createLogger("webhook:slack");
const slack_post = defineEventHandler(async (event) => {
  const nitroApp = useNitroApp();
  const chatBot = nitroApp.chatBot;
  if (!chatBot) {
    setResponseStatus(event, 503);
    return { error: { code: "not_initialized", message: "Chat bot not initialized" } };
  }
  const handler = chatBot.webhooks.slack;
  if (!handler) {
    setResponseStatus(event, 404);
    return { error: { code: "slack_not_configured", message: "Slack adapter not configured" } };
  }
  const request = toWebRequest(event);
  try {
    const response = await handler(request, {
      waitUntil: (promise) => {
        promise.catch((err) => log.error("waitUntil rejected:", err));
      }
    });
    setResponseStatus(event, response.status);
    for (const [key, value] of response.headers.entries()) {
      setResponseHeader(event, key, value);
    }
    const text = await response.text();
    if (!text) {
      return { accepted: true };
    }
    try {
      return JSON.parse(text);
    } catch {
      log.warn("slack webhook response is not JSON:", { status: response.status, body: text.slice(0, 200) });
      return text;
    }
  } catch (err) {
    log.error("slack webhook handler error:", err);
    setResponseStatus(event, 500);
    return { error: { code: "internal_error", message: "Slack webhook processing failed" } };
  }
});

export { slack_post as default };
//# sourceMappingURL=slack.post.mjs.map
