hono-discord-verify
TypeScript icon, indicating that this package has built-in type declarations

0.4.2 • Public • Published

hono-discord-verify


version ci Downloads

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.

Readme

Keywords

Package Sidebar

Install

npm i hono-discord-verify

Weekly Downloads

3

Version

0.4.2

License

MIT

Unpacked Size

5.79 kB

Total Files

5

Last publish

Collaborators

  • whistlingzephyr