diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/BotSharpMessageParser.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/BotSharpMessageParser.cs index 57db70d7..25a97b2b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/BotSharpMessageParser.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/BotSharpMessageParser.cs @@ -1,7 +1,7 @@ -using BotSharp.Abstraction.Messaging.Models.RichContent.Template; -using BotSharp.Abstraction.Messaging.Models.RichContent; using System.Text.Json; using System.Reflection; +using BotSharp.Abstraction.Messaging.Models.RichContent.Template; +using BotSharp.Abstraction.Messaging.Models.RichContent; namespace BotSharp.Abstraction.Messaging; @@ -38,9 +38,9 @@ public static class BotSharpMessageParser { targetType = typeof(TextMessage); } - else if (richType == RichTypeEnum.JsCode) + else if (richType == RichTypeEnum.ProgramCode) { - targetType = typeof(JsCodeTemplateMessage); + targetType = typeof(ProgramCodeTemplateMessage); } else if (richType == RichTypeEnum.GenericTemplate) { @@ -88,9 +88,9 @@ public static class BotSharpMessageParser { targetType = typeof(CouponTemplateMessage); } - else if (templateType == TemplateTypeEnum.Product) + else if (templateType == TemplateTypeEnum.ProgramCode) { - targetType = typeof(ProductTemplateMessage); + targetType = typeof(ProgramCodeTemplateMessage); } else if (templateType == TemplateTypeEnum.Generic) { diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/RichTypeEnum.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/RichTypeEnum.cs index 6227f522..8d66904b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/RichTypeEnum.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/RichTypeEnum.cs @@ -9,6 +9,5 @@ public static class RichTypeEnum public const string QuickReply = "quick_reply"; public const string Text = "text"; public const string Attachment = "attachment"; - - public const string JsCode = "js_code"; + public const string ProgramCode = "program_code"; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/TemplateTypeEnum.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/TemplateTypeEnum.cs index 74f88735..73a4e9d4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/TemplateTypeEnum.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/TemplateTypeEnum.cs @@ -6,5 +6,5 @@ public static class TemplateTypeEnum public const string Coupon = "coupon"; public const string Generic = "generic"; public const string MultiSelect = "multi-select"; - public const string Product = "product"; + public const string ProgramCode = "program_code"; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/JsCodeTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/JsCodeTemplateMessage.cs deleted file mode 100644 index 1d58546b..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/JsCodeTemplateMessage.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; - -public class JsCodeTemplateMessage : IRichMessage -{ - [JsonPropertyName("rich_type")] - public string RichType => RichTypeEnum.JsCode; - - [JsonPropertyName("text")] - public string Text { get; set; } = string.Empty; -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs deleted file mode 100644 index 05af097a..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; - -public class ProductTemplateMessage : IRichMessage, ITemplateMessage -{ - [JsonPropertyName("rich_type")] - public string RichType => RichTypeEnum.GenericTemplate; - - [JsonPropertyName("text")] - [Translate] - public string Text { get; set; } = string.Empty; - - [JsonPropertyName("template_type")] - public string TemplateType => TemplateTypeEnum.Product; -} - -public class ProductElement -{ - public string Id { get; set; } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProgramCodeTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProgramCodeTemplateMessage.cs new file mode 100644 index 00000000..60f6464a --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProgramCodeTemplateMessage.cs @@ -0,0 +1,16 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; + +public class ProgramCodeTemplateMessage : IRichMessage, ITemplateMessage +{ + [JsonPropertyName("rich_type")] + public string RichType => RichTypeEnum.ProgramCode; + + [JsonPropertyName("text")] + public string Text { get; set; } = string.Empty; + + [JsonPropertyName("template_type")] + public virtual string TemplateType { get; set; } = TemplateTypeEnum.ProgramCode; + + [JsonPropertyName("language")] + public string Language { get; set; } = string.Empty; +} diff --git a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs index 43c917d2..ad8de0d7 100644 --- a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs +++ b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs @@ -49,13 +49,14 @@ public class PlotChartFn : IFunctionCallback ]); var obj = response.JsonContent(); - message.Content = obj?.GreetingMessage.IfNullOrEmptyAs("Here is the chart you ask for:"); + message.Content = obj?.GreetingMessage ?? "Here is the chart you ask for:"; message.RichContent = new RichContent { Recipient = new Recipient { Id = convService.ConversationId }, - Message = new JsCodeTemplateMessage + Message = new ProgramCodeTemplateMessage { - Text = obj?.JsCode ?? string.Empty + Text = obj?.JsCode ?? string.Empty, + Language = "javascript" } }; message.StopCompletion = true;