Skip to main content

Call Forward Example

About

This is an example of how to create a simple call forwarding dialplan. In this example, it utilizes hash, but you may prefer db. The choice is yours.

default.xml

<extension name="call_forwarding_activativation">
<condition field="destination_number" expression="^\*72$">
<action application="play_and_get_digits" data="3 12 1 14000 # tone_stream://%(10000,0,350,440) silence_stream://250 cfwd_num \d+"/>
<action application="hash" data="insert/${domain_name}-call_forward/${caller_id_number}/${cfwd_num}"/>
<action application="playback" data="tone_stream://${bong-ring}"/>
<action application="hangup"/>
</condition>
</extension>
 
<extension name="call_forwarding_deactivation">
<condition field="destination_number" expression="^\*73$">
<action application="hash" data="delete/${domain_name}-call_forward/${caller_id_number}/${destination_number}"/>
<action application="playback" data="tone_stream://${bong-ring}"/>
<action application="hangup"/>
</condition>
</extension>
 
<extension name="call_forwarding_number" continue="true">
<condition>
<action application="set" data="call_forwarding_number=${hash(select/${domain_name}-call_forward/${destination_number})}"/>
</condition>
</extension>

features.xml

<extension name="is_forward">
<condition field="destination_number" expression="^is_forward$"/>
<condition field="${call_forwarding_number}" expression="^(\d+)$">
<action application="transfer" data="$1 XML default"/>
</condition>
</extension>

Regarding default.xml

For instance, you can call the is_forward features before you bridge to your phone extension (You need to implement the extension of your choice). Also, you need to make sure that you have a support dialplan to dial out and terminate your forwarding number. This will have to go before any extensions that will be utilizing call forwarding.

<extension name="check_call_forwarding" condition="true">
<!-- change the following regular expression to match the numbers that will utilize call forwarding-->
<condition field="destination_number" expression="^(\d+)$">
<action application="execute_extension" data="is_forward XML features"/>
<action application="bridge" data="sofia/internal/$1@{domain_name}"/>
</condition>
</extension>

See also: