import { Type } from "class-transformer"; import { IsNotEmpty, IsString, IsNumber, IsNotEmptyObject, ValidateNested, ValidateIf, IsOptional } from "class-validator"; import { ConversationCommand } from "./ConversationCommand"; import { IncomingMessageVO } from "./IncomingMessageVO"; import { MessageContentVO } from "../../common/command/MessageContentVO"; import { OutgoingMessageVO } from "./OutgoingMessageVO"; export class StartConversationCommand extends ConversationCommand { static readonly commandName = "StartConversationCommand"; public readonly direction: "IN" | "OUT"; @IsString() @IsNotEmpty() public readonly contactId:string; @ValidateIf((c) => c.direction === "IN") @ValidateNested() @Type(() => IncomingMessageVO) public readonly receiveMessage?: IncomingMessageVO; @ValidateIf((c) => c.direction === "OUT") @ValidateNested() @Type(() => OutgoingMessageVO) public readonly sendMessage?: OutgoingMessageVO; constructor({ tenantId, conversationId, contactId, direction, receiveMessage, sendMessage, }: { tenantId:string; conversationId: string; contactId:string; direction: "IN" | "OUT"; receiveMessage?: IncomingMessageVO; sendMessage?: OutgoingMessageVO; }) { super({ commandName: StartConversationCommand.commandName, tenantId, conversationId, }); this.contactId = contactId; this.direction = direction; this.receiveMessage = receiveMessage; this.sendMessage = sendMessage; } }