Saltar al contenido

CIRCE / DOCUMENTACIÓN

Middleware

Hooks globales before y after alrededor de cada interacción.

Menú de documentación

src/middleware.ts envuelve comandos, menús contextuales, componentes y modales.

defineMiddleware({
  before?(ctx: MiddlewareContext): void | Promise<void>,
  after?(ctx: MiddlewareContext): void | Promise<void>,
});

interface MiddlewareContext {
  kind: "command" | "context-menu" | "component" | "modal";
  name: string;            // nombre del comando o customId
  logger: Logger;
  correlationId: string | undefined;
}
import { defineMiddleware } from "@sxnnyside/circe";

export default defineMiddleware({
  async before(ctx) {
    ctx.logger.debug(`inicio ${ctx.kind}:${ctx.name}`);
  },
  async after(ctx) {
    ctx.logger.debug(`fin ${ctx.kind}:${ctx.name}`);
  },
});

El contexto no tiene interaction. Para chequeos por handler usa guards; para métricas usa onInteractionComplete (Salud).