Operating system: debian8.5_x64
FreeSWITCH version: 1.6.8
Python version: 2.7.9
Open Python Module
Installing the Python Lib Library
Install Python-dev
To edit the modules.conf, open the Python module:
Languages/mod_python
Compile and install:
Make Make Install
Open Python support in modules.conf.xml;
Start FreeSWITCH;
Test Script API Test
To add a test script:
File path:/usr/local/freeswitch/scripts/test1.py
File contents:
Import FreeSWITCH def Fsapi (Session,stream,env,args): stream.write ("hello") Freeswitch.consolelog ("info","test")
Console testing
[Email protected]>python Test1hello .- the- . at: .:09.069753[NOTICE] Mod_python.c:212invoking PY Module:test1 .- the- . at: .:09.069753[DEBUG] Mod_python.c:283Call python script .- the- . at: .:09.069753[INFO] Switch_cpp.CPP:1360Test .- the- . at: .:09.069753[DEBUG] Mod_python.c:286finished calling Python Script[email protected]>
App Test
File path:/usr/local/freeswitch/scripts/testcall.py
File contents:
Import FreeSWITCH def handler (session, args): session.answer () freeswitch.console_log ("info" ,"testcall") session.streamfile ("Local_ Stream://moh") freeswitch.msleep (+) Session.hangup ()
Add the following configuration to the DialPlan:
<extensionname= "python test script"> <conditionField= "Destination_number"expression= "^400123456$"> <ActionApplication= "Python"Data= "Testcall"/> </condition></extension>
Register the phone, dial No. 400123456 number to hear MoH sound, and see the FreeSWITCH console log.
This article GitHub address:
Https://github.com/mike-zhang/mikeBlogEssays/blob/master/2016/20160906_freeswitch embedded Python script . MD
Welcome to Supplement
FreeSWITCH Embedding Python scripts