diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/RichContentJsonConverter .cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/RichContentJsonConverter .cs index 95c00037..20b0d949 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/RichContentJsonConverter .cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/RichContentJsonConverter .cs @@ -16,7 +16,7 @@ public class RichContentJsonConverter : JsonConverter if (root.TryGetProperty("rich_type", out JsonElement element)) { var richType = element.GetString(); - res = parser.ParseRichMessage(richType, jsonText, options); + res = parser.ParseRichMessage(richType, jsonText, root, options); } return res; diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/TemplateMessageJsonConverter.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/TemplateMessageJsonConverter.cs index fbd07e3f..7729f40f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/TemplateMessageJsonConverter.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/JsonConverters/TemplateMessageJsonConverter.cs @@ -16,7 +16,7 @@ public class TemplateMessageJsonConverter : JsonConverter if (root.TryGetProperty("template_type", out JsonElement element)) { var templateType = element.GetString(); - res = parser.ParseTemplateMessage(templateType, jsonText, options); + res = parser.ParseTemplateMessage(templateType, jsonText, root, options); } return res; diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/MessageParser.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/MessageParser.cs index abc2f621..3707de4a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/MessageParser.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/MessageParser.cs @@ -12,7 +12,7 @@ public class MessageParser { } - public IRichMessage? ParseRichMessage(string richType, string jsonText, JsonSerializerOptions options) + public IRichMessage? ParseRichMessage(string richType, string jsonText, JsonElement root, JsonSerializerOptions options) { IRichMessage? res = null; @@ -36,11 +36,22 @@ public class MessageParser { res = JsonSerializer.Deserialize(jsonText, options); } + else if (richType == RichTypeEnum.GenericTemplate) + { + if (root.TryGetProperty("element_type", out var element)) + { + var elementType = element.GetString(); + if (elementType == typeof(GenericElement).Name) + { + res = JsonSerializer.Deserialize>(jsonText, options); + } + } + } return res; } - public ITemplateMessage? ParseTemplateMessage(string templateType, string jsonText, JsonSerializerOptions options) + public ITemplateMessage? ParseTemplateMessage(string templateType, string jsonText, JsonElement root, JsonSerializerOptions options) { ITemplateMessage? res = null; @@ -60,6 +71,17 @@ public class MessageParser { res = JsonSerializer.Deserialize(jsonText, options); } + else if (templateType == TemplateTypeEnum.Generic) + { + if (root.TryGetProperty("element_type", out var element)) + { + var elementType = element.GetString(); + if (elementType == typeof(GenericElement).Name) + { + res = JsonSerializer.Deserialize>(jsonText, options); + } + } + } return res; }