Trigger shell script on queue answer

I’ve done some searching, and maybe I’ve missed an answer, but I’m looking to trigger a shell script when a queue member picks up a call. I’d like to pass the callerid of the incoming call and the “CID Num Alias” of the user who answered it to the script. I believe this is possible through the AGI, using extensions_custom.conf, but I’m not certain of the syntax or variables, and I’m guessing there is a way to do it through Asterisk to ensure that my changes are saved, backed up, not overwritten, etc.

Any help, even a quick note where I could do some more research, would be much appreciated. Thanks in advance!

There is no GUI setting for this but look at

You can add to /etc/asterisk/globals_custom.conf

In the context you could call an AGI etc…


OK, so digging into this a bit, and learning things I never knew. I’m trying to wrap my head around contexts, extensions, etc. I have a lot of experience with FreePBX GUI and Linux CLI, but not a whole lot of custom work in Asterisk config files. So, is this how I would accomplish this?

My end goal is to create a shell script that passes an API call to our helpdesk software with the callerid and “CID Num Alias” using curl, which will immediately create a helpdesk ticket. I believe I can figure this part out.

The part I’m having trouble wrapping my head around is how to call the script using the System command for an existing queue (802) which will trigger when an agent picks up the call, but not interrupt the existing flow of the actions.

So, using your link above, I understand the concept, but not the execution. Do I create a global extension like

exten => 802,n,System(/path/to/ ${CALLERID} ${AMPUSERCID})

I don’t quite understand where the QGOSUB comes in. Obviously, I can’t just stick the exten entry in anywhere, but I’m not sure of where it would go…

Thanks again!

Also, I need to ensure that this only triggers for external calls. It wouldn’t do to have the system creating tickets when an internal user calls the queue. :slight_smile:

I am so close I can almost taste it, but I need just a little push…

I’ve created a custom destination in the GUI of create-ticket,s,1. (I’ve also tried create-ticket,start,1 and create-ticket,802,1 - Nothing has worked quite yet.)

So then in extensions_custom.conf, I made:

exten => start,1,System(/usr/scripts/ ${CALLERID(num)} ${AMPUSERCID})
exten => n,Return()

Then, in globals_custom.conf, I made the line:


When I dial into the PBX and select the support queue, I get:

Attempt to reach a non-existent destination for Gosub: (Context:create-ticket, Extension:s, Priority:1)

Please take pity on my lousy dialplan skills. It’s probably something simple that I’m missing. I’ve tried several permutations of s, start and 802 in the extension portion of the create-ticket context, but I can’t quite seem to get it.

As always, your help is much appreciated. Thanks!

Also, when I run ‘dialplan show’ the following lines are present:

[ Context 'create-ticket' created by 'pbx_config' ]
  'start' =>        1. System(/usr/scripts/ ${CALLERID(num)} ${AMPUSERCID}) [pbx_config]
                    2. Return()                                   [pbx_config]

so it looks as if the subroutine is being created. I can’t figure out why application thinks it’s non-existant.

Couple of things, it’s just s not start. It doesn’t say non-existent context it says destination.

Once you have it working you need to add a test if it’s from an extension or external.



Thank you both for your advice. I did get it working using:



exten => s,1,System(/usr/scripts/ CALLID=${FROMEXTEN} EXT=${CALLERID(num)})
same => n,Return()

So you were both right. :slight_smile: (Obviously, I renamed the context.) I still haven’t figured out how to determine if it’s a call from a SIP trunk, but I might just check for a 11 digit number in the shell script, which would weed out 3 or 4 digit caller IDs.

Now the only thing I’m having trouble with is variables. The ${CALLERID(num)} is taking the extension of the agent who picks up the call, because it’s the QGOSUB is apparently taking the variables from that channel. The problem is, I don’t know how to get the “CID Num Alias” field from Asterisk, because it doesn’t appear to be in the channel. It would be the incoming caller ID for that user, but since the user isn’t making an outgoing call, I don’t think there’s an easy way to get it.

My current thinking is that I can take the extension, and use sed to strip off the first digit, if it’s a 4 digit number. Then I need to check for unintended consequences…

If you haven’t been there yet: