This code works great! It starts the call as a spy, but then you can toggle between (4) spy (listen to the call without being heard), (5) whisper (speak and be heard only to extension member), (6) barge (speak and be heard by both parties).
However, this acts as a prefix only. You need to first dial 556+extensionNumber. Would it be possible to have it prompt the caller to select the extension he wants to listen to? If so, if no active channels are present on that extension, can the system say that and prompt to either select another extension or to end the call by hanging up?
You would need an additional block of dialplan added to what’s already in place also in the from-internal-context
exten => 556,1,Noop(Entering user defined context from-internal-custom in extensions_custom.conf)
exten => 556,n,Read(spyee,please-enter-the&extension&number&followed_pound)
exten => 556,n,GoTo(from-internal-custom,556${spyee},1)
It’s crude, but works and will gives you a starting place.