BotSharp/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.UpdateBreakpoint.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Infrastructures.Enums;
2024-03-24 01:31:15 +00:00
namespace BotSharp.Core.Conversations.Services;
public partial class ConversationService : IConversationService
{
2024-05-27 12:44:01 +00:00
public async Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates)
2024-03-24 01:31:15 +00:00
{
var db = _services.GetRequiredService<IBotSharpRepository>();
2024-03-26 17:10:34 +00:00
var routingCtx = _services.GetRequiredService<IRoutingContext>();
var messageId = routingCtx.MessageId;
2024-04-08 03:15:51 +00:00
db.UpdateConversationBreakpoint(_conversationId, new ConversationBreakpoint
{
MessageId = messageId,
Breakpoint = DateTime.UtcNow,
Reason = reason
});
2024-03-24 13:56:21 +00:00
// Reset states
if (resetStates)
{
var states = _services.GetRequiredService<IConversationStateService>();
// keep language state
2024-05-27 13:17:50 +00:00
if (excludedStates == null) excludedStates = new string[] { };
if (!excludedStates.Contains(StateConst.LANGUAGE))
{
excludedStates = excludedStates.Append(StateConst.LANGUAGE).ToArray();
}
2024-05-27 12:44:01 +00:00
states.CleanStates(excludedStates);
2024-03-24 13:56:21 +00:00
}
var hooks = _services.GetServices<IConversationHook>()
.OrderBy(x => x.Priority)
.ToList();
// Before executing functions
foreach (var hook in hooks)
{
await hook.OnBreakpointUpdated(_conversationId, resetStates);
}
2024-03-24 01:31:15 +00:00
}
}