1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import process from "node:process";
import { verify_discord_signature } from "https://esm.town/v/mattx/verify_discord_signature?v=8";
export const handleDiscordInteraction = async (req: Request) => {
const body = await req.json();
const verified = await verify_discord_signature(
process.env.discordPublicIP,
JSON.stringify(body),
req.headers.get("X-Signature-Ed25519"),
req.headers.get("X-Signature-Timestamp"),
);
if (!verified) {
return new Response("signature invalid", {
status: 401,
statusText: "signature invalid",
});
}
// Check for the "call gali" command
if (body.type === 1) {
return Response.json({ type: 1 }); // PONG
}
else if (body.type === 2 && body.data?.name === "call gali") {
return Response.json({
type: 4,
data: {
content: "khanki chumu dau",
},
});
}
else {
return new Response("Not handled", { status: 422 });
}
};
// Handle other interactions here
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023