Javascript module

From Yate Documentation
Jump to: navigation, search

Embedded Javascript language support.

The Javascript module has support for programmatically routing a call step by step.
At each step a new decision can be made about where to route the call next.
You can also use it to build global scripts.

Contents

Configuration

[general]
; General settings for the Javascript module

; scripts_dir: string: The absolute or relative path used by default to load
;  scripts if no full path is specified
;scripts_dir=${sharedpath}/scripts

; include_dir: string: The absolute or relative path used when including other
;  files via #include or #require if no full path is specified
; If the file is not found in include_dir it will be searched in scripts_dir
;include_dir=${configpath}

; routing: string: Name of the file holding the routing instructions
; Example: routing=route.js
;routing=

; allow_abort: boolean: Allow messages on level DebugFail to cause an engine abort
; Never enable it in production!
;allow_abort=no

; allow_trace: boolean: Allow the scripts to specify a trace file
; Never enable it in production!
;allow_trace=no

; allow_link: boolean: Allow linking of Javascript code (jump resolving)
;allow_link=yes

; auto_extensions: boolean: Automatically load scripting extensions in new scripts
; This does not prevent script code from explicitly loading extensions
;auto_extensions=yes


[scripts]
; Add one entry in this section for each script that is to be loaded on Yate startup
; Each line has to be on the form:
;   name=script_file_name
; The name must be unique and it will identify the running script instance.
; The file name should hold either the absolute path and name or the path
;  and name relative to the scripts_dir in section [general]
; Examples:
;  faxes=fax_handler.js
;  callback=js_lib/callback.js

; The Eliza chat bot, enabled by default for your enjoyment in rmanager
eliza=eliza.js


[late_scripts]
; Add one entry in this section for each script that is to be loaded after Yate startup
; These scripts are loaded only after the engine and modules have initialized, immediately
;  after the dispatching of the "engine.start" message.
; The names must be unique and different from any in the [scripts] section.

Routing

The Javascript module has support for programmatically routing a call step by step.
At each step a new decision can be made about where to route the call next.

Configuration

To configure routing script you must list it in the javascript.conf file, in parameter: routing.

[general]
routing=route.js

Routing script

Note that you can have a single such routing script in [default] section. It is however possible to use #include to include other scripts and call functions.

The script file is loaded and parsed when the Javascript module is (re)loaded. In rmanager you can issue the reload javascript command.

You can find an example script here.

How it Works

When a call is coming, an inbound call leg is created.

The inbound call leg is associated with a new script instance.

Main code flow

The parameters in the call.route message are set in the message variable.

Then the main code flow(that is, outside any function) is executed.

The Javascript code can make decisions based on these parameters and can call methods of the Channel object to route the call to the desired destination.


See also

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers