diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index 0556b8ad..fa0a1938 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -6,6 +6,7 @@ public class RoleDialogModel /// user, system, assistant, function /// public string Role { get; set; } + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public string Content { get; set; } /// diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs index aa1db6f3..423e6563 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionExecutionValidationResult.cs @@ -19,5 +19,6 @@ public class FunctionExecutionValidationResult public string ValidationStatus { get; set; } [JsonPropertyName("validation_message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string ValidationMessage { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index fc9564f9..d30fe413 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Conversations.Models; using System.IO; +using Tensorflow; namespace BotSharp.Core.Conversations.Services; @@ -14,20 +15,32 @@ public class ConversationStorage : IConversationStorage public void Append(string agentId, string conversationId, RoleDialogModel dialog) { var conversationFile = GetStorageFile(agentId, conversationId); - File.AppendAllText(conversationFile, $"{dialog.Role}: {dialog.Content}\n"); + var sb = new StringBuilder(); + sb.AppendLine($"{dialog.Role}|{dialog.CreatedAt}"); + sb.AppendLine($" - {dialog.Content}"); + var conversation = sb.ToString(); + File.AppendAllText(conversationFile, conversation); } public List GetDialogs(string agentId, string conversationId) { var conversationFile = GetStorageFile(agentId, conversationId); var dialogs = File.ReadAllLines(conversationFile); - return dialogs.Select(x => + + var results = new List(); + for (int i = 0; i < dialogs.Length; i += 2) { - var pos = x.IndexOf(':'); - var role = x.Substring(0, pos); - var text = x.Substring(pos + 1); - return new RoleDialogModel(role, text); - }).ToList(); + var meta = dialogs[i]; + var dialog = dialogs[i + 1]; + var role = meta.Split('|')[0]; + var createdAt = DateTime.Parse(meta.Split('|')[1]); + var text = dialog.Substring(4); + results.Add(new RoleDialogModel(role, text) + { + CreatedAt = createdAt + }); + } + return results; } public void InitStorage(string agentId, string conversationId) diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs index b666bf07..6c15c19b 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Controllers/WebhookController.cs @@ -105,6 +105,13 @@ public class WebhookController : ControllerBase Recipient = JsonSerializer.Serialize(new { Id = sessionId }, jsonOpt), Message = JsonSerializer.Serialize(new { Text = "I'm pulling the relevent information, please wait a second ..." }, jsonOpt) }); + + await messenger.SendMessage(setting.ApiVersion, setting.PageId, new SendingMessageRequest + { + AccessToken = setting.PageAccessToken, + Recipient = JsonSerializer.Serialize(new { Id = sessionId }, jsonOpt), + SenderAction = SenderActionEnum.TypingOn + }); }); // Response to user