Setting outbound caller id but need to find out which extension dialled the call

We are working through a bit of customization of our system, based on Trixbox CE 2.2 (Asterisk 1.2) with FreePBX 2.5.1, where on a custom trunk we set the Outbound Caller ID to the name and number of the project we are calling out for and have a Custom dial String of “Local/[email protected]/n” to handle some calling logic.

Everything works fine, except that by setting the outbound caller id, we lose the number of the extension the call was made from.

For example, calling out from extensions 1004 and 1010, and setting the outbound callerid to 8005551212 results in all calls appearing to be from 8005551212.

I can see in the console that the extension number is there as part of the extension/channel information as the call begins, but once my macro is entered, the information is lost.

I’m sure there’s a way to maintain the information of which agent dialled the call, but I can not seem to find the right variable, or capture it before it is overwritten by the outbound callerid.


Can I do something like “Local/[email protected]/n” ? I haven’t really seen any additional information on what can be passed in a Custom Dial String (although I am still searching).

I’m hoping I can just modify the macro a little, and not have to mess with the FreePBX macros in order to accomplish this. I have a feeling this is a pretty obvious answer for someone a little more skilled at this than I am, and sure would appreciate any pointers.

Thanks in advance.


I don’t fully understand what you are trying to do, but keep in mind that if you are sending calls to the PSTN you MUST send a valid number that belongs to you or your company - something that the called party can use to return your call. Nobody wants to see your internal extension numbers in their Caller ID if you are calling on their PSTN line or cell phone, etc.

But in case I am misinterpreting your intent, I’ll also just say to be careful about variable inheritance - see and note the section “Inheritance of Channel Variables.”

Thanks, wiseoldowl, it is exactly because we do not want our internal extension number broadcasted that we are setting the outbound caller id in the CUSTOM trunk we have defined. As these are customer followup calls made on behalf of our clients, we need to make sure we broadcast our client’s phone number, to ensure the customer sees the right information on their call display. It really sucks when you are calling for Project A, and display the number for Project B. :confused:

I had already used the page you referenced as a starting point, several of the variable names I mention in my original post came from there. Good to see I was on the right track.

Unfortunately, I am trying to access existing variables, and they seem to be unavailable or overwritten by the time the call enters the macro “project-a-outdial”.

I did find some references elsewhere that suggested establishing the call, and leaving the channel open, then using the Asterisk CLI to perform “show channels” to see what channels are open, and then “show channel [channel-name]” to see the details of the channel.

What I found was that the extension I was calling from ended up getting Bridged to the channel created by using the custom dial string “Local/[email protected]/n”. I still haven’t found how to get the info from the calling extension, but I think I have a way to redo the script.

Basically I will create branches in the macro for each project, and set the outbound caller id in the macro, instead of in the trunk.

Initial testing is promising. It means modifying the macro to create a new branch for each outbound project, but that’s a minor detail at this point as it does not happen too often.

I’ll post more later.


Ok, without mucking around too much, it looks like I have found a way to solve this problem.

So, agent at extension “1956” dials outbound route “96” to dial out, then adds a project code “975” for tracking purposes, and finally dials the phone number to call “16785551212”.

Outbound route “96” strips off the “96” and passes everything else along to the CUSTOM trunk, which has a Custom Dial String of “Local/[email protected]/n”

The macro then grabs the CALLERID(num) of the agent, the PROJECTCODE, and PHONENUMBER, setting variables accordingly. This allows me to save the agent’s extension to my own variable to prevent it from being clobbered by anything else.

This next part is a little clunky, since I am working with Asterisk 1.2, and some of the funky conditional branching does not seem to be readily available, like switch (case) statements.

The macro then calls a Gosub, based on the PROJECTCODE variable and jumps to the labelled section of the dialplan where, based on the project code, the outbound callerid information is set, then channel to dial out on is set, and then returns to the previous section of the dialplan in order to actually dial out and make the connection.

As we add more projects, I just have to add another labelled section for the new project code, reload, and we can dial out for that project and track who called whom.

If someone dials an invalid project code, they get the default “all circuits are busy” message, because I have not been able to figure out how to do a case statement in the dialplan to trap invalid project codes and return a sensible message.

Like I said, a bit clunky, but so far it seems to work.