Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from asterisk.manager import Manager
- user = "meowcat"
- password = "the_mix_is_good"
- ip = '127.0.0.1'
- def createManager():
- """Returns a logged in manager"""
- manager = Manager()
- manager.connect(ip)
- manager.login(user, password)
- return manager
- def isTalking(manager, channel):
- """Get the CallerID based on the
- channel the user is connected to
- """
- # Get all current sip channels
- status = manager.status()
- # Prep for fomating based on new line
- res = status.data.replace('\r'," ").strip()
- for caller_chan in res.split("\n"):
- try:
- if caller_chan:
- if caller_chan.strip().startswith('CallerIDNum:'):
- cid_num = caller_chan.split()[1]
- if channel.strip() == caller_chan.split()[1].strip():
- #print "Chan: %s cid_name: %s" % ( caller_chan, cid_num )
- except IndexError:
- pass
- def handleTalk(event,manager):
- """Event handler for MeetmeTalking
- event.
- """
- if event.headers['Status'] == 'on':
- print "%s is talking" % event.headers['Channel']
- isTalking(manager, event.headers['Channel'])
- elif event.headers['Status'] == 'off':
- print "%s is nolongertalking" % event.headers['Channel']
- else:
- pass
- def handleEvent(event,manager):
- print "Recived Event: %s" % event.name
- def main():
- manager = createManager()
- res = manager.status()
- print res.data
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement