Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Executing a Ruby script from Asterisk (See related posts)

To run a Ruby script from Asterisk you need 2 things 1) an extension to run the script from 2) a Ruby script.

* Preparing the evironment *
1) create a script directory for Asterisk and ensure it has permission to run the scripts.

* Running the script *
1) Dial extension 3000
2) Listen to the voice say 'hello world'
3) Observe a new output.txt file has been created containing the message 'hello world!'

file: hello-world.rb
#!/usr/bin/ruby

#file : hello-world.rb

file = File.new('/etc/asterisk/ruby/output.txt','w')
file.puts 'hello world!'
file.close

file: extensions.rb
exten => 3000,1,Playback(hello-world)
exten => 3000,n,System(/etc/asterisk/ruby/./hello-world.rb)
exten => 3000,n,Hangup


file: output.txt
hello world!

You need to create an account or log in to post comments to this site.


Click here to browse all 6643 code snippets

Related Posts