domingo, 24 de marzo de 2019

python AMI event filter

#!/usr/bin/python
import os
import time
from settings import login, connection

from asterisk.ami import AMIClient

client = AMIClient(address='127.0.0.1',port=5038)
client.login(username='admin',secret='2256')


def event_listener(event,**kwargs):

       #print(vars(event))  ## print all info
    print(event[u'Channel'])  ##print only the channel name key
client.add_event_listener(
    event_listener,
    white_list='Newstate',
    ChannelStateDesc='Ringing'
)


client = AMIClient(**connection)
future = client.login(**login)
if future.response.is_error():
    raise Exception(str(future.response))


try:
    while True:
        time.sleep(10)
except (KeyboardInterrupt, SystemExit):
    client.logoff()

https://github.com/ettoreleandrotognoli/python-ami/blob/master/README.rst
https://pypi.org/project/asterisk-ami/

Python Socket

https://realpython.com/python-sockets/