mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-05 23:19:12 -05:00
FF-1277 - notitification plugins now use templating
This commit is contained in:
@@ -22,15 +22,11 @@ public class Apprise: Node
|
||||
/// <inheritdoc />
|
||||
public override string CustomColor => "#257575";
|
||||
|
||||
[Required]
|
||||
[TextVariable(1)]
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
[StringArray(2)]
|
||||
[StringArray(1)]
|
||||
public string[] Tag { get; set; } = new string[] { };
|
||||
|
||||
[DefaultValue("info")]
|
||||
[Select(nameof(MessageTypeOptions), 3)]
|
||||
[Select(nameof(MessageTypeOptions), 2)]
|
||||
public string MessageType { get; set; } = string.Empty;
|
||||
|
||||
private static List<ListOption> _MessageTypeOptions;
|
||||
@@ -42,16 +38,55 @@ public class Apprise: Node
|
||||
{
|
||||
_MessageTypeOptions = new List<ListOption>
|
||||
{
|
||||
new ListOption { Label = "Information", Value = "info"},
|
||||
new ListOption { Label = "Success", Value = "success"},
|
||||
new ListOption { Label = "Warning", Value = "warning" },
|
||||
new ListOption { Label = "Failure", Value = "failure"}
|
||||
new () { Label = "Information", Value = "info"},
|
||||
new () { Label = "Success", Value = "success"},
|
||||
new () { Label = "Warning", Value = "warning" },
|
||||
new () { Label = "Failure", Value = "failure"}
|
||||
};
|
||||
}
|
||||
return _MessageTypeOptions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Template(3, nameof(MessageTemplates))]
|
||||
public string Message { get; set; }
|
||||
|
||||
private static List<ListOption> _MessageTemplates;
|
||||
public static List<ListOption> MessageTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MessageTemplates == null)
|
||||
{
|
||||
_MessageTemplates = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Basic", Value = @"File: {{ file.Orig.FullName }}
|
||||
Size: {{ file.Size }}" },
|
||||
new () { Label = "File Size Changes", Value = @"
|
||||
{{ difference = file.Size - file.Orig.Size }}
|
||||
{{ percent = (difference / file.Orig.Size) * 100 | math.round 2 }}
|
||||
|
||||
Input File: {{ file.Orig.FullName }}
|
||||
Output File: {{ file.FullName }}
|
||||
Original Size: {{ file.Orig.Size | file_size }}
|
||||
Final Size: {{ file.Size | file_size }}
|
||||
|
||||
{{- if difference < 0 }}
|
||||
File grew in size: {{ difference | math.abs | file_size }}
|
||||
{{ else }}
|
||||
File shrunk in size by: {{ difference | file_size }} / {{ percent }}%
|
||||
{{ end }}"}
|
||||
};
|
||||
}
|
||||
return _MessageTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
@@ -79,7 +114,7 @@ public class Apprise: Node
|
||||
else
|
||||
url += settings.Endpoint;
|
||||
|
||||
string message = args.ReplaceVariables(this.Message);
|
||||
string message = args.RenderTemplate!(this.Message);
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
args.Logger?.WLog("No message to send");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace FileFlows.DiscordNodes.Communication;
|
||||
|
||||
@@ -19,17 +19,26 @@ public class Discord: Node
|
||||
/// <inheritdoc />
|
||||
public override string CustomColor => "#5865F2";
|
||||
|
||||
[Required]
|
||||
/// <summary>
|
||||
/// Gets or sets the title
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string Message { get; set; }
|
||||
|
||||
[TextVariable(2)]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message type
|
||||
/// </summary>
|
||||
[DefaultValue("standard")]
|
||||
[Select(nameof(MessageTypeOptions), 3)]
|
||||
[Select(nameof(MessageTypeOptions), 2)]
|
||||
public string MessageType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Template(3, nameof(MessageTemplates))]
|
||||
public string Message { get; set; }
|
||||
|
||||
private static List<ListOption> _MessageTypeOptions;
|
||||
public static List<ListOption> MessageTypeOptions
|
||||
{
|
||||
@@ -51,6 +60,37 @@ public class Discord: Node
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ListOption> _MessageTemplates;
|
||||
public static List<ListOption> MessageTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MessageTemplates == null)
|
||||
{
|
||||
_MessageTemplates = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Basic", Value = @"File: {{ file.Orig.FullName }}
|
||||
Size: {{ file.Size }}" },
|
||||
new () { Label = "File Size Changes", Value = @"
|
||||
{{ difference = file.Size - file.Orig.Size }}
|
||||
{{ percent = (difference / file.Orig.Size) * 100 | math.round 2 }}
|
||||
|
||||
Input File: {{ file.Orig.FullName }}
|
||||
Output File: {{ file.FullName }}
|
||||
Original Size: {{ file.Orig.Size | file_size }}
|
||||
Final Size: {{ file.Size | file_size }}
|
||||
|
||||
{{- if difference < 0 }}
|
||||
File grew in size: {{ difference | math.abs | file_size }}
|
||||
{{ else }}
|
||||
File shrunk in size by: {{ difference | file_size }} / {{ percent }}%
|
||||
{{ end }}"}
|
||||
};
|
||||
}
|
||||
return _MessageTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
const int colorInfo = 0x1F61E6;
|
||||
const int colorSuccess= 0x80E61F;
|
||||
const int colorError = 0xE7421F;
|
||||
@@ -75,7 +115,7 @@ public class Discord: Node
|
||||
return 2;
|
||||
}
|
||||
|
||||
string message = args.ReplaceVariables(this.Message);
|
||||
var message = args.RenderTemplate!(Message);
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
args.Logger?.WLog("No message to send");
|
||||
@@ -84,6 +124,7 @@ public class Discord: Node
|
||||
|
||||
string title = args.ReplaceVariables(this.Title)?.EmptyAsNull() ??
|
||||
this.MessageType?.EmptyAsNull() ?? "Information";
|
||||
|
||||
|
||||
// replace new lines
|
||||
message = message.Replace("\\r\\n", "\r\n");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MailKit.Net.Smtp;
|
||||
using MimeKit;
|
||||
using Scriban;
|
||||
|
||||
namespace FileFlows.Communication
|
||||
{
|
||||
@@ -20,9 +20,44 @@ namespace FileFlows.Communication
|
||||
[TextVariable(2)]
|
||||
public string Subject { get; set; }
|
||||
|
||||
[TextArea(3)]
|
||||
/// <summary>
|
||||
/// Gets or sets the message
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Template(3, nameof(BodyTemplates))]
|
||||
public string Body { get; set; }
|
||||
|
||||
private static List<ListOption> _BodyTemplates;
|
||||
public static List<ListOption> BodyTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_BodyTemplates == null)
|
||||
{
|
||||
_BodyTemplates = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Basic", Value = @"File: {{ file.Orig.FullName }}
|
||||
Size: {{ file.Size }}" },
|
||||
new () { Label = "File Size Changes", Value = @"
|
||||
{{ difference = file.Size - file.Orig.Size }}
|
||||
{{ percent = (difference / file.Orig.Size) * 100 | math.round 2 }}
|
||||
|
||||
Input File: {{ file.Orig.FullName }}
|
||||
Output File: {{ file.FullName }}
|
||||
Original Size: {{ file.Orig.Size | file_size }}
|
||||
Final Size: {{ file.Size | file_size }}
|
||||
|
||||
{{- if difference < 0 }}
|
||||
File grew in size: {{ difference | math.abs | file_size }}
|
||||
{{ else }}
|
||||
File shrunk in size by: {{ difference | file_size }} / {{ percent }}%
|
||||
{{ end }}"}
|
||||
};
|
||||
}
|
||||
return _BodyTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
try
|
||||
@@ -62,18 +97,7 @@ namespace FileFlows.Communication
|
||||
if (string.IsNullOrEmpty(this.Body))
|
||||
return string.Empty;
|
||||
|
||||
string body = this.Body;
|
||||
var dict = new Dictionary<string, object>();
|
||||
foreach(string key in args.Variables.Keys)
|
||||
{
|
||||
string newKey = key.Replace(".", "");
|
||||
body = body.Replace(key, newKey);
|
||||
if (dict.ContainsKey(newKey) == false)
|
||||
dict.Add(newKey, args.Variables[key]);
|
||||
}
|
||||
var template = Template.Parse(body);
|
||||
string result = template.Render(dict).Trim();
|
||||
return result;
|
||||
return args.RenderTemplate!(this.Body);
|
||||
}
|
||||
|
||||
private void SendDotNet(NodeParameters args, PluginSettings settings, string sender, string subject, string body)
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="Scriban.Signed" Version="5.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -37,26 +37,59 @@ public class Gotify: Node
|
||||
/// </summary>
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/gotify";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message to send
|
||||
/// </summary>
|
||||
[Required]
|
||||
[TextVariable(1)]
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the message
|
||||
/// </summary>
|
||||
[TextVariable(2)]
|
||||
[TextVariable(1)]
|
||||
public string Title { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the priority of the message
|
||||
/// </summary>
|
||||
[NumberInt(3)]
|
||||
[NumberInt(2)]
|
||||
[Range(1, 100)]
|
||||
[DefaultValue(2)]
|
||||
public int Priority { get; set; } = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Template(3, nameof(MessageTemplates))]
|
||||
public string Message { get; set; }
|
||||
|
||||
private static List<ListOption> _MessageTemplates;
|
||||
public static List<ListOption> MessageTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MessageTemplates == null)
|
||||
{
|
||||
_MessageTemplates = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Basic", Value = @"File: {{ file.Orig.FullName }}
|
||||
Size: {{ file.Size }}" },
|
||||
new () { Label = "File Size Changes", Value = @"
|
||||
{{ difference = file.Size - file.Orig.Size }}
|
||||
{{ percent = (difference / file.Orig.Size) * 100 | math.round 2 }}
|
||||
|
||||
Input File: {{ file.Orig.FullName }}
|
||||
Output File: {{ file.FullName }}
|
||||
Original Size: {{ file.Orig.Size | file_size }}
|
||||
Final Size: {{ file.Size | file_size }}
|
||||
|
||||
{{- if difference < 0 }}
|
||||
File grew in size: {{ difference | math.abs | file_size }}
|
||||
{{ else }}
|
||||
File shrunk in size by: {{ difference | file_size }} / {{ percent }}%
|
||||
{{ end }}"}
|
||||
};
|
||||
}
|
||||
return _MessageTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the flow element
|
||||
@@ -81,7 +114,7 @@ public class Gotify: Node
|
||||
return 2;
|
||||
}
|
||||
|
||||
string message = args.ReplaceVariables(this.Message);
|
||||
string message = args.RenderTemplate!(this.Message);
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
args.Logger?.WLog("No message to send");
|
||||
|
||||
@@ -35,12 +35,43 @@ public class Telegram: Node
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/telegram";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message to send
|
||||
/// Gets or sets the message
|
||||
/// </summary>
|
||||
[Required]
|
||||
[TextVariable(1)]
|
||||
[Template(1, nameof(MessageTemplates))]
|
||||
public string Message { get; set; }
|
||||
|
||||
private static List<ListOption> _MessageTemplates;
|
||||
public static List<ListOption> MessageTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MessageTemplates == null)
|
||||
{
|
||||
_MessageTemplates = new List<ListOption>
|
||||
{
|
||||
new () { Label = "Basic", Value = @"File: {{ file.Orig.FullName }}
|
||||
Size: {{ file.Size }}" },
|
||||
new () { Label = "File Size Changes", Value = @"
|
||||
{{ difference = file.Size - file.Orig.Size }}
|
||||
{{ percent = (difference / file.Orig.Size) * 100 | math.round 2 }}
|
||||
|
||||
Input File: {{ file.Orig.FullName }}
|
||||
Output File: {{ file.FullName }}
|
||||
Original Size: {{ file.Orig.Size | file_size }}
|
||||
Final Size: {{ file.Size | file_size }}
|
||||
|
||||
{{- if difference < 0 }}
|
||||
File grew in size: {{ difference | math.abs | file_size }}
|
||||
{{ else }}
|
||||
File shrunk in size by: {{ difference | file_size }} / {{ percent }}%
|
||||
{{ end }}"}
|
||||
};
|
||||
}
|
||||
return _MessageTemplates;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a telegram message
|
||||
/// </summary>
|
||||
@@ -94,7 +125,7 @@ public class Telegram: Node
|
||||
return 2;
|
||||
}
|
||||
|
||||
var message = args.ReplaceVariables(Message);
|
||||
var message = args.RenderTemplate!(Message);
|
||||
|
||||
var result = SendMessage(settings.BotToken, settings.ChatId, message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user