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',
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: [
{

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:
* 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,
);
}

View File

@ -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;
};

View File

@ -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',
},
},

View File

@ -411,7 +411,7 @@ export class BlockService extends BaseService<Block, BlockPopulate, BlockFull> {
'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<Block, BlockPopulate, BlockFull> {
}
} 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!');
}

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:
* 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(),

View File

@ -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,
},

View File

@ -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);
}
}

View File

@ -224,7 +224,7 @@ export default class WebEventWrapper<N extends ChannelName> 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<N extends ChannelName> extends EventWrapper
attachment: {
type: fileType,
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:
* 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: [],

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:
* 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,

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:
* 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: [],

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:
* 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<ContentFieldInput> = ({
})}
{...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"
/>

View File

@ -36,7 +36,7 @@ export const ATTACHMENT_BLOCK_TEMPLATE: Partial<IBlockAttributes> = {
message: {
attachment: {
type: FileType.unknown,
payload: { attachment_id: null },
payload: { id: null },
},
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:
* 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 = () => {
<AttachmentInput
label=""
{...rest}
value={value.payload?.attachment_id}
value={value.payload?.id}
accept={Object.values(MIME_TYPES).flat().join(",")}
format="full"
size={256}
@ -65,7 +65,7 @@ const AttachmentMessageForm = () => {
onChange({
type: type ? getFileType(type) : FileType.unknown,
payload: {
attachment_id: id,
id,
},
});
}}

View File

@ -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;
};