diff --git a/api/src/channel/lib/__test__/common.mock.ts b/api/src/channel/lib/__test__/common.mock.ts index a45304b5..9bceceae 100644 --- a/api/src/channel/lib/__test__/common.mock.ts +++ b/api/src/channel/lib/__test__/common.mock.ts @@ -117,7 +117,7 @@ export const contentMessage: StdOutgoingListMessage = { desc: 'About being first', thumbnail: { type: 'image', - payload: { attachment_id: attachment.id }, + payload: { id: attachment.id }, }, getPayload() { return this.title; @@ -133,7 +133,7 @@ export const contentMessage: StdOutgoingListMessage = { desc: 'About being second', thumbnail: { type: 'image', - payload: { attachment_id: attachment.id }, + payload: { id: attachment.id }, }, getPayload() { return this.title; @@ -153,7 +153,7 @@ export const contentMessage: StdOutgoingListMessage = { export const attachmentMessage: StdOutgoingAttachmentMessage = { attachment: { type: FileType.image, - payload: { attachment_id: attachment.id }, + payload: { id: attachment.id }, }, quickReplies: [ { diff --git a/api/src/chat/repositories/block.repository.ts b/api/src/chat/repositories/block.repository.ts index 31b0bacd..f7a50609 100644 --- a/api/src/chat/repositories/block.repository.ts +++ b/api/src/chat/repositories/block.repository.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. @@ -57,7 +57,7 @@ export class BlockRepository extends BaseRepository< 'url' in block.message.attachment.payload ) { this.logger?.error( - 'NOTE: `url` payload has been deprecated in favor of `attachment_id`', + 'NOTE: `url` payload has been deprecated in favor of `id`', block.name, ); } diff --git a/api/src/chat/schemas/types/attachment.ts b/api/src/chat/schemas/types/attachment.ts index 7c5ea4c4..0a3afe28 100644 --- a/api/src/chat/schemas/types/attachment.ts +++ b/api/src/chat/schemas/types/attachment.ts @@ -15,8 +15,8 @@ export enum FileType { } export type AttachmentForeignKey = { - attachment_id: string | null; - /** @deprecated use "attachment_id" instead */ + id: string | null; + /** @deprecated use "id" instead */ url?: string; }; diff --git a/api/src/chat/services/block.service.spec.ts b/api/src/chat/services/block.service.spec.ts index 48c59eb8..e81840bb 100644 --- a/api/src/chat/services/block.service.spec.ts +++ b/api/src/chat/services/block.service.spec.ts @@ -390,7 +390,7 @@ describe('BlockService', () => { attachments: { type: FileType.file, payload: { - attachment_id: '9'.repeat(24), + id: '9'.repeat(24), url: 'http://link.to/the/file', }, }, diff --git a/api/src/chat/services/block.service.ts b/api/src/chat/services/block.service.ts index 9c778e1a..3e4c0418 100644 --- a/api/src/chat/services/block.service.ts +++ b/api/src/chat/services/block.service.ts @@ -411,7 +411,7 @@ export class BlockService extends BaseService { 'url' in block.message.attachment.payload ) { this.logger.error( - 'Attachment Model : `url` payload has been deprecated in favor of `attachment_id`', + 'Attachment Model : `url` payload has been deprecated in favor of `id`', block.id, block.message, ); @@ -521,7 +521,7 @@ export class BlockService extends BaseService { } } else if (blockMessage && 'attachment' in blockMessage) { const attachmentPayload = blockMessage.attachment.payload; - if (!attachmentPayload.attachment_id) { + if (!attachmentPayload.id) { this.checkDeprecatedAttachmentUrl(block); throw new Error('Remote attachments are no longer supported!'); } diff --git a/api/src/chat/validation-rules/is-message.ts b/api/src/chat/validation-rules/is-message.ts index fbd1589b..67688d94 100644 --- a/api/src/chat/validation-rules/is-message.ts +++ b/api/src/chat/validation-rules/is-message.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. @@ -71,7 +71,7 @@ export function isValidMessage(msg: any) { .required(), payload: Joi.object().keys({ url: Joi.string().uri(), - attachment_id: Joi.string().allow(null), + id: Joi.string().allow(null), }), }), elements: Joi.boolean(), diff --git a/api/src/extensions/channels/web/__test__/events.mock.ts b/api/src/extensions/channels/web/__test__/events.mock.ts index 9be7b095..1c85ac63 100644 --- a/api/src/extensions/channels/web/__test__/events.mock.ts +++ b/api/src/extensions/channels/web/__test__/events.mock.ts @@ -149,14 +149,14 @@ export const webEvents: [string, Web.IncomingMessage, any][] = [ attachments: { type: FileType.image, payload: { - attachment_id: '9'.repeat(24), + id: '9'.repeat(24), }, }, }, message: { attachment: { payload: { - attachment_id: '9'.repeat(24), + id: '9'.repeat(24), }, type: FileType.image, }, diff --git a/api/src/extensions/channels/web/base-web-channel.ts b/api/src/extensions/channels/web/base-web-channel.ts index 45a9a466..84719b9a 100644 --- a/api/src/extensions/channels/web/base-web-channel.ts +++ b/api/src/extensions/channels/web/base-web-channel.ts @@ -155,9 +155,7 @@ export default abstract class BaseWebChannelHandler< type: Web.IncomingMessageType.file, data: { type: attachmentPayload.type, - url: await this.getPublicUrl( - attachmentPayload.payload.attachment_id, - ), + url: await this.getPublicUrl(attachmentPayload.payload.id), }, }; } @@ -992,7 +990,7 @@ export default abstract class BaseWebChannelHandler< type: Web.OutgoingMessageType.file, data: { type: message.attachment.type, - url: await this.getPublicUrl(message.attachment.payload.attachment_id), + url: await this.getPublicUrl(message.attachment.payload.id), }, }; if (message.quickReplies && message.quickReplies.length > 0) { @@ -1034,10 +1032,8 @@ export default abstract class BaseWebChannelHandler< if (fields.image_url && item[fields.image_url]) { const attachmentPayload = item[fields.image_url] .payload as AttachmentForeignKey; - if (attachmentPayload.attachment_id) { - element.image_url = await this.getPublicUrl( - attachmentPayload.attachment_id, - ); + if (attachmentPayload.id) { + element.image_url = await this.getPublicUrl(attachmentPayload.id); } } diff --git a/api/src/extensions/channels/web/wrapper.ts b/api/src/extensions/channels/web/wrapper.ts index 03f737c6..b26cf7ac 100644 --- a/api/src/extensions/channels/web/wrapper.ts +++ b/api/src/extensions/channels/web/wrapper.ts @@ -224,7 +224,7 @@ export default class WebEventWrapper extends EventWrapper attachments: { type: Attachment.getTypeByMime(this._adapter.raw.data.type), payload: { - attachment_id: this._adapter.attachment.id, + id: this._adapter.attachment.id, }, }, }; @@ -278,7 +278,7 @@ export default class WebEventWrapper extends EventWrapper attachment: { type: fileType, payload: { - attachment_id: this._adapter.attachment.id, + id: this._adapter.attachment.id, }, }, }; diff --git a/api/src/utils/test/fixtures/block.ts b/api/src/utils/test/fixtures/block.ts index b66611ce..a167268c 100644 --- a/api/src/utils/test/fixtures/block.ts +++ b/api/src/utils/test/fixtures/block.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. @@ -9,7 +9,7 @@ import mongoose from 'mongoose'; import { BlockCreateDto } from '@/chat/dto/block.dto'; -import { BlockModel, Block } from '@/chat/schemas/block.schema'; +import { Block, BlockModel } from '@/chat/schemas/block.schema'; import { CategoryModel } from '@/chat/schemas/category.schema'; import { FileType } from '@/chat/schemas/types/attachment'; import { ButtonType } from '@/chat/schemas/types/button'; @@ -131,7 +131,7 @@ export const blocks: BlockCreateDto[] = [ attachment: { type: FileType.image, payload: { - attachment_id: '1', + id: '1', }, }, quickReplies: [], diff --git a/api/src/utils/test/fixtures/content.ts b/api/src/utils/test/fixtures/content.ts index 33c3d379..d2dbe5de 100644 --- a/api/src/utils/test/fixtures/content.ts +++ b/api/src/utils/test/fixtures/content.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. @@ -99,7 +99,7 @@ const contents: ContentCreateDto[] = [ image: { type: 'image', payload: { - attachment_id: null, + id: null, }, }, }, @@ -111,7 +111,7 @@ const contents: ContentCreateDto[] = [ image: { type: 'image', payload: { - attachment_id: null, + id: null, }, }, }, @@ -151,8 +151,7 @@ export const installContentFixtures = async () => { ({ name }) => name === `${contentFixture.title.replace(' ', '')}.jpg`, ); if (attachment) { - contentFixture.dynamicFields.image.payload.attachment_id = - attachment.id; + contentFixture.dynamicFields.image.payload.id = attachment.id; } return { ...contentFixture, diff --git a/api/src/utils/test/mocks/block.ts b/api/src/utils/test/mocks/block.ts index 1c8d3c58..171ad2a1 100644 --- a/api/src/utils/test/mocks/block.ts +++ b/api/src/utils/test/mocks/block.ts @@ -1,5 +1,5 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. @@ -189,7 +189,7 @@ export const attachmentBlock: BlockFull = { type: FileType.image, payload: { url: 'https://fr.facebookbrand.com/wp-content/uploads/2016/09/messenger_icon2.png', - attachment_id: '1234', + id: '1234', }, }, quickReplies: [], diff --git a/frontend/src/components/contents/ContentDialog.tsx b/frontend/src/components/contents/ContentDialog.tsx index 8b2e965a..c04b3a75 100644 --- a/frontend/src/components/contents/ContentDialog.tsx +++ b/frontend/src/components/contents/ContentDialog.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import LinkIcon from "@mui/icons-material/Link"; import { Dialog, @@ -110,9 +111,9 @@ const ContentFieldInput: React.FC = ({ })} {...field} onChange={(id, mimeType) => { - field.onChange({ type: mimeType, payload: { attachment_id: id } }); + field.onChange({ type: mimeType, payload: { id } }); }} - value={field.value?.payload?.attachment_id} + value={field.value?.payload?.id} accept={MIME_TYPES["images"].join(",")} format="full" /> diff --git a/frontend/src/components/visual-editor/constants.ts b/frontend/src/components/visual-editor/constants.ts index c84bf8b8..2dcc132d 100644 --- a/frontend/src/components/visual-editor/constants.ts +++ b/frontend/src/components/visual-editor/constants.ts @@ -36,7 +36,7 @@ export const ATTACHMENT_BLOCK_TEMPLATE: Partial = { message: { attachment: { type: FileType.unknown, - payload: { attachment_id: null }, + payload: { id: null }, }, quickReplies: [], }, diff --git a/frontend/src/components/visual-editor/form/AttachmentMessageForm.tsx b/frontend/src/components/visual-editor/form/AttachmentMessageForm.tsx index 99bc1031..35da99fb 100644 --- a/frontend/src/components/visual-editor/form/AttachmentMessageForm.tsx +++ b/frontend/src/components/visual-editor/form/AttachmentMessageForm.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { Controller, useFormContext } from "react-hook-form"; import AttachmentInput from "@/app-components/attachment/AttachmentInput"; @@ -41,8 +42,7 @@ const AttachmentMessageForm = () => { validate: { required: (value) => { return ( - !!value?.payload?.attachment_id || - t("message.attachment_is_required") + !!value?.payload?.id || t("message.attachment_is_required") ); }, }, @@ -55,7 +55,7 @@ const AttachmentMessageForm = () => { { onChange({ type: type ? getFileType(type) : FileType.unknown, payload: { - attachment_id: id, + id, }, }); }} diff --git a/frontend/src/types/message.types.ts b/frontend/src/types/message.types.ts index 60d63b7d..5e0d4cf0 100644 --- a/frontend/src/types/message.types.ts +++ b/frontend/src/types/message.types.ts @@ -52,8 +52,8 @@ export interface AttachmentAttrs { } export type AttachmentForeignKey = { - attachment_id: string | null; - /** @deprecated use attachment_id instead */ + id: string | null; + /** @deprecated use id instead */ url?: string; };