def onUserReconnected( self, agi ): """Handle the user interaction after they've re-connected""" log.info( """Connection re-established with the user""" ) # XXX should handle unexpected failures in here... delta = self.stopTime - self.startTime minutes, seconds = divmod( delta, 60 ) seconds = int(seconds) hours, minutes = divmod( minutes, 60 ) duration = [] if hours: duration.append( '%s hour%s'%(hours,['','s'][hours!=1])) if minutes: duration.append( '%s second%s'%(minutes,['','s'][minutes!=1])) if seconds: duration.append( '%s second%s'%(seconds,['','s'][seconds!=1])) if not duration: duration = '0' else: duration = " ".join( duration ) seq = fastagi.InSequence( ) seq.append( agi.wait, 1 ) seq.append( agi.execute, "Festival", "Call to account %r took %s"%(self.account,duration) ) seq.append( agi.wait, 1 ) seq.append( agi.execute, "Festival", "Repeating, call to account %r took %s"%(self.account,duration) ) seq.append( agi.wait, 1 ) seq.append( agi.finish ) def logSuccess( ): log.debug( """Finished successfully!""" ) return defer.succeed( True ) seq.append( logSuccess ) seq.append( self.cleanUp, agi ) return seq()
def collectAudio(self): s = fastagi.InSequence() s.append(self.agi.streamFile, self.prompt) #s.append(self.agi.recordFile, self.filename, self.format, self.escapeDigits, silence = self.silence_duration) s.append(self.agi.execute, "Record", self.filename + ".wav") df = s() df.addCallback(self._startLoop) df.addErrback(noop)
def testFunction(agi): """Demonstrate simple use of the AGI interface with sequence of actions""" log.debug('testFunction') sequence = fastagi.InSequence() sequence.append(agi.sayDateTime, time.time()) sequence.append(agi.finish) def onFailure(reason): log.error("Failure: %s", reason.getTraceback()) agi.finish() return sequence().addErrback(onFailure)
def testFunction( agi ): """Print out known AGI variables""" log.debug( 'testFunction' ) print 'AGI Variables' pprint.pprint( agi.variables ) print 'Channel Variables' sequence = fastagi.InSequence() sequence.append( printVar, None, agi, envVars(agi) ) sequence.append( agi.finish ) def onFailure( reason ): log.error( "Failure: %s", reason.getTraceback()) agi.finish() return sequence().addErrback( onFailure )
def setupSurvey(self, agi): """AGI application to allow the user to set up the survey Screen 1: You have # questions. To listen to a question, press the number of the question. To record a new question, press pound. To finish setup, press star. """ seq = fastagi.InSequence() seq.append(agi.wait, 2) base = """You currently have %s question%s. To listen to a question press the number of the question. To record a new question, press pound. To finish survey setup, press star. """ % ( len(self.questions), ['', 's'][len(self.questions) == 1], ) if len(base) != 1: base += 's' base = " ".join(base.split()) seq.append(agi.execute, 'Festival', base) seq.append(agi.finish, ) return seq() seq.append(agi.streamFile, self.YOU_CURRENTLY_HAVE) seq.append(agi.sayNumber, len(self.questions)) if len(self.questions) == 1: seq.append(agi.streamFile, self.QUESTION_IN_YOUR_SURVEY) else: seq.append(agi.streamFile, self.QUESTIONS_IN_YOUR_SURVEY) seq.append(agi.streamFile, self.TO_LISTEN_TO_SURVEY_QUESTION) seq.append(agi.streamFile, self.TO_RECORD_A_NEW_SURVEY_QUESTION) seq.append(agi.streamFile, self.TO_FINISH_SURVEY_SETUP) seq.append(agi.finish, ) return seq()
def sayAccount(account_num): global agi sequence = fastagi.InSequence() sequence.append(agi.sayDigits, account_num) sequence.append(agi.finish) sequence().addBoth(onFailure)