File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed
BotSharp.Abstraction/Conversations
BotSharp.Core/Conversations/Services Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1+ using BotSharp . Abstraction . Repositories . Filters ;
2+
13namespace BotSharp . Abstraction . Conversations ;
24
35public abstract class ConversationHookBase : IConversationHook
@@ -37,6 +39,12 @@ public virtual Task OnDialogsLoaded(List<RoleDialogModel> dialogs)
3739 return Task . CompletedTask ;
3840 }
3941
42+ public virtual Task < string > OnConversationsListing ( ConversationFilter filter )
43+ => Task . FromResult ( string . Empty ) ;
44+
45+ public virtual Task OnConversationCreating ( Conversation conversation )
46+ => Task . CompletedTask ;
47+
4048 public virtual Task OnConversationEnding ( RoleDialogModel message )
4149 => Task . CompletedTask ;
4250
Original file line number Diff line number Diff line change 11using BotSharp . Abstraction . Hooks ;
2+ using BotSharp . Abstraction . Repositories . Filters ;
23
34namespace BotSharp . Abstraction . Conversations ;
45
@@ -19,6 +20,20 @@ public interface IConversationHook : IHookBase
1920 /// <returns></returns>
2021 Task < string > GetConversationIntent ( ) => Task . FromResult ( string . Empty ) ;
2122
23+ /// <summary>
24+ /// Triggered when listing conversations.
25+ /// </summary>
26+ /// <param name="filter"></param>
27+ /// <returns></returns>
28+ Task < string > OnConversationsListing ( ConversationFilter filter ) ;
29+
30+ /// <summary>
31+ /// Triggered when a new conversation is creating.
32+ /// </summary>
33+ /// <param name="conversation"></param>
34+ /// <returns></returns>
35+ Task OnConversationCreating ( Conversation conversation ) ;
36+
2237 /// <summary>
2338 /// Triggered when user connects with agent first time.
2439 /// This hook is the good timing to show welcome infomation.
Original file line number Diff line number Diff line change @@ -84,6 +84,13 @@ public async Task<PagedItems<Conversation>> GetConversations(ConversationFilter
8484 }
8585
8686 var db = _services . GetRequiredService < IBotSharpRepository > ( ) ;
87+
88+ var hooks = _services . GetHooks < IConversationHook > ( filter . AgentId ) ;
89+ foreach ( var hook in hooks )
90+ {
91+ await hook . OnConversationsListing ( filter ) ;
92+ }
93+
8794 var conversations = await db . GetConversations ( filter ) ;
8895 return conversations ;
8996 }
@@ -112,9 +119,14 @@ public async Task<Conversation> NewConversation(Conversation sess)
112119 record . Tags = sess . Tags ;
113120 record . Title = string . IsNullOrEmpty ( record . Title ) ? "New Conversation" : record . Title ;
114121
115- await db . CreateNewConversation ( record ) ;
122+ var hooks = _services . GetHooks < IConversationHook > ( sess . AgentId ) ;
123+ foreach ( var hook in hooks )
124+ {
125+ // If user connect agent first time
126+ await hook . OnConversationCreating ( record ) ;
127+ }
116128
117- var hooks = _services . GetHooks < IConversationHook > ( record . AgentId ) ;
129+ await db . CreateNewConversation ( record ) ;
118130
119131 foreach ( var hook in hooks )
120132 {
You can’t perform that action at this time.
0 commit comments