I am working to get LCR (Least Cost Routing) working with Freeswitch.
Using mod_lcr in Freeswitch 1.4.9. I have set it up and it is working.
My install is actually a FusionPBX instance, but this should not matter for the following discussion.
The problem is – I want to set the caller-ID for specific routes (i.e. digits) and I am using regexes in the cid column of the LCR table, as per the documentation.
It is working inasmuch I can see in the output and logs that this sets the "origination_caller_id_number" variable. However, the destination phone does not show that caller-ID.
Also if I set this variable "origination_caller_id_number" in the dial plan without LCR it does not get used seemingly and the callee never sees it.
If I set "effective_caller_id_name" then the callee sees it.
Next I tried: use LCR in the dial plan as application, then set effective_caller_id_name = ${origination_caller_id_number}, which should have been set by the LCR app, then call BRIDGE with the "auto_lcr_route" variable.
See the XML here:
<extension name="LCR.Route.1" >
<condition field="destination_number" expression="^300(\d{9,17})$" >
<action application="set" data="sip_h_X-accountcode=${accountcode}" />
<action application="set" data="sip_h_X-Tag=" />
<action application="set" data="call_direction=outbound" />
<action application="set" data="hangup_after_bridge=true" />
<action application="set" data="inherit_codec=true" />
<action application="set" data="continue_on_fail=true" />
<action application="lcr" data="$1" />
<action application="set" data="effective_caller_id_name=${origination_caller_id_number}" />
<action application="bridge" data="${lcr_auto_route}" />
</condition>
</extension>
The call completes successfully but it does not set the "effective_caller_id_name" at all.
The FusionPBX CDR data "Application log section" shows
Application Log
Name Data
set call_direction=outbound
set call_direction=outbound
set hangup_after_bridge=true
set inherit_codec=true
set continue_on_fail=true
lcr xxxxxxxx
set effective_caller_id_name= <--------- nothing set here. Phone shows SIP "FROM" user.
bridge [lcr_carrier=carrier1,lcr_rate=0.15552,origination_caller_id_number=
99999999]sofia/gateway/cae1e311-8cbc-4ae9-af28-1e2d9706779a/xxxxxxx|
[lcr_carrier=carrier2,lcr_rate=0.90625,origination_caller_id_number=
99999999]sofia/gateway/09266491-caee-4e67-920e-a30c2610a84c/xxxxxxxx
As you can see from this log, the "origination_caller_id_number" SHOULD have been set after the LCR application has been run.
It seems that when LCR sets "origination_caller_id_number", it is in another scope and cannot be retrieved from the dialplan?
So there are two questions:
- Why does the caller ID not show when the bridge application uses the variable "origination_caller_id_number"?
Chances are that the receiving phone provider may not understand what's being sent, or maybe only uses "…_name" instead of "…_number" – but mod_lcr only sets that one variable – which brings me to the 2nd question:
- Is the variable actually being set by running the LCR application, or does this happen only upon executing BRIDGE?
and
- Why can I not set "effective_caller_id_name" by retrieving the value of "origination_caller_id_number"?
the value is apparently being set by the LCR application but I cannot retrieve it from the dialplan. The Freeswitch documentation is very hazy about scoping issues – so is this normal? Can I do something to get to that value?
Best Answer
I worked it out myself.
To answer the questions:
Whether the number shows as caller-ID on the remote phone depends on the service provider / carrier (mainly the one of the originating end).
No, the LCR application does not set the channel variables. It does set a few variables of its own, the most notable being "auto_lcr_route". This contains the result value of the LCR call. Only when calling "BRIDGE" will channel variables get set.
That is answered in (2) - no variables were set at this stage, except "lcr_auto_route". So after all, it isn't a scoping issue.
The way I solved it was to extract the "origination_caller_id_number" value from the lcr_auto_route variable value with a regex, like so:
Note that you need to use the ~ character and prefix the regex with "m:" (and not the usual "|") because auto_lcr_route may contain multiple calling routes separated by a "|" character.