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.


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 a Dial event, update the call state.


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


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


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


On a Newstate event, update the call state.


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


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


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.


Return a set of all queued (outgoing) calls.


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


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.


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.


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.


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.


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


Called when dialing the call has started.


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