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
|
|
|
|
2025-01-28 05:10:37 +00:00
|
|
|
var body = new BotSharpStatsInput
|
2025-01-24 05:45:43 +00:00
|
|
|
{
|
2025-01-28 05:10:37 +00:00
|
|
|
Category = StatsCategory.AgentCall,
|
|
|
|
|
Group = message.CurrentAgentId,
|
|
|
|
|
Data = [
|
|
|
|
|
new StatsKeyValuePair("agent_call_count", 1)
|
|
|
|
|
],
|
2025-01-24 19:42:17 +00:00
|
|
|
RecordTime = DateTime.UtcNow
|
2025-01-24 05:45:43 +00:00
|
|
|
};
|
2025-01-28 05:10:37 +00:00
|
|
|
globalStats.UpdateStats("global-agent-call", body);
|
2025-01-24 05:45:43 +00:00
|
|
|
}
|
|
|
|
|
}
|