Rrrr: As you have found, this gets messy in a hurry. I'm reluctant to even document this until Philippe has time to do some more work on it. But here goes...
First of all, this only works
at all on some phones. We've tested it successfully on Yealink T46G, Grandstream GXP2200, and Cisco 7970. It doesn't work at all on Digium Phones or Mocet Communicator. Probably would work on Aastra phones, but I haven't tried it yet. Either of the sendrpid extension settings works on any of the phones I've tested if it works at all.
The basic call flow in FreePBX works like this but be advised that the dialplan code is different in every version of FreePBX. So you'd have to adjust this to match your version. An outbound call starts out in
macro-user-callerid then hits
sub-record-check and then
macro-dialout-trunk. You'll find all of these in
extensions_additional.conf. About 11 lines into
macro-dialout-trunk, it runs
macro-outbound-callerid. So far, so good. That's the piece we moved to
extensions_override_freepbx.conf, and it's where we inserted our CNAM lookup code. As we've both discovered, that works fine if all you want to do is add the CallerID Name of the called party to the CDR.
If you want to actually display the CallerID Name of the called party on the phone once the call is connected, there's more. Further down in the
macro-dialout-trunk context, you'll see another macro function call to
macro-dialout-trunk-predial-hook. This was supposed to let you adjust the CallerID info (again) and then return to
macro-dialout-trunk for completion of the call. Unfortunately, as presently written, if you
Set(PREDIAL_HOOK_RET=BYPASS), then it basically hangs up your call when the macro exits and returns to
macro-dialout-trunk. That's obviously not what we want.
What this means is you have to create [
macro-dialout-trunk-predial-hook] in extensions_override_freepbx.conf as well. In that context...
(1) You've got to set the CallerID name properly:
Code:
exten => s,1,Set(CONNECTEDLINE(num,i)=${DIAL_NUMBER})
exten => s,n,Set(CONNECTEDLINE(name,i)=${var1})
(2) Then you've got to set the BYPASS flag:
Code:
exten => s,n,Set(PREDIAL_HOOK_RET=BYPASS)
(3) And then you've got to copy-and-paste the remainder of the
macro-dialout-trunk code from below the call to
macro-dialout-trunk-predial-hook (minus the two CONNECTEDLINE entries) into the bottom of
macro-dialout-trunk-predial-hook. Otherwise, the outbound call just hangs up when the macro exits and returns to
macro-dialout-trunk. The reason is the code currently jumps to the end of the context when BYPASS is detected rather than just jumping over the two CONNECTEDLINE entries.
(4) Finally, you've got to exit gracefully from the macro with MacroExit() at every spot where the code could end, i.e. at the end of the main code and at the end of each of the s-markers:
Code:
main code is here, then...
exten => s,n,MacroExit()
exten => s-BUSY,1,Noop(Dial failed due to trunk reporting BUSY - giving up)
exten => s-BUSY,n,Playtones(busy)
exten => s-BUSY,n,Busy(20)
exten => s,n,MacroExit()
...
Like I said. It works, but it is U-G-L-Y. What would be preferable would be a goto/jump in
macro-dialout-trunk over the two CONNECTEDLINE entries when the BYPASS flag was set or perhaps adding another flag for CNAMSET to just jump over the CONNECTEDLINE entries rather than jumping to the end of the context and hanging up the call. Then we could do this with 5 lines of code in extensions_override_freepbx.conf :
Code:
[macro-dialout-trunk-predial-hook]
exten => s,1,Set(CONNECTEDLINE(num,i)=${DIAL_NUMBER})
exten => s,n,Set(CONNECTEDLINE(name,i)=${var1})
exten => s,n,Set(PREDIAL_HOOK_RET=CNAMSET)
exten => s,n,MacroExit()
I'll pass this along to Philippe for further review.