Freeswitch - Hello World !!

So we learned how to install Freeswitch . Now lets start learning Freeswitch by a simple scenario . We will define a sip account in Freeswitch and write a simple dialplan so that when someone calls 100 he will hear hello world  . 

Freeswitch configuration files are in /usr/local/freeswitch/conf directory if you install it from source code . 

Step1 - Configuring sip account on Freeswitch And Registering the phone :

- Decide on new username and password and Open /usr/local/freeswitch/conf/directory/default folder . 
- Create 2000.xml file . 
- Put the following content in that :
<include>
        <user id="USERNAME">
                <params>
                        <param name="password" value="PASSWORD"/>
                </params>
        </user>
</include>
- Replace USERNAME and PASSWORD with yours .
This is the Basic sip account configuration but we need more . we should set the callerid name and number and ofcourse the context . We will use context in dialplan to define dial rules for this sip account .

<include>
        <user id="2000">
                <params>
                        <param name="password" value="abc123abc"/>
                </params>
                <variables>
                        <variable name="effective_caller_id_name" value="Omid Mohajerani"/>
                        <variable name="effective_caller_id_number" value="2000"/>
                        <variable name="user_context" value="special"/>
                </variables>
        </user>
</include>

- Reload in-memory Freeswitch configuration by running reloadxml command in Freeswitch console ( ./usr/local/freeswitch/bin/fs_cli

SIP account is ready . Now you can use a sip softphone to register the sip account .

Step 2 - Writing the dial plan 
Freeswitch dialplan files are in /usr/local/Freeswitch/conf/dialplan . you will see 3 default dialplan files , public.xml , default.xml and features.xml .It would be nice to take a look at them .

- Create special.xml file . This is the context name that we used in sip account definition . 
- Put the content as below :

<include>
  <context name="special">

<extension name="play_and_get_digits example">
    <condition field="destination_number" expression="^100$">
    <action application="play_and_get_digits" data="2 5 3 7000 # $${base_dir}/sounds/en/hello-world.wav /invalid.wav foobar \d+"/>
</condition>
</extension>
  </context>
</include>

- play_and_get_digits is an application to play a file and get DTMF . unlike the Asterisk that has three application ( playback , background and Read ) to have diffrent kind of playing files , Freeswitch has one and we can simulate the two other one with the play_and_get_digits application .

Freeswitch diaplan language is using Perl Regex that you should be familiar with . 

Comments