Using the ESL connection object for call control
Sometimes, it is convenient (or even necessary) to control a call from a script. In such cases, you can use the ESL connection object to control a call from an ESL script. This recipe will demonstrate a simple script that will answer a call, play a prompt, accept some caller input, and then route the call based on that input. With these basic concepts demonstrated, you will be able to write custom scripts that meet your specific needs.
Getting ready
This recipe is an example of an "outbound" connection from the FreeSWITCH dialplan to an ESL script. As such, you should have read the Establishing an outbound event socket connection recipe earlier in this chapter. This recipe will require at least two terminal windows: one for fs_cli
and one for the script. Although the script presented here is written in Perl, the connection object applies to all ESL-enabled languages.
How to do it...
First, add a new extension to your dialplan by following these...