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 upon that input. With these basic concepts demonstrated you will then be able to write custom scripts that meet your specific needs.
This recipe is an example of an "outbound" connection from the FreeSWITCH dialplan to an ESL script. As such, you should read Establishing an outbound socket connection 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.