We are using Call Automation and Job Router together to manage our call jobs.
When we get Microsoft.Communication.IncomingCall event from azure event grid webhook, we do following
- Answer the call
const { callConnection } = await callAutomationClient.answerCall(incomingCallContext, ACS_EVENT_GRID_BASE_URL);
const { callConnectionId } = callConnection;
- sleep for 5s
await new Promise((resolve) => setTimeout(resolve, 5000));
- play hold music
const callConnection = await callAutomationClient.getCallConnection(callConnectionId);
const callConnectionProperties = await callConnection.getCallConnectionProperties();
const playSource = {
url: audioFileUrl,
kind: "fileSource"
};
// Configure play options to loop the audio
const playOptions = {
loop: true
};
await callConnection
.getCallMedia()
.play([playSource], [ callConnectionProperties.source ], playOptions);
If we run Step 1 and 3 consecutively without sleep then getCallConnection is not able to find the callConnection. I think azure takes time to distribute the info about the call, so a sleep of 5s is needed.
We even tried to reuse callConnection object but that also gives problem in getCallConnectionProperties
Due to this after first ring on the incoming call, we have to wait for around 10-15s to listen to hold music of audioFileUrl.
Questions
- Is there a way to optimize this by removing sleep? Relying on another event to detect call answered is not an option because we are doing further processing in IncomingCall event.
- Is there a way to pass audioFileUrl while answering the call?