Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for full info:</p> <p>Now the obvious flaw with the setup you have is as follows: Dialplan() is inititated when initially passed to FastAGIFactory. From there on - you are always accessing the same instance of a class over and over agian. Now - whenever a new call comes in <code>Dialplan().__call__()</code> method is called and <code>Dialplan().agi</code> paramater gets overwritten by the last call. Looking at the sample you used I would suggest tryiing following approach and then taking it from there:</p> <pre><code>#! /usr/bin/env python """Read digits from the user in various ways...""" from twisted.internet import reactor, defer from starpy import fastagi, error import logging, time log = logging.getLogger( 'hellofastagi' ) class DialPlan( object ): """Stupid little application to report how many times it's been accessed""" def __init__( self,application, agi ): self.application = application self.agi = agi def start( self ): """Begin the dial-plan-like operations""" return self.agi.answer().addCallbacks( self.onAnswered, self.answerFailure ) def answerFailure( self, reason ): """Deal with a failure to answer""" log.warn( """Unable to answer channel %r: %s""", self.agi.variables['agi_channel'], reason.getTraceback(), ) self.agi.finish() def onAnswered( self, resultLine ): """We've managed to answer the channel, yay!""" return self.agi.wait( 2.0 ).addCallback( self.onWaited ) def onWaited( self, result ): """We've finished waiting, tell the user the number""" return self.agi.sayNumber( self.application.count, '*' ).addErrback( self.onNumberFailed, ).addCallbacks( self.onFinished, self.onFinished, ) 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(), ) class CallCounterApplication(object): def __init__( self ): self.count = 0 def __call__(self,agi): self.count = self.count+1 dp = Dialplan(self,agi) return dp.start() if __name__ == "__main__": logging.basicConfig() fastagi.log.setLevel( logging.DEBUG ) f = fastagi.FastAGIFactory(CallCounterApplication()) reactor.listenTCP(4573, f, 50, '10.0.0.167') # only binding on local interface reactor.run() </code></pre> <p>What I did here was created an application container which would create a new Dialplan() instance on every succesful call. </p> <p>EDIT: Mind you - as I had no asterisk box available, this was not tested, and may not run when copypasted 1:1. But the principle remains the same</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload