On Mon, Mar 8, 2010 at 2:33 PM, Aloysius Lloyd <lloyd.aloysius@gmail.com> wrote:
Hi All,

I would like to setup follow me dialplan for individual extensions. Some extensions need a follow-me and some not. If the the follow-me not reach any live person the call should go to the FreeSWTICH voicemail.I have the extensions range from 201 -209. Also I am using the following Default dial plan to call between extensions.

<extension name="Local_Extension">
      <condition field="destination_number" expression="^(20[0-9])$">
<action application="set" data="dialed_extension=$1"/>
<action application="export" data="dialed_extension=$1"/>
<!-- bind_meta_app can have these args <key> [a|b|ab] [a|b|o|s] <app> -->
<action application="bind_meta_app" data="1 b s execute_extension::dx XML features"/>
<action application="bind_meta_app" data="2 b s record_session::$${recordings_dir}/${caller_id_number}.${strftime(%Y-%m-%d-%H-%M-%S)}.wav"/>
<action application="bind_meta_app" data="3 b s execute_extension::cf XML features"/>
<action application="set" data="ringback=${us-ring}"/>
<action application="set" data="transfer_ringback=$${hold_music}"/>
<action application="set" data="call_timeout=30"/>
<!-- <action application="set" data="sip_exclude_contact=${network_addr}"/> -->
<action application="set" data="hangup_after_bridge=true"/>
<!--<action application="set" data="continue_on_fail=NORMAL_TEMPORARY_FAILURE,USER_BUSY,NO_ANSWER,TIMEOUT,NO_ROUTE_DESTINATION"/> -->
<action application="set" data="continue_on_fail=true"/>
<action application="hash" data="insert/${domain_name}-call_return/${dialed_extension}/${caller_id_number}"/>
<action application="hash" data="insert/${domain_name}-last_dial_ext/${dialed_extension}/${uuid}"/>
<action application="set" data="called_party_callgroup=${user_data(${dialed_extension}@${domain_name} var callgroup)}"/>
<!--<action application="export" data="nolocal:sip_secure_media=${user_data(${dialed_extension}@${domain_name} var sip_secure_media)}"/>-->
<action application="hash" data="insert/${domain_name}-last_dial/${called_party_callgroup}/${uuid}"/>
<action application="bridge" data="user/${dialed_extension}@${domain_name},${followme}"/>
<action application="answer"/>
<action application="sleep" data="1000"/>
<action application="voicemail" data="default ${domain_name} ${dialed_extension}"/>
      </condition>
 </extension>

I use the wiki samples to make a follow me dial plan for extension 201. Here is the dial plan.

<extension name="201_followme">
  <condition field="destination_number" expression="201">
   <action application="set" data="hangup_after_bridge=true"/>
   <action application="set" data="continue_on_fail=true"/>
   <action application="set" data="ignore_early_media=true"/>
   <action application="set" data="call_timeout=10"/>
   <action application="bridge" data="sofia/$${domain}/201"/>
   <action application="set" data="call_timeout=13"/>
   <action application="bridge" data="sofia/gateway/voicepulse/14161235555" />
   <action application="answer"/>
   <action application="sleep" data="1000"/>
   <action application="voicemail" data="default $${domain} 201"/>
  </condition>
</extension>


Call to extension 201 , there are two dialplan matching the request. Either Local_Extension or follwme_201. Which order freeswtich select?

It will match whichever one comes first in the file. You could, for example, put this 201 extension above the Local_Extension. You could also put a custom chan var in the user directory for those who need the follow-me. Then you could have two conditions, both of which need to match:

<extension name="Local, follow me">
  <condition field="${followme}" expression="^yes$"/>
  <condition field="destination_number expression="^(20\d)$">
    <!-- followme stuff here -->
    ...
  </condition>
</extension>

<extension name="Local No follow me">
  <condition field="${followme}" expression="^$"/>
  <condition field="destination_number expression="^(20\d)$">
    <!-- normal local extension stuff here -->
    ...
  </condition>
</extension>

Then in the user setup in the directory add the followme variable only to those who need it. You can also add a variable for the followme phone number if you want. Inside the <variables> node just add whatever you want:

  <variable name="followme" value="yes"/>
  <variable name="followme_number" value="14161235555"/>
Or even
  <variable name="followme_dialstring" value="sofia/gateway/voicepulse/14161235555"/>

Then you could use ${followme_number} in your bridge like this:
  <action application="bridge" data="sofia/gateway/
voicepulse/${followme_number}" />
 
Or ${followme_dialstring} like this:
  <action application="bridge" data="${followme_dialstring}" />

Make sense? :)

Give it a try and report back your success/failure/questions/comments/etc.
-MC