How do I perform custom action X when an extension answers a ringing channel?
It’s a simple ask which comes up periodically in the forum and I have occasionally tried to come up with a supportable way of doing this just with dialplan in FreePBX. In the past I have hacked away at the macro-confirm context, which works but is an ugly solution. Today after this thread, I thought of a totally different approach, and came up with this:
[run-on-answer]
exten => s,1,Noop(Entering user defined context macro-run-on-answer in extensions_custom.conf)
exten => s,n,DumpChan
; add additional lines as requred
exten => s,n,Return
[from-internal-custom]
; dial prefix **44 you can use to dial local extensions that will exectue a macro when the
; extension answers
exten => _**44XX.,1,Noop(Entering user defined context from-internal-custom in extensions_custom.conf)
exten => _**44XX.,n,Dial(Local/${EXTEN:4}@from-internal,,U(run-on-answer));
exten => _**44XX.,n,Hangup
The above goes in extensions_custom.conf and then reload dialplan. When you call a local extension with the **44 prefix, it will run the Macro on answer. I would use this with static queue agents by defining them with a prefix instead of just the extension number.
I’ve tested a bit, and appears to be working as expected, but needs a real workout before putting into production.
@PitzKey well this didn’t seem to work for me, care to explain further why modifying this isn’t cool?
I created the the custom dial plan and the dynamic route, the routed my inbound calls to the route but for some reason/s it didn’t hit the context when i dialed the queue.
But so far the above configurations I gave seem to work perfectly and I am able to run the script and save some data in a db I created. Actually what you could also help me on is how to access the data I am now entering in the DB and display back, so far I seem to find out that I need to lean ARI, which I have started.
You’re modifying core contexts generated by FreePBX. While I’m sure in your basic testing it’s working as expected, there are going to be unintended consequences of doing this. I recommend you put some effort into making some of the suggestions work instead of doing it your way.