diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs index 38e017d67..c475d6a5c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs @@ -16,13 +16,12 @@ public interface IConversationService /// Send message to LLM /// /// - /// /// /// /// This delegate is useful when you want to report progress on UI /// This delegate is useful when you want to report progress on UI /// - Task SendMessage(string agentId, + Task SendMessage(string agentId, RoleDialogModel lastDalog, Func onMessageReceived, Func onFunctionExecuting, diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 098fef830..73f817474 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -35,7 +35,7 @@ List GetAgents(string? name = null, bool? disabled = null, bool? allowRou void UpdateConversationStates(string conversationId, List states); void UpdateConversationStatus(string conversationId, string status); Conversation GetConversation(string conversationId); - List GetConversations(string userId); + List GetConversations(string? agentId = null, string? status = null, string? channel = null, string? userId = null); void UpdateConversationTitle(string conversationId, string title); List GetLastConversations(); void AddExectionLogs(string conversationId, List logs); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index 613ab4fb4..adf843348 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -9,7 +9,7 @@ namespace BotSharp.Core.Conversations.Services; public partial class ConversationService { - public async Task SendMessage(string agentId, + public async Task SendMessage(string agentId, RoleDialogModel message, Func onMessageReceived, Func onFunctionExecuting, @@ -73,12 +73,15 @@ private async Task GetConversationRecord(string agentId) { var converation = await GetConversation(_conversationId); - // Create conversation if this conversation not exists + // Create conversation if this conversation does not exist if (converation == null) { + var state = _services.GetRequiredService(); + var channel = state.GetState("channel"); var sess = new Conversation { Id = _conversationId, + Channel = channel, AgentId = agentId }; converation = await NewConversation(sess); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index ff64a1e6b..92084c781 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -57,7 +57,8 @@ public async Task> GetConversations() { var db = _services.GetRequiredService(); var user = db.GetUserById(_user.Id); - var conversations = db.GetConversations(user.Role == UserRole.CSR ? null : user?.Id); + var targetUserId = user.Role == UserRole.CSR ? null : user?.Id; + var conversations = db.GetConversations(userId: targetUserId); return conversations.OrderByDescending(x => x.CreatedTime).ToList(); } diff --git a/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs b/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs index 1cb826b73..75191edfa 100644 --- a/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs +++ b/src/Infrastructure/BotSharp.Core/Evaluations/EvaluatingService.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Evaluations; using BotSharp.Abstraction.Evaluations.Models; using BotSharp.Abstraction.Evaluations.Settings; @@ -87,12 +88,15 @@ public async Task Evaluate(string conversationId, EvaluationRe private async Task SendMessage(string agentId, string conversationId, string text) { var conv = _services.GetRequiredService(); - conv.SetConversationId(conversationId, new List()); + conv.SetConversationId(conversationId, new List + { + $"channel={ConversationChannel.OpenAPI}" + }); RoleDialogModel response = default; await conv.SendMessage(agentId, - new RoleDialogModel("user", text), + new RoleDialogModel(AgentRole.User, text), async msg => response = msg, fnExecuting => Task.CompletedTask, fnExecuted => Task.CompletedTask); diff --git a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs index f4505d685..159465050 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs @@ -131,7 +131,7 @@ public Conversation GetConversation(string conversationId) throw new NotImplementedException(); } - public List GetConversations(string userId) + public List GetConversations(string? agentId = null, string? status = null, string? channel = null, string? userId = null) { throw new NotImplementedException(); } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index 1bd787ea6..6716f9f5b 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -128,12 +128,7 @@ private IQueryable UserAgents public void Add(object entity) { - if (entity is Conversation conversation) - { - _conversations.Add(conversation); - _changedTableNames.Add(nameof(Conversation)); - } - else if (entity is Agent agent) + if (entity is Agent agent) { _agents.Add(agent); _changedTableNames.Add(nameof(Agent)); @@ -159,20 +154,7 @@ public int Transaction(Action action) // Persist to disk foreach (var table in _changedTableNames) { - if (table == nameof(Conversation)) - { - foreach (var conversation in _conversations) - { - var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, conversation.Id); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - var path = Path.Combine(dir, "conversation.json"); - File.WriteAllText(path, JsonSerializer.Serialize(conversation, _options)); - } - } - else if (table == nameof(Agent)) + if (table == nameof(Agent)) { foreach (var agent in _agents) { @@ -730,32 +712,29 @@ public void UpdateConversationStatus(string conversationId, string status) public Conversation GetConversation(string conversationId) { var convDir = FindConversationDirectory(conversationId); - if (!string.IsNullOrEmpty(convDir)) - { - var convFile = Path.Combine(convDir, "conversation.json"); - var content = File.ReadAllText(convFile); - var record = JsonSerializer.Deserialize(content, _options); + if (string.IsNullOrEmpty(convDir)) return null; - var dialogFile = Path.Combine(convDir, "dialogs.txt"); - if (record != null) - { - record.Dialogs = CollectDialogElements(dialogFile); - } + var convFile = Path.Combine(convDir, "conversation.json"); + var content = File.ReadAllText(convFile); + var record = JsonSerializer.Deserialize(content, _options); - var stateFile = Path.Combine(convDir, "state.dict"); - if (record != null) - { - var states = CollectConversationStates(stateFile); - record.States = new ConversationState(states); - } + var dialogFile = Path.Combine(convDir, "dialogs.txt"); + if (record != null) + { + record.Dialogs = CollectDialogElements(dialogFile); + } - return record; + var stateFile = Path.Combine(convDir, "state.dict"); + if (record != null) + { + var states = CollectConversationStates(stateFile); + record.States = new ConversationState(states); } - return null; + return record; } - public List GetConversations(string userId) + public List GetConversations(string? agentId = null, string? status = null, string? channel = null, string? userId = null) { var records = new List(); var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir); @@ -767,10 +746,16 @@ public List GetConversations(string userId) var json = File.ReadAllText(path); var record = JsonSerializer.Deserialize(json, _options); - if (record != null && (record.UserId == userId || userId == null)) - { - records.Add(record); - } + if (record == null) continue; + + var matched = true; + if (!string.IsNullOrEmpty(agentId)) matched = matched && record.AgentId == agentId; + if (!string.IsNullOrEmpty(status)) matched = matched && record.Status == status; + if (!string.IsNullOrEmpty(channel)) matched = matched && record.Channel == channel; + if (!string.IsNullOrEmpty(userId)) matched = matched && record.UserId == userId; + + if (!matched) continue; + records.Add(record); } return records; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 72ab4aa9c..5527f13f2 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -143,11 +143,11 @@ protected RoutingRule[] GetRoutingRecords() // Filter agents by profile var state = _services.GetRequiredService(); - var name = state.GetState("channel"); - var specifiedProfile = agents.FirstOrDefault(x => x.Profiles.Contains(name)); + var channel = state.GetState("channel"); + var specifiedProfile = agents.FirstOrDefault(x => x.Profiles.Contains(channel)); if (specifiedProfile != null) { - records = records.Where(x => specifiedProfile.Profiles.Contains(name)).ToArray(); + records = records.Where(x => specifiedProfile.Profiles.Contains(channel)).ToArray(); } return records; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index de82fbf18..dde374821 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -1,4 +1,6 @@ +using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.ApiAdapters; +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Models; using BotSharp.OpenAPI.ViewModels.Conversations; @@ -30,6 +32,7 @@ public async Task NewConversation([FromRoute] string agen var conv = new Conversation { AgentId = agentId, + Channel = ConversationChannel.OpenAPI, UserId = _user.Id }; conv = await service.NewConversation(conv); @@ -98,13 +101,13 @@ public async Task SendMessage([FromRoute] string agentId, var conv = _services.GetRequiredService(); conv.SetConversationId(conversationId, input.States); conv.States.SetState("channel", input.Channel) - .SetState("provider", input.Provider) - .SetState("model", input.Model) - .SetState("temperature", input.Temperature) - .SetState("sampling_factor", input.SamplingFactor); + .SetState("provider", input.Provider) + .SetState("model", input.Model) + .SetState("temperature", input.Temperature) + .SetState("sampling_factor", input.SamplingFactor); var response = new ChatResponseModel(); - var inputMsg = new RoleDialogModel("user", input.Text); + var inputMsg = new RoleDialogModel(AgentRole.User, input.Text); await conv.SendMessage(agentId, inputMsg, async msg => { diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/NewMessageModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/NewMessageModel.cs index 4b84f8f56..1750a3037 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/NewMessageModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/NewMessageModel.cs @@ -1,8 +1,9 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; namespace BotSharp.OpenAPI.ViewModels.Conversations; public class NewMessageModel : IncomingMessageModel { - public override string Channel { get; set; } = "openapi"; + public override string Channel { get; set; } = ConversationChannel.OpenAPI; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs index 6da688954..33e5e1687 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs @@ -1,8 +1,9 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; namespace BotSharp.OpenAPI.ViewModels.Instructs; public class InstructMessageModel : IncomingMessageModel { - public override string Channel { get; set; } = "openapi"; + public override string Channel { get; set; } = ConversationChannel.OpenAPI; public string? Template { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index 0fa194dee..5dd17606d 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -76,13 +76,13 @@ public async Task SendMessage([FromBody] OpenAiMessageInput input) var conv = _services.GetRequiredService(); conv.SetConversationId(input.ConversationId, input.States); - conv.States.SetState("provider", input.Provider) - .SetState("model", input.Model) - .SetState("channel", input.Channel) - .SetState("temperature", input.Temperature) - .SetState("sampling_factor", input.SamplingFactor); + conv.States.SetState("channel", input.Channel) + .SetState("provider", input.Provider) + .SetState("model", input.Model) + .SetState("temperature", input.Temperature) + .SetState("sampling_factor", input.SamplingFactor); - var result = await conv.SendMessage(input.AgentId, + var result = await conv.SendMessage(input.AgentId, message, async msg => await OnChunkReceived(outputStream, msg), diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs b/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs index 65dfd4910..4ffdadbe4 100644 --- a/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs +++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Conversations.Models; using System.Collections.Generic; using System.Linq; @@ -9,7 +10,7 @@ public class OpenAiMessageInput : IncomingMessageModel { public string AgentId { get; set; } = string.Empty; public string ConversationId { get; set; } = string.Empty; - public override string Channel { get; set; } = "webchat"; + public override string Channel { get; set; } = ConversationChannel.WebChat; public List Messages { get; set; } = new List(); diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs index 465eca070..a11be86d7 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/Services/MessageHandleService.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Agents.Enums; +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Messaging.Models.RichContent; using BotSharp.Abstraction.Utilities; @@ -48,58 +50,59 @@ await messenger.SendMessage(setting.ApiVersion, setting.PageId, var conv = _services.GetRequiredService(); conv.SetConversationId(sender, new List { - "channel=messenger" + $"channel={ConversationChannel.Messenger}" }); var replies = new List(); - var result = await conv.SendMessage(agentId, new RoleDialogModel("user", message), async msg => - { - if (msg.RichContent != null) + var result = await conv.SendMessage(agentId, + new RoleDialogModel(AgentRole.User, message), async msg => { - // Official API doesn't support to show extra content above the products - if (!string.IsNullOrEmpty(msg.RichContent.Message.Text) && - // avoid duplicated text - msg.RichContent.Message is not QuickReplyMessage) + if (msg.RichContent != null) { - replies.Add(new TextMessage(msg.RichContent.Message.Text)); - } + // Official API doesn't support to show extra content above the products + if (!string.IsNullOrEmpty(msg.RichContent.Message.Text) && + // avoid duplicated text + msg.RichContent.Message is not QuickReplyMessage) + { + replies.Add(new TextMessage(msg.RichContent.Message.Text)); + } - if (msg.RichContent.Message is GenericTemplateMessage genericTemplate) - { - replies.Add(new AttachmentMessage + if (msg.RichContent.Message is GenericTemplateMessage genericTemplate) { - Attachment = new AttachmentBody + replies.Add(new AttachmentMessage { - Payload = genericTemplate - } - }); - } - else if (msg.RichContent.Message is CouponTemplateMessage couponTemplate) - { - replies.Add(new AttachmentMessage + Attachment = new AttachmentBody + { + Payload = genericTemplate + } + }); + } + else if (msg.RichContent.Message is CouponTemplateMessage couponTemplate) { - Attachment = new AttachmentBody + replies.Add(new AttachmentMessage { - Payload = couponTemplate - } - }); - } - else if (msg.RichContent.Message is QuickReplyMessage quickReplyMessage) - { - replies.Add(quickReplyMessage); + Attachment = new AttachmentBody + { + Payload = couponTemplate + } + }); + } + else if (msg.RichContent.Message is QuickReplyMessage quickReplyMessage) + { + replies.Add(quickReplyMessage); + } + else + { + replies.Add(msg.RichContent.Message); + } } else { - replies.Add(msg.RichContent.Message); + replies.Add(new TextMessage(msg.Content)); } - } - else - { - replies.Add(new TextMessage(msg.Content)); - } - }, - _ => Task.CompletedTask, - _ => Task.CompletedTask); + }, + _ => Task.CompletedTask, + _ => Task.CompletedTask); // Response to user foreach(var reply in replies) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationCollection.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationCollection.cs index 3eace7ee7..8a6ed4f85 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationCollection.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationCollection.cs @@ -7,6 +7,7 @@ public class ConversationCollection : MongoBase public string AgentId { get; set; } public string UserId { get; set; } public string Title { get; set; } + public string Channel { get; set; } public string Status { get; set; } public List States { get; set; } public DateTime CreatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs index 71c59f940..cc55794bf 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs @@ -32,12 +32,7 @@ public MongoRepository(MongoDbContext dc, IServiceProvider services) public void Add(object entity) { - if (entity is Conversation conversation) - { - _conversations.Add(conversation); - _changedTableNames.Add(nameof(Conversation)); - } - else if (entity is Agent agent) + if (entity is Agent agent) { _agents.Add(agent); _changedTableNames.Add(nameof(Agent)); @@ -61,33 +56,7 @@ public int Transaction(Action action) foreach (var table in _changedTableNames) { - if (table == nameof(Conversation)) - { - var conversations = _conversations.Select(x => new ConversationCollection - { - Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(), - AgentId = x.AgentId, - UserId = !string.IsNullOrEmpty(x.UserId) ? x.UserId : string.Empty, - Title = x.Title, - States = x.States?.ToKeyValueList() ?? new List(), - CreatedTime = x.CreatedTime, - UpdatedTime = x.UpdatedTime - }).ToList(); - - foreach (var conversation in conversations) - { - var filter = Builders.Filter.Eq(x => x.Id, conversation.Id); - var update = Builders.Update - .Set(x => x.AgentId, conversation.AgentId) - .Set(x => x.UserId, conversation.UserId) - .Set(x => x.Title, conversation.Title) - .Set(x => x.States, conversation.States) - .Set(x => x.CreatedTime, conversation.CreatedTime) - .Set(x => x.UpdatedTime, conversation.UpdatedTime); - _dc.Conversations.UpdateOne(filter, update, _options); - } - } - else if (table == nameof(Agent)) + if (table == nameof(Agent)) { var agents = _agents.Select(x => new AgentCollection { @@ -610,6 +579,7 @@ public void CreateNewConversation(Conversation conversation) AgentId = conversation.AgentId, UserId = !string.IsNullOrEmpty(conversation.UserId) ? conversation.UserId : string.Empty, Title = conversation.Title, + Channel = conversation.Channel, Status = conversation.Status, States = conversation.States?.ToKeyValueList() ?? new List(), CreatedTime = DateTime.UtcNow, @@ -670,6 +640,7 @@ public void AppendConversationDialogs(string conversationId, List _dc.ConversationDialogs.UpdateOne(filterDialog, updateDialog); _dc.Conversations.UpdateOne(filterConv, updateConv); } + public void UpdateConversationTitle(string conversationId, string title) { if (string.IsNullOrEmpty(conversationId)) return; @@ -684,6 +655,7 @@ public void UpdateConversationTitle(string conversationId, string title) _dc.Conversations.UpdateOne(filterConv, updateConv); } + public List GetConversationStates(string conversationId) { var states = new List(); @@ -745,6 +717,7 @@ public Conversation GetConversation(string conversationId) AgentId = conv.AgentId.ToString(), UserId = conv.UserId.ToString(), Title = conv.Title, + Channel = conv.Channel, Status = conv.Status, Dialogs = dialogElements, States = new ConversationState(conv.States ?? new List()), @@ -753,13 +726,20 @@ public Conversation GetConversation(string conversationId) }; } - public List GetConversations(string userId) + public List GetConversations(string? agentId = null, string? status = null, string? channel = null, string? userId = null) { var records = new List(); if (string.IsNullOrEmpty(userId)) return records; - var filterByUserId = Builders.Filter.Eq(x => x.UserId, userId); - var conversations = _dc.Conversations.Find(filterByUserId).ToList(); + var builder = Builders.Filter; + var filters = new List>(); + + if (!string.IsNullOrEmpty(agentId)) filters.Add(builder.Eq(x => x.AgentId, agentId)); + if (!string.IsNullOrEmpty(status)) filters.Add(builder.Eq(x => x.Status, status)); + if (!string.IsNullOrEmpty(channel)) filters.Add(builder.Eq(x => x.Channel, channel)); + if (!string.IsNullOrEmpty(userId)) filters.Add(builder.Eq(x => x.UserId, userId)); + + var conversations = _dc.Conversations.Find(builder.And(filters)).ToList(); foreach (var conv in conversations) { @@ -770,6 +750,7 @@ public List GetConversations(string userId) AgentId = conv.AgentId.ToString(), UserId = conv.UserId.ToString(), Title = conv.Title, + Channel = conv.Channel, Status = conv.Status, CreatedTime = conv.CreatedTime, UpdatedTime = conv.UpdatedTime @@ -791,6 +772,7 @@ public List GetLastConversations() AgentId = c.AgentId.ToString(), UserId = c.UserId.ToString(), Title = c.Title, + Channel = c.Channel, Status = c.Status, CreatedTime = c.CreatedTime, UpdatedTime = c.UpdatedTime diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs index 7913c0567..ec2cd1a47 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioVoiceController.cs @@ -15,6 +15,7 @@ using Twilio.TwiML.Messaging; using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.Conversations.Models; +using BotSharp.Abstraction.Conversations.Enums; namespace BotSharp.Plugin.Twilio.Controllers; @@ -46,20 +47,22 @@ public async Task ReceivedVoiceMessage([FromRoute] string agentId, var conv = _services.GetRequiredService(); conv.SetConversationId(sessionId, new List { - "channel=phone", + $"channel={ConversationChannel.Phone}", $"calling_phone={input.DialCallSid}" }); VoiceResponse response = default; - var result = await conv.SendMessage(agentId, new RoleDialogModel(AgentRole.User, input.SpeechResult), async msg => - { - response = HangUp(msg.Content); - }, async functionExecuting => - { - }, async functionExecuted => - { - }); + var result = await conv.SendMessage(agentId, + new RoleDialogModel(AgentRole.User, input.SpeechResult), + async msg => + { + response = HangUp(msg.Content); + }, async functionExecuting => + { + }, async functionExecuted => + { + }); return TwiML(response); }