hono-discord-verify
v0.4.2
Published
A Hono middleware for verifying Discord interactions payload signature.
Downloads
79
Maintainers
Readme
hono-discord-verify
A Discord HTTP bot verification middleware for Hono. Built on top of discord-interactions.
Installation
npm i hono-discord-verify
Usage
import { Hono } from "hono";
import discordVerify from "hono-discord-verify";
import {
InteractionResponseType,
InteractionType,
type APIInteractionResponse,
} from "discord-api-types/v10";
const app = new Hono();
const textRes = (text: string): APIInteractionResponse => ({
type: InteractionResponseType.ChannelMessageWithSource,
data: { content: text },
});
app.post("/interactions", discordVerify(publicKey), (c) => {
const body = c.get("interaction");
if (body.type === InteractionType.ApplicationCommand) {
if (body.data?.name === "ping") {
return c.json(textRes("Pong!"));
}
}
return c.text("invalid interaction", 401);
});
See discord-api-types for types and discord-interactions for more info.