diff --git a/callautomation-openai-sample-csharp/CallAutomationOpenAI/Program.cs b/callautomation-openai-sample-csharp/CallAutomationOpenAI/Program.cs index e9dc06dc..c2b1ed1c 100644 --- a/callautomation-openai-sample-csharp/CallAutomationOpenAI/Program.cs +++ b/callautomation-openai-sample-csharp/CallAutomationOpenAI/Program.cs @@ -43,6 +43,7 @@ You are an assisant designed to answer the customer query and analyze the sentim string transferFailedContext = "TransferFailed"; string connectAgentContext = "ConnectAgent"; +string goodbyeContext = "Goodbye"; string agentPhonenumber = builder.Configuration.GetValue("AgentPhoneNumber"); string chatResponseExtractPattern = @"\s*Content:(.*)\s*Score:(.*\d+)\s*Intent:(.*)\s*Category:(.*)"; @@ -113,9 +114,10 @@ You are an assisant designed to answer the customer query and analyze the sentim client.GetEventProcessor().AttachOngoingEventProcessor(answerCallResult.CallConnection.CallConnectionId, async (playCompletedEvent) => { logger.LogInformation($"Play completed event received for connection id: {playCompletedEvent.CallConnectionId}."); - if (!string.IsNullOrWhiteSpace(playCompletedEvent.OperationContext) && playCompletedEvent.OperationContext.Equals(transferFailedContext, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(playCompletedEvent.OperationContext) && (playCompletedEvent.OperationContext.Equals(transferFailedContext, StringComparison.OrdinalIgnoreCase) + || playCompletedEvent.OperationContext.Equals(goodbyeContext, StringComparison.OrdinalIgnoreCase))) { - logger.LogInformation($"Call transfer failed, disconnecting the call..."); + logger.LogInformation($"Disconnecting the call..."); await answerCallResult.CallConnection.HangUpAsync(true); } else if (!string.IsNullOrWhiteSpace(playCompletedEvent.OperationContext) && playCompletedEvent.OperationContext.Equals(connectAgentContext, StringComparison.OrdinalIgnoreCase)) @@ -216,7 +218,7 @@ await HandlePlayAsync(connectAgentPrompt, else { Console.WriteLine($"Recognize failed event received for connection id: {recognizeFailedEvent.CallConnectionId}. Playing goodbye message..."); - await HandlePlayAsync(goodbyePrompt, "RecognizeFailed", callConnectionMedia); + await HandlePlayAsync(goodbyePrompt, goodbyeContext, callConnectionMedia); } }); }