[Freeswitch-users] Need help using api_hangup_hook and session_in_hangup_hook
Herman Griffin
herman.griffin at gmail.com
Mon Jan 9 06:05:43 MSK 2012
To those that are interested,
I figured out a solution to this problem through experimentation. I
don't know if this is the correct way nor do I know the drawback when
compared to pyrun. However, this does provide a Freeswitch Session
object to my Python code.
Instead of using:
<action application="set" data="session_in_hangup_hook=true"/>
<action application="set" data="api_hangup_hook=pyrun emergency.hangup"/>
I used:
<action application="set" data="session_in_hangup_hook=true"/>
<action application="set" data="api_hangup_hook=python emergency.hangup"/>
The python module looks like this (emergency.hangup). You need a
function named fsapi(session,stream,event,args):
def fsapi(session,stream,event,args):
pass:
Herman Griffin
www.hermangriffin.com
On Sat, Jan 7, 2012 at 9:28 AM, Herman Griffin <herman.griffin at gmail.com> wrote:
> Hello,
>
> I'm using the api_hangup_hook and session_in_hangup variables with a
> pyrun. How do I access the session object from inside the python
> module?
>
> ---------------------------------
> Here are some logs :
>
> Dialplan: sofia/external/3105795721 at 72.37.252.18 Absolute Condition [emergency]
> Dialplan: sofia/external/3105795721 at 72.37.252.18 Action
> set(session_in_hangup_hook=true)
> Dialplan: sofia/external/3105795721 at 72.37.252.18 Action
> set(api_hangup_hook=pyrun emergency.hangup)
> Dialplan: sofia/external/3105795721 at 72.37.252.18 Absolute Condition [emergency]
> .
> .
> 2012-01-07 09:21:57.693488 [DEBUG] mod_python.c:281 Call python script
> 2012-01-07 09:21:57.693488 [DEBUG] mod_python.c:284 Finished calling
> python script
> 2012-01-07 09:21:57.693488 [ERR] mod_python.c:293 Error calling python script
> 2012-01-07 09:21:57.693488 [ERR] mod_python.c:164 Python Error by
> calling script "emergency.hangup": <type 'exceptions.NameError'>
> Message: global name 'session' is not defined
> Exception: None
>
> Traceback (most recent call last)
> File: "/usr/local/freeswitch/scripts/python/emergency/hangup.py",
> line 34, in runtime
>
>
>
> ----------------------------------------------------------
> Here is the simple script
>
> python module emergency.hangup:
>
> from freeswitch import *
>
> def runtime(arg):
> consoleLog("info", print(dir(session)))
>
>
>
> Thanks,
> Herman
Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users
mailing list