[Freeswitch-users] Hangup_hook is not getting called in mod_python script

Deepika Yadav deepikay at iiitd.ac.in
Thu Sep 14 18:50:12 UTC 2017


Since it is a callback mechanism. Before passing to the 4449 extension, the
user simply dials a fixed mobile number, the extension '1234' passes it to
python script incoming_call_handler.py as follows:

*1234 extension in public domain*

<extension name="public_did">
    <condition field="destination_number" expression="^(1234)$">
       <action application="python" data="python.incoming_call_handler"/>
    </condition>
  </extension>

After the* incoming_call_handler.py* hangs it up and initiate a thread to
callback

def handler(session, args):
    callerid =  session.getVariable('caller_id_number')
    number  = (callerid[len(callerid)-10:])
    freeswitch.consoleLog('INFO','Called by %s\n' % number )
    session.hangup()
    new_api_obj = API()
    new_api_obj.executeString("pyrun python.callback " + callerid)


*Callback.py:*
It originates the call by transferring to extension 4449

def runtime(arg1):

    phone_number = arg1[len(arg1)-10:]
    new_api_obj = API()
    command_string = "originate sofia/gateway/MySIP/91" + phone_number + "
4449"
    result = new_api_obj.executeString("reloadxml")
    return_val = new_api_obj.executeString(command_string)

*4449*
4449 calls Sangoshthi_IVR_handler to play IVR menu on call answer

<extension name="record_topic">
<condition field="destination_number" expression="^4449">
<action application="set" data="execute_on_answer=python
*python.sangoshthi_IVR_handler/>*
<action application="sleep" data="30000"/>
</condition>
</extension>

Yes, the python script is running successfully the only thing is when
caller drops the call the hang u callback registered using hangup_hook does
not called.

Regards,
Deepika





On Thu, Sep 14, 2017 at 9:16 PM, Michael Jerris <mike at jerris.com> wrote:

>
> On Sep 14, 2017, at 6:01 AM, Deepika Yadav <deepikay at iiitd.ac.in> wrote:
>
> Hi,
>
> I have implemented a functionality where when a person with his mobile
> phone number calls a specific number (that of SIM inserted in our GOIP
> hardware), the incoming is hanged and that person is called back.
>
> After the IVR menu starts playing and if in between caller hangs up,
> hangup_event is not detected and the registered hangup_hook does not get
> called.
>
> Code is as follows;
>
> *XML file that starts python script when the person answers the cal*l:
>
> <extension name="record_topic">
>         <condition field="destination_number" expression="^4449">
>         <action application="set" data="execute_on_answer=python
> *python.sangoshthi_IVR_handler*"/>
>
>          <action application="sleep" data="30000"/>
>         </condition>
> </extension>
>
>
> This part is really strange.  If you want to execute that python script
> when the call answers after originating to the endpoint, just make the
> python the only thing in dial plan, and use ignore_early_media on the
> originate.  It won’t hit the dial plan until answer.  As for the rest of
> your question, it seems like you are saying you don’t get the hanguphook
> when the python script isn’t running?
>
> *Python Script handler:*
>
> def handler(session, args):
>
>     session.setHangupHook(hangup_hook)
>     session.setInputCallback(input_callback)
>
>     print('session object value is ', str(session))
>
>     callerid =  session.getVariable('caller_id_number')
>     call_uuid = session.getVariable('uuid')
>
>     phone_number = callerid[len(callerid)-10:]
>
>      initial_greeting(session, phone_number, call_uuid)
>
>
> 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().
>
>     """
>     print('PERSON HANGED UPPPPP...........')
>     freeswitch.consoleLog("INFO", "hangup hook for '%s'\n" % what)
>
> --
> Regards,
> Deepika
> https://deepikay.wixsite.com/deepika
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>



-- 
Regards,
Deepika
https://deepikay.wixsite.com/deepika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20170915/f644dc24/attachment.html>


More information about the FreeSWITCH-users mailing list