0.4.2 • Published 9 months ago

hono-discord-verify v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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.

0.4.2

9 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.3.0

9 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.1.0

9 months ago