From 15ce459971aa89068f9cd4ba18f69d6bb18012ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Tue, 22 Oct 2024 09:05:56 +0800 Subject: [PATCH 1/4] Add a CallingPhone column to the ConversationDocument --- .../BotSharp.Abstraction/Conversations/Models/Conversation.cs | 2 ++ .../BotSharp.Core/Conversations/Services/ConversationService.cs | 2 ++ .../Collections/ConversationDocument.cs | 1 + .../Repository/MongoRepository.Conversation.cs | 1 + 4 files changed, 6 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index 38734d75..c2be970f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -28,6 +28,8 @@ public class Conversation public List Tags { get; set; } = new(); + public string CallingPhone { get; set; } + public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 97b69d44..a9c56fa9 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -172,10 +172,12 @@ public partial class ConversationService : IConversationService { var state = _services.GetRequiredService(); var channel = state.GetState("channel"); + var callingPhone = state.GetState("calling_phone"); var sess = new Conversation { Id = _conversationId, Channel = channel, + CallingPhone = callingPhone, AgentId = agentId }; converation = await NewConversation(sess); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index 609d637d..b23f26a4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -10,6 +10,7 @@ public class ConversationDocument : MongoBase public string Status { get; set; } public int DialogCount { get; set; } public List Tags { get; set; } + public string CallingPhone { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index ff7cefcd..f0104788 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -17,6 +17,7 @@ public partial class MongoRepository UserId = !string.IsNullOrEmpty(conversation.UserId) ? conversation.UserId : string.Empty, Title = conversation.Title, Channel = conversation.Channel, + CallingPhone = conversation.CallingPhone, TaskId = conversation.TaskId, Status = conversation.Status, Tags = conversation.Tags ?? new(), From ad0b6bb6f41599d1dc417c559113a2812e7dbe31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Tue, 22 Oct 2024 09:19:27 +0800 Subject: [PATCH 2/4] optimize tags init --- .../Repository/FileRepository/FileRepository.Conversation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index bc9912b3..7da6c849 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -10,7 +10,7 @@ namespace BotSharp.Core.Repository var utcNow = DateTime.UtcNow; conversation.CreatedTime = utcNow; conversation.UpdatedTime = utcNow; - conversation.Tags = conversation.Tags ?? new(); + conversation.Tags ??= new(); var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, conversation.Id); if (!Directory.Exists(dir)) From 127f501771e69dd2959ce3f244348353de0d17ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Fri, 25 Oct 2024 10:12:59 +0800 Subject: [PATCH 3/4] conversation add channelId field --- .../Conversations/Models/Conversation.cs | 7 +++++-- .../Conversations/Services/ConversationService.cs | 4 ++-- .../Collections/ConversationDocument.cs | 2 +- .../Services/TwilioMessageQueueService.cs | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index c2be970f..5ded2c7c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -24,12 +24,15 @@ public class Conversation public string Channel { get; set; } = ConversationChannel.OpenAPI; + /// + /// Channel id, like phone number, email address, etc. + /// + public string ChannelId { get; set; } + public int DialogCount { get; set; } public List Tags { get; set; } = new(); - public string CallingPhone { get; set; } - public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index a9c56fa9..070f4c59 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -172,12 +172,12 @@ public partial class ConversationService : IConversationService { var state = _services.GetRequiredService(); var channel = state.GetState("channel"); - var callingPhone = state.GetState("calling_phone"); + var channelId = state.GetState("channel_id"); var sess = new Conversation { Id = _conversationId, Channel = channel, - CallingPhone = callingPhone, + ChannelId = channelId, AgentId = agentId }; converation = await NewConversation(sess); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index b23f26a4..28b0391a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -7,10 +7,10 @@ public class ConversationDocument : MongoBase public string? TaskId { get; set; } public string Title { get; set; } public string Channel { get; set; } + public string ChannelId { get; set; } public string Status { get; set; } public int DialogCount { get; set; } public List Tags { get; set; } - public string CallingPhone { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs index fe63ba82..b98f9330 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs @@ -108,6 +108,7 @@ namespace BotSharp.Plugin.Twilio.Services var states = new List { new("channel", ConversationChannel.Phone), + new("channel_id", message.From), new("calling_phone", message.From) }; states.AddRange(message.States.Select(kvp => new MessageState(kvp.Key, kvp.Value))); From f635bbcb496581bc980bc8844fb2150681252682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Fri, 25 Oct 2024 10:18:43 +0800 Subject: [PATCH 4/4] add channelId --- .../Repository/MongoRepository.Conversation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index f0104788..d8159da1 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -17,7 +17,7 @@ public partial class MongoRepository UserId = !string.IsNullOrEmpty(conversation.UserId) ? conversation.UserId : string.Empty, Title = conversation.Title, Channel = conversation.Channel, - CallingPhone = conversation.CallingPhone, + ChannelId = conversation.ChannelId, TaskId = conversation.TaskId, Status = conversation.Status, Tags = conversation.Tags ?? new(),