def do_text(self): caller_id = models.caller_id_if_valid(self.call_id()) if models.caller_id_can_vote(caller_id): session_info = json.loads(web.data())['session'] msg = session_info['initialText'] m = re.match("^(v|V|vote|VOTE)\s+([0-9]{2})$", msg) if m: vote_code = m.groups()[1] candidate = models.find_candidate_by_code(vote_code) if candidate: models.record_vote(caller_id, candidate['id']) t = Tropo() t.message( "You have voted for %s as most disruptive startup. Thanks for voting! Tropo <3s you!" % candidate['name'], to=caller_id, channel='TEXT') return t.RenderJson() else: return self.do_help_text("Sorry, there's no candidate %s. " % vote_code) else: return self.do_help_text("Sorry, we didn't understand your text message. ") elif not caller_id: return self.do_help_text("You need to have caller ID enabled to vote.") else: t = Tropo() t.message("Oops, it looks like you have voted already.", to=caller_id, channel='TEXT') return t.RenderJson()
def do_response(self): answer = self.get_answer() candidate = models.find_candidate_by_code(answer) if not candidate: return self.do_bad_choice() else: t = Tropo() prompt = "You chose %s, is that correct? " % candidate['name'] choices = self.confirm_choices() t.ask(choices, say=prompt + self.confirm_prompt()) t.on(event="continue", next=self.confirm_url(candidate['id'])) return t.RenderJson()