diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index 38734d75..5ded2c7c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -24,6 +24,11 @@ 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(); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 97b69d44..070f4c59 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 channelId = state.GetState("channel_id"); var sess = new Conversation { Id = _conversationId, Channel = channel, + ChannelId = channelId, AgentId = agentId }; converation = await NewConversation(sess); 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)) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index 609d637d..28b0391a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -7,6 +7,7 @@ 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; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index ff7cefcd..d8159da1 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, + ChannelId = conversation.ChannelId, TaskId = conversation.TaskId, Status = conversation.Status, Tags = conversation.Tags ?? new(), 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)));