export default async function(req: Request): Promise<Response> {
if (req.method === "GET") {
const url = new URL(req.url);
const mode = url.searchParams.get("hub.mode");
const token = url.searchParams.get("hub.verify_token");
const challenge = url.searchParams.get("hub.challenge");
if (mode === "subscribe" && token === Deno.env.get("WHATSAPP_WEBHOOK_VERIFY_TOKEN")) {
return new Response(challenge, { status: 200 });
}
return Response.json({ error: "Invalid verify token" }, { status: 403 });
}
if (req.method === "POST") {
return Response.json({ status: 200 });
}
return Response.json({ error: "Method Not Allowed" }, { status: 405 });
}