Calling an External Script from the Dialplan

From Etel

Jump to: navigation, search

Contents

Calling an External Script from the Dialplan

Problem

You want to call an external script from the dialplan to process a call using a third party library and scripting language.

Solution

Adding these lines to your extension.conf in /etc/asterisk:

[oreilly]
exten => _X.,1,AGI(hello_world.php)

And this script to /var/lib/asterisk/agi-bin/:

 #!/usr/local/bin/php -q
 <?php
  set_time_limit(0);
  require('phpagi.php');

  $agi = new AGI();

  $agi->answer();

  // Play the tt-monkeys file from /var/lib/asterisk/sounds
  $agi->stream_file('tt-monkeys');

  $agi->hangup();
 ?>
 

Would result in this being executed by Asterisk and the audio 'tt-monkeys' being played from /var/lib/asterisk/sounds/:

-- Executing [123@oreilly:1] AGI("SIP/3000-01828e00", "hello_world.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/hello_world.php
-- Playing 'tt-monkeys' (escape_digits=) (sample_offset 0)
-- Spawn extension (oreilly, 123, 1) exited non-zero on 'SIP/3000-01828e00'

Discussion

Coming soon...

See Also:

Metadata

  • By: Jason Goecke
Personal tools