From a1bc56b4810cb8e02a8aabed2637b3508f674ad2 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 24 Nov 2023 17:26:33 -0600 Subject: [PATCH] Add more template rich message. --- .../Conversations/Models/RoleDialogModel.cs | 4 +- .../Messaging/IRichMessage.cs | 6 + .../Messaging/ITemplateMessage.cs | 7 + .../Messaging/Models/IMessageTemplate.cs | 6 - .../Models/RichContent/ElementAction.cs | 15 +++ .../Models/RichContent/ElementButton.cs | 17 +++ .../Models/RichContent/QuickReplyElement.cs | 5 +- .../Models/RichContent/QuickReplyMessage.cs | 3 +- .../Models/RichContent/RichContent.cs | 2 +- ...onTemplate.cs => ButtonTemplateMessage.cs} | 3 +- .../RichContent/Template/CommonTemplate.cs | 10 -- .../Template/CouponTemplateMessage.cs | 34 +++++ .../Template/GenericTemplateMessage.cs | 18 +++ ...plate.cs => MultiSelectTemplateMessage.cs} | 3 +- .../Template/ProductTemplateMessage.cs | 11 ++ .../Template/TemplateMessageBase.cs | 12 ++ .../Models/RichContent/TextMessage.cs | 8 +- .../Models/RichContentJsonConverter .cs | 16 --- .../Messaging/RichContentJsonConverter .cs | 16 +++ .../Messaging/TemplateMessageJsonConverter.cs | 16 +++ .../ConversationService.SendMessage.cs | 8 +- .../BotSharp.Plugin.MetaMessenger.csproj | 2 +- .../Controllers/WebhookController.cs | 121 +++--------------- .../GraphAPIs/AuthHeaderHandler.cs | 6 - .../GraphAPIs/IMessengerGraphAPI.cs | 5 - .../Interfaces/IResponseMessage.cs | 5 - .../MessagingModels/AttachementPayload.cs | 11 -- .../MessagingModels/AttachmentBody.cs | 3 +- ...emplateMessage.cs => AttachmentMessage.cs} | 8 +- .../MessagingModels/QuickReplyMessage.cs | 18 --- .../MessagingModels/QuickReplyMessageItem.cs | 18 --- .../MessagingModels/SenderActionEnum.cs | 2 - .../MessagingModels/SendingMessageRequest.cs | 6 + .../MessagingModels/SendingMessageResponse.cs | 5 - .../MetaMessengerPlugin.cs | 13 +- .../Services/MessageHandleService.cs | 107 ++++++++++++++++ .../BotSharp.Plugin.MetaMessenger/Using.cs | 22 ++++ .../WebhookModels/WebhookMessage.cs | 1 + .../WebhookModels/WebhookMessageBody.cs | 12 +- .../WebhookModels/WebhookMessagePostback.cs | 10 ++ .../WebhookModels/WebhookMessageUser.cs | 4 - .../WebhookModels/WebhookObject.cs | 4 - .../WebhookModels/WebhookRequest.cs | 4 - .../WebhookModels/WebhookResponse.cs | 4 - src/WebStarter/Program.cs | 8 +- 45 files changed, 358 insertions(+), 261 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/ITemplateMessage.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/IMessageTemplate.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementAction.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs rename src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/{ButtonTemplate.cs => ButtonTemplateMessage.cs} (90%) delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CommonTemplate.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs rename src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/{MultiSelectTemplate.cs => MultiSelectTemplateMessage.cs} (89%) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContentJsonConverter .cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/RichContentJsonConverter .cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Messaging/TemplateMessageJsonConverter.cs delete mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/Interfaces/IResponseMessage.cs delete mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachementPayload.cs rename src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/{TemplateMessage.cs => AttachmentMessage.cs} (66%) delete mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessage.cs delete mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessageItem.cs create mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs create mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/Using.cs create mode 100644 src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessagePostback.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index 4664d4e7..e9b40722 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -1,5 +1,5 @@ using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Messaging.Models; +using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Messaging.Models.RichContent; namespace BotSharp.Abstraction.Conversations.Models; @@ -45,7 +45,7 @@ public class RoleDialogModel : ITrackableMessage [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object Data { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public RichContent? RichContent { get; set; } + public RichContent? RichContent { get; set; } /// /// Stop conversation completion diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs new file mode 100644 index 00000000..0fce3f4c --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Abstraction.Messaging; + +public interface IRichMessage +{ + string Text { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/ITemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/ITemplateMessage.cs new file mode 100644 index 00000000..63890240 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/ITemplateMessage.cs @@ -0,0 +1,7 @@ +namespace BotSharp.Abstraction.Messaging; + +public interface ITemplateMessage +{ + [JsonPropertyName("template_type")] + string TemplateType => string.Empty; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/IMessageTemplate.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/IMessageTemplate.cs deleted file mode 100644 index 357dc937..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/IMessageTemplate.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace BotSharp.Abstraction.Messaging.Models; - -public interface IMessageTemplate -{ - string Text { get; set; } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementAction.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementAction.cs new file mode 100644 index 00000000..5a2682bd --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementAction.cs @@ -0,0 +1,15 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent; + +public class ElementAction +{ + public string Type { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Url { get; set; } + + [JsonPropertyName("webview_height_ratio")] + public string WebViewHeightRatio { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Payload { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs new file mode 100644 index 00000000..b3642194 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs @@ -0,0 +1,17 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent; + +/// +/// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons +/// +public class ElementButton +{ + public string Type { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Url { get; set; } + + public string Title { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string Payload { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyElement.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyElement.cs index cea110f1..a831c269 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyElement.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyElement.cs @@ -4,11 +4,12 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent public class QuickReplyElement { [JsonPropertyName("content_type")] - public string ContentType { get; set; } = string.Empty; + public string ContentType { get; set; } = "text"; + public string Title { get; set; } = string.Empty; public string? Payload { get; set; } + [JsonPropertyName("image_url")] public string? ImageUrl { get; set; } - public string? PostBackUrl { get; set; } } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs index b7c273e8..b0081c81 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs @@ -1,7 +1,6 @@ - namespace BotSharp.Abstraction.Messaging.Models.RichContent { - public class QuickReplyMessage : IMessageTemplate + public class QuickReplyMessage : IRichMessage { public string Text { get; set; } = string.Empty; diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs index 18afce0e..47c47ab5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/RichContent.cs @@ -1,6 +1,6 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent { - public class RichContent where T : IMessageTemplate + public class RichContent where T : IRichMessage { public Recipient Recipient { get; set; } = new Recipient(); /// diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplate.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs similarity index 90% rename from src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplate.cs rename to src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs index 9119901a..243c75b5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplate.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs @@ -1,7 +1,6 @@ - namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template { - public class ButtonTemplate : IMessageTemplate + public class ButtonTemplateMessage : IRichMessage { public string Text { get; set; } = string.Empty; diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CommonTemplate.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CommonTemplate.cs deleted file mode 100644 index e4b3ea8c..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CommonTemplate.cs +++ /dev/null @@ -1,10 +0,0 @@ - -namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template -{ - public class CommonTemplate - { - [JsonPropertyName("template_type")] - public string TemplateType { get; set; } = string.Empty; - public T Elements { get; set; } - } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs new file mode 100644 index 00000000..8fb74efd --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs @@ -0,0 +1,34 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; + +/// +/// Coupon Template +/// https://developers.facebook.com/docs/messenger-platform/send-messages/template/coupon +/// +public class CouponTemplateMessage : IRichMessage, ITemplateMessage +{ + [JsonIgnore] + public string Text { get; set; } + public string Title { get; set; } + public string Subtitle { get; set; } + + [JsonPropertyName("template_type")] + public string TemplateType => "coupon"; + + [JsonPropertyName("coupon_code")] + public string CouponCode { get; set; } + + [JsonPropertyName("coupon_url")] + public string CouponUrl { get; set; } + + [JsonPropertyName("coupon_url_button_title")] + public string CouponUrlButtonTitle { get; set; } = "Shop now"; + + [JsonPropertyName("coupon_pre_message")] + public string CouponPreMessage { get; set; } = "Here's a deal just for you!"; + + [JsonPropertyName("image_url")] + public string ImageUrl { get; set; } + + [JsonPropertyName("payload")] + public string Payload { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs new file mode 100644 index 00000000..6bb78fc3 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs @@ -0,0 +1,18 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; + +public class GenericTemplateMessage : TemplateMessageBase, IRichMessage, ITemplateMessage +{ + [JsonPropertyName("template_type")] + public override string TemplateType => "generic"; +} + +public class GenericElement +{ + public string Title { get; set; } + public string Subtitle { get; set; } + [JsonPropertyName("image_url")] + public string ImageUrl { get; set; } + [JsonPropertyName("default_action")] + public ElementAction DefaultAction { get; set; } + public ElementButton[] Buttons { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplate.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs similarity index 89% rename from src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplate.cs rename to src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs index caab4ca3..df8e1183 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplate.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs @@ -1,7 +1,6 @@ - namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template { - public class MultiSelectTemplate : IMessageTemplate + public class MultiSelectTemplateMessage : IRichMessage { 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 new file mode 100644 index 00000000..bfbdcbb3 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs @@ -0,0 +1,11 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template; + +public class ProductTemplateMessage : TemplateMessageBase, IRichMessage +{ + public override string TemplateType => "product"; +} + +public class ProductElement +{ + public string Id { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs new file mode 100644 index 00000000..b2d568cc --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs @@ -0,0 +1,12 @@ +namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template +{ + public class TemplateMessageBase + { + [JsonIgnore] + public string Text { get; set; } + + [JsonPropertyName("template_type")] + public virtual string TemplateType => string.Empty; + public T[] Elements { get; set; } + } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs index 1cc8918a..dfb611d3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs @@ -1,7 +1,11 @@ - namespace BotSharp.Abstraction.Messaging.Models.RichContent; -public class TextMessage : IMessageTemplate +public class TextMessage : IRichMessage { public string Text { get; set; } = string.Empty; + + public TextMessage(string text) + { + Text = text; + } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContentJsonConverter .cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContentJsonConverter .cs deleted file mode 100644 index d194d687..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContentJsonConverter .cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Text.Json; - -namespace BotSharp.Abstraction.Messaging.Models; - -public class RichContentJsonConverter : JsonConverter -{ - public override IMessageTemplate? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } - - public override void Write(Utf8JsonWriter writer, IMessageTemplate value, JsonSerializerOptions options) - { - JsonSerializer.Serialize(writer, value, value.GetType(), options); - } -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/RichContentJsonConverter .cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/RichContentJsonConverter .cs new file mode 100644 index 00000000..5234f7fd --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/RichContentJsonConverter .cs @@ -0,0 +1,16 @@ +using System.Text.Json; + +namespace BotSharp.Abstraction.Messaging; + +public class RichContentJsonConverter : JsonConverter +{ + public override IRichMessage? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + public override void Write(Utf8JsonWriter writer, IRichMessage value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, value.GetType(), options); + } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/TemplateMessageJsonConverter.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/TemplateMessageJsonConverter.cs new file mode 100644 index 00000000..36e68a71 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/TemplateMessageJsonConverter.cs @@ -0,0 +1,16 @@ +using System.Text.Json; + +namespace BotSharp.Abstraction.Messaging; + +public class TemplateMessageJsonConverter : JsonConverter +{ + public override ITemplateMessage? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + public override void Write(Utf8JsonWriter writer, ITemplateMessage value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, value.GetType(), options); + } +} diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 69c21d48..613ab4fb 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -1,5 +1,5 @@ using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Messaging.Models; +using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Messaging.Models.RichContent; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; @@ -104,7 +104,7 @@ public partial class ConversationService // Process rich content if (response.RichContent != null && - response.RichContent is RichContent template && + response.RichContent is RichContent template && string.IsNullOrEmpty(template.Message.Text)) { template.Message.Text = response.Content; @@ -112,10 +112,10 @@ public partial class ConversationService // Only read content from RichContent for UI rendering. When richContent is null, create a basic text message for richContent. var state = _services.GetRequiredService(); - response.RichContent = response.RichContent ?? new RichContent + response.RichContent = response.RichContent ?? new RichContent { Recipient = new Recipient { Id = state.GetConversationId() }, - Message = new TextMessage { Text = response.Content } + Message = new TextMessage(response.Content) }; var hooks = _services.GetServices().ToList(); diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj b/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj index 7ce8a94e..d4ce7850 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj @@ -5,7 +5,7 @@ $(LangVersion) $(BotSharpVersion) $(GeneratePackageOnBuild) - True + GenerateDocumentationFile diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs index f6a51bd7..883c1b2b 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs @@ -1,21 +1,7 @@ -using BotSharp.Abstraction.Conversations.Models; -using BotSharp.Abstraction.Conversations; -using BotSharp.Plugin.MetaMessenger.GraphAPIs; -using BotSharp.Plugin.MetaMessenger.MessagingModels; -using BotSharp.Plugin.MetaMessenger.Settings; -using BotSharp.Plugin.MetaMessenger.WebhookModels; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; + using Refit; -using Microsoft.Extensions.Logging; namespace BotSharp.Plugin.MetaMessenger.Controllers; @@ -41,7 +27,7 @@ public class WebhookController : ControllerBase [FromQuery(Name = "hub.challenge")] string challenge, [FromRoute] string agentId) { - Console.WriteLine(agentId); + Console.WriteLine($"Verificate {mode} {token} {challenge} {agentId}"); return challenge; } @@ -64,103 +50,32 @@ public class WebhookController : ControllerBase // https://developers.facebook.com/docs/messenger-platform/webhooks#verification-requests try { + string senderId = ""; + string message = ""; + // received message if (req.Entry[0].Messaging[0].Message != null) { - var reply = new QuickReplyMessage(); - var senderId = req.Entry[0].Messaging[0].Sender.Id; - var input = req.Entry[0].Messaging[0].Message.Text; - - var setting = _services.GetRequiredService(); - var messenger = _services.GetRequiredService(); - var jsonOpt = new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - }; - - var recipient = JsonSerializer.Serialize(new { Id = senderId }, jsonOpt); - - // Marking seen - await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest - { - AccessToken = setting.PageAccessToken, - Recipient = recipient, - SenderAction = SenderActionEnum.MarkSeen - }); - - // Typing on - await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest - { - AccessToken = setting.PageAccessToken, - Recipient = recipient, - SenderAction = SenderActionEnum.TypingOn - }); - - // Go to LLM - var conv = _services.GetRequiredService(); - conv.SetConversationId(senderId, new List - { - "channel=messenger" - }); - - var result = await conv.SendMessage(agentId, new RoleDialogModel("user", input), async msg => - { - reply.Text = msg.Content; - }, async functionExecuting => - { - /*await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest - { - AccessToken = setting.PageAccessToken, - Recipient = JsonSerializer.Serialize(new { Id = sessionId }, jsonOpt), - Message = JsonSerializer.Serialize(new { Text = "I'm pulling the relevent information, please wait a second ..." }, jsonOpt) - });*/ - }, async functionExecuted => - { - // Render structured data - if (functionExecuted.Data != null) - { - // validate data format - var json = JsonSerializer.Serialize(functionExecuted.Data, jsonOpt); - - try - { - var parsed = JsonSerializer.Deserialize(json, jsonOpt); - if (parsed.Length > 0) - { - reply.QuickReplies = parsed; - } - } - catch(Exception ex) - { - _logger.LogError(ex, ex.Message); - } - } - }); - - // Response to user - await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest - { - AccessToken = setting.PageAccessToken, - Recipient = recipient, - Message = JsonSerializer.Serialize(reply, jsonOpt) - }); - - // Typing off - await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest - { - AccessToken = setting.PageAccessToken, - Recipient = recipient, - SenderAction = SenderActionEnum.TypingOff - }); + senderId = req.Entry[0].Messaging[0].Sender.Id; + message = req.Entry[0].Messaging[0].Message.Text; } + else if (req.Entry[0].Messaging[0].Postback != null) + { + senderId = req.Entry[0].Messaging[0].Sender.Id; + message = req.Entry[0].Messaging[0].Postback.Payload; + } + + var handler = _services.GetRequiredService(); + + await handler.Handle(senderId, agentId, message); } catch (ApiException ex) { - Console.WriteLine(ex.Content); + _logger.LogError(ex.Content); } catch (Exception ex) { - Console.WriteLine(ex.ToString()); + _logger.LogError(ex.ToString()); } return Ok(new WebhookResponse diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/AuthHeaderHandler.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/AuthHeaderHandler.cs index 35b11acd..3a11dfa3 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/AuthHeaderHandler.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/AuthHeaderHandler.cs @@ -1,11 +1,5 @@ using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using System.Threading; -using BotSharp.Plugin.MetaMessenger.Settings; namespace BotSharp.Plugin.MetaMessenger.GraphAPIs; diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/IMessengerGraphAPI.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/IMessengerGraphAPI.cs index bd81188f..6cf90816 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/IMessengerGraphAPI.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/GraphAPIs/IMessengerGraphAPI.cs @@ -1,9 +1,4 @@ -using BotSharp.Plugin.MetaMessenger.MessagingModels; using Refit; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; namespace BotSharp.Plugin.MetaMessenger.GraphAPIs; diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Interfaces/IResponseMessage.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Interfaces/IResponseMessage.cs deleted file mode 100644 index c03e5ea9..00000000 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/Interfaces/IResponseMessage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace BotSharp.Plugin.MetaMessenger.Interfaces; - -public interface IResponseMessage -{ -} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachementPayload.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachementPayload.cs deleted file mode 100644 index f78fd762..00000000 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachementPayload.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Text.Json.Serialization; - -namespace BotSharp.Plugin.MetaMessenger.MessagingModels; - -public class AttachementPayload -{ - [JsonPropertyName("template_type")] - public string TemplateType { get; set; } - public string Text { get; set; } - public ButtonItem[] Buttons { get; set; } -} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentBody.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentBody.cs index 90c5de53..26e26a16 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentBody.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentBody.cs @@ -2,6 +2,7 @@ namespace BotSharp.Plugin.MetaMessenger.MessagingModels; public class AttachmentBody { + [JsonPropertyName("type")] public string Type { get; set; } = "template"; - public AttachementPayload Payload { get; set; } + public ITemplateMessage Payload { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/TemplateMessage.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs similarity index 66% rename from src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/TemplateMessage.cs rename to src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs index 1981b258..08aaad34 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/TemplateMessage.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs @@ -1,13 +1,13 @@ -using BotSharp.Plugin.MetaMessenger.Interfaces; -using System.Text.Json.Serialization; - namespace BotSharp.Plugin.MetaMessenger.MessagingModels; /// /// https://developers.facebook.com/docs/messenger-platform/send-messages/templates /// -public class TemplateMessage : IResponseMessage +public class AttachmentMessage : IRichMessage { + [JsonIgnore] + public string Text { get; set; } + [JsonPropertyName("attachment")] public AttachmentBody Attachment { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessage.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessage.cs deleted file mode 100644 index 9d577143..00000000 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessage.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BotSharp.Plugin.MetaMessenger.Interfaces; -using System.Text.Json.Serialization; - -namespace BotSharp.Plugin.MetaMessenger.MessagingModels; - -/// -/// Quick Replies -/// https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies -/// -public class QuickReplyMessage : IResponseMessage -{ - [JsonPropertyName("text")] - public string Text { get; set; } - - [JsonPropertyName("quick_replies")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public QuickReplyMessageItem[]? QuickReplies { get; set; } -} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessageItem.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessageItem.cs deleted file mode 100644 index a8782d69..00000000 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/QuickReplyMessageItem.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text.Json.Serialization; - -namespace BotSharp.Plugin.MetaMessenger.MessagingModels; - -public class QuickReplyMessageItem -{ - [JsonPropertyName("content_type")] - public string ContentType { get; set; } = "text"; - - [JsonPropertyName("title")] - public string Title { get; set; } - - [JsonPropertyName("payload")] - public string Payload { get; set; } - - [JsonPropertyName("image_url")] - public string ImageUrl { get; set; } -} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SenderActionEnum.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SenderActionEnum.cs index ad24e33d..8fcec25e 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SenderActionEnum.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SenderActionEnum.cs @@ -1,5 +1,3 @@ -using System.Runtime.Serialization; - namespace BotSharp.Plugin.MetaMessenger.MessagingModels; public enum SenderActionEnum diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageRequest.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageRequest.cs index 1419856f..5008faaa 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageRequest.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageRequest.cs @@ -27,4 +27,10 @@ public class SendingMessageRequest [AliasAs("sender_action")] public SenderActionEnum? SenderAction { get; set; } + + public SendingMessageRequest(string token, string recipient) + { + AccessToken = token; + Recipient = recipient; + } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageResponse.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageResponse.cs index df598c85..237b87e3 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageResponse.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/SendingMessageResponse.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json.Serialization; - namespace BotSharp.Plugin.MetaMessenger.MessagingModels; public class SendingMessageResponse diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs index 73cdedb0..5ca6e387 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs @@ -1,13 +1,4 @@ -using BotSharp.Abstraction.Plugins; -using BotSharp.Plugin.MetaMessenger.GraphAPIs; -using BotSharp.Plugin.MetaMessenger.Settings; -using BotSharp.Abstraction.Utilities; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; using Refit; -using System; -using System.Collections.Generic; -using System.Text; namespace BotSharp.Plugin.MetaMessenger; @@ -35,6 +26,8 @@ public class MetaMessengerPlugin : IBotSharpPlugin var setting = sp.GetRequiredService(); c.BaseAddress = new Uri($"{setting.Endpoint}"); }); - //.AddHttpMessageHandler(); + //.AddHttpMessageHandler(); + + services.AddScoped(); } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs new file mode 100644 index 00000000..a3c58021 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs @@ -0,0 +1,107 @@ +using BotSharp.Abstraction.Messaging.Models.RichContent; + +namespace BotSharp.Plugin.MetaMessenger.Services; + +public class MessageHandleService +{ + private readonly IServiceProvider _services; + private JsonSerializerOptions _serializerOptions; + public MessageHandleService(IServiceProvider services) + { + _services = services; + + _serializerOptions = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + Converters = + { + new RichContentJsonConverter(), + new TemplateMessageJsonConverter() + } + }; + } + + public async Task Handle(string sender, string agentId, string message) + { + + var setting = _services.GetRequiredService(); + var messenger = _services.GetRequiredService(); + + var recipient = JsonSerializer.Serialize(new { Id = sender }, _serializerOptions); + + // Marking seen + await messenger.SendMessage(setting.ApiVersion, setting.PageId, + new SendingMessageRequest(setting.PageAccessToken, recipient) + { + SenderAction = SenderActionEnum.MarkSeen + }); + + // Typing on + await messenger.SendMessage(setting.ApiVersion, setting.PageId, + new SendingMessageRequest(setting.PageAccessToken, recipient) + { + SenderAction = SenderActionEnum.TypingOn + }); + + // Go to LLM + var conv = _services.GetRequiredService(); + conv.SetConversationId(sender, new List + { + "channel=messenger" + }); + + var replies = new List(); + var result = await conv.SendMessage(agentId, new RoleDialogModel("user", message), async msg => + { + if (!string.IsNullOrEmpty(msg.Content)) + { + replies.Add(new TextMessage(msg.Content)); + } + + if (msg.RichContent.Message is GenericTemplateMessage genericTemplate) + { + replies.Add(new AttachmentMessage + { + Attachment = new AttachmentBody + { + Payload = genericTemplate + } + }); + } + else if (msg.RichContent.Message is CouponTemplateMessage couponTemplate) + { + replies.Add(new AttachmentMessage + { + Attachment = new AttachmentBody + { + Payload = couponTemplate + } + }); + } + else if (msg.RichContent.Message is not TextMessage) + { + replies.Add(msg.RichContent.Message); + } + }, + _ => Task.CompletedTask, + _ => Task.CompletedTask); + + // Response to user + foreach(var reply in replies) + { + await messenger.SendMessage(setting.ApiVersion, setting.PageId, + new SendingMessageRequest(setting.PageAccessToken, recipient) + { + Message = JsonSerializer.Serialize(reply, _serializerOptions) + }); + Thread.Sleep(500); + } + + // Typing off + await messenger.SendMessage(setting.ApiVersion, setting.PageId, + new SendingMessageRequest(setting.PageAccessToken, recipient) + { + SenderAction = SenderActionEnum.TypingOff + }); + } +} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Using.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Using.cs new file mode 100644 index 00000000..5ab5419f --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Using.cs @@ -0,0 +1,22 @@ +global using System; +global using System.IO; +global using System.Text.Json; +global using System.Threading; +global using System.Threading.Tasks; +global using System.Collections.Generic; +global using System.Runtime.Serialization; +global using System.Text.Json.Serialization; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Logging; +global using Microsoft.Extensions.Configuration; +global using BotSharp.Abstraction.Plugins; +global using BotSharp.Plugin.MetaMessenger.GraphAPIs; +global using BotSharp.Plugin.MetaMessenger.Settings; +global using BotSharp.Abstraction.Utilities; +global using BotSharp.Plugin.MetaMessenger.Services; +global using BotSharp.Plugin.MetaMessenger.WebhookModels; +global using BotSharp.Plugin.MetaMessenger.MessagingModels; +global using BotSharp.Abstraction.Messaging; +global using BotSharp.Abstraction.Conversations.Models; +global using BotSharp.Abstraction.Conversations; +global using BotSharp.Abstraction.Messaging.Models.RichContent.Template; diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessage.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessage.cs index 20d72c37..ab718e45 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessage.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessage.cs @@ -5,5 +5,6 @@ public class WebhookMessage public WebhookMessageUser Sender { get; set; } public WebhookMessageUser Recipient { get; set; } public WebhookMessageBody Message { get; set; } + public WebhookMessagePostback Postback { get; set; } public long TimeStamp { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageBody.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageBody.cs index 0c745c9e..629a7746 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageBody.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageBody.cs @@ -1,8 +1,4 @@ -using BotSharp.Plugin.MetaMessenger.MessagingModels; -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json.Serialization; +using BotSharp.Abstraction.Messaging.Models.RichContent; namespace BotSharp.Plugin.MetaMessenger.WebhookModels; @@ -10,7 +6,11 @@ public class WebhookMessageBody { [JsonPropertyName("mid")] public string Id { get;set; } + + [JsonPropertyName("text")] public string Text { get;set; } + [JsonPropertyName("quick_reply")] - public QuickReplyMessageItem QuickReply { get;set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public QuickReplyMessage QuickReply { get;set; } } diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessagePostback.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessagePostback.cs new file mode 100644 index 00000000..cd0eff61 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessagePostback.cs @@ -0,0 +1,10 @@ +namespace BotSharp.Plugin.MetaMessenger.WebhookModels; + +public class WebhookMessagePostback +{ + public string Title { get; set; } + public string Payload { get; set; } + + [JsonPropertyName("mid")] + public string Id { get; set; } +} diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageUser.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageUser.cs index 5c7ae01c..f0a7b129 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageUser.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookMessageUser.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace BotSharp.Plugin.MetaMessenger.WebhookModels; public class WebhookMessageUser diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookObject.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookObject.cs index 9466bce8..d3c500f7 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookObject.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookObject.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace BotSharp.Plugin.MetaMessenger.WebhookModels; public class WebhookObject diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookRequest.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookRequest.cs index d73949c4..99ac21bd 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookRequest.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookRequest.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace BotSharp.Plugin.MetaMessenger.WebhookModels; public class WebhookRequest diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookResponse.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookResponse.cs index 77335d6d..5ad4b3db 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookResponse.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/WebhookModels/WebhookResponse.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace BotSharp.Plugin.MetaMessenger.WebhookModels; public class WebhookResponse diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 94ba66aa..87fdfd2c 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Users; using BotSharp.Core; using BotSharp.Core.Users.Services; @@ -8,7 +9,12 @@ using System.Text; var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllers(); +builder.Services.AddControllers() + .AddJsonOptions(options => + { + options.JsonSerializerOptions.Converters.Add(new RichContentJsonConverter()); + options.JsonSerializerOptions.Converters.Add(new TemplateMessageJsonConverter()); + }); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer();