BotSharp/src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2025-01-24 05:45:43 +00:00
using BotSharp.Abstraction.Statistics.Enums;
using BotSharp.Abstraction.Statistics.Models;
using BotSharp.Abstraction.Statistics.Services;
namespace BotSharp.Logger.Hooks;
public class GlobalStatsConversationHook : ConversationHookBase
{
private readonly IServiceProvider _services;
public GlobalStatsConversationHook(
IServiceProvider services)
{
_services = services;
}
public override async Task OnMessageReceived(RoleDialogModel message)
{
UpdateAgentCall(message);
}
public override async Task OnPostbackMessageReceived(RoleDialogModel message, PostbackMessageModel replyMsg)
{
UpdateAgentCall(message);
}
private void UpdateAgentCall(RoleDialogModel message)
{
// record agent call
2025-01-28 00:23:33 +00:00
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
2025-01-24 05:45:43 +00:00
var body = new BotSharpStats
{
Category = StatCategory.AgentCall,
Group = $"Agent: {message.CurrentAgentId}",
Data = new Dictionary<string, object>
{
{ "agent_id", message.CurrentAgentId },
{ "agent_call_count", 1 }
},
2025-01-24 19:42:17 +00:00
RecordTime = DateTime.UtcNow
2025-01-24 05:45:43 +00:00
};
globalStats.UpdateAgentCall(body);
}
}