GithubHelp home page GithubHelp logo

dedayoa / python-ami Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ettoreleandrotognoli/python-ami

0.0 1.0 0.0 101 KB

Python AMI Client

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.82% Python 99.18%

python-ami's Introduction

Python AMI Client

image

image

image

image

Maintainability

Test Coverage

CodeFactor

A simple Python AMI client http://programandonoaquario.blogspot.com.br

See the code of conduct.

Install

Install asterisk-ami

pip install asterisk-ami

Install latest asterisk-ami

pip install git+https://github.com/ettoreleandrotognoli/python-ami

Usage

Connect

from asterisk.ami import AMIClient

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

Disconnect

client.logoff()

Send an action

from asterisk.ami import SimpleAction

action = SimpleAction(
    'Originate',
    Channel='SIP/2010',
    Exten='2010',
    Priority=1,
    Context='default',
    CallerID='python',
)
client.send_action(action)

Send an action with adapter

from asterisk.ami import AMIClientAdapter

adapter = AMIClientAdapter(client)
adapter.Originate(
    Channel='SIP/2010',
    Exten='2010',
    Priority=1,
    Context='default',
    CallerID='python',
)

Synchronous Response

#without adapter
future = client.send_action(action)
response = future.response

#with adapter
future = adapter.Originate(...)
response = future.response

Asynchronous Response

def callback_response(response):
    print(response)

#without adapter
future = client.send_action(action,callback=callback_response)

#with adapter
future = adapter.Originate(...,_callback=callback_response)

#you can use the future to wait the callback execute
reponse = future.response

Listen Events

def event_listener(event,**kwargs):
    print(event)

client.add_event_listener(event_listener)

Filter Events

With a custom class

from asterisk.ami import EventListener

class RegistryEventListener(EventListener):

    def on_Registry(event,**kwargs):
        print('Registry Event',event)

client.add_event_listener(RegistryEventListener())

class AllEventListener(EventListener):

    def on_event(event,**kwargs):
        print('Event',event)

client.add_event_listener(AllEventListener())

With black or white list

def event_listener(event,**kwargs):
    print(event)

client.add_event_listener(
    event_listener, white_list=['Registry','PeerStatus']
)

client.add_event_listener(
    event_listener, black_list=['VarSet']
)

Like a custom class

def event_listener(event,**kwargs):
    print(event)

client.add_event_listener(
    on_VarSet=event_listener,
    on_ExtensionStatus=event_listener
)

client.add_event_listener(
    on_event=event_listener
)

Filter Event Value

def event_listener(event,**kwargs):
    print('Ringing',event)


client.add_event_listener(
    event_listener,
    white_list='Newstate',
    ChannelStateDesc='Ringing',
    ConnectedLineNum='2004',
)

Filter with regex

import re

def event_listener(event,**kwargs):
    print(event)

client.add_event_listener(
    on_Newstate=event_listener,
    white_list=re.compile('.*'),
    ChannelStateDesc=re.compile('^Ring.*'),
)

python-ami's People

Contributors

ettoreleandrotognoli avatar sq9mev avatar psaavedra avatar spike77453 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.