// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.Agents;
using System.Environment;
codeunit 4307 "Agent Message"
{
InherentEntitlements = X;
InherentPermissions = X;
var
FeatureAccessManagement: Codeunit "Feature Access Management";
///
/// Get the message text for the given agent task message.
///
/// The task ID of the message.
/// The unique identifier of the message.
/// The body of the agent task message.
procedure GetText(TaskID: BigInteger; MessageID: Guid): Text
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.GetText(TaskID, MessageID));
end;
///
/// Get the message text for the given agent task message.
/// The record is not retrieved again; the caller must ensure the record is up to date.
///
/// Agent task message.
/// The body of the agent task message.
procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.GetText(AgentTaskMessage));
end;
///
/// Updates the message text.
///
/// The task ID of the message.
/// The unique identifier of the message.
/// New message text to set.
procedure UpdateText(TaskID: BigInteger; MessageID: Guid; NewMessageText: Text)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.UpdateText(TaskID, MessageID, NewMessageText);
end;
///
/// Updates the message text.
///
///
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
///
/// The message record to update.
/// New message text to set.
procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.UpdateText(AgentTaskMessage, NewMessageText);
end;
///
/// Check if it is possible to edit the message.
///
/// The task ID of the message.
/// The unique identifier of the message.
/// If it is possible to change the message.
procedure IsEditable(TaskID: BigInteger; MessageID: Guid): Boolean
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.IsEditable(TaskID, MessageID));
end;
///
/// Check if it is possible to edit the message.
/// The record is not retrieved again; the caller must ensure the record is up to date.
///
/// Agent task message to verify.
/// If it is possible to change the message.
procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.IsEditable(AgentTaskMessage));
end;
///
/// Sets the message status to sent.
///
/// The task ID of the message.
/// The unique identifier of the message.
procedure SetStatusToSent(TaskID: BigInteger; MessageID: Guid)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.SetStatusToSent(TaskID, MessageID);
end;
///
/// Sets the message status to sent.
///
///
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
///
/// Agent task message to update status.
procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
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;
///
/// Set whether to ignore attachments for the message.
/// When set to true, attachments will be marked as ignored and will not be processed by the agent.
/// The default value is false.
///
/// If true, attachments will be marked as ignored when added to a message.
procedure SetIgnoreAttachment(IgnoreAttachment: Boolean)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.SetIgnoreAttachment(IgnoreAttachment);
end;
///
/// Downloads the attachments for a specific message.
///
/// Message to download attachments for.
procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.DownloadAttachments(AgentTaskMessage);
end;
///
/// Shows the attachments for a specific message. If file is not supported to be shown, it will be downloaded.
///
/// Task ID to download attachments for.
/// File ID to download.
procedure ShowAttachment(TaskID: BigInteger; FileID: BigInteger)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.ShowOrDownloadAttachment(TaskId, FileID, false);
end;
///
/// Shows the attachments for a specific message. If file is not supported to be shown, it will be downloaded.
///
/// Agent file to display.
procedure ShowAttachment(var AgentTaskFile: Record "Agent Task File")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.ShowOrDownloadAttachment(AgentTaskFile, false);
end;
///
/// Loads the attachments for a specific message to the temporary buffer.
///
/// Task ID to download attachments for.
/// Message ID to download attachments for.
/// Temporary buffer to load the attachments.
procedure GetAttachments(TaskID: BigInteger; MessageID: Guid; var TempAgentTaskFile: Record "Agent Task File" temporary)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.GetAttachments(TaskID, MessageID, TempAgentTaskFile);
end;
///
/// Get the display text for the file size.
///
/// The size in bytes.
/// The display text for the file size.
procedure GetFileSizeDisplayText(SizeInBytes: Decimal): Text
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.GetFileSizeDisplayText(SizeInBytes));
end;
}