def started(self): # database handling self.store = Store(self.path("db").child("storage").path) # the recordings path self.recordingsPath = self.path("db").child("recordings") if not self.recordingsPath.exists(): self.recordingsPath.createDirectory() # start AGI service f = fastagi.FastAGIFactory(self.connected) reactor.listenTCP( 4573, f, 50, '127.0.0.1') # start web server web.WebMixIn.started(self) f = manager.AMIFactory('admin', 'admin') def r(proto): self.admin = proto self.admin.registerEvent("ConferenceDTMF", self.conferenceDTMF) self.admin.registerEvent("ConferenceJoin", self.conferenceJoin) self.admin.registerEvent("ConferenceLeave", self.conferenceLeave) f.login("127.0.0.1", 5038).addCallback(r) self.sessions = {} self.recentlyDisconnected = {} t = task.LoopingCall(self.cleanRecentlyDisconnected) t.start(30)
def started(self): # database handling print self.path("db").path self.store = Store(self.path("db").child("storage").path) p = self.path("db").child("audio") if not p.exists(): p.createDirectory() # start AGI service f = fastagi.FastAGIFactory(self.connected) reactor.listenTCP(4573, f, 50, '127.0.0.1')
def getApp(name, cb): f= fastagi.FastAGIFactory(cb) #logging.basicConfig() log.setLevel(logging.DEBUG) fastagi.log.setLevel(logging.INFO) ivrservice = internet.TCPServer(4570,f,500,) application = service.Application(name) ivrservice.setServiceParent(application) return application
def __init__(self, instance_config, test_object): """Constructor for pluggable modules""" super(FastAGIModule, self).__init__() self.test_object = test_object self.port = instance_config.get('port', 4573) self.host = instance_config.get('host', '127.0.0.1') self.commands = instance_config.get('commands') if 'callback' in instance_config: self.callback_module = instance_config['callback']['module'] self.callback_method = instance_config['callback']['method'] fastagi_factory = fastagi.FastAGIFactory(self.fastagi_connect) reactor.listenTCP(self.port, fastagi_factory, test_object.reactor_timeout, self.host)
def create_fastagi_factory(self, count=1): """Create n instances of AGI. Each AGI instance will attempt to connect to a previously created instance of Asterisk. When a connection is complete, the fastagi_connect method will be called. Keyword arguments: count The number of instances of AGI to create """ for i in range(count): host = "127.0.0.%d" % (i + 1) self.fastagi.append(None) LOGGER.info("Creating FastAGI Factory %d" % (i + 1)) fastagi_factory = fastagi.FastAGIFactory(self.fastagi_connect) reactor.listenTCP(4573, fastagi_factory, self.reactor_timeout, host)
def started(self): # start AGI service f = fastagi.FastAGIFactory(self.connected) reactor.listenTCP(4573, f, 50, '127.0.0.1') self.sessions = set() # establish AMI admin connection f = manager.AMIFactory('admin', 'admin') def r(proto): self.admin = proto self.admin.registerEvent("ConferenceDTMF", log.msg) self.admin.registerEvent("MeetmeJoin", self.joined) self.admin.registerEvent("MeetmeLeave", self.left) self.admin.originate("SIP/5010", context="default", exten="503", priority="1") f.login("127.0.0.1", 5038).addCallback(r) self.chan2user = {}
"""Having introduced, actually read the time""" t = time.time() t2 = t + 20.0 df = agi.sayDateTime(t2, format='HM') def onDateFinished(resultLine): # now need to sleep until .5 seconds before the time df = agi.wait(t2 - .5 - time.time()) def onDoBeep(result): df = agi.streamFile('beep') return df return df.addCallback(onDoBeep) return df.addCallback(onDateFinished) return df.addCallback(onSaid).addErrback(onFailed).addCallbacks( cleanup, cleanup, ) if __name__ == "__main__": logging.basicConfig() fastagi.log.setLevel(logging.INFO) f = fastagi.FastAGIFactory(testFunction) reactor.listenTCP(4574, f, 50, '127.0.0.1') # only binding on local interface reactor.run()
def run(self, mainFunction): """Start up the AGI server with the given mainFunction""" f = fastagi.FastAGIFactory(mainFunction) return reactor.listenTCP(self.port, f, 50, self.interface)
#------------------------------------------------------------------------------# import settings from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.engine.url import URL from starpy import fastagi import agi #start logging logFile = logfile.LogFile.fromFullPath('/var/log/qmlremis/agi.log') log.addObserver(log.FileLogObserver(logFile).emit) #connect mysql engine = create_engine(URL(**settings.DATABASE)) Session = sessionmaker(bind=engine) session = Session() #connect websocket ws = OperClientFactory("ws://localhost:9000/Oper") connectWS(ws) ragi = agi.RemisAgi(session, ws.protocol()) factory = fastagi.FastAGIFactory(ragi.main) log.msg("start QmlRemis AGI Server") application = Application("QmlRemis AGI Server") srv = TCPServer(4573, factory) srv.setServiceParent(application)
) def onFinished(self, resultLine): """We said the number correctly, hang up on the user""" return self.agi.finish() def onNumberFailed(self, reason): """We were unable to read the number to the user""" log.warn( """Unable to read number to user on channel %r: %s""", self.agi.variables['agi_channel'], reason.getTraceback(), ) def onHangupFailure(self, reason): """Failed trying to hang up""" log.warn( """Unable to hang up channel %r: %s""", self.agi.variables['agi_channel'], reason.getTraceback(), ) if __name__ == "__main__": logging.basicConfig() fastagi.log.setLevel(logging.DEBUG) f = fastagi.FastAGIFactory(DialPlan()) reactor.listenTCP(4573, f, 50, '127.0.0.1') # only binding on local interface reactor.run()
cmd = 'rm -rf'+ ' '+ src os.system('cp -r '+ src + ' ' + dst ) os.system(cmd) self.agi.finish() def onFailure(self,error): print error def stop(self,result): print result self.agi.finish() def myivr(agi): Ivr(agi) def createDaemon(): if os.fork(): print "Daemon is started" sys.exit() if __name__=="__main__": createDaemon() f = fastagi.FastAGIFactory(myivr) reactor.listenTCP(4576,f,50,'') reactor.run()