FreeSWITCH中文网,电话机器人开发网 ,微信订阅号:


Python ESL

tags:FreeSWITCH Python ESL 创建时间:2015-09-28 14:04:09


In the FreeSWITCH source directory change to libs/esl and run:

make pymod

make pymod-install

This should install the ESL module into your python site-packages folder. If for some reason you want to manually install it or keep it locally you still must run the make pymod command to compile it but then can copy the libs/esl/ and libs/esl/ to a folder of your choosing.

See the "Pre-requisites" section at the ESL page for the libraries needed.


The python module provides two classes: ESLconnection and ESLevent. They are documented generally (non-python specific) at the ESL page, in the "ESL Object" section.

You will want to first include the module:

import ESL

You can then establish a connection using:

con = ESL.ESLconnection("", "8021", "ClueCon")


\#!/usr/bin/env python

' - subscribe to all events and print them to stdout
import ESL

con = ESL.ESLconnection('localhost', '8021', 'ClueCon')

if con.connected:'plain', 'all')
    while 1:
        e = con.recvEvent()
        if e:
            print e.serialize()

\#!/usr/bin/env python

import SocketServer
import ESL

class ESLRequestHandler(SocketServer.BaseRequestHandler):
    def setup(self):
        print self.client_address, 'connected!'

        fd = self.request.fileno()
        print fd

        con = ESL.ESLconnection(fd)
        print 'Connected: ', con.connected()
        if con.connected():

            info = con.getInfo()

            uuid = info.getHeader("unique-id")
            print uuid
            con.execute("answer", "", uuid)
            con.execute("playback", "/ram/swimp.raw", uuid);

\# server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer((', 8040), ESLRequestHandler)

\#!/usr/bin/env python

' - execute a single command over ESL
from optparse import OptionParser
import sys

import ESL

def main(argv):
    parser = OptionParser()
    parser.add_option('-a', '--auth', dest='auth', default='ClueCon',
                      help='ESL password')
    parser.add_option('-s', '--server', dest='server', default='',
                      help='FreeSWITCH server IP address')
    parser.add_option('-p', '--port', dest='port', default='8021',
                      help='FreeSWITCH server event socket port')
    parser.add_option('-c', '--command', dest='command', default='status',
                      help='command to run, surround multi-word commands in ""s')

    (options, args) = parser.parse_args()

    con = ESL.ESLconnection(options.server, options.port, options.auth)

    if not con.connected():
        print 'Not Connected'

    # Run command
    e = con.api(options.command)
    if e:
        print e.getBody()

if __name__ == '__main__':

上海老李,QQ:1354608370,FreeSWITCH QQ群: