fix: rename attachment_id to id

This commit is contained in:
Mohamed Marrouchi 2025-01-09 18:05:53 +01:00
parent 20cf7171fa
commit 0ac7d7cac5
16 changed files with 41 additions and 45 deletions

View File

@ -117,7 +117,7 @@ export const contentMessage: StdOutgoingListMessage = {
desc: 'About being first', desc: 'About being first',
thumbnail: { thumbnail: {
type: 'image', type: 'image',
payload: { attachment_id: attachment.id }, payload: { id: attachment.id },
}, },
getPayload() { getPayload() {
return this.title; return this.title;
@ -133,7 +133,7 @@ export const contentMessage: StdOutgoingListMessage = {
desc: 'About being second', desc: 'About being second',
thumbnail: { thumbnail: {
type: 'image', type: 'image',
payload: { attachment_id: attachment.id }, payload: { id: attachment.id },
}, },
getPayload() { getPayload() {
return this.title; return this.title;
@ -153,7 +153,7 @@ export const contentMessage: StdOutgoingListMessage = {
export const attachmentMessage: StdOutgoingAttachmentMessage = { export const attachmentMessage: StdOutgoingAttachmentMessage = {
attachment: { attachment: {
type: FileType.image, type: FileType.image,
payload: { attachment_id: attachment.id }, payload: { id: attachment.id },
}, },
quickReplies: [ quickReplies: [
{ {

View File

@ -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: * 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. * 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 'url' in block.message.attachment.payload
) { ) {
this.logger?.error( 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, block.name,
); );
} }

View File

@ -15,8 +15,8 @@ export enum FileType {
} }
export type AttachmentForeignKey = { export type AttachmentForeignKey = {
attachment_id: string | null; id: string | null;
/** @deprecated use "attachment_id" instead */ /** @deprecated use "id" instead */
url?: string; url?: string;
}; };

View File

@ -390,7 +390,7 @@ describe('BlockService', () => {
attachments: { attachments: {
type: FileType.file, type: FileType.file,
payload: { payload: {
attachment_id: '9'.repeat(24), id: '9'.repeat(24),
url: 'http://link.to/the/file', url: 'http://link.to/the/file',
}, },
}, },

View File

@ -411,7 +411,7 @@ export class BlockService extends BaseService<Block, BlockPopulate, BlockFull> {
'url' in block.message.attachment.payload 'url' in block.message.attachment.payload
) { ) {
this.logger.error( 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.id,
block.message, block.message,
); );
@ -521,7 +521,7 @@ export class BlockService extends BaseService<Block, BlockPopulate, BlockFull> {
} }
} else if (blockMessage && 'attachment' in blockMessage) { } else if (blockMessage && 'attachment' in blockMessage) {
const attachmentPayload = blockMessage.attachment.payload; const attachmentPayload = blockMessage.attachment.payload;
if (!attachmentPayload.attachment_id) { if (!attachmentPayload.id) {
this.checkDeprecatedAttachmentUrl(block); this.checkDeprecatedAttachmentUrl(block);
throw new Error('Remote attachments are no longer supported!'); throw new Error('Remote attachments are no longer supported!');
} }

View File

@ -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: * 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. * 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(), .required(),
payload: Joi.object().keys({ payload: Joi.object().keys({
url: Joi.string().uri(), url: Joi.string().uri(),
attachment_id: Joi.string().allow(null), id: Joi.string().allow(null),
}), }),
}), }),
elements: Joi.boolean(), elements: Joi.boolean(),

View File

@ -149,14 +149,14 @@ export const webEvents: [string, Web.IncomingMessage, any][] = [
attachments: { attachments: {
type: FileType.image, type: FileType.image,
payload: { payload: {
attachment_id: '9'.repeat(24), id: '9'.repeat(24),
}, },
}, },
}, },
message: { message: {
attachment: { attachment: {
payload: { payload: {
attachment_id: '9'.repeat(24), id: '9'.repeat(24),
}, },
type: FileType.image, type: FileType.image,
}, },

View File

@ -155,9 +155,7 @@ export default abstract class BaseWebChannelHandler<
type: Web.IncomingMessageType.file, type: Web.IncomingMessageType.file,
data: { data: {
type: attachmentPayload.type, type: attachmentPayload.type,
url: await this.getPublicUrl( url: await this.getPublicUrl(attachmentPayload.payload.id),
attachmentPayload.payload.attachment_id,
),
}, },
}; };
} }
@ -992,7 +990,7 @@ export default abstract class BaseWebChannelHandler<
type: Web.OutgoingMessageType.file, type: Web.OutgoingMessageType.file,
data: { data: {
type: message.attachment.type, 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) { if (message.quickReplies && message.quickReplies.length > 0) {
@ -1034,10 +1032,8 @@ export default abstract class BaseWebChannelHandler<
if (fields.image_url && item[fields.image_url]) { if (fields.image_url && item[fields.image_url]) {
const attachmentPayload = item[fields.image_url] const attachmentPayload = item[fields.image_url]
.payload as AttachmentForeignKey; .payload as AttachmentForeignKey;
if (attachmentPayload.attachment_id) { if (attachmentPayload.id) {
element.image_url = await this.getPublicUrl( element.image_url = await this.getPublicUrl(attachmentPayload.id);
attachmentPayload.attachment_id,
);
} }
} }

View File

@ -224,7 +224,7 @@ export default class WebEventWrapper<N extends ChannelName> extends EventWrapper
attachments: { attachments: {
type: Attachment.getTypeByMime(this._adapter.raw.data.type), type: Attachment.getTypeByMime(this._adapter.raw.data.type),
payload: { payload: {
attachment_id: this._adapter.attachment.id, id: this._adapter.attachment.id,
}, },
}, },
}; };
@ -278,7 +278,7 @@ export default class WebEventWrapper<N extends ChannelName> extends EventWrapper
attachment: { attachment: {
type: fileType, type: fileType,
payload: { payload: {
attachment_id: this._adapter.attachment.id, id: this._adapter.attachment.id,
}, },
}, },
}; };

View File

@ -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: * 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. * 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 mongoose from 'mongoose';
import { BlockCreateDto } from '@/chat/dto/block.dto'; 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 { CategoryModel } from '@/chat/schemas/category.schema';
import { FileType } from '@/chat/schemas/types/attachment'; import { FileType } from '@/chat/schemas/types/attachment';
import { ButtonType } from '@/chat/schemas/types/button'; import { ButtonType } from '@/chat/schemas/types/button';
@ -131,7 +131,7 @@ export const blocks: BlockCreateDto[] = [
attachment: { attachment: {
type: FileType.image, type: FileType.image,
payload: { payload: {
attachment_id: '1', id: '1',
}, },
}, },
quickReplies: [], quickReplies: [],

View File

@ -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: * 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. * 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: { image: {
type: 'image', type: 'image',
payload: { payload: {
attachment_id: null, id: null,
}, },
}, },
}, },
@ -111,7 +111,7 @@ const contents: ContentCreateDto[] = [
image: { image: {
type: 'image', type: 'image',
payload: { payload: {
attachment_id: null, id: null,
}, },
}, },
}, },
@ -151,8 +151,7 @@ export const installContentFixtures = async () => {
({ name }) => name === `${contentFixture.title.replace(' ', '')}.jpg`, ({ name }) => name === `${contentFixture.title.replace(' ', '')}.jpg`,
); );
if (attachment) { if (attachment) {
contentFixture.dynamicFields.image.payload.attachment_id = contentFixture.dynamicFields.image.payload.id = attachment.id;
attachment.id;
} }
return { return {
...contentFixture, ...contentFixture,

View File

@ -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: * 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. * 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, type: FileType.image,
payload: { payload: {
url: 'https://fr.facebookbrand.com/wp-content/uploads/2016/09/messenger_icon2.png', url: 'https://fr.facebookbrand.com/wp-content/uploads/2016/09/messenger_icon2.png',
attachment_id: '1234', id: '1234',
}, },
}, },
quickReplies: [], quickReplies: [],

