py-asterisk
py-asterisk copied to clipboard
subscribe to end of a call
Hi, I'm trying to use your API to trigger some action when a call is finish, like merge the monitored up/down called audio. I'have successfully implemented the callback on the NewState -> Up for incoming call but I can't make it work for end of call. Can you help me or provide me a example please ? I tried with subscribing to event like Leave, hangup, parkedcall... thanks a lot.
Hello. This code is very ugly, but it works for me.
def main():
def hangup_handler(ami, event):
dialstatus = event['DialStatus']
if dialstatus in ('BUSY', ):
channel = event['Channel']
channel.Hangup()
return
logger.debug('O__0 main function was started ;-)')
while True:
try:
ami_listener = get_ami()
ami_listener.events.subscribe('DialEnd', hangup_handler)
break
except Exception:
logger.error(traceback.format_exc())
sleep(5)
while True:
try:
ami_listener.serve_forever()
except Exception:
logger.error(traceback.format_exc())
ami_listener._connect()
sleep(5)
if __name__ == '__main__':
main()
I think you need to handle an action 'Hangup'
thanks for your snippet. Yes you are right, it's working with the Hangup event. Thanks a lot.