Examples
Caller region based routing
Consider a toll free number enabled both for Canada and the US; in order to execute different actions based on caller’s country we would use the get_region_code action. For example, consider this dialplan fragment:
<extension name="example">
<condition field="destination_number" expression="^18005551234$" require-nested="false">
<!-- If the module is invoked via hooks, the following line is not necessary -->
<action inline="true" application="phonenumber" data="get_region_code caller"/>
<condition field="${phonenumber_caller_region_code}" expression="^US$" break="never">
<action application="log" data="INFO Inbound call from US customer"/>
<!-- actions for US callers ... -->
</condition>
<condition field="${phonenumber_caller_region_code}" expression="^CA$" break="never">
<action application="log" data="INFO Inbound call from Canadian customer"/>
<!-- actions for Canadian callers ... -->
</condition>
<condition field="${phonenumber_caller_region_code}" expression="^(?!.*(US|CA))" break="never">
<action application="log" data="INFO Catch all, got ${phonenumber_caller_region_code}"/>
<!-- Catch all actions ... -->
</condition>
</condition>
</extension>
Override caller name
Suppose you want the caller name to be resolved to the geographical description of the caller if it’s not already set. This is achievable through the get_description_for_number action; for example, this fragment could be added to the dialplan section before bridging calls to your extensions:
<condition field="${sip_from_display}" expression="^([\+\-\(\)\ 0-9]+)$" break="never">
<action inline="true" application="phonenumber" data="get_description_for_number ${sip_from_display}"/>
<action inline="true" application="set" data="effective_caller_id_name=${phonenumber_number_description_for_number}"/>
</condition>
<!-- ... bridge/answer ... -->
Enchance analytical data
Consider the following dialplan action (or its hook equivalent):
<action inline="true" application="phonenumber" data="format,get_number_type,get_region_code,get_description_for_number caller default_region=US,locale=en_US"/>
The results are readily available as channel variables, for example in the case of applications using the Event Socket Library, or at the end of the call as a CDR record:
<?xml version="1.0"?>
<cdr core-uuid="63aacf97-90c6-470b-bc5b-6c0c7b954454" switchname="test">
<channel_data>
<state>CS_REPORTING</state>
<direction>inbound</direction>
<!-- ... -->
</channel_data>
<variables>
<sip_from_user>16172531000</sip_from_user>
<sip_from_uri>16172531000%40test</sip_from_uri>
<!-- ... -->
<phonenumber_caller_format>%2B16172531000</phonenumber_caller_format>
<phonenumber_caller_number_type>FIXED_LINE_OR_MOBILE</phonenumber_caller_number_type>
<phonenumber_caller_region_code>US</phonenumber_caller_region_code>
<phonenumber_caller_description_for_number>Cambridge,%20MA</phonenumber_caller_description_for_number>
<!-- ... -->
</variables>
<app_log>
<application app_name="phonenumber" app_data="format,get_number_type,get_region_code,get_description_for_number caller default_region=US,locale=en_US" app_stamp="0"></application>
</app_log>
<callflow dialplan="XML" unique-id="bf04e77c-2989-4590-9751-19c0fabcd871" profile_index="1">
<caller_profile>
<username>16172531000</username>
<caller_id_name>16172531000</caller_id_name>
<caller_id_number>16172531000</caller_id_number>
<ani>16172531000</ani>
<!-- ... -->
</caller_profile>
</callflow>
</cdr>
The appended data can be further integrated in your data warehouse for a variety of purposes.