View File

@ -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: * 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. * 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). * 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 LinkIcon from "@mui/icons-material/Link";
import { import {
Dialog, Dialog,
@ -110,9 +111,9 @@ const ContentFieldInput: React.FC<ContentFieldInput> = ({
})} })}
{...field} {...field}
onChange={(id, mimeType) => { 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(",")} accept={MIME_TYPES["images"].join(",")}
format="full" format="full"
/> />

View File

@ -36,7 +36,7 @@ export const ATTACHMENT_BLOCK_TEMPLATE: Partial<IBlockAttributes> = {
message: { message: {
attachment: { attachment: {
type: FileType.unknown, type: FileType.unknown,
payload: { attachment_id: null }, payload: { id: null },
}, },
quickReplies: [], quickReplies: [],
}, },

View File

@ -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: * 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. * 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). * 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 { Controller, useFormContext } from "react-hook-form";
import AttachmentInput from "@/app-components/attachment/AttachmentInput"; import AttachmentInput from "@/app-components/attachment/AttachmentInput";
@ -41,8 +42,7 @@ const AttachmentMessageForm = () => {
validate: { validate: {
required: (value) => { required: (value) => {
return ( return (
!!value?.payload?.attachment_id || !!value?.payload?.id || t("message.attachment_is_required")
t("message.attachment_is_required")
); );
}, },
}, },
@ -55,7 +55,7 @@ const AttachmentMessageForm = () => {
<AttachmentInput <AttachmentInput
label="" label=""
{...rest} {...rest}
value={value.payload?.attachment_id} value={value.payload?.id}
accept={Object.values(MIME_TYPES).flat().join(",")} accept={Object.values(MIME_TYPES).flat().join(",")}
format="full" format="full"
size={256} size={256}
@ -65,7 +65,7 @@ const AttachmentMessageForm = () => {
onChange({ onChange({
type: type ? getFileType(type) : FileType.unknown, type: type ? getFileType(type) : FileType.unknown,
payload: { payload: {
attachment_id: id, id,
}, },
}); });
}} }}

View File

@ -52,8 +52,8 @@ export interface AttachmentAttrs {
} }
export type AttachmentForeignKey = { export type AttachmentForeignKey = {
attachment_id: string | null; id: string | null;
/** @deprecated use attachment_id instead */ /** @deprecated use id instead */
url?: string; url?: string;
}; };