class SupportAgent(Entity): ready = True sop = None currentIssue = None issues = property(lambda self: ( i for i in Issue.objects if not i.resolved and i.assignedTo == self)) online = property(lambda self: self.conversation.online) available = property( lambda self: self.online and self.ready and self.currentIssue is None and not self.conversation.askingQuestion) busy = property(lambda self: not self.available) teams = property(lambda self: (team for team in Team.objects if self in team.agents)) name = property(lambda self: self.conversation.buddyName) responsive = property(lambda self: self.conversation.responsive) def __init__(self, jid): self.jid = jid self.conversation = Conversation(jid) def __getstate__(self): return {'jid': self.jid, 'ready': self.ready} @staticmethod def construct(state): agent = SupportAgent(state['jid']) agent.ready = state['ready'] return agent def tell(self, message, **kwargs): self.conversation.say(message, **kwargs) def ask(self, question, answers, **kwargs): return self.conversation.ask(question, answers, **kwargs) def engage(self, issue): assert self.available self.currentIssue = issue issue.assignedTo = self issue.whenResolved(self.issueResolved) def issueResolved(self, issue): if issue != self.currentIssue: #got resolved by someone else return log("Agent %s resolved issue \"%s\" resolution=%s" % (self.name, issue.description, issue.resolution), type='issues') self.currentIssue = None self.sop = None if self.available and any(self.issues): self.engage(self.issues.next()) return issue
class SupportAgent(Entity): ready = True sop = None currentIssue = None issues = property(lambda self: (i for i in Issue.objects if not i.resolved and i.assignedTo == self)) online = property(lambda self: self.conversation.online) available = property(lambda self: self.online and self.ready and self.currentIssue is None and not self.conversation.askingQuestion) busy = property(lambda self: not self.available) teams = property(lambda self: (team for team in Team.objects if self in team.agents)) name = property(lambda self: self.conversation.buddyName) responsive = property(lambda self: self.conversation.responsive) def __init__(self, jid): self.jid = jid self.conversation = Conversation(jid) def __getstate__(self): return { 'jid' : self.jid, 'ready' : self.ready } @staticmethod def construct(state): agent = SupportAgent( state['jid'] ) agent.ready = state['ready'] return agent def tell(self, message, **kwargs): self.conversation.say(message, **kwargs) def ask(self, question, answers, **kwargs): return self.conversation.ask(question, answers, **kwargs) def engage(self, issue): assert self.available self.currentIssue = issue issue.assignedTo = self issue.whenResolved(self.issueResolved) def issueResolved(self, issue): if issue != self.currentIssue: #got resolved by someone else return log("Agent %s resolved issue \"%s\" resolution=%s" % (self.name, issue.description, issue.resolution), type='issues') self.currentIssue = None self.sop = None if self.available and any(self.issues): self.engage( self.issues.next() ) return issue
def auth_request(conversation): result = None try: if conversation.authorized: conversation.say("You are already authorized to use this droned.") raise AssertionError('Already authorized to use this droned') conversation.say("Ok, I will pass your request along to the environment administrator. I will let you know what they decide.") deputy = Conversation(jabber_config.DEPUTY) try: question = "%s has requested authorization, do you wish to <b>grant</b> or <b>deny</b> this request?" % conversation.buddy answers = ('grant','deny') d = deputy.ask(question, answers) wfd = defer.waitForDeferred(d) yield wfd answer = wfd.getResult() except AlreadyAskingQuestion: err = "Sorry, the environment administrator is busy dealing with something else right now. " err += "You should wait and try again later, or if it is urgent contact them directly. " err += "The environment administrator is %s" % jabber_config.DEPUTY conversation.say(err) raise AssertionError('Administrator is busy') if answer == 'grant': conversation.grantAuthorization() deputy.say("%s has been granted authorization." % conversation.buddy) else: err = "Your request for authorization has been denied. If you wish to discuss this further you " err += "should contact the environment administrator directly. " err += "The environment administrator is %s" % jabber_config.DEPUTY conversation.say(err) deputy.say("%s has been denied authorization." % conversation.buddy) except AssertionError: pass except: result = Failure() yield result