README

Path: README
Last Update: Thu Mar 26 12:00:26 -0600 2009

radp - Ruby Asterisk Dial Plan

This program/library creates Asterisk dialplans from ruby code.

Requirements

  • ruby
  • rake (optional)

Installation

  rake install ||
  ruby setup.rb --help | less

Usage

  radp extensions.radp > extensions.conf
  asterisk -rx "extensions reload"

Example

  ## This is an example of a "macro"
  def mydial(*args)
    n = Dial(args)
    Congestion()
    @p = n+101
    Busy()
  end

  context :incoming do
    ext :s do
      n = Dial('SIP/sipura',20)
      Answer()
      Playback('chunky-bacon')
      Hangup()
      @p = n+101
      Busy()
    end
  end

  context :outgoing do
    %w{800 866 877 888}.each do |x|
      ext "_1#{x}NXXXXXX" do
        mydial('ZAP/1/${EXTEN}')
      end
    end
    ext('_NXXXXXX') { mydial('IAX2/NuFone/1505${EXTEN}') }
    ext('_1NXXNXXXXXX') { mydial('IAX2/NuFone/1505${EXTEN}') }
    ext '*' do VoiceMailMain() end
  end

  ## vim: filetype=ruby

Documentation

  See the RADP class.

Things you should be aware of

  • Asterisk dialplans are static, not dynamic. In other words, radp generates a static dialplan.
  • You can use any capitalization for Asterisk applications that Asterisk would accept, but if you begin an application with a capital letter and the application has no arguments, you must include the parentheses. e.g. Answer()
  • This is not syntactically correct:
      ext 's' { Answer(); Playback(tt-monkeys); Hangup() }
    

    You must either use do...end or parenthesize the arguments, as in:

      ext('s') { Answer(); Playback(tt-monkeys); Hangup() }
      ext 's' do Answer(); Playback(tt-monkeys); Hangup(); end
    
  • Also accepts input on stdin
  • No special processing of arguments is done. In particular, The following produce the same output:
      Dial('ZAP/1,30')
      Dial('ZAP/1', 30)
    
  • context, ext, etc. do not return objects (app returns the priority, though), so it‘s not possible to keep a reference to a context and add extensions to it after creating a new context.

Advanced Usage

You can also use radp as a library, in which case it behaves a little differently (because it is not wrapped in an instance_eval). Simply treat it as a library and it will work as expected.

GitHub

github.com/fugalh/radp

License

Copyright (C) 2005 Hans Fugal

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

[Validate]