Skip to content

Commit 16b9703

Browse files
authored
Merge pull request #742 from hchen2020/master
ITwilioHook
2 parents aaf8c59 + aefde06 commit 16b9703

File tree

13 files changed

+372
-80
lines changed

13 files changed

+372
-80
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ public interface IConversationHook
1010
Conversation Conversation { get; }
1111
IConversationHook SetConversation(Conversation conversation);
1212

13+
/// <summary>
14+
/// Get the predifined intent for the conversation.
15+
/// It will send to the conversation context to help LLM to understand the user's intent.
16+
/// </summary>
17+
/// <returns></returns>
18+
Task<string> GetConversationIntent() => Task.FromResult(string.Empty);
19+
1320
/// <summary>
1421
/// Triggered when user connects with agent first time.
1522
/// This hook is the good timing to show welcome infomation.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Infrastructures;
2+
3+
public class HookEmitOption
4+
{
5+
public bool OnlyOnce { get; set; }
6+
}

src/Infrastructure/BotSharp.Core/Infrastructures/HookEmitter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ namespace BotSharp.Core.Infrastructures;
44

55
public static class HookEmitter
66
{
7-
public static HookEmittedResult Emit<T>(IServiceProvider services, Action<T> action)
7+
public static HookEmittedResult Emit<T>(IServiceProvider services, Action<T> action, HookEmitOption? option = null)
88
{
99
var logger = services.GetRequiredService<ILogger<T>>();
1010
var result = new HookEmittedResult();
1111
var hooks = services.GetServices<T>();
12+
option = option ?? new();
1213

1314
foreach (var hook in hooks)
1415
{
1516
try
1617
{
1718
logger.LogInformation($"Emit hook action on {action.Method.Name}({hook.GetType().Name})");
1819
action(hook);
20+
21+
if (option.OnlyOnce)
22+
{
23+
break;
24+
}
1925
}
2026
catch (Exception ex)
2127
{
@@ -26,18 +32,24 @@ public static HookEmittedResult Emit<T>(IServiceProvider services, Action<T> act
2632
return result;
2733
}
2834

29-
public static async Task<HookEmittedResult> Emit<T>(IServiceProvider services, Func<T, Task> action)
35+
public static async Task<HookEmittedResult> Emit<T>(IServiceProvider services, Func<T, Task> action, HookEmitOption? option = null)
3036
{
3137
var logger = services.GetRequiredService<ILogger<T>>();
3238
var result = new HookEmittedResult();
3339
var hooks = services.GetServices<T>();
40+
option = option ?? new();
3441

3542
foreach (var hook in hooks)
3643
{
3744
try
3845
{
3946
logger.LogInformation($"Emit hook action on {action.Method.Name}({hook.GetType().Name})");
4047
await action(hook);
48+
49+
if (option.OnlyOnce)
50+
{
51+
break;
52+
}
4153
}
4254
catch (Exception ex)
4355
{

0 commit comments

Comments
 (0)