Hope this helps,Start by trying to understand setInputCallback and go from there.I highly recommend that you read up in the wiki and in the new FreeSWITCH book about events. Also, the FreeSWITCH Cookbook has good information about events. (Full disclosure: I'm co-author of both of those books). Also, don't be afraid of checking out all the Lua examples. Lua is easy to read if you're familiar with any scripting language and you can borrow ideas from existing scripts.I don't think it's any more complicated than that.Again, I'm not a Python guy so if someone else could verify my logic/syntax that would be good. Under the elif you have a consoleLog function call. After that line you could put all your code for handling the voicemail. Keep in mind that avmd is non-block, i.e. you aren't forced to sleep while detecting the beep. You could be playing a message or whatnot. As soon as the avmd detects a beep it will send the event and the inputcallback will be called and in your case the elif block will get executed. In that block of code you could stop the playback of your sound file and then initiate a new playback. (I'm assuming that you want to play a message after the beep?) Something like this:I don't know Python but if it works like other languages then when an event comes in the input callback is called:The "what" tells you the type of input. In this case you test for what=="dtmf" (for when the user presses a dtmf key) and for what=="event" for when an event comes in. In your specific case you check for an event and to see if the variable avmd_detect is true. If so then you are assuming that this is the mod_avmd event that it's detected a beep. (This is not the optimal method because you can actually check the event headers to make sure it's the correct event. I'll leave that as a research project for you.)def input_callback(session, what, obj):if (what == "dtmf"):consoleLog("info", what + " from callback " + obj.digit + "\n")returnelif (what == "event" and session.getVariable('avmd_detect') == "TRUE"):consoleLog("info", "Voicemail Detected\n")
def input_callback(session, what, obj):if (what == "dtmf"):consoleLog("info", what + " from callback " + obj.digit + "\n")returnelif (what == "event" and session.getVariable('avmd_detect') == "TRUE"):session.execute("avmd", "stop")consoleLog("info", "Voicemail Detected\n")session.execute("speak", "flite|kal|'Hi this is '")return "TRUE"
def handler(session, args):session.answer()# session.setVariable("hangup_after_bridge", "false")callback = session.setInputCallback("input_callback")session.execute("avmd", "start")consoleLog("info", "AVMD start\n")session.execute("sleep", "18000") # this could be a playbackconsoleLog("info", "AVMD status %s\n" % session.getVariable('avmd_detect'))session.execute("avmd", "stop")consoleLog("info", "AVMD stop\n")session.setHangupHook(hangup_hook)session.hangup() #hangup the call
MCOn Fri, Jul 26, 2013 at 2:46 PM, raj singh <rajictdialer@gmail.com> wrote:
Can you please tell how callback works, my understanding is that it handles user input, not sure how it works when we are trying to catch voicemails?ThanksOn Fri, Jul 26, 2013 at 1:25 PM, Michael Collins <msc@freeswitch.org> wrote:I would do your "voicemail" stuff in the callback where you detect that the avmd detected true. I would also put the avmd_stop app in that code block.-MCOn Thu, Jul 25, 2013 at 7:33 PM, Raghu <srraghu45@gmail.com> wrote:Thanks for checking it Michael. I thought i was trying execute 'speak' when AVMD detects a beep as below, but may be i am missing something. Please review the code and let me know if i am missing anything:from freeswitch import *# WARNING: known bugs with hangup hooks, use with extreme cautiondef hangup_hook(session, what):%s!!\n\n" % what)returndef input_callback(session, what, obj):if (what == "dtmf"):consoleLog("info", what + " from callback " + obj.digit + "\n")returnelif (what == "event" and session.getVariable('avmd_detect') == "TRUE"):consoleLog("info", "Voicemail Detected\n")return "TRUE"def handler(session, args):session.answer()# session.setVariable("hangup_after_bridge", "false")callback = session.setInputCallback("input_callback")session.execute("avmd", "start")consoleLog("info", "AVMD start\n")session.execute("sleep", "18000")consoleLog("info", "AVMD status %s\n" % session.getVariable('avmd_detect'))if session.getVariable('avmd_detect'):consoleLog("info", "Beep Detected\n")session.execute("speak", "flite|kal|'Hi this is '")session.execute("avmd", "stop")session.execute("speak", "flite|kal|'Hi this is '")consoleLog("info","callback returned %s!!\n\n" % callback)session.execute("avmd", "stop")consoleLog("info", "AVMD stop\n")session.setHangupHook(hangup_hook)session.hangup() #hangup the callAppreciate it!--
Michael S Collins
Twitter: @mercutioviz
http://www.FreeSWITCH.org
http://www.ClueCon.com
http://www.OSTAG.org
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org
http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server
http://www.cudatel.com
Official FreeSWITCH Sites
http://www.freeswitch.org
http://wiki.freeswitch.org
http://www.cluecon.com
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org