The waiting time for agent and client represents the average time each had to wait in between messages. For example: (Message order timeline): C = Client message, A = Agent message
C1→ C2→ A1→ C3
In this case the client wait time is calculated as the difference between C1→A1, this is the time client waited to receive a message from the agent and the agent wait time will be A1→C3.
1- The duration between agent assignment time to agent first response is added to the client waited time.
2- We will always consider the number of responses, not the message numbers (after a response from the agent or client, they can continue to send messages to explain situations, but all will be considered as a single response, and the time of the first message will be considered.
3- Who ended the conversations is important to calculate the waiting time as explained below.
C1→A1→C2→A2→C3
For this case the total client wait time will be: C1→A1 + C2→A2 as C3 is still waiting for the agent to respond and the conversation has closed on the agent so only the previous two are considered. The agent wait time will be A1→C2 + A2→C3 and agent is not waiting for a client response at this stage.
On the backend side we have implemented the rules and calculations by creating additional variables called:
totalClientWaitTimeInSeconds
totalAgentWaitTimeInSeconds
timesClientWaited
timesAgentWaited
isAgentWaiting
lastClientResponseTime
lastAgentResponseTime
By using the total wait timings and diving them by the count/times waited count we are able to calculate the average wait times that are stored as:averageAgentWaitTime
,averageClientWaitTime
in the conversation table.
isAgentWaiting
is a boolean value representing the state of the agent, i.e. is the agent currently waiting for a message from the client = true and if not then false. The false value also suggests that the client is waiting for the agent to respond.
lastClientResponseTime
and lastAgentResponseTime
are used to keep track of who sent the last message time, this last message will be C1 in this flow: C1→C2→C3→C4→A1 this means its the time of the last message sent by the client or agent after which they have been waiting for a response.
A flow chart created to explain the calculation when ending the conversation: