Asterisk extension language

Posted by Scott Laird Mon, 10 Oct 2005 19:28:54 GMT

While I really like all of the things that Asterisk allows me to do with my phone system, I’m really not very fond of its configuration language. The language provided in Asterisk 1.0 is slightly better then sendmail.cf, but it’s still a lousy language. They made a few small improvements early in the Asterisk 1.2 development process that helped a bit, but I assumed that we’d have to wait for another year or two before someone broke down and wrote a decent language for Asterisk.

It looks like I may have been overly pessimestic. I discovered the Asterisk extension language on a list of new features for Asterisk 1.2 today. Somehow I’d missed this when it first went into Asterisk.

Here’s a chunk out of my old config file. It’s not perfect, but it’s what you get when you’re stuck dealing with line numbers:

[macro-diallocal]
  exten => s,1,AbsoluteTimeout(7200)
  exten => s,n,SetAMAFlags(default)
  exten => s,n(analog),Dial(${TRUNK}/${ARG1})
  exten => s,n,Congestion
  exten => s,analog+101,Macro(condsetcid)
  exten => s,n,SetCIDName(LAIRD SCOTT)
  exten => s,n,SetAMAFlags(billing)
  exten => s,n(nufone),Dial(${NUFONE}/1${ARG1})
  exten => s,n,Congestion
  exten => s,nufone+101,Busy

And here’s the equivalent using the new configuration language:

macro diallocal( number ) {
  AbsoluteTimeout(7200);
  SetAMAFlags(default);
  Dial(${TRUNK}/${number});
  if(${DIALSTATUS} = "CONGESTION" || ${DIALSTATUS} = "CHANUNAVAILABLE") {
    &condsetcid();
    SetCIDName("LAIRD SCOTT");
    SetAMAFlags(billing);
    Dial(${NUFONE}/1${number});
    switch(${DIALSTATUS}) {
      case BUSY:
        Busy;
      default:
        Congestion;
    }
  }
}

It’s still not ideal–${VAR} is ugly–but it’s vastly better then the old syntax. This plus a bit of Rails integration should give us a really nice phone environment. I’m rapidly approaching the “tear it down and rebuild it” point with my Asterisk system–there’s a lot of stuff that I’d like to add that just doesn’t fit in with my current configuration files–so I’ll have a set of articles on integrating Asterisk, AEL, and Rails in a few weeks.

Posted in  | Tags , , ,  | 6 comments

Comments

  1. JonR800 said 1 day later:

    This is not HUGELY important. I imagine the old stuff might still work. In the 1.2 UPGRADE.txt they list a few things in your AEL code as deprecated. IMHO, the new format is a lot more readable.

    The applications AbsoluteTimeout, DigitTimeout, and ResponseTimeout have been deprecated in favor of the function TIMEOUT(timeouttype):

    AbsoluteTimeout(300) Set(TIMEOUT(absolute)=300) DigitTimeout(15) Set(TIMEOUT(digit)=15) ResponseTimeout(15) Set(TIMEOUT(response)=15)

    The TIMEOUT() function can also return the currently set timeouts:

    Set(DTIMEOUT=${TIMEOUT(digit)})

    The applications SetCIDName, SetCIDNum, and SetRDNIS have been deprecated in favor of the CALLERID(datatype) function:

    SetCIDName(Joe Cool) Set(CALLERID(name)=Joe Cool) SetCIDNum(2025551212) Set(CALLERID(number)=2025551212) SetRDNIS(2024561414) Set(CALLERID(RDNIS)=2024561414)

  2. Hans Fugal said 8 days later:

    I have always struggled with the asterisk dialplan syntax - it’s about as far from ruby as you can get. I took a look at using AGI but walked away from that approach frustrated when I realized you can’t maintain control at some key points, such as when you do a Dial (which makes Dial(30); VoiceMail impossible to do).

    I also wrote an asterisk preprocessing language just for kicks, but that’s not a really good solution (although it could work pretty well with #execute)

    AEL is better but still a joke.

    I think what is really needed is some way similar to AGI but with complete control. I have been thinking about it since reading your post and I think I have an approach with promise: a new module (similar to the AEL module) that talks over a socket to a daemon. If the protocol is kept dead simple (and I see no reason why it shouldn’t be) it would be very simple to write your dialplans in straight ruby (or perl, PHP, C/C++, Java, C#, sh, lisp, assembly, etc.). Here’s a taste of what it could be like:

     require 'asterisk'
     # this is a from-the-hip mockup
     class DialLocal < Asterisk::Context
       def s
         absolute_timeout 7200
         ama_flags = :default
         ret = dial("#{trunk}/#{arg1}")
         switch ret
         when Asterisk::BUSY
           condsetcid
           cid_name = "LAIRD SCOTT"
           ama_flags = :billing
           busy if dial("#{nufone}/1#{arg1}").busy?
           congestion
         else 
           congestion
         end
     end
     DialLocal.new.listen
    
  3. Hans Fugal said 8 days later:

    heh, oops. You get the idea. If I knew what markup this was I might try again.

  4. Jay Batson said 8 days later:

    … stop wasting your time with Asterisk, and go download Pingtel’s open source IP PBX: SIPx. (See either http://www.pingtel.com for the for-fee “supported” version, or http://www.sipfoundry.com for the current open source.)

    All the config files are nicely-structured XML (or VoiceXML). It’s gaining a very nice community (many of which are disaffected Asterisk users…. :-)

    It’s not an all-in-one-box solution like Asterisk; it wants you to have an external IP/PSTN gateway. Pingtel – unlike Digium – is not out out sell you hardware.

    As the guy who oversaw the initial creation of this (too), I can vouch for the code being “well structured,” modern stuff that (in my admittedly biased opinion) will be hitting its stride when Asterisk hits its ceiling.

    Of course, I’m biased.

  5. anono said 4 months later:

    And if it doesn’t run on FreeBSD or OSX that’s a limitation.

  6. strider22 said 9 months later:

    Pingtel – unlike Digium – is not out out sell you hardware.

    So instead of hardware they sell software & support … that’s supposed to make me feel their motives are pure.

    See either http://www.pingtel.com for the for-fee “supported” version, or http://www.sipfoundry.com for the current open source.

    I feel like I’m only a replacement for their test department, making sure it works on a wide variety of hardware. For that I get a crippled version. See the differences. http://www.pingtel.com/page.php?id=133

Comments are disabled