What I want to do is, when a call is waiting on a virtual queue, I need the count of agents on breaks of that particular queue. > Break : 3, LunchBreak :4
I have definitions on statServerReporting filters, for all notready statues such as below.
AUX_RC_1 : PairExist(“Lunch Break”,Lunch Break")
AUX_RC_2 : PairExist(“Meeting”,Meeting")
AUX_RC_3 : PairExist(“Break”,Break") etc.
I have this piece of code on statServerProtocol.Received event, for every virtual queue on the system.
The problem is I can not get the count on the row “int count = Convert.ToInt32(@event.StringValue);”, it is always empty .
Probably because you are casting response as EventStatisticOpened. The class that has the actual value is EventInfo, and you have to match it against the REQ_ID (ReferenceId of the RequestOpenStat/Ex that you are holding in your variable queueStatisticId) to know about which Statistic it refers to
Hey, I am grateful for your response. Thank you. But it is EventStatisticOpened. (I tried EventInfo too neveretheless).
Here are the logs. My agent is on “Break” break type which maps to AUX_RC_3, I was expecting to see “1” (@event.StringValue: 1 ) as count but it is “” ( @event.StringValue: )
AUX_RC_3 : PairExist(“Break”,“Break”)
I have put together a small example code for you to use as a reference:
using Genesyslab.Platform.Commons.Protocols;
using Genesyslab.Platform.Reporting.Protocols;
using Genesyslab.Platform.Reporting.Protocols.StatServer;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Events;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Requests;
using System;
using System.Collections.Generic;
namespace StatServerReasonCode
{
class Program
{
static Dictionary<int, Tuple<string, string>> referenceIds = new Dictionary<int, Tuple<string, string>>();
static void Main(string[] args)
{
string statServerHost = "10.131.3.101";
int statServerPort = 7000;
StatServerProtocol exampleProtocol = new StatServerProtocol(new Endpoint(statServerHost, statServerPort));
// Specifies a method to handle non-request related messages
exampleProtocol.Received += statServer_StatReceived;
exampleProtocol.Open();
// All your Groups that you want to monitor
HashSet<string> agentGroups = new HashSet<string>
{
"Group1",
"Group2",
"Group3",
"Group4"
};
// All filters that you want to apply to your Statistic Type in separate statistics
HashSet<string> filters = new HashSet<string>
{
"AUX_RC_1",
"AUX_RC_2",
"AUX_RC_3"
};
foreach (string groupName in agentGroups)
{
foreach (string filter in filters)
{
// This is used to get which object/filter when the EventInfo is received.
// Will later be added to the static dictionary referenceIds to be retreived later on the
// Message handler "statServer_StatReceived" method
Tuple<string, string> agentGroupAndFilter = new Tuple<string, string>(groupName, filter);
StatisticObject statObject = StatisticObject.Create();
statObject.ObjectType = StatisticObjectType.GroupAgents;
statObject.TenantName = "Environment";
statObject.ObjectId = agentGroupAndFilter.Item1;
StatisticMetric statMetric = StatisticMetric.Create();
statMetric.StatisticType = "CurrNumberNotReadyStatuses";
statMetric.Filter = agentGroupAndFilter.Item2;
Notification statNotification = Notification.Create();
statNotification.Mode = NotificationMode.Immediate;
statNotification.Insensitivity = 1;
RequestOpenStatistic requestOpenStatistic = RequestOpenStatistic.Create();
requestOpenStatistic.StatisticObject = statObject;
requestOpenStatistic.StatisticMetric = statMetric;
requestOpenStatistic.Notification = statNotification;
IMessage response = exampleProtocol.Request(requestOpenStatistic);
referenceIds.Add(requestOpenStatistic.ReferenceId, agentGroupAndFilter);
switch(response.Name)
{
case "EventStatisticOpened":
Console.WriteLine($"Registered statistic for object {groupName} and filter {filter}");
break;
case "EventError":
Console.WriteLine($"Error opening statistic for object {groupName} and filter {filter}");
break;
}
}
}
}
private static void statServer_StatReceived(object sender, EventArgs e)
{
IMessage message = ((MessageEventArgs)e).Message;
// Discard messages that are not of type "EventInfo" (message that contains statistic values)
if (!message.Name.Equals("EventInfo", StringComparison.InvariantCultureIgnoreCase)) return;
EventInfo eventInfo = (EventInfo)message;
// Discard messages that are not about a statistic that we are waiting for the data
if (!referenceIds.ContainsKey(eventInfo.ReferenceId)) return;
// Get the group/filter combination based on the ReferenceId of the received message
Tuple<string, string> agentGroupAndFilter = referenceIds[eventInfo.ReferenceId];
string groupName = agentGroupAndFilter.Item1;
string filter = agentGroupAndFilter.Item2;
Console.WriteLine($"Received current value of group {groupName}, filter {filter}: {eventInfo.IntValue}");
}
}
}
I appreciate the effort you’ve put in to help me! Thank you very much! I can get the count now on a sample project that represents mine.
The problem now is, I need the count in an immediate call since on protocol received I read the call count waiting on each virtual queue. Inside this function I need an immediate request-response of this agent-break counts. That was why I had tried to read the response immediately afterwards. I have adjusted my code to read both queries on statProtocol.received but the response of the agentcount is not available when I need that since its not immediate this way.
Do you think there is a way to accomplish this?
For the following :
907 is my virtual queue and result : 1 because I am on the line and the agent of this queue is on break (AUX_RC_3 which will be queried with a referanceId of 10002), so I need the count of agents who are under this virtQueue.
2022-04-04 10:26:56,579: [ INFO] OnWaitingCallsEventInfo()- result : 1 referanceId : 907
2022-04-04 10:26:56,579: [ INFO] OnWaitingCallsEventInfo()- referanceId (queue.DbId) : 907 için result : 1, queue.QueueName :VQ_TestCampaign, queue.QueueMaxAgent :0.
2022-04-04 10:26:56,583: [ INFO] GetCampaingNameFromVirtualQueueId() - QueueId : 907 , VQ_TestCampaign - virtualQueue.Switch.Name : SIPSwitch_DR , AgentGroupName Found : TestCampaign
2022-04-04 10:26:56,886: [ INFO] - OnWaitingCallsEventInfo - Agents on break : I needed the count here
2022-04-04 10:26:56,886: [ INFO] - OnWaitingCallsEventInfo - – ResultValues , IsCallFirstCall false , FirstCallTime: 4.04.2022 10:26:56
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10000 → AUX_RC_1
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10001 → AUX_RC_2
2022-04-04 10:26:56,886: [ INFO] OnWaitingCallsEventInfo()- result : 1 referanceId : 10002 → AUX_RC_3 → but I got it here
2022-04-04 10:26:56,889: [ INFO] OnWaitingCallsEventInfo()- result : 0 referanceId : 10003 → AUX_RC_4
Long story short, I need the reponse here :
switch (response.Name)
{
case "EventStatisticOpened":
Console.WriteLine($"{methodName} - Registered statistic for object {agentGroupName} and filter {agentGroupAndFilter}"); [b]--> here [/b]
break;
case "EventError":
Console.WriteLine($"{methodName} - Error opening statistic for object {agentGroupName} and filter {agentGroupAndFilter}");
break;
default:
Console.WriteLine($"{methodName} - response.Name : {agentGroupName} and filter {agentGroupAndFilter}");
break;
}
Getting the Statistic Values is always assyncronous either through Notification or through using the RequestPeekStatistic (note that you cant even use the StatServerProtocol.Request to get it synchronously).
That means that you will always receive the values on the EventInfo as part of the MessageEventArgs on the Method that you set as handler on StatServerProtocol.Received event.
When you use Immediate notification and Insensitivity = 1, you receive an assyncronous EventInfo whenever the statistical value changes.
If you need to do something in your code upon receiving the data, use that handler.
The way has actually been explained quite well and clearly from hsujdik. You have 2 ways to do it, it is how it works, async or sync, you need to do your effort there to close the circle.