Skip to content

Commit 6c1cebe

Browse files
author
Jicheng Lu
committed
add message delete event
1 parent 656b533 commit 6c1cebe

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ public virtual Task OnConversationInitialized(Conversation conversation)
6767

6868
public virtual Task OnUserAgentConnectedInitially(Conversation conversation)
6969
=> Task.CompletedTask;
70+
71+
public virtual Task OnMessageDeleted(string conversationId, string messageId)
72+
=> Task.CompletedTask;
7073
}

‎src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ public interface IConversationHook
8484
/// <param name="conversation"></param>
8585
/// <returns></returns>
8686
Task OnHumanInterventionNeeded(RoleDialogModel message);
87+
88+
/// <summary>
89+
/// Delete message in a conversation
90+
/// </summary>
91+
/// <param name="conversationId"></param>
92+
/// <param name="messageId"></param>
93+
/// <returns></returns>
94+
Task OnMessageDeleted(string conversationId, string messageId);
8795
}

‎src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.TruncateMessage.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public async Task<bool> TruncateConversation(string conversationId, string messa
88
{
99
var db = _services.GetRequiredService<IBotSharpRepository>();
1010
var isSaved = db.TruncateConversation(conversationId, messageId, true);
11+
var hooks = _services.GetServices<IConversationHook>().ToList();
12+
foreach (var hook in hooks)
13+
{
14+
await hook.OnMessageDeleted(conversationId, messageId);
15+
}
1116
return await Task.FromResult(isSaved);
1217
}
1318
}

‎src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static IServiceCollection AddBotSharpOpenAPI(this IServiceCollection serv
3030
bool enableValidation)
3131
{
3232
services.AddScoped<IUserIdentity, UserIdentity>();
33-
services.AddHostedService<ConversationTimeoutService>();
33+
//services.AddHostedService<ConversationTimeoutService>();
3434

3535
// Add bearer authentication
3636
var schema = "MIXED_SCHEME";

‎src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,14 @@ public override async Task OnResponseGenerated(RoleDialogModel message)
9696

9797
await base.OnResponseGenerated(message);
9898
}
99+
100+
public override async Task OnMessageDeleted(string conversationId, string messageId)
101+
{
102+
await _chatHub.Clients.User(_user.Id).SendAsync("OnMessageDeleted", new ChatResponseModel
103+
{
104+
ConversationId = conversationId,
105+
MessageId = messageId
106+
});
107+
await base.OnMessageDeleted(conversationId, messageId);
108+
}
99109
}

0 commit comments

Comments
 (0)