2024-12-30 20:18:48 +01:00
|
|
|
import { apiRoute } from "@/api";
|
2024-11-25 16:54:46 +01:00
|
|
|
import { createRoute } from "@hono/zod-openapi";
|
|
|
|
|
import { getLogger } from "@logtape/logtape";
|
|
|
|
|
import chalk from "chalk";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
|
|
const route = createRoute({
|
|
|
|
|
method: "post",
|
|
|
|
|
path: "/messaging",
|
|
|
|
|
summary: "Endpoint for the Instance Messaging Versia Extension.",
|
|
|
|
|
description: "https://versia.pub/extensions/instance-messaging.",
|
|
|
|
|
request: {
|
|
|
|
|
body: {
|
|
|
|
|
content: {
|
|
|
|
|
"text/plain": {
|
|
|
|
|
schema: z.string(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Message saved",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
const content = await context.req.text();
|
|
|
|
|
|
|
|
|
|
getLogger(["federation", "messaging"])
|
|
|
|
|
.info`Received message via ${chalk.bold("Instance Messaging")}:\n${content}`;
|
|
|
|
|
|
2024-12-07 13:24:24 +01:00
|
|
|
return context.text("", 200);
|
2024-11-25 16:54:46 +01:00
|
|
|
}),
|
|
|
|
|
);
|