From 1c35eff513ab6fab97afc7986ba6a67bd056107b Mon Sep 17 00:00:00 2001 From: CyberFlame Date: Mon, 28 Oct 2024 06:50:52 +1300 Subject: [PATCH] hopefully enables webhook ingestion Signed-off-by: CyberFlame --- src/server.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/server.ts b/src/server.ts index 013252f..3183a40 100644 --- a/src/server.ts +++ b/src/server.ts @@ -240,6 +240,21 @@ router.get('/oauth-callback', async (c) => { } }); +router.post('/webhooks', async (c) => { + const signature = c.req.header('x-signature-ed25519')!; + const timestamp = c.req.header('x-signature-timestamp')!; + const body = await c.req.text(); + if (!(await verifyKey(body, signature as string, timestamp, c.env.DISCORD_PUBLIC_KEY))) + return new Response('Invalid request', { status: 401 }); + const interaction = await c.req.json(); + + switch (interaction["type"]) { + case "PING": { + return Response(status=204) + } + } +} + router.all('*', () => new Response('Not Found.', { status: 404 })); export default router;