- We log into Genesys PureCloud agent browser app.
- Then we log in with our Desktop .Net app
- Then we go on queue in Genesys PureCloud agent browser app.
- An incoming call comes in and the application receives the notification of it and records the conversation Id and knows the Participants and Calls and their ids in the conversation. Calls are indexed in a concurrent dictionary so they can be looked up by callID and related back to the conversation. The application receives events but due to a legacy interface, it tracks individual calls by call ID.
- The user sees the calls in the desktop application and can answer the call by double-clicking on it. And causes the following code to run called with the call ID of the call they double-clicked on.
From our logs we can see this code always runs and seems to work (from the perspective of the code), but sometimes on the first incoming call it doesn't actually connect the call to answer it. When it doesn't answer it the call can be answered from the Genesys Purecloud agent browser app, and then our desktop application gets the event that it is answered and displays the call as answered. Once a call has been answered from the Genesys Purecloud agent browser app, all the calls after that are able to be answered from our desktop app
`C#
// To simplify the code example just do this here (we have a provider class that does this for us):
private readonly IConversationsApi _conversationsApi = new ConversationsApi();
// Mandatory method required for legacy interface
// It was not async by design, but shouldn't block GUI
public void Answer(string callId)
{
_logger.LogTrace($"For callId: {callId}.");
var body = new MediaParticipantRequest
{
State = MediaParticipantRequest.StateEnum.Connected
};
// This is equivalent of what is done. We have code that does essentially this
// because we have all the calls indexed in a concurrent dictionary.
// We know this is getting the correct conversationId and agent participantId from the logs.
// Not including the code that does this because it is working 100% of the time.
var (conversationId, agentParticipantId) = GetConversationIdAndAgentPariticipantIdFromCallId(callId);
if (conversationId != null && agentParticipantId != null)
{
// We see this in the logs whenever the user clicks to answer the call:
_logger.LogTrace($"For callId: {callId} using conversation ID: {conversationId}, agent participant ID: {agentParticipantId}.");
// The enclosing method containing this code is not, by previous design,
// an async method so we can't simply await with ConfigureAwait(false).
// This locks up if we wait on the Gui thread where this gets called, so we
// have to wait for the task to complete on another thread.
// This starts the async process and returns the task to track its completion
var task = _conversationsApi.PatchConversationsCallParticipantAsync(
conversationId, agentParticipantId, body);
Task.Run(() =>
{
try
{
task.Wait();
// We always see this, without exception thrown, whether it succeeded
// in answering (connecting) the call or not
_logger.LogTrace($"PatchConversationsCallParticipantAsync completed for callId: {callId}.");
}
catch (Exception e)
{
// We don't get an exception, whether it succeeded
// in answering (connecting) the call or not
_logger.LogError(e.ToString());
}
}
);
}
else
{
// We don't get this because it succeeds in finding the conversationId
_logger.LogWarning($"No answer data found for call with callId: {callId}.");
}
}
`