Skip to content

Instantly share code, notes, and snippets.

@ettoreleandrotognoli
Created October 25, 2019 16:09
Show Gist options
  • Save ettoreleandrotognoli/1ca9b28cb72187504cd7d930db6a7a13 to your computer and use it in GitHub Desktop.
Save ettoreleandrotognoli/1ca9b28cb72187504cd7d930db6a7a13 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import time
from asterisk.ami import AMIClient
from asterisk.ami import EventListener
def event_notification(source, event):
os.system('notify-send "%s" "%s"' % (event.name, str(event)))
client = AMIClient(address="127.0.0.1",port=5038)
future = client.login(username="admin",secret="password")
if future.response.is_error():
raise Exception(str(future.response))
client.add_event_listener(EventListener(on_event=event_notification, white_list='Newstate', ChannelStateDesc='Ringing'))
try:
while True:
time.sleep(10)
except (KeyboardInterrupt, SystemExit):
client.logoff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment