summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-07-08 21:46:04 +0200
committerRory& <root@rory.gay>2026-07-15 00:27:03 +0200
commitdf705baba04b706e7d2f94ef6be5e9f38dc5a2df (patch)
treebc589472cf1a01f0b63bf7106ecd89dff874dfd7
parentFix webhook message edit test (diff)
downloadserver-ts-df705baba04b706e7d2f94ef6be5e9f38dc5a2df.tar.xz
Fix webhook edit
-rw-r--r--assets/openapi.json107
-rw-r--r--assets/schemas.json26
-rw-r--r--src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts25
-rw-r--r--src/schemas/uncategorised/WebhookExecuteSchema.ts9
4 files changed, 12 insertions, 155 deletions
diff --git a/assets/openapi.json b/assets/openapi.json

index e8acfd44..34fff09f 100644 --- a/assets/openapi.json +++ b/assets/openapi.json
@@ -7001,31 +7001,7 @@ } }, "allowed_mentions": { - "type": "object", - "properties": { - "parse": { - "type": "array", - "items": { - "type": "string" - } - }, - "roles": { - "type": "array", - "items": { - "type": "string" - } - }, - "users": { - "type": "array", - "items": { - "type": "string" - } - }, - "replied_user": { - "type": "boolean" - } - }, - "additionalProperties": false + "$ref": "#/components/schemas/AllowedMentions" }, "components": { "type": "array", @@ -14993,86 +14969,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/MessageEditSchema" - } - } - } - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Message" - } - } - } - }, - "400": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/APIErrorResponse" - } - } - } - }, - "403": { - "description": "No description available" - }, - "404": { - "description": "No description available" - } - }, - "parameters": [ - { - "name": "webhook_id", - "in": "path", - "required": true, - "schema": { - "type": "string" - }, - "description": "webhook_id" - }, - { - "name": "webhook_token", - "in": "path", - "required": true, - "schema": { - "type": "string" - }, - "description": "webhook_token" - }, - { - "name": "message_id", - "in": "path", - "required": true, - "schema": { - "type": "string" - }, - "description": "message_id" - } - ], - "tags": [ - "webhooks" - ] - }, - "put": { - "x-right-required": "SEND_BACKDATED_EVENTS", - "x-permission-required": "SEND_MESSAGES", - "security": [ - { - "bearer": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MessageCreateSchema" + "$ref": "#/components/schemas/WebhookExecuteSchema" } } } diff --git a/assets/schemas.json b/assets/schemas.json
index 57dd9d6a..06555dbf 100644 --- a/assets/schemas.json +++ b/assets/schemas.json
@@ -7461,31 +7461,7 @@ } }, "allowed_mentions": { - "type": "object", - "properties": { - "parse": { - "type": "array", - "items": { - "type": "string" - } - }, - "roles": { - "type": "array", - "items": { - "type": "string" - } - }, - "users": { - "type": "array", - "items": { - "type": "string" - } - }, - "replied_user": { - "type": "boolean" - } - }, - "additionalProperties": false + "$ref": "#/definitions/AllowedMentions" }, "components": { "type": "array", diff --git a/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts b/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts
index 0902765c..8d69512a 100644 --- a/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts +++ b/src/api/routes/webhooks/#webhook_id/#webhook_token/messages/#message_id.ts
@@ -20,21 +20,9 @@ import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server/HTTPError"; import multer from "multer"; import { handleMessage, postHandleMessage, route } from "@spacebar/api/util"; -import { Attachment, Channel, Message, Webhook } from "@spacebar/database"; -import { - MessageCreateEvent, - MessageDeleteEvent, - MessageUpdateEvent, - Snowflake, - SpacebarApiErrors, - emitEvent, - getPermission, - getRights, - uploadFile, - NewUrlUserSignatureData, - DiscordApiErrors, -} from "@spacebar/util"; -import { MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageEditSchema, ChannelType } from "@spacebar/schemas"; +import { Channel, Message, Webhook } from "@spacebar/database"; +import { MessageDeleteEvent, MessageUpdateEvent, emitEvent, DiscordApiErrors } from "@spacebar/util"; +import { ChannelType, WebhookExecuteSchema } from "@spacebar/schemas"; const router = Router({ mergeParams: true }); // TODO: message content/embed string length limit @@ -63,7 +51,7 @@ const messageUpload = multer({ router.patch( "/", route({ - requestBody: "MessageEditSchema", + requestBody: "WebhookExecuteSchema", responses: { 200: { body: "Message", @@ -77,7 +65,7 @@ router.patch( }), async (req: Request, res: Response) => { const { webhook_id, webhook_token, message_id } = req.params as { [key: string]: string }; - const body = req.body as MessageEditSchema; + const body = req.body as WebhookExecuteSchema; await assertValidWebhookAuth(webhook_id, webhook_token, message_id); @@ -91,7 +79,8 @@ router.patch( // TODO: should message_reference be overridable? message_reference: message.message_reference, ...body, - author_id: message.author_id, + // author_id: message.author_id, + author_id: undefined, // skip rights check webhook_id: message.webhook_id, channel_id: message.channel_id, id: message_id, diff --git a/src/schemas/uncategorised/WebhookExecuteSchema.ts b/src/schemas/uncategorised/WebhookExecuteSchema.ts
index 147a2d1a..655a239c 100644 --- a/src/schemas/uncategorised/WebhookExecuteSchema.ts +++ b/src/schemas/uncategorised/WebhookExecuteSchema.ts
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Embed } from "@spacebar/schemas"; +import { AllowedMentions, Embed } from "@spacebar/schemas"; import { MessageCreateAttachment, PollCreationSchema } from "./MessageCreateSchema"; export interface WebhookExecuteSchema { @@ -25,12 +25,7 @@ export interface WebhookExecuteSchema { avatar_url?: string; tts?: boolean; embeds?: Embed[]; - allowed_mentions?: { - parse?: string[]; - roles?: string[]; - users?: string[]; - replied_user?: boolean; - }; + allowed_mentions?: AllowedMentions; // eslint-disable-next-line @typescript-eslint/no-explicit-any components?: any[]; file?: { filename: string };