Table of Contents
List of Tables
List of Examples
db_url
parameterdb_table
parameterdb_col_username
parameterdb_col_password
parameterdb_col_ip
parameterdb_col_port
parameterdb_col_events
parameterfs_subscribe
parameter
freeswitch_esl()
usagefreeswitch_scripting is a helper module that exposes full control over the FreeSWITCH ESL interface to the OpenSIPS script.
It allows the OpenSIPS script writer to subscribe to generic FreeSWITCH ESL events as well as to run arbitrary FreeSWITCH ESL commands and interpret their results. It makes use of the freeswitch module for the management of ESL connections and event subscriptions.
Credits for the initial idea and working code samples providing both ESL events and commands go to Giovanni Maruzzelli <gmaruzz@opentelecom.it>.
The following modules must be loaded together with this module:
freeswitch
(optional) an SQL DB module
An SQL database URL which the module will use in order to load a set of FreeSWITCH ESL sockets and their event subscriptions.
Default value is “NULL” (DB support disabled).
Example 1.1. Setting the db_url
parameter
... modparam("freeswitch_scripting", "db_url", "dbdriver://username:password@dbhost/dbname") ...
The SQL table name for this module.
Default value is “freeswitch”.
Example 1.2. Setting the db_table
parameter
... modparam("freeswitch_scripting", "db_table", "freeswitch_sockets") ...
The SQL column name for the "username" ESL connect information.
Default value is “username”.
Example 1.3. Setting the db_col_username
parameter
... modparam("freeswitch_scripting", "db_col_username", "user") ...
The SQL column name for the "password" ESL connect information.
Default value is “password”.
Example 1.4. Setting the db_col_password
parameter
... modparam("freeswitch_scripting", "db_col_password", "pass") ...
The SQL column name for the "ip" ESL connect information.
Default value is “ip”.
Example 1.5. Setting the db_col_ip
parameter
... modparam("freeswitch_scripting", "db_col_ip", "ip_addr") ...
The SQL column name for the "port" ESL connect information.
Default value is “port”.
Example 1.6. Setting the db_col_port
parameter
... modparam("freeswitch_scripting", "db_col_port", "tcp_port") ...
The SQL column name for the comma-separated, case-sensitive FreeSWITCH event names which OpenSIPS will subscribe to.
Default value is “events_csv”.
Example 1.7. Setting the db_col_events
parameter
... modparam("freeswitch_scripting", "db_col_events", "fs_events") ...
Add a FreeSWITCH ESL URL to which OpenSIPS will connect at startup. The URL syntax includes support for specifying a list of events to subscribe to and follows this pattern: [fs://][[username]:password@]host[:port][?event1[,event2]...]
This parameter can be set multiple times.
Example 1.8. Setting the fs_subscribe
parameter
... modparam("freeswitch_scripting", "fs_subscribe", ":ClueCon@10.0.0.10?CHANNEL_STATE") modparam("freeswitch_scripting", "fs_subscribe", ":ClueCon@10.0.0.11:8021?DTMF,BACKGROUND_JOB") ...
Run an arbitrary command on an arbitrary FreeSWITCH ESL socket. The socket need not necessarily be defined in the database or through fs_subscribe. However, if this is the case, then the "password" part of the URL becomes mandatory.
The current OpenSIPS worker will block until an answer from FreeSWITCH arrives. The timeout for this operation can be controlled via the esl_cmd_timeout parameter of the freeswitch connection manager module.
Meaning of the parameters is as follows:
command (string) - the ESL command string to execute.
freeswitch_url (string) - the ESL interface to connect to. The syntax is: [fs://][[username]:password@]host[:port][?event1[,event2]...]. The "?events" part of the URL will be silently discarded.
response_var (var, optional) - a variable which will hold the text result of the ESL command.
Return value
1 (success) - the ESL command executed successfully and any output variables were successfully written to. Note that this does not say anything about the nature of the ESL answer (it may well be a "-ERR" type of response)
-1 (failure) - internal error or the ESL command failed to execute
This function can be used from any route.
Example 1.9.
freeswitch_esl()
usage
... # ESL socket 10.0.0.10 is defined in the database (password "ClueCon") $var(rc) = freeswitch_esl("bgapi originate {origination_uuid=123456789}user/1010 9386\njob-uuid: foobar", "10.0.0.10", "$var(response)"); if ($var(rc) < 0) { xlog("failed to execute ESL command ($var(rc))\n"); return -1; } ... # ESL socket 10.0.0.10 is new, we must specify a password $var(rc) = freeswitch_esl("bgapi originate {origination_uuid=123456789}user/1010 9386\njob-uuid: foobar", ":ClueCon@10.0.0.10", $var(response)); if ($var(rc) < 0) { xlog("failed to execute ESL command ($var(rc))\n"); return -1; } ...
Ensures that the given FreeSWITCH ESL socket is subscribed to the given list of events. In case an event cannot be subscribed to, the freeswitch driver will periodically retry to subscribe to it until an fs_unsubscribe MI command for the respective event is issued.
Parameters:
freeswitch_url - the ESL interface to connect to. The syntax is: [fs://][[username]:password@]host[:port][?event1[,event2]...]. The "?events" part of the URL will be silently discarded.
event - the name of the event to subscribe to
... - (other events)
Ensures that the given FreeSWITCH ESL socket is unsubscribed from the given list of events.
Parameters:
freeswitch_url - the ESL interface to search for. The syntax is: [fs://][[username]:password@]host[:port][?event1[,event2]...]. The "?events" part of the URL will be silently discarded.
event - the name of the event to unsubscribe from
... - (other events)
Displays the current set of FreeSWITCH ESL sockets and the list of events that the module is subscribed to for each socket.
Replaces the current set* of FreeSWITCH ESL sockets along with their respective events with the current data (ESL sockets and their events) found in the "freeswitch" table.
* this includes any sockets/events provisioned through fs_subscribe, MI fs_subscribe commands or previous DB data set.
This event is raised when OpenSIPS receives an ESL event notification from a socket that the "freeswitch_scripting" module is subscribed to.
Parameters:
name - the name of the event
sender - the FreeSWITCH sender IP address
body - the full JSON-encoded body of the event, as sent by FreeSWITCH. Use the json module ($json variable) to easily interpret it.
Table 2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
Name | DevScore | Commits | Lines ++ | Lines -- | |
---|---|---|---|---|---|
1. | Liviu Chircu (@liviuchircu) | 46 | 25 | 1925 | 276 |
2. | Vlad Patrascu (@rvlad-patrascu) | 8 | 3 | 137 | 124 |
3. | Razvan Crainea (@razvancrainea) | 5 | 3 | 3 | 1 |
4. | Bogdan-Andrei Iancu (@bogdan-iancu) | 4 | 2 | 4 | 2 |
5. | Maksym Sobolyev (@sobomax) | 3 | 1 | 4 | 4 |
6. | Peter Lemenkov (@lemenkov) | 3 | 1 | 1 | 1 |
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits. Regarding imported patches/code, we do our best to count the work on behalf of the proper owner, as per the "fix_authors" and "mod_renames" arrays in opensips/doc/build-contrib.sh. If you identify any patches/commits which do not get properly attributed to you, please submit a pull request which extends "fix_authors" and/or "mod_renames".
(3) ignoring whitespace edits, renamed files and auto-generated files
Table 2.2. Most recently active contributors(1) to this module
Name | Commit Activity | |
---|---|---|
1. | Maksym Sobolyev (@sobomax) | Feb 2023 - Feb 2023 |
2. | Liviu Chircu (@liviuchircu) | Dec 2017 - Jan 2023 |
3. | Bogdan-Andrei Iancu (@bogdan-iancu) | Apr 2019 - Mar 2020 |
4. | Razvan Crainea (@razvancrainea) | May 2019 - Sep 2019 |
5. | Vlad Patrascu (@rvlad-patrascu) | Jan 2019 - Apr 2019 |
6. | Peter Lemenkov (@lemenkov) | Jun 2018 - Jun 2018 |
(1) including any documentation-related commits, excluding merge commits
Last edited by: Liviu Chircu (@liviuchircu), Vlad Patrascu (@rvlad-patrascu), Peter Lemenkov (@lemenkov).
Documentation Copyrights:
Copyright © 2017 www.opensips-solutions.com