Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] mod_python post-processing after hangup


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
joes.mailing.lists at ...
Guest





PostPosted: Thu Sep 11, 2008 12:27 am    Post subject: [Freeswitch-users] mod_python post-processing after hangup Reply with quote

Hi,
I'd like to run some process after a hangup, in the background.

I'm using mod_python and would like to run something after a call
ends. In the
snippet below I'd like the call to hangup at 'session.hangup(1)' then the
consoleLog to print the 'Testing' message 15 seconds later.

At present, if I hangup my call, it works, however if I stay on the line
the call doesn't hangup until the call to sleep comes back.

How can accomplish this functionality without using
mod_event_socket, is there a way?
Should I stick this in the hangup_hook? Will the hangup_hook
maintain state for a
database call?

Cheers,
Joe
-----------------------------
-----------------------------
import os
from freeswitch import *
import time
def hangup_hook(session, what):
consoleLog("info","hangup hook for %s!!\n\n" % what)
return
def input_callback(session, what, obj):
if (what == "dtmf"):
consoleLog("info", what + " " + obj.digit + "\n")
else:
consoleLog("info", what + " " + obj.serialize() + "\n")
return "pause"
def handler(session, args):
session.answer()
session.setHangupHook(hangup_hook)
session.setInputCallback(input_callback)
session.streamFile(session.getVariable("hold_music"))
session.hangup(1)
time.sleep(15)
consoleLog("info", "Testing.")
-----------------------------
-----------------------------

_______________________________________________
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
Back to top
mcollins at fcnetwork.com
Guest





PostPosted: Thu Sep 11, 2008 12:51 am    Post subject: [Freeswitch-users] mod_python post-processing after hangup Reply with quote

IIRC, Anthony mentioned an elegant way of handling this not too long
ago, although it was with a different language. The gist of it was this:

While (session.is.active) {
Do stuff
}
Do stuff after hangup

Obviously you'll need to use Python-ish syntax but you get the idea.

Alternatively you can research using the api_hangup_hook channel
variable and see if possibly this will let you do what you wish to do:
http://wiki.freeswitch.org/wiki/Channel_Variables#api_hangup_hook

in any event, please report back what you tried and if you get it to
work please add it to the more samples section of the mod_python wiki
page since that needs a little love from the Pythoners out there.

-MC


Quote:
-----Original Message-----
From: freeswitch-users-bounces@lists.freeswitch.org
[mailto:freeswitch-
Quote:
users-bounces@lists.freeswitch.org] On Behalf Of Novak Joe
Sent: Wednesday, September 10, 2008 10:26 PM
To: freeswitch-users@lists.freeswitch.org
Subject: [Freeswitch-users] mod_python post-processing after hangup

Hi,
I'd like to run some process after a hangup, in the background.

I'm using mod_python and would like to run something after a call
ends. In the
snippet below I'd like the call to hangup at 'session.hangup(1)'
then
Quote:
the
consoleLog to print the 'Testing' message 15 seconds later.

At present, if I hangup my call, it works, however if I stay on the
line
Quote:
the call doesn't hangup until the call to sleep comes back.

How can accomplish this functionality without using
mod_event_socket, is there a way?
Should I stick this in the hangup_hook? Will the hangup_hook
maintain state for a
database call?

Cheers,
Joe
-----------------------------
-----------------------------
import os
from freeswitch import *
import time
def hangup_hook(session, what):
consoleLog("info","hangup hook for %s!!\n\n" % what)
return
def input_callback(session, what, obj):
if (what == "dtmf"):
consoleLog("info", what + " " + obj.digit + "\n")
else:
consoleLog("info", what + " " + obj.serialize() + "\n")

return "pause"
def handler(session, args):
session.answer()
session.setHangupHook(hangup_hook)
session.setInputCallback(input_callback)
session.streamFile(session.getVariable("hold_music"))
session.hangup(1)
time.sleep(15)
consoleLog("info", "Testing.")
-----------------------------
-----------------------------

_______________________________________________
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
Quote:
http://www.freeswitch.org

_______________________________________________
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
Back to top
joes.mailing.lists at ...
Guest





PostPosted: Fri Sep 12, 2008 10:48 pm    Post subject: [Freeswitch-users] mod_python post-processing after hangup Reply with quote

Hi,

I received loads of useful hints on IRC yesterday regarding this
problem, and as a result was able to come up with a decent solution
which just involves using the API and 'runtime' functions to run my
post-processing job in a thread after hangup. I don't think it is
possible to pass objects via this method, but what I've worked out is
sufficient for my needs.

I also updated the wiki to include this example in hopes of saving
the good souls at IRC from having to repeat this again.
http://wiki.freeswitch.org/wiki/Mod_python#Run_something_in_a_thread_using_API

I'd also appreciate it if someone could take a look at the wiki and
confirm that the example I've described is appropriate.

If possible, I'd also like to add something about usage of the API
in general. I spent a good amount of time searching about on my own,
but still ended up asking some pretty silly questions in this vein on
IRC.
I'm still a bit shaky regarding what is what, as the word API
appears in many different places throughout the wiki but appears to
refer to several different APIs. The mod_python API wiki entry refers
to the Lua entry, and the Lua entry simply provides an example of how
to instantiate a new API object, which is then followed by a lengthy
section titled API:
http://wiki.freeswitch.org/wiki/Mod_lua#API
which doesn't mention the executeString method anywhere except in
the context of stream:write.

The one I've actually been interested - I think! - is this guy,
http://www.freeswitch.org/docs/class_a_p_i.html

If I can get confirmation/further_explanation of this, I'll be happy
to update the mod_python wiki accordingly, and hopefully stave off
this particular variety of confusion in future!

Cheers,
Joe

Quote:
IIRC, Anthony mentioned an elegant way of handling this not too long
ago, although it was with a different language. The gist of it was this:

While (session.is.active) {
Do stuff
}
Do stuff after hangup

Obviously you'll need to use Python-ish syntax but you get the idea.

Alternatively you can research using the api_hangup_hook channel
variable and see if possibly this will let you do what you wish to do:
http://wiki.freeswitch.org/wiki/Channel_Variables#api_hangup_hook

in any event, please report back what you tried and if you get it to
work please add it to the more samples section of the mod_python wiki
page since that needs a little love from the Pythoners out there.

_______________________________________________
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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services