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_voice(self): t = Tropo() t.say("Roses are red, violets are blue.") t.say("Please vote for the startup that most disrupts you.") caller_id = models.caller_id_if_valid(self.call_id()) if models.caller_id_can_vote(caller_id): t.on(event="continue", next="/vote/menu") elif not caller_id: t.say("Oops, you need to have caller eye dee enabled to vote. Goodbye.") t.hangup() else: t.say("Oops, it looks like you have voted already. Goodbye.") t.hangup() return t.RenderJson()