Back
Version 45
7/26/2023
let discordInteractionHook = async (
req: express.Request,
res: express.Response,
) => {
// BEGIN:Validate
const { default: nacl } = await import("npm:tweetnacl@1.0.3");
// Your public key can be found on your application in the Developer Portal
const PUBLIC_KEY =
"7e3f109c2f97a7bb8ee9464dedf6c6bab8aae3b256d2f4fb927ce46ae851ccbe";
const signature = req.get("X-Signature-Ed25519");
const timestamp = req.get("X-Signature-Timestamp");
const body = JSON.stringify(req.body); // rawBody is expected to be a string, not raw bytes
const isVerified = nacl.sign.detached.verify(
Buffer.from(timestamp + body),
Buffer.from(signature, "hex"),
Buffer.from(PUBLIC_KEY, "hex"),
);
if (!demo.naclValidate(PUBLIC_KEY, signature, timestamp, body)) {
return res.status(401).end("invalid request signature");
}
// END:Validate
// console.log(req.body);
// console.log(req.header);
if (req.body["type"] == 1) {
res.json({ type: 1 });
}
else {
res.json({
"type": 4,
"data": {
"tts": false,
"content": "Congrats on sending your command!",
"embeds": [],
"allowed_mentions": { "parse": [] },
},
});
Updated: October 23, 2023