Resolve issue "Update Conversation title dynamically"
This commit is contained in:
parent
8aaa3c6b50
commit
59160bffcb
|
|
@ -8,6 +8,7 @@ public interface IConversationService
|
|||
void SetConversationId(string conversationId, List<string> states);
|
||||
Task<Conversation> GetConversation(string id);
|
||||
Task<List<Conversation>> GetConversations();
|
||||
Task<Conversation> UpdateConversationTitle(string id, string title);
|
||||
Task<List<Conversation>> GetLastConversations();
|
||||
Task DeleteConversation(string id);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public interface IBotSharpRepository
|
|||
void UpdateConversationStatus(string conversationId, string status);
|
||||
Conversation GetConversation(string conversationId);
|
||||
List<Conversation> GetConversations(string userId);
|
||||
void UpdateConversationTitle(string conversationId, string title);
|
||||
List<Conversation> GetLastConversations();
|
||||
void AddExectionLogs(string conversationId, List<string> logs);
|
||||
List<string> GetExectionLogs(string conversationId);
|
||||
|
|
|
|||
|
|
@ -128,5 +128,7 @@ public partial class ConversationService
|
|||
|
||||
// Add to dialog history
|
||||
_storage.Append(_conversationId, response);
|
||||
var conversation = _services.GetRequiredService<IConversationService>();
|
||||
var updatedConversation = await conversation.UpdateConversationTitle(_conversationId, response.Instruction.Reason);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,13 @@ public partial class ConversationService : IConversationService
|
|||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Conversation> UpdateConversationTitle(string id, string title)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.UpdateConversationTitle(id, title);
|
||||
var conversation = db.GetConversation(id);
|
||||
return conversation;
|
||||
}
|
||||
public async Task<Conversation> GetConversation(string id)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
|
|
|||
|
|
@ -150,7 +150,10 @@ public class BotSharpDbContext : Database, IBotSharpRepository
|
|||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpdateConversationTitle(string conversationId, string title)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void UpdateConversationStates(string conversationId, List<StateKeyValue> states)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
|||
|
|
@ -654,7 +654,22 @@ public class FileRepository : IBotSharpRepository
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
public void UpdateConversationTitle(string conversationId, string title)
|
||||
{
|
||||
var convDir = FindConversationDirectory(conversationId);
|
||||
if (!string.IsNullOrEmpty(convDir))
|
||||
{
|
||||
var convFile = Path.Combine(convDir, "conversation.json");
|
||||
var content = File.ReadAllText(convFile);
|
||||
var record = JsonSerializer.Deserialize<Conversation>(content, _options);
|
||||
if (record != null)
|
||||
{
|
||||
record.Title = title;
|
||||
record.UpdatedTime = DateTime.UtcNow;
|
||||
File.WriteAllText(convFile, JsonSerializer.Serialize(record, _options));
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<StateKeyValue> GetConversationStates(string conversationId)
|
||||
{
|
||||
var curStates = new List<StateKeyValue>();
|
||||
|
|
|
|||
|
|
@ -656,7 +656,20 @@ public class MongoRepository : IBotSharpRepository
|
|||
_dc.ConversationDialogs.UpdateOne(filterDialog, updateDialog);
|
||||
_dc.Conversations.UpdateOne(filterConv, updateConv);
|
||||
}
|
||||
public void UpdateConversationTitle(string conversationId, string title)
|
||||
{
|
||||
if (string.IsNullOrEmpty(conversationId)) return;
|
||||
|
||||
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
|
||||
var foundConv = _dc.Conversations.Find(filterConv).FirstOrDefault();
|
||||
if (foundConv == null) return;
|
||||
|
||||
var updateConv = Builders<ConversationCollection>.Update
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow)
|
||||
.Set(x => x.Title, title);
|
||||
|
||||
_dc.Conversations.UpdateOne(filterConv, updateConv);
|
||||
}
|
||||
public List<StateKeyValue> GetConversationStates(string conversationId)
|
||||
{
|
||||
var states = new List<StateKeyValue>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue