I am encountering an issue with Answering Machine Detection (AVMD) in a Lua script where removing a fixed sleep time of 15 seconds causes voicemail detection to fail. Below is the code snippet that highlights the situation:
if leg_a_session:ready() then
leg_a_session:sleep(100)
leg_a_session:execute(“avmd_start”)
leg_a_session:execute(“sleep”, “15000”)
if leg_a_session:getState() == "CS_HANGUP" or leg_a_session:getState() == "CS_DESTROY" then
callID = leg_a_session:getVariable("uuid")
send_disposition_reason(callStartTime, callInitiationTime, dialed_cust_number, callID, "CALLER_DISCONNECT")
return -1
end
leg_a_session:execute("avmd_stop")
leg_a_session:sleep(100)
avmd_detect = leg_a_session:getVariable("avmd_detect")
Logger.notice("[Dialer] : avmd_detect : " .. tostring(avmd_detect))
end
Behavior with Sleep: When the sleep
time is set to 15 seconds (leg_a_session:execute("sleep", "15000")
), AVMD successfully detects voicemail, and the system processes the call as expected. Logs indicate avmd_detect
is set to TRUE
when voicemail is detected.
- Behavior without Sleep: When the 15-second sleep is removed, AVMD does not detect voicemail consistently. This results in missed voicemail detection and incorrect call dispositions.
- Context:
- AVMD is initiated with
leg_a_session:execute("avmd_start")
. - After the sleep period,
leg_a_session:getVariable("avmd_detect")
is used to determine whether voicemail is detected.
- Are there alternative ways to wait for AVMD detection without relying on a fixed sleep time?
- Can AVMD be configured to trigger an event or callback when detection is complete?
- Is there a best practice for dynamically polling AVMD detection without introducing delays?
Any guidance on optimizing AVMD handling or alternative solutions to this issue would be greatly appreciated.
Thank you for your time and support!