Mod perl Rosetta

From FreeSWITCH Wiki
Jump to: navigation, search

This page should help all of those using citats Asterisk::AGI Perl modules migrate to mod_perl.

Here is a simple example from the src how to originate a call and play a file.

# Example Perl script to originate. perlrun
freeswitch::console_log("info", "Perl in da house!!!\n");

$session = new freeswitch::Session("sofia/10.0.1.100/1002") ;
$session->execute("playback", "/sr8k.wav");
$session->hangup();

Here we have the AGI commands and their replacements, need to be checked below

$AGI->stream_file($filename, $digits)
$session->execute("playback", "/sr8k.wav");

$AGI->send_text($text)

$AGI->send_image($image)

$AGI->say_number($number, $digits) 

$AGI->say_digits($number, $digits) 

$AGI->answer() 

$AGI->get_data($filename, $timeout, $maxdigits) 
$session->execute("playAndGetDigits","1,1,1,1000,"*#",tempfile,"","")
     SWIG_croak("Usage: CoreSession_read(self,min_digits,max_digits,prompt_audio_file,timeout,valid_terminators);");

for example: my $pin = $session->read(3,6,'enterpin.wav',10,'#')

      SWIG_croak("Usage: CoreSession_playAndGetDigits(self,min_digits,max_digits,max_tries,timeout,terminators,audio_files,bad_input_audio_files,digits_regex);");

$AGI->set_callerid($number) 

$AGI->set_context($context) 

$AGI->set_extension($extension) 

$AGI->set_priority($priority) 

$AGI->hangup($channel) 

$AGI->exec($app, $options) 
      SWIG_croak("Usage: API_execute(self,command,data);");

$AGI->set_variable($variable, $value) 

$AGI->get_variable($variable) 

$AGI->verbose($message, $level) 

$AGI->database_get($family, $key) 

$AGI->database_put($family, $key, $value) 

$AGI->database_del($family, $key) 

$AGI->database_deltree($family, $key)

For the complete list of functions available see Mod perl functions and classes