CallManager and Call

class obelus.ami.CallManager(ami)

A CallManager helps you originate calls and track the status of those calls using an AMI instance.

listen_for_incoming_calls(call_factory)

When an incoming call is detected, call the given call_factory. The call_factory will be called with the headers of the “Newchannel” event for the call, and must return a Call instance (possibly a subclass).

on_dial(event)

On a Dial event, update the call state.

on_hangup(event)

On a Hangup event, recognize that the channel is dead, and that the associated call has ended if it has no more channels.

on_local_bridge(event)

On a LocalBridge event, recognize that the two channels belongs to the same call.

on_new_channel(event)

On a Newchannel event, register the channel as a candidate incoming call.

on_new_state(event)

On a Newstate event, update the call state.

on_originate_response(event)

On an OriginateResponse event, mark the associated call failed or queued.

on_soft_hangup_request(event)

On a SoftHangupRequest event, update the call’s hangup cause if desirable.

on_var_set(event)

On a VarSet event, check if the variable is our tracking variable and associate the channel with a call by us.

originate(call, headers, variables=None)

Originate a call with the given headers (and, optionally, call-specific variables). call should be a Call instance.

queued_calls()

Return a set of all queued (outgoing) calls.

setup_event_handlers()

Setup the AMI event handlers required for call tracking. This is implicitly called on __init__().

setup_filters()

Setup server-side AMI event filters tailored for this CallManager, in order to limit resource consumption in the AMI protocol.

Calling this method is not required for proper functioning, but recommended if your Asterisk receives a lot of traffic and generates a lot of AMI events by default.

This method only relies on whitelisting, you can therefore setup more server-side filters if you are interested in other events.

tracked_calls()

Return a set of currently tracked calls (both incoming and originated). Note: some queued calls may be untracked yet.

class obelus.ami.Call

Base class for call objects tracked by the CallManager. It is recommended you subclass this class and override the various event handlers.

call_ended(cause, cause_desc)

Called when the call ends. cause is the numeric cause sent by Asterisk, cause_desc its textual description.

call_failed(exc)

Called when a call fails early. This either means the Originate command was rejected, or a failed OriginateResponse event was received just after the command was accepted.

call_queued()

Called when a call is queued (i.e. when the Originate command is accepted).

call_state_changed(state, state_desc)

Called when a call has its state changed. state is the new numeric state, state_desc its textual description.

dialing_finished(status)

Called when dialing the call has finished with the given status.

dialing_started()

Called when dialing the call has started.

unique_ids()

Get the alive channels related this call. Return a list of unique ids.