panoramisk - AMI

An API to communicate with Asterisk’s AMI

Configure Asterisk

In /etc/asterisk/manager.conf, add:

[username]
secret=password
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.255
read = all
write = all

Launch:

$ rasterisk -x 'manager reload'

API

class panoramisk.Manager(**config)[source]

Main object:

>>> manager = Manager(
...    host='127.0.0.1',
...    port=5038,
...    ssl=False,
...    encoding='utf8')
close()[source]

Close the connection

connect()[source]

connect to the server

register_event(pattern, callback=None)[source]

register an event. See Message:

>>> def callback(manager, event):
...     print(manager, event)
>>> manager = Manager()
>>> manager.register_event('Meetme*', callback)
<function callback at 0x...>

You can also use the manager as a decorator:

>>> manager = Manager()
>>> @manager.register_event('Meetme*')
... def callback(manager, event):
...     print(manager, event)
send_action(action, as_list=False, **kwargs)[source]

Send an Action to the server:

Parameters:
  • action (Action or dict or Command) – an Action or dict with action name and parameters to send
  • as_list (boolean) – If True, the action Future will retrieve all responses
Returns:

a Future that will receive the response

Return type:

asyncio.Future

Example:

To retrieve answer in a coroutine:

manager = Manager()
resp = yield from manager.send_action({'Action': 'Status'})

With a callback:

manager = Manager()
future = manager.send_action({'Action': 'Status'})
future.add_done_callback(handle_status_response)

See https://wiki.asterisk.org/wiki/display/AST/AMI+Actions for more information on actions

send_agi_command(channel, command, as_list=False)[source]

Send a Command to the server:

Parameters:
  • channel (String) – Channel name where to launch command. Ex: ‘SIP/000000-00000a53’
  • command (String) – command to launch. Ex: ‘GET VARIABLE async_agi_server’
  • as_list (boolean) – If True, the action Future will retrieve all responses
Returns:

a Future that will receive the response

Return type:

asyncio.Future

Example:
manager = Manager()
resp = manager.send_agi_command('SIP/000000-00000a53',
                                'GET VARIABLE async_agi_server')

Return a response Message. See https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_AGI

send_command(command, as_list=False)[source]

Send a Command to the server:

manager = Manager()
resp = manager.send_command('http show status')

Return a response Message. See https://wiki.asterisk.org/wiki/display/AST/ManagerAction_Command