Chanspy spygroup


we need to monitor calls from/to our callcenter and ONLY calls from/to the callcenter. So we generated a custom context, put the desired extension in this context and set the SPYGROUP.

This works for incomming calls but we also need to monitor outgoing calls.

Any idee how we can set SPYGROUP on outgoing calls originated from the ‘callcenter’ extension.

Thanks in advance

Can you clarify how you are setting the group on the incoming calls?

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

Hi Philippe,

For inbound calls i use a custom context in extension_custom.conf

include => chanspy-group

exten => 585044706,1,Set(SPYGROUP=Techsupport)
exten => 585044706,n,Set(__FROM_DID=${EXTEN})
exten => 585044706,n,GotoIf($[ “${CALLERID(name)}” != “” ] ?cidok)
exten => 585044706,n,Set(CALLERID(name)=${CALLERID(num)})
exten => 585044706,n(cidok),Noop(CallerID is ${CALLERID(all)})
exten => 585044706,n,SetMusicOnHold(dbd)
exten => 585044706,n,Set(__MOHCLASS=dbd)
exten => 585044706,n,Set(FAX_RX=disabled)
exten => 585044706,n,Playback(for-quality-purposes&this-call-may-be&recorded)
exten => 585044706,n,Goto(from-did-direct,44706,1))

this works fine. this for testing. in future i will use a pattern to select the needed extensions.

for incomming outgoing calls i tried this



exten => _0ZXXX.,1,GotoIf($"[${CALLERID(num)}" = “_44.]”?SPYGROUP:weiter)
exten => _0ZXXX.,n(SPYGROUP),Set(SPYGROUP=Techsupport)
exten => _0ZXXX.,n(weiter),Macro(dialout-trunk,2,${EXTEN},)

Now i changed


exten => _0ZXXX.,1,GotoIf($"[${CALLERID(num)}" = “_44.]”?SPYGROUP:weiter)
exten => _0ZXXX.,n(SPYGROUP),Set(SPYGROUP=Techsupport)
exten => _0ZXXX.,n(weiter),Macro(dialout-trunk,2,${EXTEN},)


exten => _0ZXX.,1,Set(SUCHMUSTER="(447.)")
exten => _0ZXX.,n,GotoIf($["${CALLERID(num)}" : ${SUCHMUSTER}]?SPYGROUP:weiter)
exten => _0ZXX.,n(SPYGROUP),Set(SPYGROUP=Techsupport)
exten => _0ZXX.,n(weiter),Macro(dialout-trunk,2,${EXTEN},)

and it workes. But there is one more question. Whow can i define two expressions? All extension starting with 44 or starting with 86?


I see what you are doing. It would seem to me that the following approach would be more generalized and supportable. Maybe something we could consider for inclusion into FreePBX if someone wants to sponsor the cost of development since this type of functionality is clearly of interest to commercial entities who could benefit.

Add a SPY Group Module that does the following:

Inbound Calls:

Provides a hook into Queues and Ring Groups (it could hook Inbound Routes also) that sets the SPYGROUP for any call that comes through that path. So any agent assigned to that incoming call will be a member of that group. This also means an agent could be a member of multiple SPYGROUPs if they took calls for different Queues with different SPYGROUP ids.

Outbound Calls:

Provide a hook to the extension/user, which would set an AstDB attribute in the extension’s AMPUSER object that identified them as a member of a specific SPYGROUP. Then any call they originated would include them in the SPYGROUP. We would want to determine if this should be all calls originated by the user, or simply outbound calls vs. internal calls to the system such as extension to extensions or call into a user’s voicemail.

You could then have the module create feature codes for each defined SPYGROUP so that calls could be monitored for different SPYGROUPS. Even in simply cases, this could be useful to simply define a different SPYGROUP for inbound vs. outbound calls for a specific set of agents if there was a desire to differentiate.

That would be my take on implementing this in a more generalized way. Putting in the hooks as you have done will probably be OK but more difficult to maintain and could be effected by system upgrades and changes.


Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx


thanks for your advise. I will check it out.


I see that no one pushed forward on sponsoring you to get the Spy Channel working in FreePBX. Basically, what I’d be looking for is the ability to directionally spy and/or coach a specific extensions (SIP, IAX, whatever, if you can dial the digits to make an interoffice call, that’s the number I’d like to dial once activating the ExtenSpy(), ChanSpy() whatever to listen to that specific extension).

I’m playing around with the ChanSpy() and ExtenSpy() features of Asterisk 1.4, but I cannot seem to get it to let me choose who I am listening to. Once I activate the ChanSpy() (555, by default) and/or ExtenSpy (I’ve defined it as 779 - “SPY” in the telephone keypad) - I get the first channel that’s available, and I have to hit * and/or # to bounce around to other channels. In a room of 20 agents, it’s kind of cumbersome to find anyone, and once you find them, you are hesitant to look for someone else :).

Anyway, I would consider sponsoring this development, if I knew what I was getting myself into and what, if any, benefit there would be to my company (besides the ability to use the feature).

We’re using FreePBX that’s included with TrixBox v2.4.

Thanks for any assistance.

I was able to get the directional spying working, posted my comments/solution as a response to the posting that made the light-bulb go off for me …

can you post how you got this to work?

thank you

You may use SpyGroup application -
It stores the extensions need to be monitored in MySQL database.