Re: Embedded scripting proposal
Francisco Olarte (M <
folarte@...>
2010-10-04 16:02:30 GMT
On Mon, Oct 4, 2010 at 4:48 PM, Paul Chitescu <paulc@...> wrote:
> Hi people!
>
> We decided to introduce embedded scripting in Yate as a more powerful
> alternative to regexroute and external modules. We want to know your
> questions, opinions and improvement suggestions.
.....
I think scripting will be a great add-on for Yate, and as someone
pointed out a way to easily handle any message will be specially
useful ( I'm thinking in the kind of manipulations we are presently
truing to do with the regexroute mini-language could be done in two
lines of script, and having proper subroutines and variables will help
a lot ).
I understand the reasons to embed JavaScript, but I'll like to have
some language like python/perl with a more complete library. We are
presetnly developing some control modules for Yate using the external
module interface which need to read BerkeleyDb databases, perform
connections to some other servers speaking their protocol and I'm not
quite sure this can be done easily from JavaScript ( it cannot be done
from raw perl/python, but the modules to do it are there on CPAN and
similar, I'm not aware of anything similar for JavaScript ).
I think starting with JavaScript is right, but the interface to the
scripting engine should have some intermediate class or whatever
dessigned to make it easier to plug another scripting engine
implementation there.
Regards.
Francisco Olarte.
>
> The reason to introduce scripting in Yate is to be able to perform complex
> routing and IVR like functions without the drawback of running an external
> interpreter. A script running in an external interpreter is slower to start,
> has more overhead processing the messages and cannot use all functionality of
> Yate. While regexroute can do arbitrary message processing it cannot keep a
> context associated with each call and the language itself is very weak.
>
> We are choosing the Javascript language. It is simple enough to be used by
> beginners and basic functionality can be extended by experts. Moreover, there
> are several implementation libraries suitable for embedding.
>
> We plan for the script instances to sit besides the controlled call legs just
> like pbxassist does now. The script will be able to control the call flow and
> route the call to various destinations.
>
> A set of (Javascript) expressions will select which instruction block to
> instantiate for each incoming call, much like we do now in regexroute. Once an
> instance is created all further interaction will occur in that context.
>
>
> // optional, reserved for future compatibility
> language javascript
>
> // include another file containing Javascript code
> library "/path/to/library.js"
>
> // declare a function we are going to use
> function isAuth() {
> return username != "";
> }
>
> // send international calls of authenticated users directly to a gateway
> // in this case there is no instruction block, just a route
> called.match(/^00/) && isAuth() :: "sip/sip:" + called +
> " <at> gateway.xyz"
>
> // unauthenticated callers are not allowed to call outside
> called.length >= 4 && !isAuth() :: { error("noauth"); }
>
> // secondary dialer, also declare it as a function
> called == "1234" ::
> secondary_dialer()
> {
> answer();
> play("/path/to/prompt_file.au");
> }
>
> // alternative for the above
> function secondary_dialer2() { answer(); play("/path/to/prompt_file.au"); }
> called == "1235" :: { secondary_dialer2(); }
>
> // match and use a global variable shared between all instances
> getGlobal("chans_used") < 30 ::
> {
> setGlobal("chans_used",getGlobal("chans_used")+1);
> ...
> }
>
> // handling of later messages
> called == "123456" :: {
>
> function onAnswer() {
> ...
> }
>
> function onHangup() {
> ...
> }
>
> // this code is executed on entering the block
> ring("tone/ring");
> sleep(1);
> answer();
> ...
> }
>
> // include another scripting file with similar syntax
> include "/path/to/next_script_control";
>
>
> Paul
>