My current setup: incoming calls are routed to a dialplan that plays a brief greeting and uses the
dial() command to ring the appropriate extensions while playing on-hold music.
What I am trying to do: record (monitor to a file) the inbound audio of incoming calls up until the point that those calls are answered. In other words, only record up until the point the
dial() command finishes executing and a call is either connected/bridged or sent somewhere else (like voicemail).
Why I am trying to do this: The main reason is that I am receiving automated calls which treat the on-hold music as a human answering (or a voicemail) and start playing back important information during that dialing period. By the time a real human answers the call (or the call actually gets sent to voicemail), the important information has already been missed.
The problem: the
monitor() command continues to record the audio after a call has been answered (which is not desirable). There is a
StopMonitor() command but if you place it after the
dial() command then it will only get executed if the call is not answered (so obviously this does not solve my problem).
Possible Solutions: I have considered using Pre-Bridge Handlers to execute a macro or gosub routine which would then call StopMonitor() when the call is answered.
The issue is that If I call
StopMonitor() in pre-bridge macro or gosub routine, it seems to have no effect and the call continues to be recorded, perhaps because—according to the Asterisk docs—“these handlers are executed on the called party channel, after it is answered” even though they are executed before the call is bridged. Unfortunately, the
StopMonitor() dialplan command doesn’t appear to allow you to specify a channel to stop monitoring.
After some research, I discovered that the AMI also has a StopMonitor API command that does let you specify the channel, however all my attempts at using the AMI (through PHP AGI) to accomplish this have failed. Any help/advice is appreciated, thanks.