Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from asterisk.ami import AMIClient
- from asterisk.ami import EventListener
- connection = {
- 'address': 'sip.*********.com',
- 'port': 5038
- }
- login = {
- 'username': 'admin',
- 'secret': '***********'
- }
- def event_notification(source, event):
- if event.name in ['AgentConnect']:
- # print(f'name: {event.name}')
- # print(f'event: {vars(event)}')
- print(f'event: {event.keys.get("CallerIDNum", "Nope")} -> {event.keys.get("ConnectedLineNum", "Nope")}')
- return
- client = AMIClient(**connection)
- future = client.login(**login)
- 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:
- print('Listener started')
- while True:
- time.sleep(10)
- except (KeyboardInterrupt, SystemExit):
- client.logoff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement