/usr/lib/python2.7/dist-packages/examples/connecttoivr.py is in python-starpy 1.0.1.0.git.20140806-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Example script to generate a call to connect a remote channel to an IVR"""
from starpy import manager
from twisted.internet import reactor
import sys, logging
def main( channel = 'sip/20035@aci.on.ca', connectTo=('outgoing','s','1') ):
f = manager.AMIFactory(sys.argv[1], sys.argv[2])
df = f.login()
def onLogin( protocol ):
"""On Login, attempt to originate the call"""
context, extension, priority = connectTo
df = protocol.originate(
channel,
context,extension,priority,
)
def onFinished( result ):
df = protocol.logoff()
def onLogoff( result ):
reactor.stop()
return df.addCallbacks( onLogoff, onLogoff )
def onFailure( reason ):
print reason.getTraceback()
return reason
df.addErrback( onFailure )
df.addCallbacks( onFinished, onFinished )
return df
def onFailure( reason ):
"""Unable to log in!"""
print reason.getTraceback()
reactor.stop()
df.addCallbacks( onLogin, onFailure )
return df
if __name__ == "__main__":
manager.log.setLevel( logging.DEBUG )
logging.basicConfig()
reactor.callWhenRunning( main )
reactor.run()
|