简体   繁体   中英

Python ARI playback status

I am using ARI code from here:

http://techvoiper.blogspot.com/2015/08/asterisk-ari-interfacing-using-python.html

Now, what I want to do is know the status of playback if the caller hangs up while the audio has not been completed?

While the playback starts, 'PlaybackStarted' event is registered, and on completion, 'PlaybackFinished' is registered. But when the caller hangs up while the audio has been playing, it still returns 'PlaybackFinished'.

In this case, I want the playback_status to be set into something like : playback_status = 'partial'.

How can I achieve this?

My ChannelHangupRequest gives me:

{u'timestamp': u'2017-01-27T10:04:17.447+0545', u'type': u'ChannelHangupRequest', u'channel': {u'accountcode': u'', u'name': u'SIP/3002-00000012', u'language': u'en', u'caller': {u'name': u'', u'number': u'3002'}, u'creationtime': u'2017-01-27T10:04:15.847+0545', u'state': u'Up', u'connected': {u'name': u'', u'number': u''}, u'dialplan': {u'priority': 2, u'exten': u'3001', u'context': u'default'}, u'id': u'1485490755.36'}, u'application': u'hello-world'}

You can find a sample of the API in the ari-py github repository

There you'll see that there is a ChannelHangupRequest event which has a cause integer attribute, you then can find the mapping definition here

The event should be catch using the client.on_channel_event("ChannelHangupRequest", <callback_function>) .

The callback_function will receive a channel object as first argument and an event dictionary as second. The event dictionary will have a type key corresponding to the event( ChannelHangupRequest ) and a cause key corresponding integer value(mapping of the cause).

This way you will be able to differentiate if the playback went through or if call was hang up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM