Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Agent] Add API to add attachment to task message #3327

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ codeunit 4307 "Agent Message"
AgentMessageImpl.SetStatusToSent(AgentTaskMessage);
end;

/// <summary>
/// Add an attachment to the task message.
/// </summary>
/// <param name="FileName">The name of the file to be attached.</param>
/// <param name="FileMIMEType">The MIME type of the file to be attached.</param>
/// <param name="Attachment">The attachment stream.</param>
[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;

/// <summary>
/// Downloads the attachments for a specific message.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace System.Agents;

using System.Integration;
using System.Environment;
using System.Integration;

codeunit 4300 "Agent Task Impl."
{
Expand Down
Loading