diff --git a/api/mod.ts b/api/mod.ts index c03b8fa..c20a30a 100644 --- a/api/mod.ts +++ b/api/mod.ts @@ -2,35 +2,15 @@ import { route } from "reroute"; import { serveSpa } from "serve_spa"; import { api } from "./serveApi.ts"; import { fromFileUrl } from "std/path/mod.ts"; +// New function that handles the webhook +import { handleWebhook } from "../bot/mod.ts"; -// Export the Webhook Route function so it can be used in bot/mod.ts -export async function handleWebhook(req: Request): Promise { - if (req.method === "POST" && new URL(req.url).pathname === "/webhook") { - try { - const body = await req.json(); - console.log("Received webhook data:", JSON.stringify(body, null, 2)); - - // Log before processing update - console.log("Processing update through handleUpdate..."); - await bot.handleUpdate(body); // Process the update - // Log after processing update - console.log("Update processed successfully."); - - return new Response(JSON.stringify({ status: 'ok' }), { headers: { 'Content-Type': 'application/json' } }); - } catch (error) { - // Detailed error logging - console.error("Error in handleRequest or handleUpdate:", error); - return new Response("Error", { status: 500 }); - } - } - return new Response("Not Found", { status: 404 }); -} export async function serveUi() { const server = Deno.serve({ port: 8443 }, (request) => route(request, { "/api/*": (request) => api.fetch(request), - "/webhook": handleWebhook, // Create the Webhook Route handle + "/webhook": handleWebhook, // Create the webhook route handle "/*": (request) => serveSpa(request, { fsRoot: fromFileUrl(new URL("../ui/", import.meta.url)),