forked from pinks/eris
1
0
Fork 0

api/mod.ts aktualisiert

Create "async function handleWebhook"
This commit is contained in:
Akiru 2024-01-26 07:30:42 +00:00
parent 04b0f9bdf5
commit a7e41b63df
1 changed files with 25 additions and 1 deletions

View File

@ -3,10 +3,34 @@ import { serveSpa } from "serve_spa";
import { api } from "./serveApi.ts"; import { api } from "./serveApi.ts";
import { fromFileUrl } from "std/path/mod.ts"; import { fromFileUrl } from "std/path/mod.ts";
// Export the Webhook Route function so it can be used in bot/mod.ts
export async function handleWebhook(req: Request): Promise<Response> {
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() { export async function serveUi() {
const server = Deno.serve({ port: 5999 }, (request) => const server = Deno.serve({ port: 8443 }, (request) =>
route(request, { route(request, {
"/api/*": (request) => api.fetch(request), "/api/*": (request) => api.fetch(request),
"/webhook": handleWebhook, // Create the Webhook Route handle
"/*": (request) => "/*": (request) =>
serveSpa(request, { serveSpa(request, {
fsRoot: fromFileUrl(new URL("../ui/", import.meta.url)), fsRoot: fromFileUrl(new URL("../ui/", import.meta.url)),