Skip to content

Instantly share code, notes, and snippets.

@marrold
Created July 24, 2021 01:15
Show Gist options
  • Save marrold/8c4cf1b7c89dc3935626f5ab85d4cd0f to your computer and use it in GitHub Desktop.
Save marrold/8c4cf1b7c89dc3935626f5ab85d4cd0f to your computer and use it in GitHub Desktop.
import time
from settings import login, connection
from asterisk.ami import AMIClient,AutoReconnect
def ami_disconnected(client, response):
print(f"The AMI has disconnected: {response}")
def event_notification(source, event):
print(f"Event: {event}")
client = AMIClient(**connection)
auto_reconnect = AutoReconnect(client, delay=10, on_disconnect=ami_disconnected)
future = client.login(**login)
if future.response.is_error():
raise Exception(str(future.response))
client.add_event_listener(event_notification)
try:
while True:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
client.logoff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment