1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { respondToDiscordCommand } from "https://esm.town/v/demo/respondToDiscordCommand";
import { naclValidateRequest } from "https://esm.town/v/demo/naclValidateRequest";
import process from "node:process";
export let discordInteractionHook = async (
req: express.Request,
res: express.Response,
) => {
// https://discord.com/developers/applications/<application_id>/information
const pub = process.env.personalBotPublicKey;
if (!(await naclValidateRequest(req, pub))) {
return res.status(401).end("invalid request signature");
}
// Handle ping request
// https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction
if (req.body["type"] == 1) {
res.json({ type: 1 });
return;
}
// Logic
console.log(req.body);
res.json(respondToDiscordCommand(req.body));
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.