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(run_forever=False, on_startup=None, on_shutdown=None)[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)
run_forever(on_startup, on_shutdown)[source]

Start loop forever

send_action(action, as_list=None, **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 will retrieve all responses
Returns:

an Action that will receive the response(s)

Return type:

panoramisk.actions.Action

Example:

To retrieve answer:

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

Or with an async for:

manager = Manager()
async for resp in  manager.send_action({'Action': 'Status'}):
    print(resp)

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 = await manager.send_command('http show status')

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