Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.3 KB
Raw Blame
import { readRequestText, RequestBodyError } from "@/lib/security/request-body";
import { NextRequest, NextResponse } from "next/server";
import { ChannelError, dispatchChannelInbound, receiveDiscord } from "@/lib/channels";
import { admitChannelWebhook } from "@/lib/channels/webhook-admission";
import { channelWorkflowRuntime } from "../../workflow-runtime";

export async function handlePostDiscord(req: NextRequest, id: string) {
  try {
    admitChannelWebhook(req, id);
    const body = await readRequestText(req, 1024 * 1024);
    const result = await receiveDiscord(id, body, req.headers.get("x-signature-timestamp"), req.headers.get("x-signature-ed25519"));
    if (result.ping) return NextResponse.json({ type: 1 });
    if (!result.event) throw new ChannelError("invalid_discord_interaction");
    const dispatched = await dispatchChannelInbound(id, result.event, channelWorkflowRuntime());
    return NextResponse.json({ type: 4, data: { content: dispatched.workflow ? "Workflow started." : "Received by MSO Channels.", flags: 64 } });
  } catch (error) {
    const value = error instanceof ChannelError ? error : error instanceof RequestBodyError ? new ChannelError(error.message, error.status) : new ChannelError("invalid_channel_interaction");
    return NextResponse.json({ error: value.code }, { status: value.status });
  }
}