API components

ESL client API

class switchio.api.Client(host='127.0.0.1', port='8021', auth='ClueCon', call_tracking_header=None, listener=None, logger=None)

Interface for synchronous server control using the esl “inbound method” as described here: https://wiki.freeswitch.org/wiki/Mod_event_socket#Inbound

Provides a high level api for registering apps, originating calls, and managing an event listener and its event loop.

api(cmd, exc=True, timeout=None)

Invoke esl api command with error checking Returns an ESL.ESLEvent instance for event type “SOCKET_DATA”.

bgapi(cmd, listener=None, callback=None, client_id=None, sess_uuid=None, **jobkwargs)

Execute a non blocking api call and handle it to completion

cmd : string
command to execute
listener : EventListener instance
session listener which will handle bg job events for this cmd
callback : callable
Object to call once the listener collects the bj event result. By default the listener calls back the job instance with the response from the ‘BACKGROUND_JOB’ event’s body content plus any kwargs passed here.
cmd(cmd)

Return the string-body output from invoking a command

connect()

Connect this client

connected()

Check if connection is active

disconnect()

Disconnect the client’s underlying connection

hupall(group_id=None, timeout=5)

Hangup all calls associated with this client by iterating all managed call apps and hupall-ing with the apps callback id. If :var:`group_id` is provided look up the corresponding app an hang up calls for that specific app.

load_app(ns, on_value=None, header=None, prepend=False, funcargsmap=None, **prepost_kwargs)

Load annotated callbacks and from a namespace and add them to this client’s listener’s callback chain.

Parameters:ns – A namespace-like object containing functions marked with @callback (can be a module, class or instance).
Params str on_value:
 app group id key to be used for registering app callbacks with the EventListener. This value will be inserted in the originate command as an X-header and used to look up which app callbacks should be invoked for each received event.
originate(dest_url=None, uuid_func=<function uuid>, app_id=None, listener=None, bgapi_kwargs={}, rep_fields={}, **orig_kwargs)

Originate a call using FreeSWITCH ‘originate’ command. A non-blocking bgapi call is used by default.

see build_originate_cmd()

orig_kwargs: additional originate cmd builder kwargs forwarded to
build_originate_cmd() call

instance of Job a background job

set_orig_cmd(uuid_str=None, profile='external', gateway=None, app_name='park', app_arg_str='', dp_exten=None, dp_type='xml', dp_context='default', proxy=None, endpoint='sofia', timeout=60, caller_id='Mr_switchio', caller_id_num='1112223333', codec='PCMU', abs_codec='', xheaders=None, **kwargs)

Return a formatted originate command string conforming to the syntax dictated by mod_commands of the form:

originate <call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]

dest_url : str
call destination url with format <username_uri>@<domain>:<port>
profile : str
sofia profile (UA) name to use for making outbound call
dp_extension: str
destination dp extension where the originating session (a-leg) will processed just after the call is answered
originate command : string or callable
full cmd string if uuid_str is not None, else callable f(uuid_str) -> full cmd string
unload_app(on_value, ns=None)

Unload all callbacks associated with a particular app on_value id. If ns is provided unload only the callbacks from that particular subapp.

switchio.api.active_client(host, port='8021', auth='ClueCon', apps=None)

A context manager which delivers an active Client containing a started EventListener with applications loaded that were passed in the apps map

switchio.api.get_client(host, port='8021', auth='ClueCon', apps=None)

A context manager which delivers an active Client containing a started EventListener with applications loaded that were passed in the apps map

switchio.api.get_pool(contacts, **kwargs)

Construct and return a slave pool from a sequence of contact information.