From 16247d42c433100e465129d97084b5aed9d7686e Mon Sep 17 00:00:00 2001 From: Darrick Joo Date: Thu, 20 Mar 2025 13:42:55 +0100 Subject: [PATCH 1/2] Add agent api for adding an attachment to task message --- .../Agent/Interaction/AgentTask.Codeunit.al | 16 +++++++++++++ .../Interaction/AgentTaskImpl.Codeunit.al | 24 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al index 495ecb839d..e694c64823 100644 --- a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al @@ -53,4 +53,20 @@ codeunit 4303 "Agent Task" begin AgentTaskImpl.CreateTask(AgentSecurityID, TaskTitle, ExternalId, NewAgentTask); end; + + /// + /// Add an attachment to the task message. + /// + /// The task ID to which the message belongs. + /// The task message ID to which the attachment will be added. + /// The name of the file to be attached. + /// The MIME type of the file to be attached. + /// The attachment stream. + [Scope('OnPrem')] + procedure AddAttachmentToTaskMessage(TaskId: BigInteger; TaskMesssageId: Guid; FileName: Text[250]; FileMIMEType: Text[100]; Attachment: InStream) + var + AgentTaskImpl: Codeunit "Agent Task Impl."; + begin + AgentTaskImpl.AddAttachmentToTaskMessage(TaskId, TaskMesssageId, FileName, FileMIMEType, Attachment); + end; } \ No newline at end of file diff --git a/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al index 79afb13f3f..0c7a242be4 100644 --- a/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al @@ -5,8 +5,8 @@ namespace System.Agents; -using System.Integration; using System.Environment; +using System.Integration; codeunit 4300 "Agent Task Impl." { @@ -188,6 +188,28 @@ codeunit 4300 "Agent Task Impl." end; end; + procedure AddAttachmentToTaskMessage(TaskId: BigInteger; TaskMesssageId: Guid; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream) + var + AgentTaskFile: Record "Agent Task File"; + AgentTaskMessageAttachment: Record "Agent Task Message Attachment"; + AgentTaskImpl: Codeunit "Agent Task Impl."; + OutStream: OutStream; + begin + // Add attachment to task file + AgentTaskFile."Task ID" := TaskId; + AgentTaskFile."File Name" := FileName; + AgentTaskFile."File MIME Type" := FileMIMEType; + AgentTaskFile.Content.CreateOutStream(OutStream, AgentTaskImpl.GetDefaultEncoding()); + CopyStream(OutStream, InStream); + AgentTaskFile.Insert(); + + // Link task file to task message + AgentTaskMessageAttachment."Task ID" := TaskId; + AgentTaskMessageAttachment."Message ID" := TaskMesssageId; + AgentTaskMessageAttachment."File ID" := AgentTaskFile.ID; + AgentTaskMessageAttachment.Insert(); + end; + [EventSubscriber(ObjectType::Codeunit, Codeunit::"System Action Triggers", GetAgentTaskMessagePageId, '', true, true)] local procedure OnGetAgentTaskMessagePageId(var PageId: Integer) begin From 098bf4178a6118b56b61c7fd8f1f62b62b224316 Mon Sep 17 00:00:00 2001 From: Darrick Joo Date: Thu, 20 Mar 2025 13:54:06 +0100 Subject: [PATCH 2/2] Move AddAttachment to AgentMessage.Codeunit.al --- .../Interaction/AgentMessage.Codeunit.al | 14 ++++++++++++ .../Interaction/AgentMessageImpl.Codeunit.al | 22 +++++++++++++++++++ .../Agent/Interaction/AgentTask.Codeunit.al | 16 -------------- .../Interaction/AgentTaskImpl.Codeunit.al | 22 ------------------- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al index 1ec3011219..830749353a 100644 --- a/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al @@ -61,6 +61,20 @@ codeunit 4307 "Agent Message" AgentMessageImpl.SetStatusToSent(AgentTaskMessage); end; + /// + /// Add an attachment to the task message. + /// + /// The name of the file to be attached. + /// The MIME type of the file to be attached. + /// The attachment stream. + [Scope('OnPrem')] + procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; Attachment: InStream) + var + AgentMessageImpl: Codeunit "Agent Message Impl."; + begin + AgentMessageImpl.AddAttachment(AgentTaskMessage, FileName, FileMIMEType, Attachment); + end; + /// /// Downloads the attachments for a specific message. /// diff --git a/src/System Application/App/Agent/Interaction/AgentMessageImpl.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentMessageImpl.Codeunit.al index 17a727fd55..61fc62d8d8 100644 --- a/src/System Application/App/Agent/Interaction/AgentMessageImpl.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentMessageImpl.Codeunit.al @@ -47,6 +47,28 @@ codeunit 4308 "Agent Message Impl." UpdateAgentTaskMessageStatus(AgentTaskMessage, AgentTaskMessage.Status::Sent); end; + procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream) + var + AgentTaskFile: Record "Agent Task File"; + AgentTaskMessageAttachment: Record "Agent Task Message Attachment"; + AgentTaskImpl: Codeunit "Agent Task Impl."; + OutStream: OutStream; + begin + // Add attachment to task file + AgentTaskFile."Task ID" := AgentTaskMessage."Task ID"; + AgentTaskFile."File Name" := FileName; + AgentTaskFile."File MIME Type" := FileMIMEType; + AgentTaskFile.Content.CreateOutStream(OutStream, AgentTaskImpl.GetDefaultEncoding()); + CopyStream(OutStream, InStream); + AgentTaskFile.Insert(); + + // Link task file to task message + AgentTaskMessageAttachment."Task ID" := AgentTaskMessage."Task ID"; + AgentTaskMessageAttachment."Message ID" := AgentTaskMessage.ID; + AgentTaskMessageAttachment."File ID" := AgentTaskFile.ID; + AgentTaskMessageAttachment.Insert(); + end; + procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message") var AgentTaskFile: Record "Agent Task File"; diff --git a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al index e694c64823..495ecb839d 100644 --- a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al @@ -53,20 +53,4 @@ codeunit 4303 "Agent Task" begin AgentTaskImpl.CreateTask(AgentSecurityID, TaskTitle, ExternalId, NewAgentTask); end; - - /// - /// Add an attachment to the task message. - /// - /// The task ID to which the message belongs. - /// The task message ID to which the attachment will be added. - /// The name of the file to be attached. - /// The MIME type of the file to be attached. - /// The attachment stream. - [Scope('OnPrem')] - procedure AddAttachmentToTaskMessage(TaskId: BigInteger; TaskMesssageId: Guid; FileName: Text[250]; FileMIMEType: Text[100]; Attachment: InStream) - var - AgentTaskImpl: Codeunit "Agent Task Impl."; - begin - AgentTaskImpl.AddAttachmentToTaskMessage(TaskId, TaskMesssageId, FileName, FileMIMEType, Attachment); - end; } \ No newline at end of file diff --git a/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al index 0c7a242be4..a34b1f141a 100644 --- a/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al +++ b/src/System Application/App/Agent/Interaction/AgentTaskImpl.Codeunit.al @@ -188,28 +188,6 @@ codeunit 4300 "Agent Task Impl." end; end; - procedure AddAttachmentToTaskMessage(TaskId: BigInteger; TaskMesssageId: Guid; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream) - var - AgentTaskFile: Record "Agent Task File"; - AgentTaskMessageAttachment: Record "Agent Task Message Attachment"; - AgentTaskImpl: Codeunit "Agent Task Impl."; - OutStream: OutStream; - begin - // Add attachment to task file - AgentTaskFile."Task ID" := TaskId; - AgentTaskFile."File Name" := FileName; - AgentTaskFile."File MIME Type" := FileMIMEType; - AgentTaskFile.Content.CreateOutStream(OutStream, AgentTaskImpl.GetDefaultEncoding()); - CopyStream(OutStream, InStream); - AgentTaskFile.Insert(); - - // Link task file to task message - AgentTaskMessageAttachment."Task ID" := TaskId; - AgentTaskMessageAttachment."Message ID" := TaskMesssageId; - AgentTaskMessageAttachment."File ID" := AgentTaskFile.ID; - AgentTaskMessageAttachment.Insert(); - end; - [EventSubscriber(ObjectType::Codeunit, Codeunit::"System Action Triggers", GetAgentTaskMessagePageId, '', true, true)] local procedure OnGetAgentTaskMessagePageId(var PageId: Integer) begin