From c78556233091684bd2adabc63b5f8e2e35e42c87 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Wed, 28 Aug 2024 10:02:53 -0500 Subject: [PATCH] Disable RateLimit for phone. --- .../Hooks/RateLimitConversationHook.cs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs index 158257be..1cb09f3e 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Agents.Enums; +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Users; @@ -47,20 +48,26 @@ public class RateLimitConversationHook : ConversationHookBase } } - // Check the number of conversations - var user = _services.GetRequiredService(); - var convService = _services.GetRequiredService(); - var results = await convService.GetConversations(new ConversationFilter - { - UserId = user.Id, - StartTime = DateTime.UtcNow.AddHours(-24), - }); + var states = _services.GetRequiredService(); + var channel = states.GetState("channel"); - if (results.Count > rateLimit.MaxConversationPerDay) + // Check the number of conversations + if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email) { - message.Content = $"The number of conversations you have exceeds the system maximum of {rateLimit.MaxConversationPerDay}"; - message.StopCompletion = true; - return; + var user = _services.GetRequiredService(); + var convService = _services.GetRequiredService(); + var results = await convService.GetConversations(new ConversationFilter + { + UserId = user.Id, + StartTime = DateTime.UtcNow.AddHours(-24), + }); + + if (results.Count > rateLimit.MaxConversationPerDay) + { + message.Content = $"The number of conversations you have exceeds the system maximum of {rateLimit.MaxConversationPerDay}"; + message.StopCompletion = true; + return; + } } } }