Created
November 24, 2016 15:20
-
-
Save cblaupanda/587a07b746f0e6427ceaf013576f29af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<extension name="493055573879 incoming"> | |
<condition field="destination_number" expression="^493055573879$"> | |
<action application="set" data="dnum=$1" inline="true"/> | |
<action application="answer"/> | |
<action application="info"/> | |
<action application="sleep" data="1000"/> | |
<action application="python" data="listener"/> | |
</condition> | |
</extension> | |
/usr/share/freeswitch/scripts/listener.py | |
# -*- coding: utf-8 -*- | |
import freeswitch | |
def handler(session, args): | |
""" | |
'handler' is the default function name for apps. | |
It can be overridden with <modname>::<function> | |
`session` is a session object | |
`args` is a string with all the args passed after the module name | |
""" | |
freeswitch.consoleLog('info', 'Answering call from Python.\n') | |
freeswitch.consoleLog('info', 'Arguments: %s\n' % args) | |
session.answer() | |
session.setHangupHook(hangup_hook) | |
session.setInputCallback(input_callback) | |
session.setVariable('InputCallback', 'input_callback') | |
session.execute("playback", session.getVariable("hold_music")) | |
def input_callback(session, what, obj, args=''): | |
""" | |
Must be explicitly set up with session.setInputCallback(input_callback). | |
`session` is a session object. | |
`what` is "dtmf" or "event". | |
`obj` is a dtmf object or an event object depending on the 'what' var. | |
`args` is populated if you pass extra args to session.setInputCallback(). | |
""" | |
freeswitch.consoleLog("info", "+++++ input_callback +++++") | |
if (what == "dtmf"): | |
freeswitch.consoleLog("info", "Received DTMF: {} --> {} ".format(what, obj.digit)) | |
else: | |
freeswitch.consoleLog("info", "Received DTMF: {} --> {} ".format(what, obj.serialize())) | |
return "pause" | |
def hangup_hook(session, what, args=''): | |
""" | |
Must be explicitly set up with session.setHangupHook(hangup_hook). | |
`session` is a session object. | |
`what` is "hangup" or "transfer". | |
`args` is populated if you pass extra args to session.setInputCallback(). | |
""" | |
freeswitch.consoleLog("info", "hangup hook for '%s'\n" % what) | |
def fsapi(session, stream, env, args): | |
""" | |
Handles API calls (from fs_cli, dialplan HTTP, etc.). | |
Default name is 'fsapi', but it can be overridden with <modname>::<function> | |
`session` is a session object when called from the dial plan or the | |
string "na" when not. | |
`stream` is a switch_stream. Anything written with stream.write() is | |
returned to the caller. | |
`env` is a switch_event. | |
`args` is a string with all the args passed after the module name. | |
""" | |
if args: | |
stream.write("fsapi called with no arguments.\n") | |
else: | |
stream.write("fsapi called with these arguments: %s\n" % args) | |
stream.write(env.serialize()) | |
CLI output: | |
2016-11-24 12:38:38.773171 [NOTICE] mod_python.c:212 Invoking py module: listener | |
2016-11-24 12:38:38.773171 [DEBUG] mod_python.c:283 Call python script | |
2016-11-24 12:38:38.773171 [INFO] switch_cpp.cpp:1360 Answering call from Python. | |
2016-11-24 12:38:38.773171 [INFO] switch_cpp.cpp:1360 Arguments: | |
2016-11-24 12:38:38.773171 [INFO] switch_cpp.cpp:1360 set InputCallback | |
2016-11-24 12:38:38.773171 [DEBUG] switch_cpp.cpp:746 CoreSession::setVariable('InputCallback', 'input_callback') | |
EXECUTE sofia/internal/03055621300@sipconnect.sipgate.de playback(local_stream://moh) | |
2016-11-24 12:38:38.773171 [DEBUG] mod_local_stream.c:866 Opening Stream [moh/8000] 8000hz | |
2016-11-24 12:38:38.773171 [DEBUG] switch_ivr_play_say.c:1467 Codec Activated L16@8000hz 1 channels 20ms | |
2016-11-24 12:38:44.233186 [DEBUG] switch_rtp.c:7186 RTP RECV DTMF 2:1600 | |
2016-11-24 12:38:44.233186 [INFO] switch_channel.c:515 RECV DTMF 2:1600 | |
2016-11-24 12:38:44.233186 [DEBUG] mod_dptools.c:2223 Digit 2 | |
2016-11-24 12:38:47.353165 [DEBUG] switch_rtp.c:7186 RTP RECV DTMF 5:1600 | |
2016-11-24 12:38:47.353165 [INFO] switch_channel.c:515 RECV DTMF 5:1600 | |
2016-11-24 12:38:47.353165 [DEBUG] mod_dptools.c:2223 Digit 5 | |
2016-11-24 12:38:49.033166 [DEBUG] switch_rtp.c:7186 RTP RECV DTMF 8:1600 | |
2016-11-24 12:38:49.033166 [INFO] switch_channel.c:515 RECV DTMF 8:1600 | |
2016-11-24 12:38:49.033166 [DEBUG] mod_dptools.c:2223 Digit 8 | |
2016-11-24 12:38:51.713164 [NOTICE] sofia.c:1011 Hangup sofia/internal/03055621300@sipconnect.sipgate.de [CS_EXECUTE] [NORMAL_CLEARING] | |
2016-11-24 12:38:51.713164 [DEBUG] switch_ivr_play_say.c:1910 done playing file local_stream://moh | |
2016-11-24 12:38:51.713164 [DEBUG] switch_core_session.c:2797 sofia/internal/03055621300@sipconnect.sipgate.de skip receive message [APPLICATION_EXEC_COMPLETE] (channel is hungup already) | |
2016-11-24 12:38:51.713164 [INFO] switch_cpp.cpp:1360 hangup hook for 'hangup' | |
2016-11-24 12:38:51.713164 [DEBUG] mod_python.c:286 Finished calling python script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment