Dynamic Language Support

Coordinator
Mar 27, 2014 at 11:47 AM
I've created a fork today with a new feature in called DynamicMappingStrategy. This new strategy allows you to use dynamic code for AGI Scripts and currently supports IronPython although other dynamic languages could also be added such as IronRuby and CSScript.

It's very easy to implement the FastAGI server using this new strategy, however the style of the AGI Script is slightly different as you'll see below.

The following code sets up a new DynamicMappingStrategy, and passes in a method which will be called to get the source of the script, by name. The second param is the script engine to be used, however this currently defaults to IronPython. I may chance this so per script engines can be selected.
static void Main(string[] args)
{
    AsteriskFastAGI agi = new AsteriskFastAGI();
    agi.MappingStrategy = new DynamicMappingStrategy(GetScriptByName, "");

    agi.Start();
}

public static string GetScriptByName(string scriptName) 
{
    return @"
def TestAGI():
    agi.Answer()
    agi.StreamFile(""demo-congrats"")
    agi.Hangup()

TestAGI()
";
}
The AGI script is also different. You'll notice that to call methods such as Answer() you need to access them via the 'agi' scope variable.

There are:
  • 'agi' - used to access AGI Methods
  • 'req' - used to access the request object
  • 'chan' - used to access the channel object
This is an early preview, but didn't take long to put together (about an hour).

You can find the fork here: dynamic-fork
Please review, test and let me know your thoughts.